Fix for occasional eacces error on windows.

For reasons unknown, opening a file on windows sometimes returns
{error, eacces}. Fix by retrying open for a maximum of 10 seconds.
Max retry time now also applies to emfile errors.

Change-Id: I915416a2512def52ecbc615c058deff7e630922f
Reviewed-on: http://review.couchbase.org/14085
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Merge branch 'branch-20dp4'

* branch-20dp4:
  Fix for occasional eacces error on windows.

Change-Id: Ic179c23ae249a09cce7bd40aefbf0419c2cc40bb
Set index fd to read mode only on group shutdown

It's possible that the group shutdowns while there are still
clients streaming the view (keeping the fd ref counter > 0) and
that when it's open again, these clients are still folding the
index - this prevents the view group to open the file again.
Closes MB-4869.

Change-Id: I726d11c9642b9c5581e6d3e5acca0aa2f37a3e8b
Reviewed-on: http://review.couchbase.org/13992
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Ensure right cleanup bitmask when updater is stopped

Issue MB-4900.

Change-Id: I41caca9cef145a676fa6747e347977c5fd1d547c
Reviewed-on: http://review.couchbase.org/13991
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
MB-4523 - CURL/ICU_CONFIG overridability during configure

Originally from Xinchen Hui.

Change-Id: If9ff42bbdd9c57f3aab5971b1c811f6455978ebf
Reviewed-on: http://review.couchbase.org/14172
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: buildbot <build@couchbase.com>
Don't delete index file on POSIX error emfile

If we can't open the file because too many file descriptors
are open, just log an explicit message error and don't delete
the index file.

Change-Id: I0021fd83c67e854705da9842fc7ca40d90d8acd4
Reviewed-on: http://review.couchbase.org/14352
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Account for whitespaces in couch_doc:to_raw_json_binary/2

Change-Id: I32bcf3aaf13b5188afb39dd8cd191f68d01ac603
Reviewed-on: http://review.couchbase.org/14359
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Add MapReduce subsystem implemented as an Erlang NIF

It uses Google's V8 JavaScript engine for executing the
map and reduce functions.

Change-Id: I982c2f37ddf499daaa690e76e7435f3e852ab62a
Reviewed-on: http://review.couchbase.org/13831
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>
Make set view component use the V8 based MapReduce subsystem

Change-Id: I90b26eeb78f50a6bac4f71e7ff90cbe0e92b8f42
Reviewed-on: http://review.couchbase.org/13857
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>
Add preemption to MapReduce component

This ensures that functions that take too long, or just go
into an infinite loop, are stopped after some defined elapsed
period of time (defaults to 5 seconds). If their execution
is not stopped, an Erlang scheduler thread is kept executing
that bad JavaScript function forever (or too long).

Change-Id: I62340ab912561303cddf75855e23b6d32096bf47
Reviewed-on: http://review.couchbase.org/14028
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>
Use new MapReduce component everywhere

This removes the need for CouchJS, and therefore to link against
Spidermonkey, to use plain old couch views and for rereducing
values when doing view merging.

Change-Id: I9d1f4d749d490ac3fd33db4d74b9e5e69b6908c1
Reviewed-on: http://review.couchbase.org/14112
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>
Allow CouchDB to build without libv8

By passing --disable-v8 to the configure script, one doesn't
need to have the V8 library installed in order to build CouchDB.
However views won't work without V8.

Change-Id: I254f2a180712e24f72761204ddb3d7ec0d8bf354
Reviewed-on: http://review.couchbase.org/14153
Reviewed-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Damien Katz <damien@couchbase.com>
Add more parallelism to set view updater

By using a smaller minimum batch size/count for the writer than
the work queues batch size/item count, we achieve more parallelism
which reduces the index build/update time.

Change-Id: I0497a3b43875516bf2c97968bf6299c52d261cb3
Reviewed-on: http://review.couchbase.org/14369
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reset replica index file when main index file is reset

When starting the main index group, if its file is reset,
do a reset as well of the replica index file to ensure
there's no state mismatch between both indexes.

Change-Id: I0ceb62c6a619da0ab95f7f61073b5f52a82f027a
Reviewed-on: http://review.couchbase.org/14353
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Handle deletedness during raw json creation

The deletedness attribute was not being encoded during conversion from
document to raw json. Discovered during xdcr testing.

Change-Id: Ibbb194a1807c0f16cf88fdf0662ef76d205514ce
Reviewed-on: http://review.couchbase.org/14375
Tested-by: Srinivas Vadlamani <srinivas@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Set call timeout to infinity

Change-Id: Ie19d827d085230c3b46801805a4ad98653718251
Reviewed-on: http://review.couchbase.org/14378
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
More explicit error messages when view is missing

If a view definition is missing in a design document, throw a much
more explicit and user friendly error message.
Motivated by MB-4982.

Change-Id: I3ee4d49310c768da039025e2257b0c307dca4e8c
Reviewed-on: http://review.couchbase.org/14415
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Prevent memory leak on reduce with multiple functions

If jsonStringify throws an exception (std::bad_alloc or a V8
value) release the memory allocated for all previously computed
results and rethrow the exception.

Change-Id: Ie267e4a47f7fb535b67839429ee8b5aa73afdf37
Reviewed-on: http://review.couchbase.org/14429
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
New storage file format that uses no erlang terms.

For better integration with Couchstore, the core storage engine
no longer uses Erlang terms for persisting data to disk, but instead
uses a pure binary format that is more easily used non-erlang storage
libraries, so that they no longer have any dependencies on Erlang term
conversion.

Change-Id: I121885b487d71966672a8f2a1e86875effcd3842
Reviewed-on: http://review.couchbase.org/13557
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Damien Katz <damien@couchbase.com>