MB-20746: Delete bloom filter only if temporary filter is created 00/69100/9
authorSriram Ganesan <sriram@couchbase.com>
Sat, 22 Oct 2016 01:09:35 +0000 (18:09 -0700)
committerSriram Ganesan <sriram@couchbase.com>
Tue, 25 Oct 2016 21:57:29 +0000 (21:57 +0000)
During compaction, a temporary filter is only created in the
bloom filter callback function. There is a possibility that this
function will not get invoked if there is no data present during
compaction. So, before swapping the filter, ensure that a temporary
filter is created before deleting the original filter.

Change-Id: I4fcf11d32674be8c28dbda02724b40d3d37e335a
Reviewed-on: http://review.couchbase.org/69100
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Sriram Ganesan <sriram@couchbase.com>
src/vbucket.cc
tests/module_tests/vbucket_test.cc

index a73c4aa..6e798aa 100644 (file)
@@ -535,7 +535,7 @@ void VBucket::swapFilter() {
     // compaction.
 
     LockHolder lh(bfMutex);
-    if (bFilter) {
+    if (bFilter && tempFilter) {
         delete bFilter;
         bFilter = NULL;
     }
index 9c1117e..f5405e8 100644 (file)
@@ -209,6 +209,17 @@ static void testGetVBucketsByState(void) {
     }
 }
 
+static void testVBucketSwapFilter(void) {
+    VBucket vb(new VBucket(0, vbucket_state_active, global_stats,
+                                  checkpoint_config), NULL);
+    vb.createFilter(1, 1.0);
+    cb_assert(vb.isTempFilterAvailable() == true);
+    cb_assert(vb.getFilterStatusString() != "DOESN'T EXIST");
+
+    vb.swapFilter();
+    cb_assert(vb.getFilterStatusString() != "DOESN'T EXIST");
+}
+
 int main(int argc, char **argv) {
     (void)argc; (void)argv;
     putenv(cb_strdup("ALLOW_NO_STATS_UPDATE=yeah"));
@@ -223,4 +234,5 @@ int main(int argc, char **argv) {
     testVBucketFilter();
     testVBucketFilterFormatter();
     testGetVBucketsByState();
+    testVBucketSwapFilter();
 }