MB-9132: Remove "cover" make target

Newer version of Etap don't support creating cover
reports.

I'm not aware that we actually use this make target.

Change-Id: Icb3b363fa8c37819439bf6c3ad4086f204e82c7d
Reviewed-on: http://review.couchbase.org/29024
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9132: Update to newest etap

Apache CouchDB has a more recent version of etap that
contains the fixes that were previously applied to
the Couchbase fork.

The new version is a single module and also compiles well
with Erlang R16.

Having the same single module version as Apache CouchDB
enables GeoCouch to run the same etap tests on both,
Couchbase and Apache CouchDB.

Change-Id: I27cb726240eb91c03fb25032e2ed197494a47ffd
Reviewed-on: http://review.couchbase.org/29025
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9330 Don't send unescaped JSON object keys

Ensure yajl preserves object keys' escaping, otherwise we
are using invalid JSON and sending it to the clients.

Change-Id: I5759943f33a299a572f9057fe13f45e26705fd0e
Reviewed-on: http://review.couchbase.org/29540
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9376: Transmit the size of reduce function source

This way Couchstore can easily allocate enough
memory dynamically for reading the reduce function.

Change-Id: Ibe5095c219ca0a17467aa1a96ac58266bc186c5a
Reviewed-on: http://review.couchbase.org/29619
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Volker Mische <volker.mische@gmail.com>
MB-9307: Add find_header_bin/2

Make it possible to search for a header from a given position
backwards.

Change-Id: Id8254d2cdcce298fff964d576563ccb7383a461d
Reviewed-on: http://review.couchbase.org/29731
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9467 On JSON.stringify failure, avoid throwing exception with null value

While not a problem, the logged error reason ended up being a "null",
not very informative. Was easy to get via for example:

function(doc, meta) {
    while (true) {
        emit(doc, doc);
    }
}

Change-Id: Ic3757884398c6a87f7530d351447b94aac2aa7b3
Reviewed-on: http://review.couchbase.org/30052
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9467 Don't process documents with too large bodies

Too large documents slow down indexing and make the JavaScript engine
use too much cpu time (JSON parsing/validation), causing the whole
system to be inneficient during rebalance and failover operations or
not to be able to accomplish such operations at all.

Therefore limit the maximum size of documents passed to the JavaScript
engine, configurable via the internal parameter "indexer_max_doc_size".

Change-Id: I8e130d4c419c63f495452dab10f3e5ea96dd0db1
Reviewed-on: http://review.couchbase.org/30053
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9467 Raise explicit error if list of emitted keys exceeds limit

If more than 64k keys are emitted for a single document, raise an
explicit error informing about this fact, instead of having a badmatch
later when updating the key list for a document.

Change-Id: I61f5aa040ce026777aac52217a696f220da3d3ae
Reviewed-on: http://review.couchbase.org/30054
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9467 Enforce max total KV size that can be emitted per doc/view

To avoid consuming too much memory while running a single map function,
enforce a maximum limit for the total amount of data that can be emitted
per document and per view. This limit is configurable via the couch_config
option "max_kv_size_per_doc", section "mapreduce", and corresponds to the
sum of the byte size of all emitted keys and values.

A value of 0 for this new setting, disables the limit (meaning unlimited,
as before this change).

So far, before any memory blowup could happen, the function execution was
aborted due to the trigger of the timeout, such as in the following example
case:

function(doc, meta) {
    for (var i = 0; i < 1000000; i++) {
        for (var j = 0; j < 1000000; j++) {
            emit(doc.value, null);
        }
    }
}

However, one user was able to get V8 heap exhaustion while running a map
function. Despite unsuccessful attempts so far to reproduce the heap
exhaustion issue, this change allows to enforce sane limits.

Change-Id: I4af03208027868a461c568dcd20ff49bec27ed76
Reviewed-on: http://review.couchbase.org/30055
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Add v8 version detection to configure.ac

Detect if v8 version > 3.19 and define macro `V8_POST_3_19_API`

Change-Id: I8af6c5f9b83f977f414397833f320240f0eeca33
Reviewed-on: http://review.couchbase.org/30028
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9482 Add support for V8 versions post 3.19

v8 versions post v3.19 does not allow copyable persistent objects
and few APIs have changed. Based on macro def `V8_POST_3_19_API`,
newer API or older API can be conditionally used.

Change-Id: I325d526eda9c0a9202809c003d6ea274447080bf
Reviewed-on: http://review.couchbase.org/30029
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Add V8 include path to CPPFLAGS

Without this change the header check would succeed only if another v8.h
is located in a standard header location (/usr/include, etc) or if the
environment variable C_INCLUDE_PATH was defined and pointing to the custom
location (which used to be my case). This ensures we can build when the
only v8.h is located in a custom path supplied by --with-v8-include.

Change-Id: I35acfb34d37fd5aea2b8cb119a22edb9d9e98d87
Reviewed-on: http://review.couchbase.org/30134
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Merge remote-tracking branch 'origin/2.1.1'

* origin/2.1.1:
  MB-9467 Enforce max total KV size that can be emitted per doc/view
  MB-9467 Raise explicit error if list of emitted keys exceeds limit
  MB-9467 Don't process documents with too large bodies
  MB-9467 On JSON.stringify failure, avoid throwing exception with null value

Conflicts:
	etc/couchdb/default.ini.tpl.in
	src/mapreduce/mapreduce.cc

Change-Id: I22d8e6435079c4b1e759ee4048e5ef3c7f5c94ba
Fix test couch_set_view/test/12-errors.t after merge

Master branch has different view group APIs, so the test needs
to use the master APIs instead of those in the 2.1.1 branch.

Change-Id: I23fb381e6a7ed59c9ac9bbd23298463b07931518
Reviewed-on: http://review.couchbase.org/30137
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: buildbot <build@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-8454 Improve indexing progress stats update

Instead of updating indexing progress stats (`http://localhost:5984/_active_tasks`)
after each batch write to btrees, update the stats simultanously while items
are being loaded to Mapper Queue. Hence, it will produce an incremental
progress rather than abruptly moving by batch progress.

Change-Id: Ib82260aaa17819efb9a5b51f75a93ff40df8f6b0
Reviewed-on: http://review.couchbase.org/30201
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-8454 Fix initial index build progress stats

During initial index build, calculation of total number of changes is
inaccurate since it is assumed to be equal to the sum of current seqs
for vbuckets. This results in displaying progress stats having total_changes
much more than the actual number of changes to be processed.

For initial build case, total changes should be estimated by summation
of non-deleted docs count from each of the vbuckets belonging to a bucket.

Change-Id: Iea4e2a6ebcd614d973ac5551e46c565e3be46f7c
Reviewed-on: http://review.couchbase.org/30202
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
CBD-485 jump_to_another_version to adjust the vbucket

version in couchdb after the ep-engine compacted it

Change-Id: Id1c1e375d142788e473b32e618feb5ae97963f15
Reviewed-on: http://review.couchbase.org/30326
Tested-by: Artem Stemkovski <artem@couchbase.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-8903: Add UPR project

In couch_upr will be all the code that is needed to get
changes from an UPR stream.

Change-Id: I1c71c64819e4369a38b32a20128e9d21fd7bd022
Reviewed-on: http://review.couchbase.org/29401
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Volker Mische <volker.mische@gmail.com>