MB-20852 [11/N]: Move persistenceCheckpoint id to VBucket 77/67877/14
authorDave Rigby <daver@couchbase.com>
Tue, 13 Sep 2016 16:22:38 +0000 (17:22 +0100)
committerDave Rigby <daver@couchbase.com>
Mon, 31 Oct 2016 17:28:27 +0000 (17:28 +0000)
Currently the VBucketMap owns the persistence checkpoint IDs of all
VBuckets. Given these are properties of the VBuckets themselves (for
example one cannot form a vbucket_state record without one) it seems
more logical to have the VBucket class itself own this property.

Change-Id: I50260da628f543365081e736fdd55056a6004cd9
Reviewed-on: http://review.couchbase.org/67877
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: buildbot <build@couchbase.com>
src/vbucket.cc
src/vbucket.h
src/vbucketmap.cc
src/vbucketmap.h

index 6e798aa..bc76140 100644 (file)
@@ -431,6 +431,15 @@ size_t VBucket::getNumNonResidentItems(item_eviction_policy_t policy) {
     }
 }
 
+
+uint64_t VBucket::getPersistenceCheckpointId() const {
+    return persistenceCheckpointId.load();
+}
+
+void VBucket::setPersistenceCheckpointId(uint64_t checkpointId) {
+    persistenceCheckpointId.store(checkpointId);
+}
+
 bool VBucket::isResidentRatioUnderThreshold(float threshold,
                                             item_eviction_policy_t policy) {
     if (policy != FULL_EVICTION) {
index c9a9eb6..5cf42e9 100644 (file)
@@ -467,6 +467,12 @@ public:
         return rollbackItemCount.load(std::memory_order_relaxed);
     }
 
+    // Return the persistence checkpoint ID
+    uint64_t getPersistenceCheckpointId() const;
+
+    // Set the persistence checkpoint ID to the given value.
+    void setPersistenceCheckpointId(uint64_t checkpointId);
+
     static const vbucket_state_t ACTIVE;
     static const vbucket_state_t REPLICA;
     static const vbucket_state_t PENDING;
@@ -555,6 +561,8 @@ private:
 
     HLC hlc;
     std::string statPrefix;
+    // The persistence checkpoint ID for this vbucket.
+    AtomicValue<uint64_t> persistenceCheckpointId;
 
     static size_t chkFlushTimeout;
 
index fa5593d..1f3bf0d 100644 (file)
@@ -27,8 +27,6 @@ VBucketMap::VBucketMap(Configuration &config,
                        EventuallyPersistentStore &store) :
     bucketDeletion(new AtomicValue<bool>[config.getMaxVbuckets()]),
     bucketCreation(new AtomicValue<bool>[config.getMaxVbuckets()]),
-    persistenceCheckpointIds(new
-                             AtomicValue<uint64_t>[config.getMaxVbuckets()]),
     persistenceSeqnos(new AtomicValue<uint64_t>[config.getMaxVbuckets()]),
     size(config.getMaxVbuckets())
 {
@@ -41,7 +39,6 @@ VBucketMap::VBucketMap(Configuration &config,
     for (size_t i = 0; i < size; ++i) {
         bucketDeletion[i].store(false);
         bucketCreation[i].store(false);
-        persistenceCheckpointIds[i].store(0);
         persistenceSeqnos[i].store(0);
     }
 }
@@ -49,7 +46,6 @@ VBucketMap::VBucketMap(Configuration &config,
 VBucketMap::~VBucketMap() {
     delete[] bucketDeletion;
     delete[] bucketCreation;
-    delete[] persistenceCheckpointIds;
     delete[] persistenceSeqnos;
     while (!shards.empty()) {
         delete shards.back();
@@ -158,12 +154,23 @@ bool VBucketMap::setBucketCreation(id_type id, bool rv) {
 }
 
 uint64_t VBucketMap::getPersistenceCheckpointId(id_type id) const {
-    return persistenceCheckpointIds[id].load();
+    if (id < size) {
+        auto vb = getBucket(id);
+        if (vb) {
+            return vb->getPersistenceCheckpointId();
+        }
+    }
+    return {};
 }
 
 void VBucketMap::setPersistenceCheckpointId(id_type id,
                                             uint64_t checkpointId) {
-    persistenceCheckpointIds[id].store(checkpointId);
+    if (id < size) {
+        auto vb = getBucket(id);
+        if (vb) {
+            getBucket(id)->setPersistenceCheckpointId(checkpointId);
+        }
+    }
 }
 
 uint64_t VBucketMap::getPersistenceSeqno(id_type id) const {
index f7d7fe9..972e195 100644 (file)
@@ -82,7 +82,6 @@ private:
     std::vector<KVShard*> shards;
     AtomicValue<bool> *bucketDeletion;
     AtomicValue<bool> *bucketCreation;
-    AtomicValue<uint64_t> *persistenceCheckpointIds;
     AtomicValue<uint64_t> *persistenceSeqnos;
     const id_type size;