e7c434c364
Summary: Summary: Added a new option to ColumnFamllyOptions - optimize_filters_for_hits. This option can be used in the case where most accesses to the store are key hits and we dont need to optimize performance for key misses. This is useful when you have a very large database and most of your lookups succeed. The option allows the store to not store and use filters in the last level (the largest level which contains data). These filters can take a large amount of space for large databases (in memory and on-disk). For the last level, these filters are only useful for key misses and not for key hits. If we are not optimizing for key misses, we can choose to not store these filters for that level. This option is only provided for BlockBasedTable. We skip the filters when we are compacting Test Plan: 1. Modified db_test toalso run tests with an additonal option (skip_filters_on_last_level) 2. Added another unit test to db_test which specifically tests that filters are being skipped Reviewers: rven, igor, sdong Reviewed By: sdong Subscribers: lgalanis, yoshinorim, MarkCallaghan, rven, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D33717
82 lines
2.7 KiB
C++
82 lines
2.7 KiB
C++
// Copyright (c) 2014, 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.
|
|
|
|
#pragma once
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include <string>
|
|
#include "rocksdb/table.h"
|
|
#include "util/murmurhash.h"
|
|
#include "rocksdb/options.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
const uint32_t kCuckooMurmurSeedMultiplier = 816922183;
|
|
static inline uint64_t CuckooHash(
|
|
const Slice& user_key, uint32_t hash_cnt, bool use_module_hash,
|
|
uint64_t table_size_, bool identity_as_first_hash,
|
|
uint64_t (*get_slice_hash)(const Slice&, uint32_t, uint64_t)) {
|
|
#ifndef NDEBUG
|
|
// This part is used only in unit tests.
|
|
if (get_slice_hash != nullptr) {
|
|
return get_slice_hash(user_key, hash_cnt, table_size_);
|
|
}
|
|
#endif
|
|
uint64_t value = 0;
|
|
if (hash_cnt == 0 && identity_as_first_hash) {
|
|
value = (*reinterpret_cast<const int64_t*>(user_key.data()));
|
|
} else {
|
|
value = MurmurHash(user_key.data(), static_cast<int>(user_key.size()),
|
|
kCuckooMurmurSeedMultiplier * hash_cnt);
|
|
}
|
|
if (use_module_hash) {
|
|
return value % table_size_;
|
|
} else {
|
|
return value & (table_size_ - 1);
|
|
}
|
|
}
|
|
|
|
// Cuckoo Table is designed for applications that require fast point lookups
|
|
// but not fast range scans.
|
|
//
|
|
// Some assumptions:
|
|
// - Key length and Value length are fixed.
|
|
// - Does not support Snapshot.
|
|
// - Does not support Merge operations.
|
|
class CuckooTableFactory : public TableFactory {
|
|
public:
|
|
explicit CuckooTableFactory(const CuckooTableOptions& table_options)
|
|
: table_options_(table_options) {}
|
|
~CuckooTableFactory() {}
|
|
|
|
const char* Name() const override { return "CuckooTable"; }
|
|
|
|
Status NewTableReader(
|
|
const ImmutableCFOptions& ioptions, const EnvOptions& env_options,
|
|
const InternalKeyComparator& internal_comparator,
|
|
unique_ptr<RandomAccessFile>&& file, uint64_t file_size,
|
|
unique_ptr<TableReader>* table) const override;
|
|
|
|
TableBuilder* NewTableBuilder(const ImmutableCFOptions& options,
|
|
const InternalKeyComparator& icomparator,
|
|
WritableFile* file, const CompressionType,
|
|
const CompressionOptions&,
|
|
const bool skip_filters = false) const override;
|
|
|
|
// Sanitizes the specified DB Options.
|
|
Status SanitizeOptions(const DBOptions& db_opts,
|
|
const ColumnFamilyOptions& cf_opts) const override {
|
|
return Status::OK();
|
|
}
|
|
|
|
std::string GetPrintableTableOptions() const override;
|
|
|
|
private:
|
|
const CuckooTableOptions table_options_;
|
|
};
|
|
|
|
} // namespace rocksdb
|
|
#endif // ROCKSDB_LITE
|