MB-7092 Handle not utf8-encoded xdcr errors.

When mochijson encodes strings, it expects them to be already
utf8-encoded.  And if it's not true, it fails with some
bad_utf8_character_code error.  In some cases errors that we get from
xdc_replictaion_sup might contain non-ASCII characters that are not
properly encoded. For example if it's just a pretty-printed stacktrace
referring to some document body.  We'll just keep 7 least signi
significant bits of every character to make it look like proper
ASCII. We don't really care that we'll get some garbage because the
messages are already very far from being human-readable.

Change-Id: I2a5addcb68b95d3176127de98c6311ceee8932be
Reviewed-on: http://review.couchbase.org/22278
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7083: don't block reading upstream tap while silencing it

That seems to be same underlying issue that caused us to introduce
upstream sender.

Apparently memcached is not receiving acks-nacks on receive side of
tap producer when producer is sending batch of messages.

That means if we're blocked sending some nacks to it while it's
blocked on sending us some new tap messages, it's deadlock.

We worked around main reason for this deadlock by independently
sending (and blocking) messages to upstream.

But new-style vbucket filter change code stopped main loop of piping
messages from upstream->downstream, while doing blocking call do
upstream sender to quiesce it. That's same deadlock, but with 3
parties instread of 2.

We discussed various measures, but ended up deciding doing upstream
quiesce-ing asynchronously.

When we have done message from vbucket filter change command, we send
upstream sender silencing request, while continuing our piping
activities, except we cannot send anything to upstream to prevent
losing that data. When upstream sender is done feeding it's stuff to
kernel, it'll send us back confirmation and we'll proceed with our
rest of new-style vbucket filter change.

Similar race in old-style filter change is fixed by shooting upstream
sender instead of silencing it. The idea is that old-style vbucket
filter change doesn't require us to keep all downstream-to-upstream
messages. And that's because in old-style filter change upstream's tap
producer is going to die anyways.

Change-Id: I05abd161db13f7412da2748881cb843e54c82d6d
Reviewed-on: http://review.couchbase.org/22249
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-6766: handle aggregated XDCR stats in dest topology change

XDCR stats (docs_checked/written, data_replicated) should be able to
account all work we have done and all cost we have paid, which should
never decrease in any case. Today during in dest topology change, we
terminate old vb replicator process, create a new one and restart XDC
replication from scratch, this will cause stats retreat. As a result,
the aggregated stats on UI may drop down. This change-set makes stats
docs_checked, docs_written and data_replicated as accumulated stats
aggregated at bucket replicator.

Change-Id: Ib7c1c5231c872e45c4b7a3fa33b64bcb5deecb0a
Reviewed-on: http://review.couchbase.org/21358
Reviewed-by: Junyi Xie <junyi.couchbase@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Junyi Xie <junyi.couchbase@gmail.com>
Tested-by: Ketaki Gangal <ketakigangal@gmail.com>
MB-7096: Hibernate XDCR vbucket replicators when idle

This will reduce memory consumed  for long running, heavily loaded servers
and prevent swapping and out of memory crashes.

Change-Id: I98ffb1f285551978091659308571573154806ed2
Reviewed-on: http://review.couchbase.org/22290
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Junyi Xie <junyi.couchbase@gmail.com>
Reviewed-by: Farshid Ghods <farshid@couchbase.com>
Tested-by: Farshid Ghods <farshid@couchbase.com>
MB-7104: account failed checkpoints stats correctly

The current code incorrectly computes the failed XDCR checkpoints
and in some cases, the stat on UI is always 0 and does not show
the real number of failed checkpoints. This change-set will fix
this issue.

Change-Id: Iad48dbeb3238675263cd816e9299c0cb7e369a50
Reviewed-on: http://review.couchbase.org/22297
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Junyi Xie <junyi.couchbase@gmail.com>
Tested-by: Junyi Xie <junyi.couchbase@gmail.com>
MB-7085: update vbucket map for new bucket's vbucket maps

When vbucket map is generated or inferred from vbucket files we need
to add it to vbucket map history.

That's same fix as was made in:
ca70cf68949ba552ce56a6229098906d56d9fa69 but lost in 2.0 janitor
refactoring.

Change-Id: I5af7fd195cf39627b3d61285b8bd9356183d0c2d
Reviewed-on: http://review.couchbase.org/22288
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-7124: Don't capitalize doc id in view sample document window

[alk@tut.by: html-fuly upcased some previously css-fuly upcased text]
Change-Id: Iebecbced1508864a51ac94d8b507c065bb564b86
Signed-off-by: Aliaksey Kandratsenka <alk@tut.by>
Reviewed-on: http://review.couchbase.org/22366
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7108: send downstream confirmation request async

So that we can concurrently read stuff from downstream and avoid
potential deadlock with downstream memcached.

Otherwise it's possible that memcached would try so send us a bunch of
nacks while not reading more stuff. And that could cause gen_tcp:send
to be stuck, while memcached side is 'stuck' sending us stuff. Which
is obvious deadlock.

I.e. see MB-7083 for description of similar potential deadlock.

Change-Id: I02c34088e7d3614cb9bf57fe9dbabbf22f20c924
Reviewed-on: http://review.couchbase.org/22383
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-7128: bumped all memcached-related timeouts 3x

Change-Id: I34af670a12a4d3ad94f28519e7e09b90155b40b0
Reviewed-on: http://review.couchbase.org/22384
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-7123: send stale=false by default for dev index queries

Change-Id: I8e129abe54500c9624156a29a03a238f8e4b648a
Reviewed-on: http://review.couchbase.org/22385
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-7135: Add more stats from memcached

Change-Id: Ia8d959573df1704fe152895a6abcc8ea4b2c46ca
Reviewed-on: http://review.couchbase.org/22405
Tested-by: Bin Cui <bin.cui@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7132: change XDCR stats name from docs to mutations

Today the word "docs" in outbound XDCR stats section indeed refers
to the number of mutations. Say, if one docusments is updated twice,
we will see 2 "docs to replicate" in the stats section. This is a bit
misleading since there is only 1 doc created in system. We now use
"mutations to replicate" which looks better than "docs to replicate".

Change-Id: Ia1b13e8f76cfc2727e9d73b3ae8e40707b5059e5
Reviewed-on: http://review.couchbase.org/22381
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7145: improve capi_replication logs

We make capi_replication logs more informative and add some timing
info in the log.

Change-Id: Ica6b5406c33de833f35f7dd97109d335db8eca2e
Reviewed-on: http://review.couchbase.org/22411
Reviewed-by: Farshid Ghods <farshid@couchbase.com>
Tested-by: Farshid Ghods <farshid@couchbase.com>
MB-7145: improve XDCR logs

Change-Id: I907794180e6ea0ce662fe6bc20be5e3fb6cc9eb6
Reviewed-on: http://review.couchbase.org/22456
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>
MB-7133: make XDCR parameters from ns_config

This change will increase the http connection timeout to 60 seconds,
and shrink the batch size from 500 to 100. The new env parameters
are introduced:
	 1) "XDCR_WORKER_BATCH_SIZE" (default: 100)
	 2) "XDCR_CONNECTION_TIMEOUT" (default: 60)
	 3) "XDCR_NUM_HTTP_CONNECTIONS" (default: 20)
	 4) "XDCR_NUM_RETRIES_PER_REQUEST" (default: 2)
	 5) "XDCR_NUM_WORKER_PROCESS" (default: 4)

Change-Id: I58325f9f8494e0b1dbf4d8de5ccf9832f2359a15
Reviewed-on: http://review.couchbase.org/22460
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>
MB-7133: revert batch size to 500 and make longer timeout

This change-set will revert the batch size to 500 and make the HTTP
timeout 180 seconds. We will see if there is any perf regression
on these parameters.

Change-Id: I7058f2d7f4272c1856d3374ab5177f685bd5afe8
Reviewed-on: http://review.couchbase.org/22497
Reviewed-by: Farshid Ghods <farshid@couchbase.com>
Tested-by: Farshid Ghods <farshid@couchbase.com>
MB-7175 auth_check_bucket_uuid checks REST credentials correctly.

Change-Id: Iaed7b877dba17375ede44bec28d0b3f72c02f92f
Reviewed-on: http://review.couchbase.org/22534
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7141: include stats log to /diag output

By simple mistake /diag output actually lacked stats logs.

Change-Id: Idf60e1de0ebcaaf66246ff52485639b030c6e217
Reviewed-on: http://review.couchbase.org/22522
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-7143: close /sasl_logs http response

Change-Id: I5c7918c908203ce036d533292cb148dc80943728
Reviewed-on: http://review.couchbase.org/22523
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
MB-100: avoid unexpected EXIT messages from arm_timeout

Change-Id: I4a711a35855f8239bcbcc744b8eca5dacebf0d34
Reviewed-on: http://review.couchbase.org/22524
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>