Clarify CompactionFilter thread safety requirements
Summary: Documenting our discussion Test Plan: make Reviewers: dhruba, haobo Reviewed By: dhruba CC: igor Differential Revision: https://reviews.facebook.net/D14403
This commit is contained in:
parent
0b5b81a154
commit
930cb0b9ee
@ -40,6 +40,16 @@ class CompactionFilter {
|
|||||||
// When the value is to be preserved, the application has the option
|
// When the value is to be preserved, the application has the option
|
||||||
// to modify the existing_value and pass it back through new_value.
|
// to modify the existing_value and pass it back through new_value.
|
||||||
// value_changed needs to be set to true in this case.
|
// value_changed needs to be set to true in this case.
|
||||||
|
//
|
||||||
|
// If multithreaded compaction is being used *and* a single CompactionFilter
|
||||||
|
// instance was supplied via Options::compaction_filter, this method may be
|
||||||
|
// called from different threads concurrently. The application must ensure
|
||||||
|
// that the call is thread-safe.
|
||||||
|
//
|
||||||
|
// If the CompactionFilter was created by a factory, then it will only ever
|
||||||
|
// be used by a single thread that is doing the compaction run, and this
|
||||||
|
// call does not need to be thread-safe. However, multiple filters may be
|
||||||
|
// in existence and operating concurrently.
|
||||||
virtual bool Filter(int level,
|
virtual bool Filter(int level,
|
||||||
const Slice& key,
|
const Slice& key,
|
||||||
const Slice& existing_value,
|
const Slice& existing_value,
|
||||||
|
@ -93,16 +93,33 @@ struct Options {
|
|||||||
// Default: nullptr
|
// Default: nullptr
|
||||||
shared_ptr<MergeOperator> merge_operator;
|
shared_ptr<MergeOperator> merge_operator;
|
||||||
|
|
||||||
// The client must provide compaction_filter_factory if it requires a new
|
// A single CompactionFilter instance to call into during compaction.
|
||||||
// compaction filter to be used for different compaction processes
|
|
||||||
// Allows an application to modify/delete a key-value during background
|
// Allows an application to modify/delete a key-value during background
|
||||||
// compaction.
|
// compaction.
|
||||||
// Ideally, client should specify only one of filter or factory.
|
//
|
||||||
|
// If the client requires a new compaction filter to be used for different
|
||||||
|
// compaction runs, it can specify compaction_filter_factory instead of this
|
||||||
|
// option. The client should specify only one of the two.
|
||||||
// compaction_filter takes precedence over compaction_filter_factory if
|
// compaction_filter takes precedence over compaction_filter_factory if
|
||||||
// client specifies both.
|
// client specifies both.
|
||||||
|
//
|
||||||
|
// If multithreaded compaction is being used, the supplied CompactionFilter
|
||||||
|
// instance may be used from different threads concurrently and so should be
|
||||||
|
// thread-safe.
|
||||||
|
//
|
||||||
// Default: nullptr
|
// Default: nullptr
|
||||||
const CompactionFilter* compaction_filter;
|
const CompactionFilter* compaction_filter;
|
||||||
|
|
||||||
|
// This is a factory that provides compaction filter objects which allow
|
||||||
|
// an application to modify/delete a key-value during background compaction.
|
||||||
|
//
|
||||||
|
// A new filter will be created on each compaction run. If multithreaded
|
||||||
|
// compaction is being used, each created CompactionFilter will only be used
|
||||||
|
// from a single thread and so does not need to be thread-safe.
|
||||||
|
//
|
||||||
|
// Default: a factory that doesn't provide any object
|
||||||
|
std::shared_ptr<CompactionFilterFactory> compaction_filter_factory;
|
||||||
|
|
||||||
// If true, the database will be created if it is missing.
|
// If true, the database will be created if it is missing.
|
||||||
// Default: false
|
// Default: false
|
||||||
bool create_if_missing;
|
bool create_if_missing;
|
||||||
@ -600,11 +617,6 @@ struct Options {
|
|||||||
// Table and TableBuilder.
|
// Table and TableBuilder.
|
||||||
std::shared_ptr<TableFactory> table_factory;
|
std::shared_ptr<TableFactory> table_factory;
|
||||||
|
|
||||||
// This is a factory that provides compaction filter objects which allow
|
|
||||||
// an application to modify/delete a key-value during background compaction.
|
|
||||||
// Default: a factory that doesn't provide any object
|
|
||||||
std::shared_ptr<CompactionFilterFactory> compaction_filter_factory;
|
|
||||||
|
|
||||||
// This option allows user to to collect their own interested statistics of
|
// This option allows user to to collect their own interested statistics of
|
||||||
// the tables.
|
// the tables.
|
||||||
// Default: emtpy vector -- no user-defined statistics collection will be
|
// Default: emtpy vector -- no user-defined statistics collection will be
|
||||||
|
@ -25,6 +25,9 @@ Options::Options()
|
|||||||
: comparator(BytewiseComparator()),
|
: comparator(BytewiseComparator()),
|
||||||
merge_operator(nullptr),
|
merge_operator(nullptr),
|
||||||
compaction_filter(nullptr),
|
compaction_filter(nullptr),
|
||||||
|
compaction_filter_factory(
|
||||||
|
std::shared_ptr<CompactionFilterFactory>(
|
||||||
|
new DefaultCompactionFilterFactory())),
|
||||||
create_if_missing(false),
|
create_if_missing(false),
|
||||||
error_if_exists(false),
|
error_if_exists(false),
|
||||||
paranoid_checks(false),
|
paranoid_checks(false),
|
||||||
@ -97,9 +100,6 @@ Options::Options()
|
|||||||
memtable_factory(std::shared_ptr<SkipListFactory>(new SkipListFactory)),
|
memtable_factory(std::shared_ptr<SkipListFactory>(new SkipListFactory)),
|
||||||
table_factory(
|
table_factory(
|
||||||
std::shared_ptr<TableFactory>(new BlockBasedTableFactory())),
|
std::shared_ptr<TableFactory>(new BlockBasedTableFactory())),
|
||||||
compaction_filter_factory(
|
|
||||||
std::shared_ptr<CompactionFilterFactory>(
|
|
||||||
new DefaultCompactionFilterFactory())),
|
|
||||||
inplace_update_support(false),
|
inplace_update_support(false),
|
||||||
inplace_update_num_locks(10000) {
|
inplace_update_num_locks(10000) {
|
||||||
assert(memtable_factory.get() != nullptr);
|
assert(memtable_factory.get() != nullptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user