You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by zh...@apache.org on 2020/04/22 11:50:17 UTC

[incubator-doris] branch master updated: [SegmentV2] Fix bloom filter bits buffer not initialize as 0 (#3372)

This is an automated email from the ASF dual-hosted git repository.

zhaoc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 22e90f7  [SegmentV2] Fix bloom filter bits buffer not initialize as 0 (#3372)
22e90f7 is described below

commit 22e90f726061d90afc86e7c8f746bb1f65a51770
Author: Yingchun Lai <40...@qq.com>
AuthorDate: Wed Apr 22 06:50:05 2020 -0500

    [SegmentV2] Fix bloom filter bits buffer not initialize as 0 (#3372)
---
 be/src/olap/rowset/segment_v2/bloom_filter.h       |  1 +
 .../rowset/segment_v2/block_bloom_filter_test.cpp  | 38 +++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/be/src/olap/rowset/segment_v2/bloom_filter.h b/be/src/olap/rowset/segment_v2/bloom_filter.h
index 6c6ba4d..d744301 100644
--- a/be/src/olap/rowset/segment_v2/bloom_filter.h
+++ b/be/src/olap/rowset/segment_v2/bloom_filter.h
@@ -72,6 +72,7 @@ public:
         _size = _num_bytes + 1;
         // reserve last byte for null flag
         _data = new char[_size];
+        memset(_data, 0, _size);
         _has_null = (bool*)(_data + _num_bytes);
         *_has_null = false;
         return Status::OK();
diff --git a/be/test/olap/rowset/segment_v2/block_bloom_filter_test.cpp b/be/test/olap/rowset/segment_v2/block_bloom_filter_test.cpp
index 63601ab..28e5e77 100644
--- a/be/test/olap/rowset/segment_v2/block_bloom_filter_test.cpp
+++ b/be/test/olap/rowset/segment_v2/block_bloom_filter_test.cpp
@@ -103,27 +103,43 @@ TEST_F(BlockBloomFilterTest, SP) {
     ASSERT_TRUE(st.ok());
     ASSERT_TRUE(bf2->size() > 0);
 
-    int num = 1024;
-    int32_t values[1024];
-    for (int32_t i = 0; i < 1024; ++i) {
+    int num = _expected_num;
+    int32_t values[num];
+    for (int32_t i = 0; i < num; ++i) {
         values[i] = i * 10 + 1;
-    }
-    for (int i = 0; i < num; ++i) {
         bf->add_bytes((char*)&values[i], sizeof(int32_t));
     }
 
-    int32_t values2[1024];
-    for (int32_t i = 0; i < 1024; ++i) {
+    int32_t values2[num];
+    for (int32_t i = 0; i < num; ++i) {
         values2[i] = 15360 + i * 10 + 1;
+        bf2->add_bytes((char*)&values2[i], sizeof(int32_t));
     }
 
+    // true test
     for (int i = 0; i < num; ++i) {
-        bf2->add_bytes((char*)&values2[i], sizeof(int32_t));
+        ASSERT_TRUE(bf->test_bytes((char*)&values[i], 4));
+        ASSERT_TRUE(bf2->test_bytes((char*)&values2[i], 4));
     }
 
-    int32_t to_check = 101;
-    ASSERT_TRUE(bf->test_bytes((char*)&to_check, 4));
-    ASSERT_FALSE(bf2->test_bytes((char*)&to_check, 4));
+    // false test
+    int false_count1 = 0;
+    int false_count2 = 0;
+    for (int i = 0; i < num; ++i) {
+        int32_t to_check1 = values[i];
+        for (int j = 1; j < 10; ++j) {
+            ++to_check1;
+            false_count1 += bf->test_bytes((char*)&to_check1, 4);
+        }
+
+        int32_t to_check2 = values2[i];
+        for (int j = 1; j < 10; ++j) {
+            ++to_check2;
+            false_count2 += bf2->test_bytes((char*)&to_check2, 4);
+        }
+    }
+    ASSERT_LE((double)false_count1 / (num * 9), _fpp);
+    ASSERT_LE((double)false_count2 / (num * 9), _fpp);
 }
 
 // Test for slice


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org