MB-19886: In markDiskSnapshot() get current vb snapshot info outside streamMutex 40/64840/4
authorManu Dhundi <manu@couchbase.com>
Thu, 9 Jun 2016 20:22:45 +0000 (13:22 -0700)
committerDave Rigby <daver@couchbase.com>
Mon, 13 Jun 2016 09:26:49 +0000 (09:26 +0000)
commit99156468444de5c5a2bc319b1a70d5b4729c0d0a
tree4592aa810d6a608df9ea46434ad41d4a80fa7a7c
parentde4b97c70147d1241cf1a0fc27e8eda09491a695
MB-19886: In markDiskSnapshot() get current vb snapshot info outside streamMutex

We need this to overcome the lock inversion detected in
http://cv.jenkins.couchbase.com/job/ep-engine-threadsanitizer-3.0.x/263/console.

Explaining the lock inversion:
(1) Backfill thread sending disk snapshot:
    streamMutex (class Stream) ==> snapshotMutex (class VBucket)

(2) Front End thread receiving DCP mutation from active vb:
    snapshotMutex (class VBucket) ==> stateLock (class VBucket) ==>
                                              streamsMutex (class DcpProducer)

(3) Another front end thread disconnecting the view engine connection:
    streamsMutex (class DcpProducer) ==> streamMutex (class Stream)

Solution:
Break streamMutex (class Stream) ==> snapshotMutex (class VBucket).
This is done by making snapshot variables atomic and it should be good
as the backfill thread needs only snapshot_end.

Change-Id: Id1cff42dfe39151d9a19c826d7e47e23b3fc4d21
Reviewed-on: http://review.couchbase.org/64840
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
Well-Formed: buildbot <build@couchbase.com>
src/dcp-stream.cc
src/vbucket.h