MB-20852 [10/N]: Return by value from VBucket::getPersistedSnapshot 75/68275/8
authorDave Rigby <daver@couchbase.com>
Mon, 3 Oct 2016 09:23:39 +0000 (10:23 +0100)
committerDave Rigby <daver@couchbase.com>
Mon, 31 Oct 2016 17:28:22 +0000 (17:28 +0000)
Simplifies usage & makes it explicit that all members of the range are
returned.

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

index 73b0c6a..cf58b7b 100644 (file)
--- a/src/ep.cc
+++ b/src/ep.cc
@@ -1145,8 +1145,7 @@ void EventuallyPersistentStore::snapshotVBuckets(VBSnapshotTask::Priority prio,
             : vbuckets(vb_map), shardId(sid) { }
         bool visitBucket(RCPtr<VBucket> &vb) {
             if (vbuckets.getShardByVbId(vb->getId())->getId() == shardId) {
-                snapshot_range_t range;
-                vb->getPersistedSnapshot(range);
+                const snapshot_range_t range = vb->getPersistedSnapshot();
                 std::string failovers = vb->failovers->toJSON();
                 uint64_t chkId = vbuckets.getPersistenceCheckpointId(vb->getId());
 
@@ -1239,8 +1238,7 @@ bool EventuallyPersistentStore::persistVBState(uint16_t vbid) {
     uint64_t chkId = vbMap.getPersistenceCheckpointId(vbid);
     std::string failovers = vb->failovers->toJSON();
 
-    snapshot_range_t range;
-    vb->getPersistedSnapshot(range);
+    const snapshot_range_t range = vb->getPersistedSnapshot();
     vbucket_state vb_state(vb->getState(), chkId, 0, vb->getHighSeqno(),
                            vb->getPurgeSeqno(), range.start, range.end,
                            vb->getMaxCas(), failovers);
@@ -1304,8 +1302,7 @@ ENGINE_ERROR_CODE EventuallyPersistentStore::setVBucketState(uint16_t vbid,
         }
 
         if (to == vbucket_state_active && !transfer) {
-            snapshot_range_t range;
-            vb->getPersistedSnapshot(range);
+            const snapshot_range_t range = vb->getPersistedSnapshot();
             if (range.end == vbMap.getPersistenceSeqno(vbid)) {
                 vb->failovers->createEntry(range.end);
             } else {
index 2ab0d2f..919638b 100644 (file)
@@ -4607,8 +4607,7 @@ void EventuallyPersistentEngine::addSeqnoVbStats(const void *cookie,
         checked_snprintf(buffer, sizeof(buffer), "vb_%d:purge_seqno",
                          vb->getId());
         add_casted_stat(buffer, vb->getPurgeSeqno(), add_stat, cookie);
-        snapshot_range_t range;
-        vb->getPersistedSnapshot(range);
+        const snapshot_range_t range = vb->getPersistedSnapshot();
         checked_snprintf(buffer, sizeof(buffer),
                          "vb_%d:last_persisted_snap_start",
                          vb->getId());
index d3c54a2..c9a9eb6 100644 (file)
@@ -230,10 +230,9 @@ public:
         persisted_snapshot_end = end;
     }
 
-    void getPersistedSnapshot(snapshot_range_t& range) {
+    snapshot_range_t getPersistedSnapshot() const {
         LockHolder lh(snapshotMutex);
-        range.start = persisted_snapshot_start;
-        range.end = persisted_snapshot_end;
+        return {persisted_snapshot_start, persisted_snapshot_end};
     }
 
     uint64_t getMaxCas() {
@@ -539,7 +538,7 @@ private:
 
     /* snapshotMutex is used to update/read the pair {start, end} atomically,
        but not if reading a single field. */
-    Mutex snapshotMutex;
+    mutable Mutex snapshotMutex;
     uint64_t persisted_snapshot_start;
     uint64_t persisted_snapshot_end;