CMake: Search project include dirs before /usr/local/include

This ensures that if /usr/local/include has outdated header files
(e.g. you previously compiled and installed CB 2.5.1), then the build
of master doesn't fail due to it picking up outdated header files.

Change-Id: I9c4d7987adebb0780d3a0b08f27b666af128708d
Reviewed-on: http://review.couchbase.org/38361
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Dave Rigby <daver@couchbase.com>
MB-11344: Convert a temp item during an insert

- If a temp item is already found to exist during
warmup, then convert the temp item into a regular
item.

Change-Id: I12bc1ead075cb19f9ef397397f84abe6086f50e4
Reviewed-on: http://review.couchbase.org/38531
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: abhinav dangeti <abhinav@couchbase.com>
MB-11459: Add debug logging for high seqno incorrectly set

Change-Id: I44e80cf415f8b7c4bba70a9b684301534e026c03
Reviewed-on: http://review.couchbase.org/38606
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11405 Reduce CPU use in active system

Instead of having all the threads snooze for the minimum
snooze time across all task sets, have only 1 thread per
task set snooze while others sleep for longer duration.
This not only uses lower cpu in an active system with 5+ buckets
but also reduces lock contention in smaller configurations.

Change-Id: I99a203c3d0fb36612fb884c44684f747d2f09e42
Reviewed-on: http://review.couchbase.org/38620
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
Release cluster configuration during shutdown

> ::findleaks -v
BYTES             LEAKED         VMEM_SEG CALLER
12288                  6 fffffd7ffc35f000 MMAP
12288                  1 fffffd7ffcf6c000 MMAP
12288                  1 fffffd7ffcd6d000 MMAP
12288                  1 fffffd7ffc95c000 MMAP
12288                  1 fffffd7ffc75d000 MMAP
12288                  1 fffffd7ffc55e000 MMAP
------------------------------------------------------------------------
           Total       6 oversized leaks, 73728 bytes

CACHE             LEAKED           BUFCTL CALLER
0000000000485028       1 00000000089d0380 ep.so`MemoryTracker::MemoryTracker+0x6b
00000000004a5028       1 0000000009b92ee0 ep.so`EventuallyPersistentEngine::setClusterConfig+0x5f
000000000048a028     512 00000000098300e0 libstdc++.so.6.0.17`operator new+0x1e
------------------------------------------------------------------------
           Total     514 buffers, 40968 bytes
> 0000000009b92ee0::bufctl -v
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         9b92ee0          df8f000    c39fa1a13ad83                4
                           4a5028                0                0
                 libumem.so.1`umem_cache_alloc_debug+0xfd
                 libumem.so.1`umem_cache_alloc+0xb3
                 libumem.so.1`umem_alloc+0x64
                 libumem.so.1`malloc+0x3f
                 ep.so`EventuallyPersistentEngine::setClusterConfig+0x5f
                 ep.so`processUnknownCommand+0x73a
                 ep.so`EvpUnknownCommand+0x38
                 bucket_engine.so`bucket_unknown_command+0x23d
                 default_unknown_command+0xb8
                 process_bin_unknown_packet+0xa9
                 process_bin_packet+0xc6
                 complete_nread+0x182
                 conn_nread+0x48
                 event_handler+0x1ce
                 libevent_core-2.0.so.5.1.9`event_base_loop+0x436

Change-Id: I093d7d7112701e7c23bb9522246489d532668aa6
Reviewed-on: http://review.couchbase.org/38659
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Release allocated resources by cJSON

> ::findleaks
BYTES             LEAKED         VMEM_SEG CALLER
8192                   6 fffffd7ffc360000 MMAP
8192                   1 fffffd7ffcf6d000 MMAP
8192                   1 fffffd7ffcd6e000 MMAP
8192                   1 fffffd7ffc95d000 MMAP
8192                   1 fffffd7ffc75e000 MMAP
8192                   1 fffffd7ffc55f000 MMAP
------------------------------------------------------------------------
           Total       6 oversized leaks, 49152 bytes

CACHE             LEAKED           BUFCTL CALLER
0000000000485028       1 0000000008977380 ep.so`MemoryTracker::MemoryTracker+0x6b
00000000004a5028       1 000000001000b9a0 ep.so`EventuallyPersistentEngine::setClusterConfig+0x5f
000000000048a668    2046 000000000a0579a0 libcJSON.so.1.0.0`cJSON_New_Item+0x17
000000000048a668    2048 000000000a057c40 libcJSON.so.1.0.0`cJSON_New_Item+0x17
000000000048a668    2047 000000000a057b60 libcJSON.so.1.0.0`cJSON_New_Item+0x17
000000000048a668    2046 000000000a057a80 libcJSON.so.1.0.0`cJSON_New_Item+0x17
0000000000485668    2046 000000000a053540 libcJSON.so.1.0.0`parse_string+0x8a
0000000000485668    2046 000000000a053620 libcJSON.so.1.0.0`parse_string+0x8a
000000000048a028     512 000000000fb3e0e0 libstdc++.so.6.0.17`operator new+0x1e
------------------------------------------------------------------------
           Total   12793 buffers, 761400 bytes
> 000000000a053620::bufctl -v
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         a053620          a04dca0    c3978651e3b4b               14
                           485668                0                0
                 libumem.so.1`umem_cache_alloc_debug+0xfd
                 libumem.so.1`umem_cache_alloc+0xb3
                 libumem.so.1`umem_alloc+0x64
                 libumem.so.1`malloc+0x3f
                 libcJSON.so.1.0.0`parse_string+0x8a
                 libcJSON.so.1.0.0`parse_object+0x8f
                 libcJSON.so.1.0.0`parse_value+0xbe
                 libcJSON.so.1.0.0`parse_array+0xa6
                 libcJSON.so.1.0.0`parse_value+0x9b
                 libcJSON.so.1.0.0`cJSON_Parse+0x41
                 ep.so`FailoverTable::loadFromJSON+0x24
                 ep.so`FailoverTable::FailoverTable+0x65
                 ep.so`Warmup::createVBuckets+0x152
                 ep.so`WarmupCreateVBuckets::run+0x29
                 ep.so`ExecutorThread::run+0x262

Change-Id: I20f4d46d39996df04b60545e72e5250e8ef2e533
Reviewed-on: http://review.couchbase.org/38658
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Free SnapshotMarkers

> ::findleaks
BYTES             LEAKED         VMEM_SEG CALLER
12288                 12 fffffd7ffc35f000 MMAP
12288                  1 fffffd7ffcf7c000 MMAP
8192                   1 fffffd7ffcf6d000 MMAP
12288                  1 fffffd7ffcd7d000 MMAP
12288                  1 fffffd7ffcd6d000 MMAP
8192                   1 fffffd7ffc96d000 MMAP
12288                  1 fffffd7ffc95c000 MMAP
8192                   1 fffffd7ffc76e000 MMAP
12288                  1 fffffd7ffc75d000 MMAP
8192                   1 fffffd7ffc56f000 MMAP
12288                  1 fffffd7ffc55e000 MMAP
12288                  1 fffffd7ffc36f000 MMAP
------------------------------------------------------------------------
           Total      12 oversized leaks, 131072 bytes

CACHE             LEAKED           BUFCTL CALLER
0000000000485028       1 00000000089eb2a0 ep.so`MemoryTracker::MemoryTracker+0x6b
000000000048a028     512 0000000008a6cb60 libstdc++.so.6.0.17`operator new+0x1e
------------------------------------------------------------------------
           Total     513 buffers, 32776 bytes
> 0000000008a6cb60::bu
bufctl
bufctl_audit
> 0000000008a6cb60::bufctl -v
            ADDR          BUFADDR        TIMESTAMP           THREAD
                            CACHE          LASTLOG         CONTENTS
         8a6cb60          8a6b880    c3fb052e883da                5
                           48a028                0                0
                 libumem.so.1`umem_cache_alloc_debug+0xfd
                 libumem.so.1`umem_cache_alloc+0xb3
                 libumem.so.1`umem_alloc+0x64
                 libumem.so.1`malloc+0x3f
                 libstdc++.so.6.0.17`operator new+0x1e
                 ep.so`UprConsumer::snapshotMarker+0xc7
                 ep.so`EvpUprSnapshotMarker+0x75
                 bucket_engine.so`upr_snapshot_marker+0x8a
                 upr_snapshot_marker_executor+0x100
                 process_bin_packet+0xb8
                 complete_nread+0x182
                 conn_nread+0x48
                 event_handler+0x1ce
                 libevent_core-2.0.so.5.1.9`event_base_loop+0x436
                 worker_libevent+0x56

Change-Id: I8aeafa031b6fd9ae5d918abd9820558b311a9a72
Reviewed-on: http://review.couchbase.org/38664
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Free message from StreamEndResponse

Change-Id: I60c407870fef619d6fd56abc06f8e7064bf3b247
Reviewed-on: http://review.couchbase.org/38665
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
MB-11085: Always generate a failover entry after an unclean shutdown

Previously we would not generate a new failover entry after an
unclean shutdown if the persisted seqno did not change between
when the server was originally started and when is crashed. This can
cause issues because it is possible that mutations were received in
memory and streamed to another node and then the server crashes. If
we do not generate a new failover entry in this case then we will
not properly tell the node that received the mutations from memory
to rollback.

Change-Id: I6a97c12f2eb300984aaa81d7f9fdd0eb3272233d
Reviewed-on: http://review.couchbase.org/38698
Reviewed-by: David Liao <david.liao@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11502: Fix incorrect snap_start/end seqno's in stream retry

If we set the snap_send_seqno to always be equal to the
snap_start_seqno then it is possible that the snap_end_seqno will
be less than then start seqno and this will cause the stream
creation to fail on the producer side.

Change-Id: I73f1fdda6cf0f979c8b128f01a9366ecb6321b20
Reviewed-on: http://review.couchbase.org/38703
Reviewed-by: Sriram Ganesan <sriram@couchbase.com>
Reviewed-by: Sundararaman Sridharan <sundar@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
add INFO logs for vb creation/deletion

Change-Id: If20ab4d92a08e3eaed06b0d3dfdbfc67df3c5a50
Reviewed-on: http://review.couchbase.org/38719
Reviewed-by: Sriram Ganesan <sriram@couchbase.com>
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Sundararaman Sridharan <sundar@couchbase.com>
MB-11367: Make sure we properly release connections with the same name

When we have a connection that gets registered with the same name as
an existing connection we need to make sure the connection is
cleaned up properly.

Change-Id: I36d57aeb9a17460acb92bc926e162a6009b9e002
Reviewed-on: http://review.couchbase.org/38714
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
MB-11367: Properly close all upr connections during shutdown

When we shutdown we need to close all streams before clearing out
all of the connections in the connection map.

Change-Id: I80679547c8ad9d278f5d6a3baac7668146dd012d
Reviewed-on: http://review.couchbase.org/38715
Reviewed-by: abhinav dangeti <abhinav@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>
Log persistence seqno updates

Change-Id: Iaeb7634d92e639ad3af1329f690111ee433c7b5f
Properly set high seqno in couchkvstore

Change-Id: I0b7e32348948814cb54d93feb5d9d78c8d478196