Disallow customized hash function in DynamicBloom (#4915)

Summary:
I didn't find where customized hash function is used in DynamicBloom. This can only reduce performance. Remove it.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4915

Differential Revision: D13794452

Pulled By: siying

fbshipit-source-id: e38669b11e01444d2d782da11c7decabbd851819
main
Siying Dong 6 years ago committed by Facebook Github Bot
parent e07aa8669d
commit fc53839bfa
  1. 8
      db/memtable.cc
  2. 3
      table/bloom_block.h
  3. 2
      table/plain_table_reader.cc
  4. 15
      util/dynamic_bloom.cc
  5. 12
      util/dynamic_bloom.h

@ -110,10 +110,10 @@ MemTable::MemTable(const InternalKeyComparator& cmp,
assert(!ShouldScheduleFlush());
if (prefix_extractor_ && moptions_.memtable_prefix_bloom_bits > 0) {
prefix_bloom_.reset(new DynamicBloom(
&arena_, moptions_.memtable_prefix_bloom_bits, ioptions.bloom_locality,
6 /* hard coded 6 probes */, nullptr, moptions_.memtable_huge_page_size,
ioptions.info_log));
prefix_bloom_.reset(
new DynamicBloom(&arena_, moptions_.memtable_prefix_bloom_bits,
ioptions.bloom_locality, 6 /* hard coded 6 probes */,
moptions_.memtable_huge_page_size, ioptions.info_log));
}
}

@ -15,8 +15,7 @@ class BloomBlockBuilder {
public:
static const std::string kBloomBlock;
explicit BloomBlockBuilder(uint32_t num_probes = 6)
: bloom_(num_probes, nullptr) {}
explicit BloomBlockBuilder(uint32_t num_probes = 6) : bloom_(num_probes) {}
void SetTotalBits(Allocator* allocator, uint32_t total_bits,
uint32_t locality, size_t huge_page_tlb_size,

@ -104,7 +104,7 @@ PlainTableReader::PlainTableReader(
user_key_len_(static_cast<uint32_t>(table_properties->fixed_key_len)),
prefix_extractor_(prefix_extractor),
enable_bloom_(false),
bloom_(6, nullptr),
bloom_(6),
file_info_(std::move(file), storage_options,
static_cast<uint32_t>(table_properties->data_size)),
ioptions_(ioptions),

@ -32,20 +32,13 @@ uint32_t GetTotalBitsForLocality(uint32_t total_bits) {
DynamicBloom::DynamicBloom(Allocator* allocator, uint32_t total_bits,
uint32_t locality, uint32_t num_probes,
uint32_t (*hash_func)(const Slice& key),
size_t huge_page_tlb_size,
Logger* logger)
: DynamicBloom(num_probes, hash_func) {
size_t huge_page_tlb_size, Logger* logger)
: DynamicBloom(num_probes) {
SetTotalBits(allocator, total_bits, locality, huge_page_tlb_size, logger);
}
DynamicBloom::DynamicBloom(uint32_t num_probes,
uint32_t (*hash_func)(const Slice& key))
: kTotalBits(0),
kNumBlocks(0),
kNumProbes(num_probes),
hash_func_(hash_func == nullptr ? &BloomHash : hash_func),
data_(nullptr) {}
DynamicBloom::DynamicBloom(uint32_t num_probes)
: kTotalBits(0), kNumBlocks(0), kNumProbes(num_probes), data_(nullptr) {}
void DynamicBloom::SetRawData(unsigned char* raw_data, uint32_t total_bits,
uint32_t num_blocks) {

@ -10,6 +10,7 @@
#include "rocksdb/slice.h"
#include "port/port.h"
#include "util/hash.h"
#include <atomic>
#include <memory>
@ -35,12 +36,10 @@ class DynamicBloom {
explicit DynamicBloom(Allocator* allocator,
uint32_t total_bits, uint32_t locality = 0,
uint32_t num_probes = 6,
uint32_t (*hash_func)(const Slice& key) = nullptr,
size_t huge_page_tlb_size = 0,
Logger* logger = nullptr);
explicit DynamicBloom(uint32_t num_probes = 6,
uint32_t (*hash_func)(const Slice& key) = nullptr);
explicit DynamicBloom(uint32_t num_probes = 6);
void SetTotalBits(Allocator* allocator, uint32_t total_bits,
uint32_t locality, size_t huge_page_tlb_size,
@ -86,7 +85,6 @@ class DynamicBloom {
uint32_t kNumBlocks;
const uint32_t kNumProbes;
uint32_t (*hash_func_)(const Slice& key);
std::atomic<uint8_t>* data_;
// or_func(ptr, mask) should effect *ptr |= mask with the appropriate
@ -95,10 +93,10 @@ class DynamicBloom {
void AddHash(uint32_t hash, const OrFunc& or_func);
};
inline void DynamicBloom::Add(const Slice& key) { AddHash(hash_func_(key)); }
inline void DynamicBloom::Add(const Slice& key) { AddHash(BloomHash(key)); }
inline void DynamicBloom::AddConcurrently(const Slice& key) {
AddHashConcurrently(hash_func_(key));
AddHashConcurrently(BloomHash(key));
}
inline void DynamicBloom::AddHash(uint32_t hash) {
@ -122,7 +120,7 @@ inline void DynamicBloom::AddHashConcurrently(uint32_t hash) {
}
inline bool DynamicBloom::MayContain(const Slice& key) const {
return (MayContainHash(hash_func_(key)));
return (MayContainHash(BloomHash(key)));
}
#if defined(_MSC_VER)

Loading…
Cancel
Save