CCBC-368: Bail on bootstrap when the bucket is potentially missing

This will abort the current provider iteration on the list of hosts if
an authentication or HTTP 404 error is encountered _AND_ there is no
prior configuration

Change-Id: Ic2d4c9d0c4d9fb6045583dd6ed05eb273e876f7f
Reviewed-on: http://review.couchbase.org/35979
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-367: Fix missing host for management requests

Change-Id: Iaf6c7ec3fb3d6417b5a91e24fbd3b1246e3654c0
Reviewed-on: http://review.couchbase.org/35981
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-370: Return consistent host/port from lcb_get_host/port

Change-Id: I474616a56639beb70d4105bde4de28748980d7c1
Reviewed-on: http://review.couchbase.org/35980
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-385: Handle CMD_GET_REPLICA in failout_single_request

Change-Id: Ib3833eafa99ba88c027c15cd3554fc583f07e9ae
Reviewed-on: http://review.couchbase.org/36139
Reviewed-by: Yury Alioshinov <haster2010@gmail.com>
Tested-by: Yury Alioshinov <haster2010@gmail.com>
Reviewed-by: Brett Lawson <brett19@gmail.com>
CCBC-384: Don't abort on unrecognized WSA errors

Change-Id: Ic5ca12dc35d337ab9fde176bc13ccb69034ca143
Reviewed-on: http://review.couchbase.org/36140
Reviewed-by: Yury Alioshinov <haster2010@gmail.com>
Tested-by: Yury Alioshinov <haster2010@gmail.com>
Reviewed-by: Brett Lawson <brett19@gmail.com>
Allow to reinitialize the providers

Change-Id: I6ad4e1d7a30af8360a4b90f4a4ecaca809fd186b
Reviewed-on: http://review.couchbase.org/35248
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
init_providers: disable providers not explicitly active

Change-Id: I8cccb1beaa03f4c4a48c536c34502c5afcf99d29
Reviewed-on: http://review.couchbase.org/35249
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-389: Disarm timeout when no commands remain

Also:
- Make purge_single_server return the number of items purged
- Don't refresh bootstrap count unless something has actually failed
- Fixup log messages so users don't get alarmed. The invocation of the
  timeout callback itself is perfectly normal (and is more efficient
  than constantly rescheduling)

Change-Id: Ie52d18201711ce3b74f09b75fceb9706088450b6
Reviewed-on: http://review.couchbase.org/36242
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Brett Lawson <brett19@gmail.com>
CCBC-376: cJSON: fix memleak

Change-Id: I2ce43a4c21a865669008f6c1a609fec9c55f2d76
Reviewed-on: http://review.couchbase.org/36081
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
(cherry picked from commit 77a1140c229397cb125b87798cf98feb7086fed6)
Reviewed-on: http://review.couchbase.org/36235
libvbucket: parse 'rev' field

This adds a vbucket_config_get_revision() field which returns the
revision ID (if parsed) or -1 (if not found).

Change-Id: I1de653cf4823db0f914eee4964d003c0da4eb80e
Reviewed-on: http://review.couchbase.org/36301
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Brett Lawson <brett19@gmail.com>
CCBC-332: Use revids when comparing configs

Change-Id: I4df5a5e40f6b7765d3842f072a48427561f05f48
Reviewed-on: http://review.couchbase.org/36302
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-395: Provide lcb_cntl() API for configuration cache

Change-Id: Ib11a79e73c28b0387dde2f94092c3bc1c23269b4
Reviewed-on: http://review.couchbase.org/36330
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Brett Lawson <brett19@gmail.com>
CCBC-394: Check ringbuffer on server_start_packet_ex

Change-Id: If979226c3cdd2997ef56609ef7976968fef45bc8
Reviewed-on: http://review.couchbase.org/36525
Reviewed-by: Yury Alioshinov <haster2010@gmail.com>
Tested-by: Yury Alioshinov <haster2010@gmail.com>
Reviewed-by: Brett Lawson <brett19@gmail.com>
CCBC-392: Fix binary incompatibilities with lcb_create_compat

This changeset attempts to alleviate some of the issues experienced by
adding a new field to lcb_create_st. These steps were taken

- Use preprocessor indirection to use a new symbol for future versions.
  Future in-source references to lcb_create_compat will actually forward
  to lcb__create_compat_230 which employs a new structure layout.

- Old 'lcb_create_compat' symbol exists in the source code file only,
  but is not inside the header. Thus older applications which relied on
  the older structure shall be directed to lcb_create_compat()

- The special exception is 2.3.0 which uses the larger structure but
  with an alternate layout. In this case the library tries to perform
  some heuristics to determine the version

- As a limitation, a configuration cache filename cannot be NULL. This
  should not affect any SDKs, but is easily fixable at the user level by
  simply providing a path for the file.

- The lcb_cached_config_st structure has been reordered so that the
  filename starts first and the trailer portion of the structure becomes
  the creation options. This allows more fields to be added to the
  'lcb_create_st' field without bringing about a scenario like this
  again.

Change-Id: Ib4b5b1611a9bf588875b448f7128be97ed4e158c
Reviewed-on: http://review.couchbase.org/36559
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Update documentation for 2.3.0/2.3.1 added fields

Change-Id: Iac660ec5fa63a5085c4febb8b34e96ec688594a8
Reviewed-on: http://review.couchbase.org/36582
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-404: Don't use lcb_list_delete to remove cinfo

If the conninfo structure is in idle state, use
clist_delete so that the ll_idle count will also be decremented.

Change-Id: Idb4f0ea3da332fa3854834ee54e4975b7b1af3c5
Reviewed-on: http://review.couchbase.org/36601
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Dave Rigby <daver@couchbase.com>
CCBC-407: Increase performance on select

- fd_set is itself a bit array. Do not allocate an array of these
- select should use the maximum fd +1 as its first argument, not
  FD_SETSIZE

Change-Id: Id1d8fc199b15eba5ffe720cf483fb9a748b6e21b
Reviewed-on: http://review.couchbase.org/36758
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Brett Lawson <brett19@gmail.com>
Update release metadata for 2.3.1

Change-Id: I369011039658abfee3e2203080ae2bc37bd95970
Reviewed-on: http://review.couchbase.org/36856
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-414: Assign cccp cookie when sending over server struct

We never assigned to cccp->cmdcookie

Change-Id: Ibfaaf2f6c590d1af684c83d29bc461122ffe741d
Reviewed-on: http://review.couchbase.org/37321
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Brett Lawson <brett19@gmail.com>
CCBC-420: vbucket: don't remap to soon-to-be-removed nodes

See the bug and the linked MB issue for more details. In summary, during
a rebalance-out where nodes are being removed, the node's memcached
process will remain active accepting connections and commands but
responding to them with not-my-vbucket replies. The goal for this grace
period is to allow for a graceful remapping of items to the new master
node.

This behavior itself relies on the fact that the given node shall only
respond for _existing_ commands mapped to it before (or around) the
start of the grace period, but that no _new_ commands should be sent to
it during said period.

The means to determine if a node is in such a "Eject Wait" state (as
I'll call it here) is to check whether it has any vbuckets assigned to
it. If the node has no vbuckets assigned to its index then we should
assume that it will soon disappear. Implemented here, the number of
vbuckets a node is assigned to is the sum total of any vbucket in both
the vBucketMap and the vBucketMapForward arrays which contains the index
of the given node in its list.

The found_incorrect_master() function's purpose is to pick a node at
random (or slightly more predictable than 'random') where a command
should be forwarded to assuming that the current mapped node returns a
not-my-vbucket. In this commit I've tried to ensure that the new node
should only be one which retains vbuckets.

Change-Id: Ib8017ea07a38c2479deebcb532af131ec2150942
Reviewed-on: http://review.couchbase.org/37322
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Brett Lawson <brett19@gmail.com>