]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/plain/plain_table_bloom.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 #include "table/plain/plain_table_bloom.h"
10 #include "util/dynamic_bloom.h"
12 #include "memory/allocator.h"
14 namespace ROCKSDB_NAMESPACE
{
18 uint32_t GetTotalBitsForLocality(uint32_t total_bits
) {
20 (total_bits
+ CACHE_LINE_SIZE
* 8 - 1) / (CACHE_LINE_SIZE
* 8);
22 // Make num_blocks an odd number to make sure more bits are involved
23 // when determining which block.
24 if (num_blocks
% 2 == 0) {
28 return num_blocks
* (CACHE_LINE_SIZE
* 8);
32 PlainTableBloomV1::PlainTableBloomV1(uint32_t num_probes
)
33 : kTotalBits(0), kNumBlocks(0), kNumProbes(num_probes
), data_(nullptr) {}
35 void PlainTableBloomV1::SetRawData(char* raw_data
, uint32_t total_bits
,
36 uint32_t num_blocks
) {
38 kTotalBits
= total_bits
;
39 kNumBlocks
= num_blocks
;
42 void PlainTableBloomV1::SetTotalBits(Allocator
* allocator
, uint32_t total_bits
,
44 size_t huge_page_tlb_size
,
46 kTotalBits
= (locality
> 0) ? GetTotalBitsForLocality(total_bits
)
47 : (total_bits
+ 7) / 8 * 8;
48 kNumBlocks
= (locality
> 0) ? (kTotalBits
/ (CACHE_LINE_SIZE
* 8)) : 0;
50 assert(kNumBlocks
> 0 || kTotalBits
> 0);
51 assert(kNumProbes
> 0);
53 uint32_t sz
= kTotalBits
/ 8;
55 sz
+= CACHE_LINE_SIZE
- 1;
59 char* raw
= allocator
->AllocateAligned(sz
, huge_page_tlb_size
, logger
);
61 auto cache_line_offset
= reinterpret_cast<uintptr_t>(raw
) % CACHE_LINE_SIZE
;
62 if (kNumBlocks
> 0 && cache_line_offset
> 0) {
63 raw
+= CACHE_LINE_SIZE
- cache_line_offset
;
68 void BloomBlockBuilder::AddKeysHashes(
69 const std::vector
<uint32_t>& keys_hashes
) {
70 for (auto hash
: keys_hashes
) {
75 Slice
BloomBlockBuilder::Finish() { return bloom_
.GetRawData(); }
77 const std::string
BloomBlockBuilder::kBloomBlock
= "kBloomBlock";
78 } // namespace ROCKSDB_NAMESPACE