MB-6490 Add missing checks to state transition requests

It's possible the requested state transition will only toggle
partitions states between the active and passive sets in the
pending transition.

Change-Id: I7542b1b1d0f0a5f2dc5e31202a0473d3318e7086
Reviewed-on: http://review.couchbase.org/21347
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
MB-6807 Account for exception stringification failure

If stringification of a V8 exception fails, it returns a
NULL pointer, which causes a segmentation fault when it's
used as the parameter for std::string's constructor.

Change-Id: Ibf3d7d84f5eac9b436412608a15acf7b528ce2f8
Reviewed-on: http://review.couchbase.org/21365
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
MB-6807 Fix some harmless warnings

Comparisons between signed and unsigned integers. Harmless
in this context as there can never be more than 256 map
functions (views) per design document.

Change-Id: Ia3fef7e4c5d867e8aed16937788b0d8422feca7a
Reviewed-on: http://review.couchbase.org/21366
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
MB-6805 Notify update listeners of index updater error

It's possible that several classes of errors prevent the
indexer from progressing (like failures opening database
files for example), which means it blocks update listeners
forever, and this prevents rebalance from progressing.
For this scenarios just send an error message to the
update listeners, so that rebalance doesn't get blocked
forever.

Change-Id: I3c97296d4a06c698917b085b713c547649f18563
Reviewed-on: http://review.couchbase.org/21382
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
MB-6773 Follow new JSON rules

 * There are no longer reserved field prefixes.
 * We allow any JSON value, not just arrays or objects.

from_binary is also used mostly by the CAPI layer, in order to get a doc
record from a ID/Body pair, and should not bother compressing docs, as
they will immediately be decompressed anyway.

Change-Id: Ib1d1dbeffd0d05cd91c86078ec84cbd4410b05dc
Reviewed-on: http://review.couchbase.org/21324
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Aaron Miller <apage43@ninjawhale.com>
Don't release binary after it's transferred to a term

If compression is successful, the binary containing the
compressed content is transferred to an Erlang term.
Yet, the destructor of the compression sink class will
release the binary - while this doesn't seem to cause
any problem, the OTP man pages don't mention if it's safe
to release a binary that was transferred to an Erlang term.
All the OTP man pages say is that a binary is freed by
either calling enif_release_binary or enif_make_binary,
giving the idea they are mutually exclusive operations.

Change-Id: I341f685973031ae13b71daacd3febaf358c2f3be
Reviewed-on: http://review.couchbase.org/21339
Reviewed-by: Aaron Miller <apage43@ninjawhale.com>
Tested-by: Aaron Miller <apage43@ninjawhale.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Don't allocate binary buffer with 0 bytes

For the standard C library, the behaviour of calling malloc
to allocate a bufer with 0 bytes is implementation specific.
Some implementations return a valid pointer while others
return a NULL pointer.

It's not clear if the same problem can happen directly with
enif_alloc_binary(), or if its implementation can result in
an malloc call for 0 bytes.

Nevertheless it's safer to start with an initial binary buffer
size greater than zero.

Change-Id: I282d4fab6d86be478d0cd5233c433e4b25b6e5eb
Reviewed-on: http://review.couchbase.org/21340
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-6860 Release index file ref counter

After serving a query through the optimized path, release
the index ref counter, so that after compaction the file is
effectively deleted by the OS.

Change-Id: Iff956a0ee38ccfbe4fcf3d5edfddde1fee06cfc2
Reviewed-on: http://review.couchbase.org/21468
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>