From 4526d13a9d40c03de2279e9b1435693828170c12 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Sun, 15 Dec 2013 10:11:16 +0800 Subject: [PATCH] mds: fix stale session handling for multiple mds Don't add new caps to stale session when importing inodes. Don't touch session when importing caps because it confuses the stale session detection. Signed-off-by: Yan, Zheng --- src/mds/CInode.cc | 6 ++++-- src/mds/Capability.h | 40 ++++++++++++++++++++++++---------------- src/mds/Locker.cc | 2 +- src/mds/Server.cc | 3 ++- src/mds/SessionMap.h | 9 +++++---- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index d5d5a19a4352..94a11c986f35 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -2486,8 +2486,10 @@ Capability *CInode::add_client_cap(client_t client, Session *session, SnapRealm Capability *cap = new Capability(this, ++mdcache->last_cap_id, client); assert(client_caps.count(client) == 0); client_caps[client] = cap; - if (session) - session->add_cap(cap); + + session->add_cap(cap); + if (session->is_stale()) + cap->mark_stale(); cap->client_follows = first-1; diff --git a/src/mds/Capability.h b/src/mds/Capability.h index 6e35ba815da9..d56e9153865d 100644 --- a/src/mds/Capability.h +++ b/src/mds/Capability.h @@ -297,13 +297,17 @@ public: return Export(cap_id, _wanted, issued(), pending(), client_follows, last_sent, mseq+1, last_issue_stamp); } void merge(Export& other, bool auth_cap) { - // issued + pending - int newpending = other.pending | pending(); - if (other.issued & ~newpending) - issue(other.issued | newpending); - else - issue(newpending); - last_issue_stamp = other.last_issue_stamp; + if (!is_stale()) { + // issued + pending + int newpending = other.pending | pending(); + if (other.issued & ~newpending) + issue(other.issued | newpending); + else + issue(newpending); + last_issue_stamp = other.last_issue_stamp; + } else { + inc_last_seq(); + } client_follows = other.client_follows; @@ -313,21 +317,25 @@ public: mseq = other.mseq; } void merge(int otherwanted, int otherissued) { - // issued + pending - int newpending = pending(); - if (otherissued & ~newpending) - issue(otherissued | newpending); - else - issue(newpending); + if (!is_stale()) { + // issued + pending + int newpending = pending(); + if (otherissued & ~newpending) + issue(otherissued | newpending); + else + issue(newpending); + } else { + inc_last_seq(); + } // wanted _wanted = _wanted | otherwanted; } void revoke() { - if (pending()) - issue(0); - confirm_receipt(last_sent, 0); + if (pending() & ~CEPH_CAP_PIN) + issue(CEPH_CAP_PIN); + confirm_receipt(last_sent, CEPH_CAP_PIN); } // serializers diff --git a/src/mds/Locker.cc b/src/mds/Locker.cc index eb3005593324..25e7c82f98c8 100644 --- a/src/mds/Locker.cc +++ b/src/mds/Locker.cc @@ -1855,7 +1855,7 @@ void Locker::revoke_stale_caps(Session *session) cap->mark_stale(); CInode *in = cap->get_inode(); int issued = cap->issued(); - if (issued) { + if (issued & ~CEPH_CAP_PIN) { dout(10) << " revoking " << ccap_string(issued) << " on " << *in << dendl; cap->revoke(); diff --git a/src/mds/Server.cc b/src/mds/Server.cc index fa46636241b5..b74178b265e9 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -368,7 +368,7 @@ version_t Server::prepare_force_open_sessions(map& cm, session->is_opening() || session->is_stale()); session->inc_importing(); - mds->sessionmap.touch_session(session); +// mds->sessionmap.touch_session(session); } return pv; } @@ -706,6 +706,7 @@ void Server::reconnect_tick() ++p) { Session *session = mds->sessionmap.get_session(entity_name_t::CLIENT(p->v)); dout(1) << "reconnect gave up on " << session->info.inst << dendl; + kill_session(session); failed_reconnects++; } client_reconnect_gather.clear(); diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index ebb1ac5d7817..0eb7e7c909e2 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -281,12 +281,13 @@ public: } Session* get_or_add_session(const entity_inst_t& i) { Session *s; - if (session_map.count(i.name)) + if (session_map.count(i.name)) { s = session_map[i.name]; - else + } else { s = session_map[i.name] = new Session; - s->info.inst = i; - s->last_cap_renew = ceph_clock_now(g_ceph_context); + s->info.inst = i; + s->last_cap_renew = ceph_clock_now(g_ceph_context); + } return s; } void add_session(Session *s) { -- 2.47.3