]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: record global last_created/last_destroyed in snaptable
authorYan, Zheng <zyan@redhat.com>
Wed, 25 Oct 2017 07:12:26 +0000 (15:12 +0800)
committerYan, Zheng <zyan@redhat.com>
Fri, 9 Feb 2018 10:41:28 +0000 (18:41 +0800)
Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
src/mds/SnapClient.cc
src/mds/SnapClient.h
src/mds/SnapRealm.cc
src/mds/SnapRealm.h
src/mds/SnapServer.cc
src/mds/SnapServer.h

index e96000ebac263c577102f851c8a1e4ae8a506245..103fd2c50b198b3a5ee05485ae2c068522450fd7 100644 (file)
@@ -55,18 +55,20 @@ void SnapClient::handle_query_result(MMDSTableRequest *m)
     break;
   case 'F': // full
     {
-      set<snapid_t> old_snaps;
-      if (cached_version > 0)
-       get_snaps(old_snaps);
-
       decode(cached_snaps, p);
       decode(cached_pending_update, p);
       decode(cached_pending_destroy, p);
-      cached_version = m->get_tid();
 
-      // increase destroy_seq if any snapshot gets destroyed.
-      if (!old_snaps.empty() && old_snaps != filter(old_snaps))
-       destroy_seq++;
+      snapid_t last_created, last_destroyed;
+      decode(last_created, p);
+      decode(last_destroyed, p);
+
+      if (last_created > cached_last_created)
+       cached_last_created = last_created;
+      if (last_destroyed > cached_last_destroyed)
+       cached_last_destroyed = last_destroyed;
+
+      cached_version = m->get_tid();
     }
     break;
   default:
@@ -75,12 +77,18 @@ void SnapClient::handle_query_result(MMDSTableRequest *m)
 
   if (!committing_tids.empty()) {
     for (auto p = committing_tids.begin();
-        p != committing_tids.end() && *p < cached_version; ) {
-      if (!cached_pending_update.count(*p) && !cached_pending_destroy.count(*p)) {
+        p != committing_tids.end() && *p <= cached_version; ) {
+      if (cached_pending_update.count(*p)) {
+       if (cached_pending_update[*p].snapid > cached_last_created)
+         cached_last_created = cached_pending_update[*p].snapid;
+       ++p;
+      } else if (cached_pending_destroy.count(*p)) {
+       if (cached_pending_destroy[*p].second > cached_last_destroyed)
+         cached_last_destroyed = cached_pending_destroy[*p].second;
+       ++p;
+      } else {
        // pending update/destroy have been committed.
        committing_tids.erase(p++);
-      } else {
-       ++p;
       }
     }
   }
@@ -119,9 +127,12 @@ void SnapClient::notify_commit(version_t tid)
     committing_tids.insert(tid);
   } else if (cached_pending_update.count(tid)) {
     committing_tids.insert(tid);
+    if (cached_pending_update[tid].snapid > cached_last_created)
+      cached_last_created = cached_pending_update[tid].snapid;
   } else if (cached_pending_destroy.count(tid)) {
     committing_tids.insert(tid);
-    destroy_seq++;
+    if (cached_pending_destroy[tid].second > cached_last_destroyed)
+      cached_last_destroyed = cached_pending_destroy[tid].second;
   } else if (cached_version > tid) {
     // no need to record the tid if it has already been committed.
   } else {
index e71d9a1b849749a180cfc73dec9efb703b1b1142..cc98587788209961210acf8306f0ab951d74d5c4 100644 (file)
@@ -26,6 +26,7 @@ class LogSegment;
 
 class SnapClient : public MDSTableClient {
   version_t cached_version;
+  snapid_t cached_last_created, cached_last_destroyed;
   map<snapid_t, SnapInfo> cached_snaps;
   map<version_t, SnapInfo> cached_pending_update;
   map<version_t, pair<snapid_t,snapid_t> > cached_pending_destroy;
@@ -34,14 +35,14 @@ class SnapClient : public MDSTableClient {
 
   map<version_t, std::list<MDSInternalContextBase*> > waiting_for_version;
 
-  uint64_t destroy_seq;
-
   uint64_t sync_reqid;
   bool synced;
+
 public:
   explicit SnapClient(MDSRank *m) :
     MDSTableClient(m, TABLE_SNAP),
-    cached_version(0), destroy_seq(1), sync_reqid(0),  synced(false) {}
+    cached_version(0), cached_last_created(0), cached_last_destroyed(0),
+    sync_reqid(0), synced(false) {}
 
   void resend_queries() override;
   void handle_query_result(MMDSTableRequest *m) override;
@@ -89,7 +90,6 @@ public:
   }
 
   version_t get_cached_version() const { return cached_version; }
-  uint64_t get_destroy_seq() const { return destroy_seq; }
   void refresh(version_t want, MDSInternalContextBase *onfinish);
 
   void sync(MDSInternalContextBase *onfinish);
@@ -100,6 +100,9 @@ public:
     waiting_for_version[MAX(cached_version, 1)].push_back(c);
   }
 
+  snapid_t get_last_created() const { return cached_last_created; }
+  snapid_t get_last_destroyed() const { return cached_last_destroyed; }
+
   void get_snaps(set<snapid_t>& snaps) const;
   set<snapid_t> filter(const set<snapid_t>& snaps) const;
   const SnapInfo* get_snap_info(snapid_t snapid) const;
index b705a29f3de3181bd70e220e7655e6fb16eef892..12f0c6914432e4e40c05ee255130efd0146a539c 100644 (file)
@@ -243,8 +243,6 @@ void SnapRealm::build_snap_set(set<snapid_t> &s,
     max_seq = srnode.seq;
   if (srnode.last_created > max_last_created)
     max_last_created = srnode.last_created;
-  if (srnode.last_destroyed > max_last_destroyed)
-    max_last_destroyed = srnode.last_destroyed;
 
   // include my snaps within interval [first,last]
   for (auto p = srnode.snaps.lower_bound(first); // first element >= first
@@ -284,18 +282,17 @@ void SnapRealm::build_snap_set(set<snapid_t> &s,
 void SnapRealm::check_cache() const
 {
   assert(have_past_parents_open());
-  uint64_t destroy_seq = mdcache->mds->snapclient->get_destroy_seq();
+  snapid_t last_destroyed = mdcache->mds->snapclient->get_last_destroyed();
   if (cached_seq >= srnode.seq &&
-      cached_destroy_seq == destroy_seq)
+      cached_last_destroyed == last_destroyed)
     return;
 
   cached_snaps.clear();
   cached_snap_context.clear();
 
   cached_last_created = srnode.last_created;
-  cached_last_destroyed = srnode.last_destroyed;
   cached_seq = srnode.seq;
-  cached_destroy_seq = destroy_seq;
+  cached_last_destroyed = last_destroyed;
   build_snap_set(cached_snaps, cached_seq, cached_last_created, cached_last_destroyed,
                 0, CEPH_NOSNAP);
 
@@ -305,7 +302,6 @@ void SnapRealm::check_cache() const
   dout(10) << "check_cache rebuilt " << cached_snaps
           << " seq " << srnode.seq
           << " cached_seq " << cached_seq
-          << " cached_destroy_seq " << cached_destroy_seq
           << " cached_last_created " << cached_last_created
           << " cached_last_destroyed " << cached_last_destroyed
           << ")" << dendl;
index 5799808fa379a8f90d158f1602c14fe6aed30eb8..722fdde52dc12caf24e5d4442d7edd38779a88fb 100644 (file)
@@ -29,7 +29,6 @@ struct SnapRealm {
 protected:
   // cache
   mutable snapid_t cached_seq;           // max seq over self and all past+present parents.
-  mutable uint64_t cached_destroy_seq;
   mutable snapid_t cached_last_created;  // max last_created over all past+present parents
   mutable snapid_t cached_last_destroyed;
   mutable set<snapid_t> cached_snaps;
@@ -57,7 +56,6 @@ public:
   map<client_t, xlist<Capability*>* > client_caps;   // to identify clients who need snap notifications
 
   SnapRealm(MDCache *c, CInode *in) : 
-    cached_destroy_seq(0),
     srnode(),
     mdcache(c), inode(in),
     open(false), parent(0),
index 824f02559f8c74d6416dbff02953030be0df76af..e6eed75307a0fcb1ddb3991cbbb3c0fb1480ca6a 100644 (file)
@@ -58,6 +58,8 @@ void SnapServer::reset_state()
     if (first_free > last_snap)
       last_snap = first_free;
   }
+  last_created = last_snap;
+  last_destroyed = last_snap;
   version++;
 }
 
@@ -168,6 +170,8 @@ void SnapServer::_commit(version_t tid, MMDSTableRequest *req)
        info.stamp = snaps[info.snapid].stamp;
     } else {
       opname = "create";
+      if (info.snapid > last_created)
+       last_created = info.snapid;
     }
     dout(7) << "commit " << tid << " " << opname << " " << info << dendl;
     snaps[info.snapid] = info;
@@ -179,6 +183,8 @@ void SnapServer::_commit(version_t tid, MMDSTableRequest *req)
     snapid_t seq = pending_destroy[tid].second;
     dout(7) << "commit " << tid << " destroy " << sn << " seq " << seq << dendl;
     snaps.erase(sn);
+    if (seq > last_destroyed)
+      last_destroyed = seq;
 
     for (const auto p : mds->mdsmap->get_data_pools()) {
       need_to_purge[p].insert(sn);
@@ -255,6 +261,8 @@ bool SnapServer::_notify_prep(version_t tid)
   encode(snaps, bl);
   encode(pending_update, bl);
   encode(pending_destroy, bl);
+  encode(last_created, bl);
+  encode(last_destroyed, bl);
   assert(version == tid);
 
   for (auto p : active_clients) {
@@ -289,6 +297,8 @@ void SnapServer::handle_query(MMDSTableRequest *req)
        encode(snaps, reply->bl);
        encode(pending_update, reply->bl);
        encode(pending_destroy, reply->bl);
+       encode(last_created, reply->bl);
+       encode(last_destroyed, reply->bl);
       }
       // FIXME: implement incremental change
       break;
index 517f009289789c56dd711b5748d31871216fdbd0..94f7a5bfa11670cb473f880367265faf2cc02fc2 100644 (file)
@@ -25,6 +25,7 @@ class SnapServer : public MDSTableServer {
 protected:
   MonClient *mon_client = nullptr;
   snapid_t last_snap;
+  snapid_t last_created, last_destroyed;
   map<snapid_t, SnapInfo> snaps;
   map<int, set<snapid_t> > need_to_purge;
   
@@ -35,17 +36,19 @@ protected:
   version_t last_checked_osdmap;
 
   void encode_server_state(bufferlist& bl) const override {
-    ENCODE_START(3, 3, bl);
+    ENCODE_START(4, 3, bl);
     encode(last_snap, bl);
     encode(snaps, bl);
     encode(need_to_purge, bl);
     encode(pending_update, bl);
     encode(pending_destroy, bl);
     encode(pending_noop, bl);
+    encode(last_created, bl);
+    encode(last_destroyed, bl);
     ENCODE_FINISH(bl);
   }
   void decode_server_state(bufferlist::iterator& bl) override {
-    DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl);
+    DECODE_START_LEGACY_COMPAT_LEN(4, 3, 3, bl);
     decode(last_snap, bl);
     decode(snaps, bl);
     decode(need_to_purge, bl);
@@ -59,6 +62,13 @@ protected:
        pending_destroy[p->first].first = p->second; 
     } 
     decode(pending_noop, bl);
+    if (struct_v >= 4) {
+      decode(last_created, bl);
+      decode(last_destroyed, bl);
+    } else {
+      last_created = last_snap;
+      last_destroyed = last_snap;
+    }
     DECODE_FINISH(bl);
   }