MB-24472 [Ephemeral]: Check for null vBucket in getNumPersistedDeletes 06/78406/2
authorDave Rigby <daver@couchbase.com>
Mon, 22 May 2017 14:36:08 +0000 (15:36 +0100)
committerDave Rigby <daver@couchbase.com>
Tue, 23 May 2017 17:59:05 +0000 (17:59 +0000)
Check the vBucket obtained from the vbmap is non-null before
dereferencing. If it is null, throw std::runtime_error.

Change-Id: I181d8b7d696386bee5b18daa8b211cbc7238d87b
Reviewed-on: http://review.couchbase.org/78406
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Daniel Owen <owend@couchbase.com>
src/ephemeral_bucket.cc

index b9cff44..753d6d7 100644 (file)
@@ -216,7 +216,12 @@ size_t EphemeralBucket::getNumPersistedDeletes(uint16_t vbid) {
        meaning is the number of deletes seen by the vbucket.
        This is needed by ns-server during vb-takeover */
     VBucketPtr vb = getVBucket(vbid);
-    return vb->getNumInMemoryDeletes();
+    if (vb) {
+        return vb->getNumInMemoryDeletes();
+    }
+    throw std::runtime_error(
+            "EphemeralBucket::getNumPersistedDeletes: No vbucket with id '" +
+            std::to_string(vbid) + "' in vbMap");
 }
 
 void EphemeralBucket::notifyNewSeqno(const uint16_t vbid,