]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
FileStore: Replace Mutex with RWLock in IndexManager 7118/head
authorEvgeniy Firsov <evgeniy.firsov@sandisk.com>
Tue, 8 Dec 2015 19:18:59 +0000 (11:18 -0800)
committerEvgeniy Firsov <evgeniy.firsov@sandisk.com>
Tue, 19 Jan 2016 22:26:14 +0000 (14:26 -0800)
Signed-off-by: Evgeniy Firsov <evgeniy.firsov@sandisk.com>
src/os/filestore/IndexManager.cc
src/os/filestore/IndexManager.h

index 3a3e5c99a7ba53d01c00aa072f6e7aef233efbd0..cfd7bc8a5af7e8e28bd3ce6ae6d9e07349668bbf 100644 (file)
@@ -73,7 +73,7 @@ IndexManager::~IndexManager() {
 
 
 int IndexManager::init_index(coll_t c, const char *path, uint32_t version) {
-  Mutex::Locker l(lock);
+  RWLock::WLocker l(lock);
   int r = set_version(path, version);
   if (r < 0)
     return r;
@@ -116,9 +116,19 @@ int IndexManager::build_index(coll_t c, const char *path, CollectionIndex **inde
   }
 }
 
-int IndexManager::get_index(coll_t c, const string& baseDir, Index *index) {
+bool IndexManager::get_index_optimistic(coll_t c, Index *index) {
+  RWLock::RLocker l(lock);
+  ceph::unordered_map<coll_t, CollectionIndex* > ::iterator it = col_indices.find(c);
+  if (it == col_indices.end()) 
+    return false;
+  index->index = it->second;
+  return true;
+}
 
-  Mutex::Locker l(lock);
+int IndexManager::get_index(coll_t c, const string& baseDir, Index *index) {
+  if (get_index_optimistic(c, index))
+    return 0;
+  RWLock::WLocker l(lock);
   ceph::unordered_map<coll_t, CollectionIndex* > ::iterator it = col_indices.find(c);
   if (it == col_indices.end()) {
     char path[PATH_MAX];
index da71807dad1e84e0c7a77fde2fe9f6a80b55cbc1..433211d01bc4a292d487c8ebe02ec2a8e4f21003 100644 (file)
@@ -49,7 +49,7 @@ struct Index {
  * This is enforced by using CollectionIndex::access_lock
  */
 class IndexManager {
-  Mutex lock; ///< Lock for Index Manager
+  RWLock lock; ///< Lock for Index Manager
   bool upgrade;
   ceph::unordered_map<coll_t, CollectionIndex* > col_indices;
 
@@ -65,6 +65,7 @@ class IndexManager {
    * @return error code
    */
   int build_index(coll_t c, const char *path, CollectionIndex **index);
+  bool get_index_optimistic(coll_t c, Index *index);
 public:
   /// Constructor
   IndexManager(bool upgrade) : lock("IndexManager lock"),