MB-7656 Set error code if copy_node_pointer() fails to alloc memory

complete_new_btree() could return a NULL either on success or when
copy_node_pointer() fails to allocate memory - in both cases it
returned (via pointer argument) a status of SUCCESS, which is clearly
wrong for the second case.

Change-Id: I920477363b70aeca445433e8afffa329e578a3bc
Reviewed-on: http://review.couchbase.org/29026
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-7656 Don't use hardcoded value when calculating KV length

Change-Id: If59d6246d575c72f90cfdb7d7cb894c60d8042f9
Reviewed-on: http://review.couchbase.org/29027
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-7656 Fix counting in id btree reducer

The count must be number of entries in the tree, and not a sum of
entry count for all views.

Change-Id: I436123fb13e5ac67e48c650358e94d9f44e37df4
Reviewed-on: http://review.couchbase.org/29028
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-7656 Encode empty btree states as empty byte sequences

Exactly how it's done in Erlang side.

Change-Id: I0b20f2b314c8e6a701635aeba5d1c2144b5be511
Reviewed-on: http://review.couchbase.org/29029
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
MB-9133 Add native view index builder

The new program couch_view_index_builder will be used for
performing the final phase (btree builds) of an index build.

Sample test:

Building an index for a design document with 4 views, from
one of the evperf tests, for a dataset of 6.5M documents:

Before this change:

Total indexing time:    10m58.060s
Btree build phase time: 127.85283s

After this change:

Indexing time:          9m1.305s
Btree build phase time: 22.018846s

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