MB-14825: [BP] While trying to stream next checkpoint item, check if vbucket is valid 70/56170/3
authorManu Dhundi <manu@couchbase.com>
Thu, 7 May 2015 01:30:24 +0000 (18:30 -0700)
committerChiyoung Seo <chiyoung@couchbase.com>
Thu, 15 Oct 2015 21:41:00 +0000 (21:41 +0000)
If a vbucket is deleted in middle of a DCP connection streaming a checkpoint
item, we should handle such a scenario in a graceful manner.

Change-Id: I24fe52adc572f504f492f015f82fc8d5e0325925
Reviewed-on: http://review.couchbase.org/50674
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Reviewed-on: http://review.couchbase.org/56170
Tested-by: buildbot <build@couchbase.com>
src/dcp-stream.cc

index a143b81..94680ad 100644 (file)
@@ -300,6 +300,7 @@ DcpResponse* ActiveStream::next() {
     stream_state_t initState = state_;
 
     DcpResponse* response = NULL;
+
     switch (state_) {
         case STREAM_PENDING:
             break;
@@ -593,6 +594,13 @@ DcpResponse* ActiveStream::nextQueuedItem() {
 
 void ActiveStream::nextCheckpointItem() {
     RCPtr<VBucket> vbucket = engine->getVBucket(vb_);
+    if (!vbucket) {
+        /* The entity deleting the vbucket must set stream to dead,
+           calling setDead(END_STREAM_STATE) will cause deadlock because
+           it will try to grab streamMutex which is already acquired at this
+           point here */
+        return;
+    }
 
     bool mark = false;
     std::list<queued_item> items;