From: Yan, Zheng Date: Fri, 26 Apr 2019 04:36:06 +0000 (+0800) Subject: mds: define operator<(...) for MutationImpl::LockOp X-Git-Tag: v15.1.0~766^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=41877de4ad10af9c058165af88bd2cdfa0432b4e;p=ceph.git mds: define operator<(...) for MutationImpl::LockOp Signed-off-by: "Yan, Zheng" --- diff --git a/src/mds/Locker.cc b/src/mds/Locker.cc index 885ffd2976b2..991a62178054 100644 --- a/src/mds/Locker.cc +++ b/src/mds/Locker.cc @@ -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) { diff --git a/src/mds/Mutation.cc b/src/mds/Mutation.cc index ec26e4df1cd7..5e194301eef8 100644 --- a/src/mds/Mutation.cc +++ b/src/mds/Mutation.cc @@ -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) { diff --git a/src/mds/Mutation.h b/src/mds/Mutation.h index b1b22470b833..6e556bec6d16 100644 --- a/src/mds/Mutation.h +++ b/src/mds/Mutation.h @@ -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 { @@ -114,7 +125,7 @@ public: reserve(32); } }; - typedef set lock_set; + typedef set lock_set; typedef lock_set::iterator lock_iterator; lock_set locks; // full ordering diff --git a/src/mds/SimpleLock.h b/src/mds/SimpleLock.h index 2d719b271b91..272202230319 100644 --- a/src/mds/SimpleLock.h +++ b/src/mds/SimpleLock.h @@ -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); }