0af157f9bf
Summary:
1. Make filter_block.h a base class. Derive block_based_filter_block and full_filter_block. The previous one is the traditional filter block. The full_filter_block is newly added. It would generate a filter block that contain all the keys in SST file.
2. When querying a key, table would first check if full_filter is available. If not, it would go to the exact data block and check using block_based filter.
3. User could choose to use full_filter or tradional(block_based_filter). They would be stored in SST file with different meta index name. "filter.filter_policy" or "full_filter.filter_policy". Then, Table reader is able to know the fllter block type.
4. Some optimizations have been done for full_filter_block, thus it requires a different interface compared to the original one in filter_policy.h.
5. Actual implementation of filter bits coding/decoding is placed in util/bloom_impl.cc
Benchmark: base commit 1d23b5c470
Command:
db_bench --db=/dev/shm/rocksdb --num_levels=6 --key_size=20 --prefix_size=20 --keys_per_prefix=0 --value_size=100 --write_buffer_size=134217728 --max_write_buffer_number=2 --target_file_size_base=33554432 --max_bytes_for_level_base=1073741824 --verify_checksum=false --max_background_compactions=4 --use_plain_table=0 --memtablerep=prefix_hash --open_files=-1 --mmap_read=1 --mmap_write=0 --bloom_bits=10 --bloom_locality=1 --memtable_bloom_bits=500000 --compression_type=lz4 --num=393216000 --use_hash_search=1 --block_size=1024 --block_restart_interval=16 --use_existing_db=1 --threads=1 --benchmarks=readrandom —disable_auto_compactions=1
Read QPS increase for about 30% from 2230002 to 2991411.
Test Plan:
make all check
valgrind db_test
db_stress --use_block_based_filter = 0
./auto_sanity_test.sh
Reviewers: igor, yhchiang, ljin, sdong
Reviewed By: sdong
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D20979
80 lines
2.8 KiB
C++
80 lines
2.8 KiB
C++
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
//
|
|
// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
//
|
|
// A filter block is stored near the end of a Table file. It contains
|
|
// filters (e.g., bloom filters) for all data blocks in the table combined
|
|
// into a single filter block.
|
|
//
|
|
// It is a base class for BlockBasedFilter and FullFilter.
|
|
// These two are both used in BlockBasedTable. The first one contain filter
|
|
// For a part of keys in sst file, the second contain filter for all keys
|
|
// in sst file.
|
|
|
|
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "rocksdb/options.h"
|
|
#include "rocksdb/slice.h"
|
|
#include "rocksdb/table.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
const uint64_t kNotValid = ULLONG_MAX;
|
|
|
|
// A FilterBlockBuilder is used to construct all of the filters for a
|
|
// particular Table. It generates a single string which is stored as
|
|
// a special block in the Table.
|
|
//
|
|
// The sequence of calls to FilterBlockBuilder must match the regexp:
|
|
// (StartBlock Add*)* Finish
|
|
//
|
|
// BlockBased/Full FilterBlock would be called in the same way.
|
|
class FilterBlockBuilder {
|
|
public:
|
|
explicit FilterBlockBuilder() {}
|
|
virtual ~FilterBlockBuilder() {}
|
|
|
|
virtual bool IsBlockBased() = 0; // If is blockbased filter
|
|
virtual void StartBlock(uint64_t block_offset) = 0; // Start new block filter
|
|
virtual void Add(const Slice& key) = 0; // Add a key to current filter
|
|
virtual Slice Finish() = 0; // Generate Filter
|
|
|
|
private:
|
|
// No copying allowed
|
|
FilterBlockBuilder(const FilterBlockBuilder&);
|
|
void operator=(const FilterBlockBuilder&);
|
|
};
|
|
|
|
// A FilterBlockReader is used to parse filter from SST table.
|
|
// KeyMayMatch and PrefixMayMatch would trigger filter checking
|
|
//
|
|
// BlockBased/Full FilterBlock would be called in the same way.
|
|
class FilterBlockReader {
|
|
public:
|
|
explicit FilterBlockReader() {}
|
|
virtual ~FilterBlockReader() {}
|
|
|
|
virtual bool IsBlockBased() = 0; // If is blockbased filter
|
|
virtual bool KeyMayMatch(const Slice& key,
|
|
uint64_t block_offset = kNotValid) = 0;
|
|
virtual bool PrefixMayMatch(const Slice& prefix,
|
|
uint64_t block_offset = kNotValid) = 0;
|
|
virtual size_t ApproximateMemoryUsage() const = 0;
|
|
|
|
private:
|
|
// No copying allowed
|
|
FilterBlockReader(const FilterBlockReader&);
|
|
void operator=(const FilterBlockReader&);
|
|
};
|
|
|
|
} // namespace rocksdb
|