Disable btree native implementation on windows

Change-Id: If6be6d9155b4972e88448ce44a619562582fba2b
Reviewed-on: http://review.couchbase.org/13487
Tested-by: Bin Cui <bin.cui@gmail.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Move set view group stats into public ETS table

Change-Id: I7dcaa79ede72f7b12132ef8bf2a0484699d0fd12
Reviewed-on: http://review.couchbase.org/13565
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Add replica partitions info to queries with ?debug=true

This adds information about list of all replica partitions, and
which are on transfer from the replica group to main group, to the
"debug_info" object returned by the server when queries have the
?debug=true parameter.

Change-Id: Id9b8a9a2e98fb100551ea3292c9f946d67b827d9
Reviewed-on: http://review.couchbase.org/13620
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Include row origin node in map queries with ?debug=true

For map queries in debug mode, besides the partition ID,
include the URL of the node from where each row comes.
Example query response:

{
  "rows": [
      {
         "value" : "doc_000031",
         "id" : "doc_000031",
         "node" : "local",
         "partition" : 31,
         "key" : 32
      },
      {
         "value" : "doc_000032",
         "id" : "doc_000032",
         "node" : "http://10.17.4.149:9501/_view_merge/",
         "partition" : 32,
         "key" : 32
      },
      (....)
  ]
}

Change-Id: I7ec9c5f93e1984a49844bb0146bcf161ad937eb9
Reviewed-on: http://review.couchbase.org/13621
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Remove no longer necessary logging

This logging was added to help debug a deadlock fixed
by dbebcf91442d999409b1cde67d49b6f45cb7506b.

Change-Id: Id1767b24beb0d4dee441eea1adf373883869b429
Reviewed-on: http://review.couchbase.org/13622
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Improve set view indexer performance

Instead of having the mapper queue item by item, let
it queue all the items at once. This reduces messaging
with the work queue, reducing the time the mapper gets
blocked waiting the response to gen_server synchronous
calls.
A quick test showed that an index build time decreased
from 4 minutes to 3 minutes and 22 seconds (repeated the
test several times and reached the same results on a
machine with an ssd disk).

Change-Id: I6b2546e51df2ed6c467e584f4188d70eb2449a2b
Reviewed-on: http://review.couchbase.org/13632
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Avoid function_clause error for queries with ?debug=true

When merging the results of the local main and replica indexes
and the query has ?debug=true, the merge would fail with a
function_clause error. The solution is just to ignore debug
information in the callback used by the view merger.
We're only interested in the debug information from the view
merging step done at a higher level (multiple nodes, triggered
by ns_server).

Change-Id: I16778154a415b39ce308cbdb5cf7b401da8f66ca
Reviewed-on: http://review.couchbase.org/13677
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Remove unnecessary lists:flatten/1 call

Change-Id: I37cedea83c1cb04ed68e1f6c4ce5ada9228a802d
Reviewed-on: http://review.couchbase.org/13686
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Unblock cleanup waiters when updater finishes normally

If the updater is not interrupted and finishes normally,
unblock cleanup waiters if any.

Issue observed in MB-4850.

Change-Id: I141292af72f6960c8680dcc3462029ce71cf7e28
Reviewed-on: http://review.couchbase.org/13694
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Avoid function_clause error for queries with ?debug=true

When merging the results of the local main and replica indexes
and the query has ?debug=true, the merge would fail with a
function_clause error. The solution is just to ignore debug
information in the callback used by the view merger.
We're only interested in the debug information from the view
merging step done at a higher level (multiple nodes, triggered
by ns_server).

Change-Id: I16778154a415b39ce308cbdb5cf7b401da8f66ca
Reviewed-on: http://review.couchbase.org/13677
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-on: http://review.couchbase.org/13696
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Improve set view indexer performance

Instead of having the mapper queue item by item, let
it queue all the items at once. This reduces messaging
with the work queue, reducing the time the mapper gets
blocked waiting the response to gen_server synchronous
calls.
A quick test showed that an index build time decreased
from 4 minutes to 3 minutes and 22 seconds (repeated the
test several times and reached the same results on a
machine with an ssd disk).

Change-Id: I6b2546e51df2ed6c467e584f4188d70eb2449a2b
Reviewed-on: http://review.couchbase.org/13632
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-on: http://review.couchbase.org/13695
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Remove unnecessary lists:flatten/1 call

Change-Id: I37cedea83c1cb04ed68e1f6c4ce5ada9228a802d
Reviewed-on: http://review.couchbase.org/13686
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-on: http://review.couchbase.org/13697
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
fixed make check

Change-Id: I26fb6f0e0f90b8c5f49560fc4fe4fe4ef1cdf89b
Reviewed-on: http://review.couchbase.org/13701
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Merge branch 'branch-20dp4'

* branch-20dp4:
  fixed make check
  Remove unnecessary lists:flatten/1 call
  Improve set view indexer performance
  Avoid function_clause error for queries with ?debug=true
  Unblock cleanup waiters when updater finishes normally
  Disable btree native implementation on windows

Change-Id: I91aeda7066c22ce7b3c78ace9b64b4f3e34d0016
Include row origin node in map queries with ?debug=true

For map queries in debug mode, besides the partition ID,
include the URL of the node from where each row comes.
Example query response:

{
  "rows": [
      {
         "value" : "doc_000031",
         "id" : "doc_000031",
         "node" : "local",
         "partition" : 31,
         "key" : 32
      },
      {
         "value" : "doc_000032",
         "id" : "doc_000032",
         "node" : "http://10.17.4.149:9501/_view_merge/",
         "partition" : 32,
         "key" : 32
      },
      (....)
  ]
}

Change-Id: I7ec9c5f93e1984a49844bb0146bcf161ad937eb9
Reviewed-on: http://review.couchbase.org/13621
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-on: http://review.couchbase.org/13703
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Merge branch 'branch-20dp4'

* branch-20dp4:
  Include row origin node in map queries with ?debug=true

Change-Id: I27bfc415efe29b1485c150ca3ea238d16f2ba8db
Separate barriers for main and active index updates

Replica index updates can prevent main index updates from
running sooner, causing clients to wait for a very long
time to get responses to view queries. Therefore use a
separate, and smaller, pool for replica index updaters.

This relates to MB-4848.

Change-Id: If356994fc35ac24e5b09199b18304244ca7af777
Reviewed-on: http://review.couchbase.org/13704
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Better updater's doc loader error reporting

Change-Id: I38ec2d733796eb599e779dbf10151e208cef8be2
Reviewed-on: http://review.couchbase.org/13720
Reviewed-by: Damien Katz <damien@couchbase.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Fix problem when a file is deleted during compaction.

When a file is deleted during compaction, the .compact file
hangs around. Allow recreation by deleting the .compact file during
creation requests and then creating the file normally.

Change-Id: I6bc7d79a87e5c39f4b560d0e840a78a4f02cc323
Reviewed-on: http://review.couchbase.org/13761
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Damien Katz <damien@couchbase.com>
Reviewed-by: Damien Katz <damien@couchbase.com>
Add erl_diag module to help diagnose/debug issues

Taken from: https://github.com/fdmanana/erlang-utils

Change-Id: I6b6b1068b8d8c315c17c761d527a60c54e9e0ec0
Reviewed-on: http://review.couchbase.org/13759
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>