MB-7532 Set the default value of a rev sequence num to 1.

As the XDCR always expects a positive value for a revision
sequence number, its default value should be initialized to 1.

Change-Id: I6a281ad55d9c5d7e4ed93a6d4e33c609606f7f29
Reviewed-on: http://review.couchbase.org/23964
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Reviewed-by: Jin Lim <jin@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
MB-7567: Don't copy chk_end when merging checkpoints

Change-Id: I2c195e1efb6b562ca3c3b71568512ffa8e535112
Reviewed-on: http://review.couchbase.org/24144
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-7204: Invalid checkpoint displays error from cbstats

Change-Id: Ic429130e89d3014c22e28c6501647d06da027ab4
Reviewed-on: http://review.couchbase.org/24146
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-7580: Make sure mutation number is always increasing

Change-Id: Ic079c9b78f3f4bd9cd88b0605853e80120b72ced
Reviewed-on: http://review.couchbase.org/24147
Reviewed-by: Jin Lim <jin@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
MB-7583: Move checkpoint cursors when checkpoints are merged

Change-Id: Id121b2567dac41c6c29e0aaf8793f2247b33f869
Reviewed-on: http://review.couchbase.org/24150
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
MB-7593: Increase queue_size when re-persisting an item in same chk

Change-Id: I88d9d92207db0a7a637ca6b58b23147a3d94c0a4
Reviewed-on: http://review.couchbase.org/24186
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
MB-7375: Return TMPFAIL for locked key when doing touch or gat

Change-Id: I7c5205a6c0a62c887e2681f98e46f056852b1ac7
Reviewed-on: http://review.couchbase.org/24281
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-7652: Make sure to register cursors in chks when moving them

This was accidnetally left out of my previous checkpoint cheanges

Change-Id: Ib6ded7ba88bd2589a6a243cdecbbf9bf1b7985ec
Reviewed-on: http://review.couchbase.org/24327
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-100: Remove unused variables and redundent assignments

Change-Id: Ic31c276a06c09f91e6cbf5ddaf9accb7184761df
Reviewed-on: http://review.couchbase.org/24335
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-7519: Better flusher batching for writes

This change removes the outgoing queue in ep.cc and pushes
dirty items directly from the checkpoint queues into the
couchkvstore where they are persisted to disk. This
improves batching because we are now able to grab all
dirty items in a vbucket as opposed to grabbing items
an putting them into an intermediate queue where they
would wait to be persisted.

Change-Id: I39e9c25ad3380b3e045002967c9532b16758e187
Reviewed-on: http://review.couchbase.org/24190
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-7476: Prepend bucket name to all log messages

Change-Id: I1053494b5359c702c25e4bffa7e88959cb87be53
Reviewed-on: http://review.couchbase.org/24249
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Merge remote-tracking branch 'gerrit/2.0.1' into 2.0.2

Change-Id: Icc38e08ae2b7684e64dd260c014c6e711dcdcaf0
Merge remote-tracking branch 'gerrit/2.0.1' into 2.0.2

Change-Id: I03ef5ebbae2231cc926f1b77f117e25420f2030c
CBD-821 Extend an item's NRU value to two bits.

The current NRU scheme allocates only one bit per item in memory
cache and resets it to false whenever it is updated or referenced.
However, this scheme doesn't have the re-reference frequency of
each item and treats update and read operations with the same
weight in a cache management.

To support the easy and simple prediction of the re-reference
frequency, this change extends an item's NRU value to two bits,
so that it can have the re-reference hint for each item.

Basically, when a new item is inserted, its NRU value is set to
the intermediate value (i.e., two), and decremented as long as
the value is greater than zero whenever the item is referenced
later. The new item eviction algorithm (shown in another change)
uses an item's NRU value to collect the list of items with high
NRU values, which will be candidates for evictions.

Change-Id: Id863d68f1e0cfed6382a2ad53a2d7b089029df70
Reviewed-on: http://review.couchbase.org/24439
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
CBD-821 Adapt the item pager to use the extended NRU bits.

An item's NRU value is extended to two bits, which allows us
to have the range of 0 - 3 values. More frequently accessed
items will likely have zero NRU value as their NRU values are
decremented everytime they are referenced.

The item pager is adapted to leverage the extended NRU bits:

Phase 1:
1. Scan the next vbucket and collect items whose NRU score is 3
2. Evict those items with NRU score '3'
3. Check the memory usage and go to step 1 if the memory usage
   is still above the low watermark.

Once the phase 1 is completed, then the pager goes to the phase
2 if the memory usage is still above the high watermark.

Phase 2:
1. Scan the next vbucket and increment every item's
   NRU score by 1
2. If its NRU score is equal to '3', then generate a random
   number N whose range is from 0 to 1, and evict that item
   if N < P where P is the probability that is calculated based
   on the current memory usage and memory low watermark.
   Note that we also differentiate the probability P depending on
   the vbucket state (active, replica).
3. Check the memory usage and go to step 1 if the memory usage is
   still above the low watermark.

Change-Id: Idfcfda834e5fe89061cd49d5abaefba0621c6a42
Reviewed-on: http://review.couchbase.org/24526
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
MB-7483: Remove duplicate stats holding bucket size

ep_max_data_size (removed)
ep_max_size

Change-Id: Ie0dd4f94b15917ad397c1902449cd6f193e73c89
Reviewed-on: http://review.couchbase.org/24638
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Revert "MB-7483: Remove duplicate stats holding bucket size"

This reverts commit 7e84fc9ce1488722e055a496382af302f655b417.

Change-Id: I889e1bb0411e0c991e061fa3eb7e9300e00e0230
Reviewed-on: http://review.couchbase.org/24669
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7509: Skip merging checkpoint end items in chk queues

Change-Id: Idd73a04fc0ff8cce774ee956c006b879bfb1fec5
Reviewed-on: http://review.couchbase.org/24675
Reviewed-by: Jin Lim <jin@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-7509 Removed item should be removed from keyIndex too.

Change-Id: I842be6f77606e99ca7b47a451fd5f03e4b95feb6
Reviewed-on: http://review.couchbase.org/24730
Reviewed-by: Jin Lim <jin@couchbase.com>
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: xiaoqin ma <maxiaoqin2005@gmail.com>
MB-7524 Schedule the stats snapshot before purging TAP connections

When the engine shuts down, we schedule the stats snapshot task
and destroy all the TAP connection instances as part of the
shutdown process. As the stats snapshot task needs to persist
TAP stats, it should be scheduled before purging those TAP
connections from memory.

Change-Id: If1e154d68d2b8fa9f9859b9eda7274dad743a07d
Reviewed-on: http://review.couchbase.org/24759
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>