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>
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