MB-9098: Acquire lock to retrieve list size

- Need for synchronizing access to shared data
to avoid segmentation faults and possible
memory corruption.

- Backporting from master:
    http://review.couchbase.org/#/c/29477/

Change-Id: Id24770dbc72c082967959aee30c8e21b9556989e
Reviewed-on: http://review.couchbase.org/29687
Reviewed-by: Sundararaman Sridharan <sundar.sridharan@gmail.com>
Tested-by: Sundararaman Sridharan <sundar.sridharan@gmail.com>
MB-9306 Fix v->isDirty assertion due to race

BGFetcher must Validate CAS values before queuing dirty
item to disk when exptime is updated

Relax assertion since downside is just another set operation

Backport from 
http://review.couchbase.org/#/c/29461/

Change-Id: Icfcce79371bb867052f12c8a8574c8a318d71ace
Reviewed-on: http://review.couchbase.org/29461
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Reviewed-on: http://review.couchbase.org/29699
Reviewed-by: abhinav dangeti <abhinav.dangeti@gmail.com>
Tested-by: abhinav dangeti <abhinav.dangeti@gmail.com>
for MB-7230: state why access log was seen corrupt

Basic debugging whenever we hit a read error on
scanning the access log

Change-Id: I4b02a9484e7d0b56c0691e062717729d9d7ed4d5
Reviewed-on: http://review.couchbase.org/29768
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-8024: Fix to the BackfillRemaining stat overflow

Note that stats used in estimating the number of backfill items
are atomic individually, but not atomic when they use together.
Therefore, there is still a small time window that can cause the
backfill estimation counter to be overflow or underflow.

This change adds a check to prevent adding a negative number to
the backfill estimation counter.

Change-Id: I4752445e680c36b387aa80ffa1a985a7926bc9f2
Reviewed-on: http://review.couchbase.org/29836
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-9147: lseek can return 0 if the file has no len

This will avoid asserting incorrectly.
Backporting change from master branch into 2.5.0

Change-Id: Ibca0d69782f753e0dbb16652d5591a21e514c9f9
Reviewed-on: http://review.couchbase.org/29048
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Reviewed-on: http://review.couchbase.org/29843
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-8244: Unit test fix in fetching-worker-stats

Change-Id: I0831bf56410f76b0c9849fffab0f8fcbfaff4b6e
Reviewed-on: http://review.couchbase.org/29856
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: abhinav dangeti <abhinav@couchbase.com>
MB-8187: chk_items estimate only for MUTATION/DELs

- During stat collection, account for chk_items (the estimate)
only during TAP_MUTATION and TAP_DELETIONS, and not at checkpoint
start and end messages.
- This way docsTotal and docsTransferred stats will show as zero
during a rebalance if the bucket were empty.

Change-Id: I5df5d19f16b7dd7abe7465d356bb748d56e20d8e
Reviewed-on: http://review.couchbase.org/29882
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-8727: Cluster Configuration Carrier Publication

Addresses MB-8727:
- CMD_SET_CLUSTER_CONFIG: 0xb4

Addresses MB-8728:
- CMD_GET_CLUSTER_CONFIG: 0xb5

- Cluster config Blob will be saved as it is received
and will be returned as it is, with assumption that
blob will be of JSON type, and that SDK will need to
check the type of the document to differentiate
between older and new version of couchbase.

Addresses MB-8729:
- NOT_MY_VBUCKET to return cluster config blob
instead of the "not my vbucket" message.
- Memcached
change: http://review.couchbase.org/#/c/29844/
For memcached to retrieve Cluster Configuration from
ep_engine in case of ENGINE_NOT_MY_VBUCKET response.
- bucket_engine
change: http://review.couchbase.org/#/c/29845/

Change-Id: I20cf4aa145139d19524f252d3444dd0f52d0965d
Reviewed-on: http://review.couchbase.org/29684
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-9434: prevent deadlock between flusher & stats

If the memcached stats thread which is holding the thread
lock tries to acquire the high priority checkpoint list
lock just to read its size, it can deadlock on the
flusher thread which may be holding the list lock & trying
to notify the same memcached thread doing the stats

To avoid this deadlock maintain the size of the high
priority checkpoints in a separate variable and allow for
dirty read on the size

Change-Id: I6f0991c22deb2cc7762e5967496b99c3baed2c12
Reviewed-on: http://review.couchbase.org/29900
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Merge branch '2.5.0'

Conflicts:
	src/backfill.cc
	src/ep_engine.cc
	src/ep_engine.h
	src/tapconnection.cc
	src/vbucket.cc
	tests/ep_testsuite.cc

Change-Id: I8dced7a9f17c7e6649cee591934d960048dda6e5
MB-9493: Always update persistence cursor pre chk id after flush loop

Change-Id: I251ce6a56c37750c98e69a2c639349ae70460f7e
Reviewed-on: http://review.couchbase.org/30142
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Fix race in warmup completion

This change fixes a race in warmup completion that is cause when
a warmup thread is finishing and another thread tries to stop
warmup. This behavior can cause two stats snapshot tasks to be
scheduled and since we only keep a task id for one of the warmup
tasks it is impossible to cancel the second one that was scheduled.

This cahnge also refactors the warmupCompletion variable so that
it can be kept in the warmup class.

Change-Id: If01929dfe35c03f12e466f3099298339c9a66960