MB-4903 Try not to take mastership over if rebalance is running.

Change-Id: I56729dba8801eeb2bf1abdf9b2fc416ff7e875d6
Reviewed-on: http://review.couchbase.org/14487
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Use less confusing name for maybe_stop_replication_status.

Change-Id: Id9f424558ec80f9ca1623b244bbf0c51970d7d9c
Reviewed-on: http://review.couchbase.org/14488
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Log error if something fails in ns_config:update_with_changes.

This function is used throughout the ns_config.erl. And shamefully in
many places we just ignore return values of ns_config functions
leaving the room for silent config update errors. So from we'll at
least have an error in log file.

Change-Id: I78ed84cf24c90f7d55368f3d80b3abdbe3413a5d
Reviewed-on: http://review.couchbase.org/14489
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-4963 Don't report rebalance as failed if it's stopped by user.

Change-Id: Ic891f0d15a51edd050351b859f9119c6d7452dcd
Reviewed-on: http://review.couchbase.org/14490
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Store rebalancer PID in config.MB-5020

Change-Id: I2711826f1fe5e97f6aa6c17db055ff805446f29d
[alk@tut.by: added reference to MB- ticket]
Signed-off-by: Aliaksey Kandratsenka <alk@tut.by>
Reviewed-on: http://review.couchbase.org/14491
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Drop rebalance status even when rebalance isn't running.MB-5020

So that if for some reason we got stale {rebalance_status,running} in
the config, it would be dropped when user requests rebalance to stop.

Change-Id: I09f9f87994dd490acd557220fac515c89ef1d5f8
[alk@tut.by: added reference to MB- ticket]
Signed-off-by: Aliaksey Kandratsenka <alk@tut.by>
Reviewed-on: http://review.couchbase.org/14492
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Add stopRebalanceIsSafe to pool details.MB-5020

Corresponding value indicates if stopping rebalance is considered safe
at this particular moment of time.

Change-Id: I953aec1ec749ab0a1f6a073444acdb46695b3631
[alk@tut.by: added reference to MB- ticket]
Signed-off-by: Aliaksey Kandratsenka <alk@tut.by>
Reviewed-on: http://review.couchbase.org/14493
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Warn user on unsafe rebalance stop attempt.MB-5020

Change-Id: I24548e8f11475cbc2d572601449cf3fecc02ff05
[alk@tut.by: added reference to MB- ticket]
Signed-off-by: Aliaksey Kandratsenka <alk@tut.by>
Reviewed-on: http://review.couchbase.org/14494
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-4893 Don't hang forever in ns_memcached:init.

If for some reason ns_memcached is not able to connect to memcached it
will try doing this forever. And since this happens in init callback,
it will block parent supervisor. Thus it makes it impossible to
terminate the parent in a graceful way.

Change-Id: If6b7536e70852ddd226410320e7d1957d3dc9dcc
Reviewed-on: http://review.couchbase.org/14496
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Constrain vb map history the same way in all the cases.

Vbucket map history constructed during config upgrade now won't
contain duplicate items. And it won't longer than ?VBMAP_HISTORY_SIZE.

Change-Id: I3987232cd9cd5028ed431dd0c6da03c5c14d5ed1
Reviewed-on: http://review.couchbase.org/14516
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
MB-4023 Use memcached port dedicated specifically to ns_server.

Change-Id: I3e7b4be666aa21c4ee18d8ae443ac37d05cd42cb
Reviewed-on: http://review.couchbase.org/14517
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Merge remote-tracking branch 'origin/branch-181' into branch-18

* origin/branch-181:
  MB-4023 Use memcached port dedicated specifically to ns_server.
  Constrain vb map history the same way in all the cases.
  MB-4893 Don't hang forever in ns_memcached:init.
  Warn user on unsafe rebalance stop attempt.MB-5020
  Add stopRebalanceIsSafe to pool details.MB-5020
  Drop rebalance status even when rebalance isn't running.MB-5020
  Store rebalancer PID in config.MB-5020
  MB-4963 Don't report rebalance as failed if it's stopped by user.
  Log error if something fails in ns_config:update_with_changes.
  Use less confusing name for maybe_stop_replication_status.
  MB-4903 Try not to take mastership over if rebalance is running.

Change-Id: I2f9c8c8c33a2ce61a0b8d1426717614da9076f36