CCBC-278: Use common config retry mechanism for bad configcache

- This uses the same error handling mechanism as when
  a bad configuration has been received from the network

- New LCB_CONFIG_CACHE_INVALID error code to notify the user of such a
  situation

Change-Id: Iecda5d4b2d4650613046ac82f6587fa8b65bedfb
Reviewed-on: http://review.couchbase.org/29454
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Use constant macro for config cache 'magic trailer'

Change-Id: I76c5d25f95006b61bd96dbe7f6de757506e1c6e6
Reviewed-on: http://review.couchbase.org/29456
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-205: Stricter/More inspectable behavior for config cache

This provides a test and an additional lcb_cntl operation to check the
status of the configuration cache. Currently this is a boolean value. In
the case where a more complex status may be desired, a new lcb_cntl
command may be added.

Change-Id: I4d40d29363ee530438c9309aef9cdcbf99589d10
Reviewed-on: http://review.couchbase.org/29457
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Fixup cmake build

Change-Id: Ia63d702015fe58226cfe32afb24690cc52ba870c
Reviewed-on: http://review.couchbase.org/29632
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-283 Apply key prefix in cbc-pillowfight

Change-Id: I0309fbd548ac3f94c4f9a750c63d547770c4ef4a
Reviewed-on: http://review.couchbase.org/29626
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
Comment on buffer/packet relocation

Change-Id: Ic19065b5c43fb7074fc261365b5930103f3b9243
Reviewed-on: http://review.couchbase.org/29610
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Use temporary filename for configcache tests

If tests are run in parallel, there may be a race condition between two
instances.

Change-Id: I8f1e452588fd27f57ec2a40912f2907a42ea52d0
Reviewed-on: http://review.couchbase.org/29611
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-282: Make server buffers reentrant-safe

When purging implicit commands, we invoke callbacks which may in turn
cause other LCB entry points to be invoked which can shift the contents
and/or positions of the ringbuffers we're reading from. This patch is an
attempt at making an (efficient) copy of the necessary data so that we
can safely invoke callbacks without worrying about reentrancy issues.

Change-Id: Id844fbe5c237ec5851cfb4f62ed47f7a0f2c159d
Reviewed-on: http://review.couchbase.org/29608
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-279: lcb_wait() should always return success

Change-Id: I7d09a982c8a17efffcb618dc2e9704bb287ad5f1
Reviewed-on: http://review.couchbase.org/29458
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reset the server's buffers upon reconnection

This fixes a crash experienced when requesting a new read with the
previous buffer still in tact.

This was exposed by calling lcb_failout_server on a timeout error while
maintaining the same server struct. This path is only followed for
failed negotiations but is the only time in code where we re-create the
socket.

Change-Id: Iedaed57ddf689189cc597eea29165d861ed14c97
Reviewed-on: http://review.couchbase.org/29681
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-275: Do a full purge when negotiation times out

In this case we must purge the server from all commands and not simply
pop individual items. This is because we get odd behavior otherwise.

Added is a test developed with sweat and blood that reproduces the old
behavior where the client would crash.

Change-Id: Ib2c3724fde22d60388e0985a109aed8d66da9a51
Reviewed-on: http://review.couchbase.org/29671
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-243 Substitute isasl with cbsasl

cbsasl has implemented both PLAIN and CRAM-MD5 authentication
mechanisms

Change-Id: I7fcb19a59951a65f363bc66bd0375c67c2a0d468
Reviewed-on: http://review.couchbase.org/29627
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
CCBC-243 Handle SASL STEP and LIST_MECHS commands

CRAM-MD5 mechanism requires handlers for PROTOCOL_BINARY_CMD_SASL_STEP
and PROTOCOL_BINARY_CMD_SASL_LIST_MECHS

Change-Id: I117d751cff2b5ddf09f9a08d82b868a7b91e785a
Reviewed-on: http://review.couchbase.org/29628
Reviewed-by: Mark Nunberg <mnunberg@haskalah.org>
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
bconf_provider: Skip all SASL commands on relocation

Change-Id: Id9ed94103945400314acbd33d1100ef8fb3a49c9
Reviewed-on: http://review.couchbase.org/29683
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
wait: return last_error iff not yet configured

Realized this when my Python tests started failing

Change-Id: I6bc6841d97af8e2ebc74b29de661be3c9ed53ba9
Reviewed-on: http://review.couchbase.org/29693
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
testutil: Common callback handling

Change-Id: I164a05aff4e8239be8c301b14648307648cf0634
Reviewed-on: http://review.couchbase.org/29685
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reset SASL info when failing out the server

Otheriwse, SASL is never retried on the next attempt

Change-Id: I9176aae87b922335f7190cf451b2cb6c28a55810
Reviewed-on: http://review.couchbase.org/29686
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
CCBC-284: compute item size correctly during set

If minSize and maxSize are set to the same value
cbc-pillowfight can sometimes crash since it may try to read
out of memory bounds from the allocated data buffer.

Avoid that crash by correcting item size to be within maxSize
Change-Id: Ica6d598f66eb3e4b696cef9ac384fa5d9362a5ed
Reviewed-on: http://review.couchbase.org/29724
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Check subsequent functionality in CCBC-275 test

Previously it was mistakenly assumed that the reason for not checking
the return code of operations which were to succeed was because of
issues in the Mock. in fact this is because the SASL context has not
actually been reset in lcb_failout_server

Change-Id: I0af4ae7e850c6f41c582d8f297d43ec188412527
Reviewed-on: http://review.couchbase.org/29690
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Add SASL related info to lcb_cntl

This creates a new version of MEMDNODE_INFO which returns the effective
SASL method, as well as a FORCE_SASL_MECH command which will fail the
server if it cannot utilize the user-defined auth method

Change-Id: I292218164cc5482ebb45e791f2c710b50a78b312
Reviewed-on: http://review.couchbase.org/29688
Tested-by: Mark Nunberg <mnunberg@haskalah.org>
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>