From 13e8901b3b70917cd7ad953a275026d5b2485b47 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 5 Jun 2019 18:05:15 +0800 Subject: [PATCH] mds: reset heartbeat inside big loop Fixes: https://tracker.ceph.com/issues/40171 Signed-off-by: "Yan, Zheng" (cherry picked from commit d90403c8df90ed06564c84bb2dd38c16861cf34e) Conflicts: src/mds/Locker.h src/mds/MDCache.cc --- src/mds/Locker.cc | 4 ++-- src/mds/Locker.h | 2 +- src/mds/MDCache.cc | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/mds/Locker.cc b/src/mds/Locker.cc index b2b4c21dc45..b2728189847 100644 --- a/src/mds/Locker.cc +++ b/src/mds/Locker.cc @@ -1992,7 +1992,7 @@ void Locker::issue_caps_set(set& inset) issue_caps(*p); } -bool Locker::issue_caps(CInode *in, Capability *only_cap) +int Locker::issue_caps(CInode *in, Capability *only_cap) { // allowed caps are determined by the lock mode. int all_allowed = in->get_caps_allowed_by_type(CAP_ANY); @@ -2116,7 +2116,7 @@ bool Locker::issue_caps(CInode *in, Capability *only_cap) break; } - return (nissued == 0); // true if no re-issued, no callbacks + return nissued; } void Locker::issue_truncate(CInode *in) diff --git a/src/mds/Locker.h b/src/mds/Locker.h index ed16aff972e..9ddf292222e 100644 --- a/src/mds/Locker.h +++ b/src/mds/Locker.h @@ -241,7 +241,7 @@ public: public: version_t issue_file_data_version(CInode *in); Capability* issue_new_caps(CInode *in, int mode, Session *session, SnapRealm *conrealm, bool is_replay); - bool issue_caps(CInode *in, Capability *only_cap=0); + int issue_caps(CInode *in, Capability *only_cap=0); void issue_caps_set(set& inset); void issue_truncate(CInode *in); void revoke_stale_caps(Session *session); diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 6a44598f176..5b8010579b8 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -3788,16 +3788,24 @@ bool MDCache::expire_recursive( void MDCache::trim_unlinked_inodes() { dout(7) << "trim_unlinked_inodes" << dendl; - list q; + int count = 0; + vector q; for (auto &p : inode_map) { CInode *in = p.second; if (in->get_parent_dn() == NULL && !in->is_base()) { dout(7) << " will trim from " << *in << dendl; q.push_back(in); } + + if (!(++count % 1000)) + mds->heartbeat_reset(); + } + for (auto& in : q) { + remove_inode_recursive(in); + + if (!(++count % 1000)) + mds->heartbeat_reset(); } - for (list::iterator p = q.begin(); p != q.end(); ++p) - remove_inode_recursive(*p); } /** recalc_auth_bits() @@ -5522,6 +5530,7 @@ void MDCache::choose_lock_states_and_reconnect_caps() map splits; + int count = 0; for (auto i : inode_map) { CInode *in = i.second; @@ -5573,6 +5582,9 @@ void MDCache::choose_lock_states_and_reconnect_caps() if (missing_snap_parent) missing_snap_parents[realm->inode].insert(in); } + + if (!(++count % 1000)) + mds->heartbeat_reset(); } send_snaps(splits); @@ -5681,6 +5693,7 @@ void MDCache::export_remaining_imported_caps() stringstream warn_str; + int count = 0; for (auto p = cap_imports.begin(); p != cap_imports.end(); ++p) { warn_str << " ino " << p->first << "\n"; for (auto q = p->second.begin(); q != p->second.end(); ++q) { @@ -5693,7 +5706,8 @@ void MDCache::export_remaining_imported_caps() } } - mds->heartbeat_reset(); + if (!(++count % 1000)) + mds->heartbeat_reset(); } for (map >::iterator p = cap_reconnect_waiters.begin(); @@ -6146,7 +6160,9 @@ void MDCache::reissue_all_caps() { dout(10) << "reissue_all_caps" << dendl; + int count = 0; for (auto &p : inode_map) { + int n = 1; CInode *in = p.second; if (in->is_head() && in->is_any_caps()) { // called by MDSRank::active_start(). There shouldn't be any frozen subtree. @@ -6155,8 +6171,12 @@ void MDCache::reissue_all_caps() continue; } if (!mds->locker->eval(in, CEPH_CAP_LOCKS)) - mds->locker->issue_caps(in); + n += mds->locker->issue_caps(in); } + + if ((count % 1000) + n >= 1000) + mds->heartbeat_reset(); + count += n; } } @@ -6234,6 +6254,7 @@ void MDCache::_queued_file_recover_cow(CInode *in, MutationRef& mut) void MDCache::identify_files_to_recover() { dout(10) << "identify_files_to_recover" << dendl; + int count = 0; for (auto &p : inode_map) { CInode *in = p.second; if (!in->is_auth()) @@ -6272,6 +6293,9 @@ void MDCache::identify_files_to_recover() } else { rejoin_check_q.push_back(in); } + + if (!(++count % 1000)) + mds->heartbeat_reset(); } } @@ -11952,10 +11976,13 @@ void MDCache::force_readonly() mds->server->force_clients_readonly(); // revoke write caps + int count = 0; for (auto &p : inode_map) { CInode *in = p.second; if (in->is_head()) mds->locker->eval(in, CEPH_CAP_LOCKS); + if (!(++count % 1000)) + mds->heartbeat_reset(); } mds->mdlog->flush(); -- 2.47.3