Truncate last unaligned bytes of access log

Truncating unaligned bytes of access log allows use of access log
even if last bytes are unaligned to blocksize.
Avoid throwing a ShortReadException which just disables the access log
Change-Id: I6e82fb0aa4b62e892e092c98654df71bee3f16d6
Reviewed-on: http://review.couchbase.org/36995
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
MB-11280 Fix Upr flow control msg parsing

Make sure value is a null-terminated string before converting.

Change-Id: I6528b548fb837d1974e296fc5e7fb84993acca7d
Reviewed-on: http://review.couchbase.org/37795
Tested-by: David Liao <david.liao@couchbase.com>
Reviewed-by: Tommie McAfee <tommie@couchbase.com>
Tested-by: Tommie McAfee <tommie@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
MB-11279: Fix incorrectly set cursor offset.

The offset should be the amount of items we skipped in the
checkpoint queues. Incorrectly setting the offset can lead to
stats inconsistencies when getting estimates on the number of
checkpoint items.

Change-Id: Ic5acf24425c310bd039625f73420cbf5922d8564
Reviewed-on: http://review.couchbase.org/37808
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11267: Change total_unacked_bytes to unacked_bytes

When we use the word total we are giving off the impression that
this is a cumulative stat and it is not.

Change-Id: Ie8b275319181f7010ed6e1ca4b091387d848df2a
Reviewed-on: http://review.couchbase.org/37853
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Add a virtual destructor for the Notifiable class

Classes with virtual functions should also have a virtual
destructor.

Change-Id: I1dfc948000f51d6ac61ad86b673410ee15cedeca
Reviewed-on: http://review.couchbase.org/37862
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11287 move taskLogs to threads, lessen locking

This fix is meant to both reduce CPU and memory usage when
there are a large number of buckets by moving non-essential
task logging to ExecutorThread to avoid lock contention in
TaskQueue mutex

Change-Id: I8c82db1fb333febcead7e981e1dcffef3ce0b0a2
Reviewed-on: http://review.couchbase.org/37881
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Remove unneccesssary checks for valid opaque

We do the same check that validateOpaue does right after this and
there is no need to do it twice.

Change-Id: If45cd12bf78b4a0490da001d432882f63c30e7e3
Reviewed-on: http://review.couchbase.org/37917
Reviewed-by: Sriram Ganesan <sriram@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Change the flow control buffer to 10MB

The original size of 2MB is too small and causes rebalanace to
become slow. We should increase the buffer to 10MB by default
in order to speed things up. Note that the amount of consumer
connections on a node will be small so this should be okay.

Change-Id: I2804f122dc5b39b0d0229aa8dc87964d711e96b4
Reviewed-on: http://review.couchbase.org/37919
Reviewed-by: David Liao <david.liao@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11287 Fix flusher,Conn notifier minSleepTime to save CPU

FlusherTask and connnotifyTask's minSleep time was set to 1.0s
With large number of buckets, this value gets averaged out to
sub-millisecond range causing all the threads to busy loop
Fix up their values to have exponential sleep upto MIN_SLEEP_TIME
for connotifyTask and 10seconds for flusher (we have a wake() method anyway)

Change-Id: Id557a38886e3af5fcce010a012c087f2e94ce337
Reviewed-on: http://review.couchbase.org/37928
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
use snooze directly in upr-consumer to avoid locking overhead

Change-Id: I01993956af864e6047f7503daea8e512f05ee44e
Reviewed-on: http://review.couchbase.org/37931
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
MB-11333: Snapshot marker should account for the extras section

We recently added an extras section to the snapshot marker and need
to account for it when doing flow control.

Change-Id: I17c8122f87d0b63da15e8f5f28c21e9ae494d081
Reviewed-on: http://review.couchbase.org/37932
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
When there are errors we still need to update flow control freed bytes

If an upr message cannot be processed due to an error we still need
to account for it as freed bytes.

Change-Id: I394b77b35dce1013618f83bcc6a02bb8fb4c7af1
Reviewed-on: http://review.couchbase.org/37918
Tested-by: Michael Wiederhold <mike@couchbase.com>
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Handle unacked bytes when closing a stream

Whn we close a streamt here may be some items that we weren't able
to process. We need to make sure that these items are accounted for
in free bytes so that flow control doesn't get out of sync.

Change-Id: I7b220cc574599c856aa040030c77ef442a4c922a
Reviewed-on: http://review.couchbase.org/37920
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11298: Allow upr to send bytes past the buffer threshold

If we have an item that is larger than the buffer size specified by
the client then in the current code we must wait for the buffer to
drain before we send that item. This makes it difficult for a client
to control when to send a buffer ack because if we have a really small
item followed by a really big item then the consumer might wait for
the producer to send more items and the producer will wait for the
consumer to ack what it has leading to a deadlock.

Change-Id: I4d1931ad8a259fee425efe44b8349901e9915cda
Reviewed-on: http://review.couchbase.org/37921
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Fix memory leak in passive stream

Once an UprResponse is passed to the PassiveStream it needs to take
care of deleting it once the item is processed. Note that we do not
have to include this in PassiveStream item or bytes count because
errors are taken care of by the UprConsumer.

Change-Id: I79914f0480b50664f1654259e8484924af5a6572
Reviewed-on: http://review.couchbase.org/37967
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11342: Check if the stream is dead before inserting an item

There is a race condition where an item can be added into a
PassiveStream even after the stream has been set to dead. This can
happen because we do not hold a lock when getting a stream in the
UprConsumer.

Change-Id: Ib557020873d4ce51b9994b002689408010571689
Reviewed-on: http://review.couchbase.org/37968
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11342: Make all PasiveStreams dead before deleting an UprConsumer

Since we check that the flow control buffers are cleared before we
delete a PassiveStream we need to set the streams to dead before we
delete them.

Change-Id: I69926268c1f823764f32c9b0b3c4a9ba73c3564d
Reviewed-on: http://review.couchbase.org/37969
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Fix occasional parallel make failures.

ep_engine.h includes generated_configuration.h (via
configuration.h). So every target that builds something that uses
ep_engine.h must also depend on ${CONFIG_SOURCE}.

Change-Id: Id5299324ae4c3fc764c10b0785b33ac132dad71b
Reviewed-on: http://review.couchbase.org/37974
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Chris Hillery <ceej@couchbase.com>
MB-11287 use less stringent memory_order for TaskQueue lock

The default memory_order for the atomic variable isLock in
TaskQueue is sequential ordering which imposes severe CPU
fence and results in high CPU usage on machines with many cores.

The acquire-release ordering should offer a balanced mix of
ordering and performance for this use-case.
http://en.cppreference.com/w/cpp/atomic/memory_order

Change-Id: Ida12cfaf428b725f5a960f4f34e527f548e01c91
Reviewed-on: http://review.couchbase.org/37976
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung@couchbase.com>
Cleanup the BufferLog when deleting an UprProducer

Change-Id: I4aab61c5133a7b5fe77e5575d4ca65964d918d75
Reviewed-on: http://review.couchbase.org/37975
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>