Merge remote branch 'origin/stuck-continuous-replications' into 1.6.x
Do not skip heartbeats when DB is updated

This patch ensures that we send a heartbeat line in the case of regular
writes to a database, each of which fails the filter condition.
Previously we could go long intervals without sending a heartbeat if the
wait_db_updated/1 function returned 'updated' and all of the updates
failed the filter.  We'd never reach the five second timeout required to
send a heartbeat inside receive_results, and we'd never send a heartbeat
from the 'timeout' clause of the keep_sending_changes function.  These
long intervals would cause a replication to crash.

The patch causes a heartbeat to be sent on every invocation of
wait_db_updated/1.  Big thanks to Paul Davis for deducing the cause of
the timeouts.

BugzID: 12605
Fix bad prepend value caused by timeouts

When timeouts occur receive_results in fabric_view_changes was using the
original returned response from initial start callback rather than the current
value in the accumulator within the state. Thus it lost the comma needed for
prepending in subsequent calls.

BugzID:13131
Backport rexi_DOWN handling from 2.0.4

Also pulls in the catchall clause in remove_ancestors so we don't crash
on unknown replies.

BugzID: 12212
BugzID: 13178
Support stale=update_after in view queries

BugzID: 10941
Honor _rev in linked documents

Cherry-pick of 8a703fae4e0e9fbc9c8a118afd0696e5838394e4

BugzID: 1322

Conflicts:

	src/fabric_view.erl
Handle {not_found, deleted} the same as {not_found, missing}
(cherry picked from commit cbd5c225bb8886a6b907683ff1bcdc69c6e77c14)
Fix callback error handling in fabric:design_docs

fabric_view:remove_down_shards invokes the callback with an error tuple
and expects an ok response, which it returns as an error to the controller.

BugzID:13065
(cherry picked from commit 1feec9731e6377a371668b7993d01b5a241f6ff7)
Change callback fun to return error tuple

and change fabric_view:remove_down_shards to expect an error tuple
rather than ok.

BugzID:13065
(cherry picked from commit 8eca9bb7f6b4384cf7773669ee6e9b2f3dc5ac31)
Fix rexi_EXIT handling for db/group info and doc_count
Merge pull request #35 from cloudant/13178-deploy-fabric2-views

BugzID: 13178
Implement get_all_security

This returns the security objects for all shards of a database. This
will be used by mem3_sync_security to handle synchronizing security
objects.

Conflicts:

	src/fabric_rpc.erl

BugzID: 13044
Port BC 0.4 DB creation/deletion logic
Teach unpack_seqs how to handle BC 0.4 and LC 1.2 style update sequences

BugzID: 13351
Backport unpack_seqs_test
Merge pull request #36 from cloudant/13351-couchdb-1.2-compatibility

13351 couchdb 1.2 compatibility
Export fabric_rpc:get_all_security/2

Accidentally unexported this function in a merge.
Ignore 'complete' messages from suppressed workers

If we have a database where one copy of a partition contributes zero
rows to a reduce view but another copy of the same partition contributes
one or more rows we can end up erroneously removing a worker which has
already contributed a row to a response.  This puts the coordinator into
an inconsistent state and can ultimately cause the response to hang.

The fix is simple -- just guard processing of 'complete' messages by
checking if the worker sending the message has already lost the race to
another copy.

BugzID: 13461
Merge pull request #38 from cloudant/13461-inconsistent-reduce-hang

BugzID: 13461
Make fabric_util:get_db zone aware

Use the new mem3:group_by_proximity method to prefer local, then
zone-local nodes over zone-remote nodes.

BugzID: 13470