MB-11459: Properly set high seqno in couchkvstore

We missed two places where we should update the cached version of
the vbucket high seqno.

Change-Id: I0b7e32348948814cb54d93feb5d9d78c8d478196
Reviewed-on: http://review.couchbase.org/38774
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11459: Add logging to diagnose incorrect high seqno on warmup

Change-Id: Id82d7c7569e37143a0413a90b54331452c8b2502
Reviewed-on: http://review.couchbase.org/38816
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11524 Check pendingQueue on poll to avoid starvation

We limit number of threads that can work on a task queue by
blocking excess tasks in a pendingQueue.
However in mixed priority scenarios, we can end up with
starvation if tasks are blocked in low priority pendingQueue
while capacity is released to a high priority task queue.

Fix is to release capacity when task finishes execution, and
have the task queues poll the pendingQueue.

This avoids starvation and also reduces mutex contentions.

Change-Id: Iaeb08a53d31d21b463502085198d07923c0731c7
Reviewed-on: http://review.couchbase.org/38825
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
MB-11407: Update last_seqno in consumer after rollback

After a rollback is issued to an UPR consumer the last_seqno
needs to be updated to the rollback seqno. Otherwise, mutations
that are sent from the UPR producer could get dropped.

Change-Id: I910850be130e08b4a052e7d152736d625cee8765
Reviewed-on: http://review.couchbase.org/38823
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11533: Give general estimate if stream name doesn't exist

In the tap-vbtakeover command we give an estimate even if the
stream we are trying to get an estimate for doesn't exist. We
should do the same thing for upr-vbtakeover.

Change-Id: Ifa2061a26fab08f6d217bb9c486f93af46bf314a
Reviewed-on: http://review.couchbase.org/38840
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11537: Items remaining for a dead stream should be 0

Change-Id: I18512199680af051130b08b780ab0af44b860593
Reviewed-on: http://review.couchbase.org/38850
Reviewed-by: Sriram Ganesan <sriram@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11405 Wake only as many threads as ready tasks

+ If a thread has uncovered only one ready task then do not
  wake more threads, since current thread will suffice.
+ Only signal threads if they are sleeping.
+ cond_broadcast and wake all threads if we have more ready tasks
  than sleeping threads
+ Aggregate and signal threads to avoid repeated mutex contentions
Change-Id: Ic130b87c19a2c5cd9eb971078c9a40b3612b5da0
Reviewed-on: http://review.couchbase.org/38756
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11347 Set thread local to NULL before calling upr_producers API

As upr_message_producers APIs provided by memcached layer can
allocate additional memory that will be freed later, we should
set the thread local to NULL before calling those APIs, so that
the allocated memory inside those APIs shouldn't be accounted for
a given bucket instance.

Change-Id: I31eac3fdc505fbde32a9b54ac8914d9d56e8992a
Reviewed-on: http://review.couchbase.org/38863
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Clear the checkpoint manager when doing partial rollback

The checkpoint manager might contain items that were rolled
back. As a result we should remove all items from the checkpoint
manager in order to make sure that we don't accidentally keep
and rolled back data.

Change-Id: I12ed857da0c000bda5a69e2182a6963c74536b3c
Reviewed-on: http://review.couchbase.org/38443
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11362: Add dcp and dcpagg stats

Add dcp and dcp agg stats that effectively point to upr and upragg
stats respectively. upr and upragg will be deprecated once all the
clients of those stats move to dcp

Change-Id: Id77301e62c23215ff97f6ee06eba82f5f64b4652
Reviewed-on: http://review.couchbase.org/38854
Reviewed-by: David Liao <david.liao@couchbase.com>
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Sriram Ganesan <sriram@couchbase.com>
MB-11576 Reserve cached Doc,DeleteCounts for safe read-only use

Dynamically allowing the cachedDocCount and cachedDeleteCount maps
to grow can be unsafe in the lock-less couch-kvstore implementation.
Pre-allocating their sizes to max number of vbucket ensures that we do
not cause a crash since the accesses should all be read-only.

Change-Id: I2ee48bfad7a8c5d4f14cb058a348b186b14cf156
Reviewed-on: http://review.couchbase.org/38894
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11347 Disable the memory accounting based on new / delete hook

This change disables the memory accounting based on new / delete
hook temporarily until we fix the memory accounting overflow
issue.

Change-Id: I9e4394c06dafd71e4e6e285a0182122334ea4686
Reviewed-on: http://review.couchbase.org/38896
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11572: CloseAllStreams before deleting them

Context: UprConsumer's deconstructor

Change-Id: Ifc5560ba3642989ae2d5edd4a3c63b7d0e6f57f5
Reviewed-on: http://review.couchbase.org/38888
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: abhinav dangeti <abhinav@couchbase.com>
MB-11347 Set thread local to NULL before calling get_failover_log

get_failover_log API is the callback function provided by
memcached layer and internally allocates more memory for buffer,
which will be freed later. Therefore, it shouln't be accounted
for a bucket memory usage.

Change-Id: I23324f88e6c87e9cb6e3d067cef2f2f2efffbf04
Reviewed-on: http://review.couchbase.org/38916
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11433: Don't aggregate upr/tap stats separately from the total

If we aggregate stats separately from the total then this can lead
to the sub-aggregate stats to not add up to the total.

Change-Id: If14a530fdc1627f6a01c797dff25ee74e9980d7b
Reviewed-on: http://review.couchbase.org/38923
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Fix to the potential starvation in UPR producer streams.

This change makes sure that all the streams belonging to a given
UPR produer are visited in a round-robin manner.

Change-Id: Ieb5a546a932dbe1ba891ef2393747da336ed12ae
Reviewed-on: http://review.couchbase.org/38929
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11579: Use the upr latest flag to set the end seqno to the vb high seqno

The "latest" flag is used to create a stream and get everything up to the
latest mutation that the vbucket currently contains. This flag should be
used by clients sho are interested in getting the latest mutations, but
do not want to have to figure out what the latest seqno is by using stats.

Change-Id: I86b6b3cebab46351b41ecdc11194c5b5607a4f28
Reviewed-on: http://review.couchbase.org/38937
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11488 Set the thread local to NULL before logging.

Any memory allocations within logging function, which can be
freed later, should not be accounted in a bucket memory usage.

Change-Id: I0a2e5b5a041e77e25708d57fa29ddfd4accb79c5
Reviewed-on: http://review.couchbase.org/38941
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11488 Set the thread local to NULL before calling thread pool API

Memory allocations and de-allocations inside a global thread pool
API should not be accounted in a bucket memory quota because they
might not be executed in the same bucket context. As a todo task,
we need to keep track of the memory overhead of the global thread
pool separately.

Change-Id: I328dc39c98a23c2e397ccae08b0dc76936d6d2f6
Reviewed-on: http://review.couchbase.org/38942
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11488 Fix to the memory leak in PassiveStream.

Change-Id: I657cc507b9fe86d9a120f6e7e4e35fd80e9de937
Reviewed-on: http://review.couchbase.org/38948
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>