[BP] MB-16915: RollbackTask to hold ref count ptr for DCP consumer instead of raw ptr 48/57448/2
authorManu Dhundi <manu@couchbase.com>
Thu, 3 Dec 2015 01:19:51 +0000 (17:19 -0800)
committerChiyoung Seo <chiyoung@couchbase.com>
Thu, 3 Dec 2015 23:35:42 +0000 (23:35 +0000)
Rollback task is spawned when a DCP consumer is asked to rollback by a DCP
producer. Rollback runs in background and there is a possibility that the DCP
consumer object gets deleted before rollback task completes. We can avoid this
if RollbackTask holds a ref counted ptr of DCP consumer instead of a raw ptr.

Change-Id: I00c1bced0ec445226e64e6f7647a3bfbfb063f94
Reviewed-on: http://review.couchbase.org/57427
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
Reviewed-on: http://review.couchbase.org/57448
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
src/dcp-consumer.cc
src/dcp-consumer.h

index ac70af5..01d970b 100644 (file)
@@ -536,7 +536,10 @@ bool DcpConsumer::doRollback(uint32_t opaque, uint16_t vbid,
     cb_assert(err == ENGINE_SUCCESS);
 
     RCPtr<VBucket> vb = engine_.getVBucket(vbid);
-    streams[vbid]->reconnectStream(vb, opaque, vb->getHighSeqno());
+    passive_stream_t stream = streams[vbid];
+    if (stream) {
+        stream->reconnectStream(vb, opaque, vb->getHighSeqno());
+    }
 
     return false;
 }
index c8b8f6f..9c54334 100644 (file)
@@ -153,7 +153,7 @@ class RollbackTask : public GlobalTask {
 public:
     RollbackTask(EventuallyPersistentEngine* e,
                  uint32_t opaque_, uint16_t vbid_,
-                 uint64_t rollbackSeqno_, DcpConsumer *conn,
+                 uint64_t rollbackSeqno_, dcp_consumer_t conn,
                  const Priority &p):
         GlobalTask(e, p, 0, false), engine(e),
         opaque(opaque_), vbid(vbid_), rollbackSeqno(rollbackSeqno_),
@@ -170,7 +170,7 @@ private:
     uint32_t opaque;
     uint16_t vbid;
     uint64_t rollbackSeqno;
-    DcpConsumer* cons;
+    dcp_consumer_t cons;
 };
 
 #endif  // SRC_DCP_CONSUMER_H_