MB-7275: fix XDCR aggregated stats issue

Today xdcr checkpoints when a new vb replicator starts but we did
not account the commit time into the stats. We also persist incorrect
number of docs checked/written and data replicated into checkpoint
doc. This change-set will fix the two issues above. Need to merge to
2.0.1.

Change-Id: I62e4682871dcfb020dff5e04538be07b911d0a34
Reviewed-on: http://review.couchbase.org/23178
Reviewed-by: Junyi Xie <junyi.couchbase@gmail.com>
Tested-by: Junyi Xie <junyi.couchbase@gmail.com>
MB-100: extracted letrec into misc.erl

Change-Id: If9765885bca09bcf47e0e1d661f6cabb0d35758f
Reviewed-on: http://review.couchbase.org/24064
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7523:ebucketmigrator:added ability to wait for end of backfill

We're spoofing backfill end message flying over tap stream to detect
when backfill is done. It'll be used in later commit to start
backfilling next vbucket as soon as backfilling of current vbucket is
complete.

Change-Id: I840b948c3420e0449a71f9a5f7b4e4f777ab79b5
Reviewed-on: http://review.couchbase.org/24065
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7523: added master events support for backfill ended event

API will be used in next commit. We need ability to trace those
events.

Change-Id: I78a787de0c32d192b58232c22a0d59de8bc1d4f9
Reviewed-on: http://review.couchbase.org/24066
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-7523: start backfill of next vbuckets as soon previous is done

As part of MB-6726 we've implemented ability to serialize just initial
phase of vbucket move where bulk of work is performed by
ep-engine. I.e. it's still not advisable to overload ep-engine with
multiple incoming or outgoing tap backfills. But it's great to have
second phase (mostly indexing) to be parallelized.

But MB-6726 ends that serial phase only when first checkpoint we're
waiting for hits disk on future master. And there's no need for this
to be affected by latency of ram -> disk.

Especially given that due to now famous "fsync" flaw in couchstore
design we see very severe latency between getting data into ram on
destination node and putting it on disk there, particularly when
there's even minimal mutations load during this time. I.e. because
ep-engine flusher has to independently fsync and commit a bunch of
vbuckets, while only one "our" vbucket is what's being waited for.

With that patch we're removing that unneeded latency "dependency", and
I've observed dramatic improvement of rebalance run time under load.

Change-Id: Ib4f52b1def2efceea1cfb41daadcc5cc9750d518
Reviewed-on: http://review.couchbase.org/24067
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Merge remote-tracking branch 'origin/2.0.1'

* origin/2.0.1:
  MB-7523: start backfill of next vbuckets as soon previous is done
  MB-7523: added master events support for backfill ended event
  MB-7523:ebucketmigrator:added ability to wait for end of backfill
  MB-100: extracted letrec into misc.erl
  MB-7275: fix XDCR aggregated stats issue

Change-Id: I2afdd3fc244c3010120d3f52b41f3b2bc1c664e7