#ifndef CACHE_TEST_COMMON_H
#define CACHE_TEST_COMMON_H
-#include "common/Mutex.h"
-#include "common/Cond.h"
+#include <pthread.h>
class WaitEvent {
public:
// vim: ts=8 sw=2 smarttab
#include "CacheClient.h"
+#include "common/Cond.h"
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_immutable_obj_cache
: m_cct(ceph_ctx), m_io_service_work(m_io_service),
m_dm_socket(m_io_service), m_ep(stream_protocol::endpoint(file)),
m_io_thread(nullptr), m_session_work(false), m_writing(false),
- m_reading(false), m_sequence_id(0),
- m_lock("ceph::cache::cacheclient::m_lock") {
+ m_reading(false), m_sequence_id(0) {
m_worker_thread_num =
m_cct->_conf.get_val<uint64_t>(
"immutable_object_cache_client_dedicated_thread_num");
req->encode();
{
- Mutex::Locker locker(m_lock);
+ std::lock_guard locker{m_lock};
m_outcoming_bl.append(req->get_payload_bufferlist());
ceph_assert(m_seq_to_req.find(req->seq) == m_seq_to_req.end());
m_seq_to_req[req->seq] = req;
ldout(m_cct, 20) << dendl;
bufferlist bl;
{
- Mutex::Locker locker(m_lock);
+ std::lock_guard locker{m_lock};
bl.swap(m_outcoming_bl);
ceph_assert(m_outcoming_bl.length() == 0);
}
ceph_assert(cb == bl.length());
{
- Mutex::Locker locker(m_lock);
+ std::lock_guard locker{m_lock};
if (m_outcoming_bl.length() == 0) {
m_writing.store(false);
return;
process(reply, reply->seq);
{
- Mutex::Locker locker(m_lock);
+ std::lock_guard locker{m_lock};
if (m_seq_to_req.size() == 0 && m_outcoming_bl.length()) {
m_reading.store(false);
return;
ldout(m_cct, 20) << dendl;
ObjectCacheRequest* current_request = nullptr;
{
- Mutex::Locker locker(m_lock);
+ std::lock_guard locker{m_lock};
ceph_assert(m_seq_to_req.find(seq_id) != m_seq_to_req.end());
current_request = m_seq_to_req[seq_id];
m_seq_to_req.erase(seq_id);
/* all pending request, which have entered into ASIO,
* will be re-dispatched to RADOS.*/
{
- Mutex::Locker locker(m_lock);
+ std::lock_guard locker{m_lock};
for (auto it : m_seq_to_req) {
it.second->type = RBDSC_READ_RADOS;
it.second->process_msg->complete(it.second);
#include <boost/algorithm/string.hpp>
#include "include/ceph_assert.h"
+#include "common/ceph_mutex.h"
#include "include/Context.h"
-#include "common/Cond.h"
-#include "common/Mutex.h"
#include "Types.h"
#include "SocketCommon.h"
std::atomic<bool> m_writing;
std::atomic<bool> m_reading;
std::atomic<uint64_t> m_sequence_id;
- Mutex m_lock;
+ ceph::mutex m_lock =
+ ceph::make_mutex("ceph::cache::cacheclient::m_lock");
std::map<uint64_t, ObjectCacheRequest*> m_seq_to_req;
bufferlist m_outcoming_bl;
bufferptr m_bp_header;
namespace immutable_obj_cache {
ObjectCacheStore::ObjectCacheStore(CephContext *cct)
- : m_cct(cct), m_rados(new librados::Rados()),
- m_ioctx_map_lock("ceph::cache::ObjectCacheStore::m_ioctx_map_lock") {
+ : m_cct(cct), m_rados(new librados::Rados()) {
m_cache_root_dir =
m_cct->_conf.get_val<std::string>("immutable_object_cache_path");
std::string cache_file_name = get_cache_file_name(pool_nspace, pool_id, snap_id, object_name);
librados::IoCtx ioctx;
{
- Mutex::Locker _locker(m_ioctx_map_lock);
+ std::lock_guard _locker{m_ioctx_map_lock};
if (m_ioctx_map.find(pool_id) == m_ioctx_map.end()) {
ret = m_rados->ioctx_create2(pool_id, ioctx);
if (ret < 0) {
#define CEPH_CACHE_OBJECT_CACHE_STORE_H
#include "common/ceph_context.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
#include "include/rados/librados.hpp"
#include "SimplePolicy.h"
CephContext *m_cct;
RadosRef m_rados;
std::map<uint64_t, librados::IoCtx> m_ioctx_map;
- Mutex m_ioctx_map_lock;
+ ceph::mutex m_ioctx_map_lock =
+ ceph::make_mutex("ceph::cache::ObjectCacheStore::m_ioctx_map_lock");
Policy* m_policy;
std::string m_cache_root_dir;
};
SimplePolicy::SimplePolicy(CephContext *cct, uint64_t cache_size,
uint64_t max_inflight, double watermark)
: cct(cct), m_watermark(watermark), m_max_inflight_ops(max_inflight),
- m_max_cache_size(cache_size),
- m_cache_map_lock("rbd::cache::SimplePolicy::m_cache_map_lock") {
+ m_max_cache_size(cache_size) {
ldout(cct, 20) << "max cache size= " << m_max_cache_size
<< " ,watermark= " << m_watermark
cache_status_t SimplePolicy::alloc_entry(std::string file_name) {
ldout(cct, 20) << "alloc entry for: " << file_name << dendl;
- RWLock::WLocker wlocker(m_cache_map_lock);
+ std::unique_lock wlocker{m_cache_map_lock};
// cache hit when promoting
if (m_cache_map.find(file_name) != m_cache_map.end()) {
cache_status_t SimplePolicy::lookup_object(std::string file_name) {
ldout(cct, 20) << "lookup: " << file_name << dendl;
- RWLock::RLocker rlocker(m_cache_map_lock);
+ std::shared_lock rlocker{m_cache_map_lock};
auto entry_it = m_cache_map.find(file_name);
// simply promote on first lookup
ldout(cct, 20) << "update status for: " << file_name
<< " new status = " << new_status << dendl;
- RWLock::WLocker locker(m_cache_map_lock);
+ std::unique_lock locker{m_cache_map_lock};
auto entry_it = m_cache_map.find(file_name);
if (entry_it == m_cache_map.end()) {
cache_status_t SimplePolicy::get_status(std::string file_name) {
ldout(cct, 20) << file_name << dendl;
- RWLock::RLocker locker(m_cache_map_lock);
+ std::shared_lock locker{m_cache_map_lock};
auto entry_it = m_cache_map.find(file_name);
if (entry_it == m_cache_map.end()) {
return OBJ_CACHE_NONE;
void SimplePolicy::get_evict_list(std::list<std::string>* obj_list) {
ldout(cct, 20) << dendl;
- RWLock::WLocker locker(m_cache_map_lock);
+ std::unique_lock locker{m_cache_map_lock};
// check free ratio, pop entries from LRU
if ((double)m_cache_size / m_max_cache_size > (1 - m_watermark)) {
// TODO(dehao): make this configurable
uint64_t SimplePolicy::get_promoting_entry_num() {
uint64_t index = 0;
- RWLock::RLocker rlocker(m_cache_map_lock);
+ std::shared_lock rlocker{m_cache_map_lock};
for (auto it : m_cache_map) {
if (it.second->status == OBJ_CACHE_SKIP) {
index++;
#define CEPH_CACHE_SIMPLE_POLICY_H
#include "common/ceph_context.h"
-#include "common/RWLock.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
#include "include/lru.h"
#include "Policy.h"
std::atomic<uint64_t> inflight_ops = 0;
std::unordered_map<std::string, Entry*> m_cache_map;
- RWLock m_cache_map_lock;
+ ceph::shared_mutex m_cache_map_lock =
+ ceph::make_shared_mutex("rbd::cache::SimplePolicy::m_cache_map_lock");
std::atomic<uint64_t> m_cache_size;