Add id to the logs of checkpoint persistence

Add the id to the logs of checkpoint persistence so that we will have the
sequence number/checkpoint id in case a timeout occurs on checkpoint
persistence

Change-Id: Ifd3c70c9d40de43f0b3f1fdc1cf495ee0dc95d60
Reviewed-on: http://review.couchbase.org/40513
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Sriram Ganesan <sriram@couchbase.com>
MB-11912 Monitor workload pattern for dynamic compaction scheduling.

This change allows us to monitor workload pattern (i.e.,
read_heavy, write_heavy, mixed) at runtime and use the monitored
workload pattern to adjust the number of concurrent compaction
tasks dynamically at runtime. If the workload pattern is read-heavy,
then only one compaction task is executed at a time.

Note that we plan to keep improving this area for better I/O
scheduling.

Change-Id: Ibbb27da0a7e9f3951571ad8068570ebbf9abb318
Reviewed-on: http://review.couchbase.org/40520
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11299: Allow rollbacks to a partial snapshot

If we roll back to a partial snapshot we need to make sure to get
the snapshot start and end seqnos for the partial snapshot in order
to make sure that we don't accidentally miss any items when
reconnecting.

Change-Id: If95d0476d8d582d6b57786387212f03b2aafc7ba
Reviewed-on: http://review.couchbase.org/40340
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11642 Batch load dcp mutations if replication

Instead of loading 1 mutation per vbucket send out 10
dcp mutations per dcp step() if it is a intra-cluster
replication stream.
This is done so that intra-cluster replication is always
faster than XDCR and views.
Noticeable  improvement seen in intra-cluster replication
Change-Id: I15fc0081852e8e11027a20febe3224acdf21b661
Reviewed-on: http://review.couchbase.org/40392
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
MB-11952 Lower the default max number of readers.

Change-Id: I43dbcc4d606eea07276327ec7b9ed4f9bf3fc0e4
Reviewed-on: http://review.couchbase.org/40579
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11941: Update current vbucket snapshot when receiving tap items

We need to update the vbucket snapshot in order to support upgrades
because we initially have a tap stream and then move to a dcp stream.
Since tap doesn't support snapshots we can just set the current snapshot
to be the same as the seqno for that item.

Change-Id: I9da32df9366508276619507cf6cb9a66557e0919
Reviewed-on: http://review.couchbase.org/40582
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11933: Only set cur snapshot when receving the first snapshot item

We were setting the current snapshot when recieving the snapshot
marker and this is incorrect because if we disconnect before recieving
any items for that snapshot then the next time the replica vbucket
tries to connect to the active the high seqno will be less than the
last snapshot start seqno and this will cause the stream request to
fail with invalid arguments.

Change-Id: I75e1f555656c24221b2697011df878c579dce70e
Reviewed-on: http://review.couchbase.org/40583
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Incorrect parameter for scheduleVBDeletion

This caused completeBeforeShutdown to be set
to false, in resetVBucket/deleteVBucket
scenarios.

Change-Id: I72a1f07f475af49a7f368695a8e83cf2c5df9e28
Reviewed-on: http://review.couchbase.org/40593
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: abhinav dangeti <abhinav@couchbase.com>
MB-11928: Fast path for rollback to 0

Right now we run through all of the headers even if we have to
rollback to 0. This change provides a fast path to rollback to
zero by immediately resetting the vbucket.

Change-Id: I8e7b62ec711838894c4eda92eaff78704bd94d50
Reviewed-on: http://review.couchbase.org/40595
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11941: Use the latest seqno during tap mutation/deletion cur snapshot

We generate the seqno when inserting the item into the hashtable when
using tap. As a reuslt we need to retrieve that seqno when updating
the latest snapshot because the byseqno passed into the mutation and
deletion functions for tap is always 0.

Change-Id: I21b7888207d9fea4f46b3d5918d1c8b60b2ea1ff
Reviewed-on: http://review.couchbase.org/40601
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11943: replace map with vector for cachedVBStates

std::map can incur thread-unsafe rb balance operations which
may invalidate concurrent iterators causing asserts or crashes
Pre-allocated vectors are thread-safe as long as the size is not
altered
Change-Id: I777b0cc7d9c421cc11425db75506fdf90044a93c
Reviewed-on: http://review.couchbase.org/40600
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11299: Don't let replica vbuckets send partial snapshots

Replica vbuckets cannot create their own snapshots and must
rely on the snapshots it received from the active vbucket
when forwarding the snapshots to a downstream consumer. In
order to make sure that this happens properly we will only
stream mutations from the closed checkpoint for non-active
vbuckets. This will guarantee that the above requirement is
met.

Change-Id: I58151ce96868e34083f87dca0ce1d18b6a12aedf
Reviewed-on: http://review.couchbase.org/40346
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11945 Remove the assertion check on sequence number in the flusher.

We sporadically observe the sequence number mismatches between the
flusher and Couchstore. This is not a regression from any recent
changes, and mostly existed much earlier. We will investigate this
issue separately to see if there are any bugs in ep-engine or
Couchstore.

Change-Id: Ifac2eae0deae09cad09dd7b5664f63bcbf828b24
Reviewed-on: http://review.couchbase.org/40630
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11916 Synchronize the access to thread job logs.

Change-Id: I9551cd70b931b1ed92f806be1df0325d922a239c
Reviewed-on: http://review.couchbase.org/40637
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11890: Active vb shouldn't initiate add Stream req

Change-Id: Ic902e632d52f426a73d7708f9c69854dc7fab874
Reviewed-on: http://review.couchbase.org/40641
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: abhinav dangeti <abhinav@couchbase.com>
MB-11958: Make sure mutations and snapshot ranges are updated together

There is a race condition where an items seqno is updated and the
flusher runs and persists both the seqno and old snapshot range
before the new snapshot range can be updated.

Change-Id: If124e5ab05c45c68a6956d28cc3898f8c18df6a9
Reviewed-on: http://review.couchbase.org/40642
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Windows don't support the %zu formatter

Change-Id: Ia36bc151f84af9cfd6c069c3d97c494753d449f3
Reviewed-on: http://review.couchbase.org/40650
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Fix the regression from the change for MB-11943

The change for MB-11943 caused the sporadic failure
in "vbucket deletion doesn't affect new data" unit test case.

This change makes sure that we have the same logic in maintaining
cachedVBState instance for a deleted vbucket.

Change-Id: I7fda66a258c46cd04820001e945e0679eed0469b
Reviewed-on: http://review.couchbase.org/40645
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Correctly return ENGINE_ERROR_CODE in processing mutation messages

Change-Id: I72cadd9beb9a024be7fab5d54c7ecf8a85a40c79
Reviewed-on: http://review.couchbase.org/40653
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11876 Safely cancel AccessScanner task on shutdown

Change-Id: I769ca2ad562ef2b27447d40b6a66c4e24ff21eb3
Reviewed-on: http://review.couchbase.org/40669
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>