]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: define operator<(...) for MutationImpl::LockOp
authorYan, Zheng <zyan@redhat.com>
Fri, 26 Apr 2019 04:36:06 +0000 (12:36 +0800)
committerYan, Zheng <zyan@redhat.com>
Sat, 9 Nov 2019 03:03:15 +0000 (11:03 +0800)
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
src/mds/Locker.cc
src/mds/Mutation.cc
src/mds/Mutation.h
src/mds/SimpleLock.h

index 885ffd2976b24f065f445ae17cb93b0b70cda684..991a6217805455e71369de66c28d6e9073a73fa8 100644 (file)
@@ -237,7 +237,7 @@ bool Locker::acquire_locks(MDRequestRef& mdr,
        } else {
          // if the lock is the latest locked one, it's possible that slave mds got the lock
          // while there are recovering mds.
-         if (!mdr->locks.count(lock) || lock == *mdr->locks.rbegin())
+         if (!mdr->locks.count(lock) || lock == mdr->locks.rbegin()->lock)
            wait = true;
        }
        if (wait) {
index ec26e4df1cd7e76d12771139ab817b02cfdbb567..5e194301eef8ba71670806d25f67c1e8e46498df 100644 (file)
@@ -84,10 +84,9 @@ void MutationImpl::LockOpVec::erase_rdlock(SimpleLock* lock)
     }
   }
 }
-
 void MutationImpl::LockOpVec::sort_and_merge()
 {
-  std::sort(begin(), end(), SimpleLock::ptr_lt());
+  std::sort(begin(), end());
   // merge ops on the same lock
   for (auto i = end() - 1; i > begin(); ) {
     auto j = i;
@@ -99,7 +98,6 @@ void MutationImpl::LockOpVec::sort_and_merge()
       i = j;
       continue;
     }
-
     // merge
     ++j;
     for (auto k = i; k > j; --k) {
index b1b22470b83358a974862a0edadba7f354df5a3e..6e556bec6d164e901f8c9dc2fa93376f2e0d7ef4 100644 (file)
@@ -73,9 +73,6 @@ public:
     SimpleLock* lock;
     mutable unsigned flags;
     mutable mds_rank_t wrlock_target;
-    operator SimpleLock*() const {
-      return lock;
-    }
     LockOp(SimpleLock *l, unsigned f=0, mds_rank_t t=MDS_RANK_NONE) :
       lock(l), flags(f), wrlock_target(t) {}
     bool is_rdlock() const { return !!(flags & RDLOCK); }
@@ -88,6 +85,20 @@ public:
       wrlock_target = MDS_RANK_NONE;
     }
     bool is_state_pin() const { return !!(flags & STATE_PIN); }
+
+    bool operator<(const LockOp& r) const {
+      if ((lock->type->type <= CEPH_LOCK_DN) && (r.lock->type->type > CEPH_LOCK_DN))
+       return true;
+      if ((lock->type->type > CEPH_LOCK_DN) == (r.lock->type->type > CEPH_LOCK_DN)) {
+       auto lp = lock->get_parent();
+       auto rp = r.lock->get_parent();
+       // then sort by object
+       if (lp == rp)
+         return (lock->type->type < r.lock->type->type);
+       return lp->is_lt(rp);
+      }
+      return false;
+    }
   };
 
   struct LockOpVec : public vector<LockOp> {
@@ -114,7 +125,7 @@ public:
       reserve(32);
     }
   };
-  typedef set<LockOp, SimpleLock::ptr_lt> lock_set;
+  typedef set<LockOp> lock_set;
   typedef lock_set::iterator lock_iterator;
   lock_set locks;  // full ordering
 
index 2d719b271b91d7a2d3b51d7d898a3a81fab6592b..272202230319b194420411b4958f6f59a75b7da4 100644 (file)
@@ -298,22 +298,6 @@ public:
     }
   }
 
-  struct ptr_lt {
-    bool operator()(const SimpleLock* l, const SimpleLock* r) const {
-      // first sort by object type (dn < inode)
-      if (!(l->type->type > CEPH_LOCK_DN) && (r->type->type > CEPH_LOCK_DN)) return true;
-      if ((l->type->type > CEPH_LOCK_DN) == (r->type->type > CEPH_LOCK_DN)) {
-       // then sort by object
-       if (l->parent->is_lt(r->parent)) return true;
-       if (l->parent == r->parent) {
-         // then sort by (inode) lock type
-         if (l->type->type < r->type->type) return true;
-       }
-      }
-      return false;
-    }
-  };
-
   void decode_locked_state(const bufferlist& bl) {
     parent->decode_lock_state(type->type, bl);
   }