MB-23714: Use a weak_ptr in DcpBackfillMemory task 58/76558/9
authorJim Walker <jim@couchbase.com>
Mon, 10 Apr 2017 15:05:24 +0000 (16:05 +0100)
committerDave Rigby <daver@couchbase.com>
Wed, 19 Apr 2017 11:33:10 +0000 (11:33 +0000)
Ensures there can be no cyclic dependency with VB pointers in the
complex DCP slab of objects and tasks.

Change-Id: I89d902ff0aa0c69dcd598653ae40cda34ea582f9
Reviewed-on: http://review.couchbase.org/76558
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
src/dcp/backfill_memory.cc
src/dcp/backfill_memory.h

index 771e330..520396e 100644 (file)
@@ -27,10 +27,22 @@ DCPBackfillMemory::DCPBackfillMemory(EphemeralVBucketPtr evb,
                                      const active_stream_t& s,
                                      uint64_t startSeqno,
                                      uint64_t endSeqno)
-    : DCPBackfill(s, startSeqno, endSeqno), evb(evb) {
+    : DCPBackfill(s, startSeqno, endSeqno), weakVb(evb) {
 }
 
 backfill_status_t DCPBackfillMemory::run() {
+    auto evb = weakVb.lock();
+    if (!evb) {
+        LOG(EXTENSION_LOG_WARNING,
+            "DCPBackfillMemory::run(): "
+            "(vb:%d) running backfill ended prematurely as weakVb can't be "
+            "locked; start seqno:%" PRIi64 ", end seqno:%" PRIi64,
+            getVBucketId(),
+            startSeqno,
+            endSeqno);
+        return backfill_finished;
+    }
+
     /* Get vb state lock */
     ReaderLockHolder rlh(evb->getStateLock());
     if (evb->getState() == vbucket_state_dead) {
index 64936e1..6dcc768 100644 (file)
@@ -51,7 +51,7 @@ public:
 
 private:
     /**
-     * Ref counted ptr to EphemeralVBucket
+     * weak pointer to EphemeralVBucket
      */
-    EphemeralVBucketPtr evb;
+    std::weak_ptr<EphemeralVBucket> weakVb;
 };