Maintain bg-fetch related stats per tap checkpoint state.

A tap checkpoint state is maintained per vbucket and needs to
include bg-fetch related stats as an item eviction is going to
be allowed for non-dirty items in the open checkpoint, which
consequently might require bg fetches in order to replicate
non-resident items through the tap checkpoint cursor.

Change-Id: Ia7f80ec4fce1988456282998760edb5f873d3fa9
Reviewed-on: http://review.couchbase.org/14097
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Don't reset bg-fetch related stats in registering TAP cursors.

If a tap cursor already exists for a given vbucket, bg-fetch
related stats in the cursor's checkpoint state should not be
reset because checkpoint synchronization requires those stats
due to item eviction in the open checkpoint.

Note that there are no logic changes in the cursor registration.

Change-Id: I20298cc502c6ebd310a0dfedb2528875c71caff4
Reviewed-on: http://review.couchbase.org/14098
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Check if there are any BG items before sending CHK_END message

We need to make sure that there are no remaining bg-fetch items
or jobs before sending CHECKPOINT_END message to the destination.

Change-Id: I2239607d763888f05eed50771611043bde9dc082
Reviewed-on: http://review.couchbase.org/14099
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Add checkpoint meta items to the checkpoint key index.

This is required to support evicting items that have been already
visited by all checkpoint cursors.

Change-Id: Ic71b7d274fe982acdeeee1c0f79f66ddd0e02a2d
Reviewed-on: http://review.couchbase.org/14120
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Evict items that were already visited by all checkpoint cursors.

This change supports evicting items which have been already
visited by all checkpoint cursors. A given item can be eligible
for eviction if its mutation id is less than the mutation id of
the item pointed by the slowest cursor.

Change-Id: I5ee0852cef18bead48335a49015640a3d1c6960e
Reviewed-on: http://review.couchbase.org/14100
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Remove unnecessary conditional operators.

Change-Id: Ia2ee522da4de78efc619afead77d73da1665ebf0
Reviewed-on: http://review.couchbase.org/14121
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Remove duplicate macros.

Change-Id: I5029c035ba52dab462cf8c65eb7fde8f4a70eee4
Reviewed-on: http://review.couchbase.org/14125
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
MB-4923 Schedule DB snapshot and cleanup tasks after the warmup.

If we don't wait until the full warmup is done, there is a
sporadic crash in non-WAL mode that can only have one database
connection and one dispatcher thread. This change schedules
vbucket snapshot, stats snapshot, and other DB cleanup tasks
right after the full warmup is completed. It is totally safe to
delay them because enabling traffics does not depend on those
tasks.

Change-Id: I2739eadfbd8bac846d7e08a2849b06cfe081b5f2
Reviewed-on: http://review.couchbase.org/14144
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Create invalid item's range list before scheduled by dispatcher.

Note that this task is only used with the vbucket versioning that
will be deprecated soon.

Change-Id: Ib4764b50d1a1f3560e972ea1b1cf72996ae1aca0
Reviewed-on: http://review.couchbase.org/14145
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Warmup should be executed by the read-only KVStore instance.

As we plan to execute the warmup through a separate thread, it
makes sense to use the read-only KVStore instance. Note that using
the same read-only KVStore by two threads (warmup thread and
read-only dispatcher) works fine as long as they don't use the
same PreparedStatement instance at the same time.

Change-Id: I4c3725eff8438e0d555e28b4fd43dfbb4f336ce9
Reviewed-on: http://review.couchbase.org/14146
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Don't abort for NEED_META response from hash table set call.

The same logic should be applied to the engine's set and
setWithMeta methods in processing NEED_META response from
hash table call.

Change-Id: Ifa782d219d422ad3457786262a770855a7f76e2f
Reviewed-on: http://review.couchbase.org/14176
Reviewed-by: Jin Lim <jin@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Merge branch 'branch-18'

* branch-18:
  Don't abort for NEED_META response from hash table set call.
  Warmup should be executed by the read-only KVStore instance.
  Create invalid item's range list before scheduled by dispatcher.
  MB-4923 Schedule DB snapshot and cleanup tasks after the warmup.
  Remove duplicate macros.
  Remove unnecessary conditional operators.
  Evict items that were already visited by all checkpoint cursors.
  Add checkpoint meta items to the checkpoint key index.
  Check if there are any BG items before sending CHK_END message
  Don't reset bg-fetch related stats in registering TAP cursors.
  Maintain bg-fetch related stats per tap checkpoint state.

Change-Id: I94092a82d2277fcf6637a26aea00631ef8e12015