Skip to content

Commit 930cb0b

Browse files
author
lovro
committed
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
1 parent 0b5b81a commit 930cb0b

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

include/rocksdb/compaction_filter.h

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ class CompactionFilter {
4040
// When the value is to be preserved, the application has the option
4141
// to modify the existing_value and pass it back through new_value.
4242
// value_changed needs to be set to true in this case.
43+
//
44+
// If multithreaded compaction is being used *and* a single CompactionFilter
45+
// instance was supplied via Options::compaction_filter, this method may be
46+
// called from different threads concurrently. The application must ensure
47+
// that the call is thread-safe.
48+
//
49+
// If the CompactionFilter was created by a factory, then it will only ever
50+
// be used by a single thread that is doing the compaction run, and this
51+
// call does not need to be thread-safe. However, multiple filters may be
52+
// in existence and operating concurrently.
4353
virtual bool Filter(int level,
4454
const Slice& key,
4555
const Slice& existing_value,

include/rocksdb/options.h

+20-8
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,33 @@ struct Options {
9393
// Default: nullptr
9494
shared_ptr<MergeOperator> merge_operator;
9595

96-
// The client must provide compaction_filter_factory if it requires a new
97-
// compaction filter to be used for different compaction processes
96+
// A single CompactionFilter instance to call into during compaction.
9897
// Allows an application to modify/delete a key-value during background
9998
// compaction.
100-
// Ideally, client should specify only one of filter or factory.
99+
//
100+
// If the client requires a new compaction filter to be used for different
101+
// compaction runs, it can specify compaction_filter_factory instead of this
102+
// option. The client should specify only one of the two.
101103
// compaction_filter takes precedence over compaction_filter_factory if
102104
// client specifies both.
105+
//
106+
// If multithreaded compaction is being used, the supplied CompactionFilter
107+
// instance may be used from different threads concurrently and so should be
108+
// thread-safe.
109+
//
103110
// Default: nullptr
104111
const CompactionFilter* compaction_filter;
105112

113+
// This is a factory that provides compaction filter objects which allow
114+
// an application to modify/delete a key-value during background compaction.
115+
//
116+
// A new filter will be created on each compaction run. If multithreaded
117+
// compaction is being used, each created CompactionFilter will only be used
118+
// from a single thread and so does not need to be thread-safe.
119+
//
120+
// Default: a factory that doesn't provide any object
121+
std::shared_ptr<CompactionFilterFactory> compaction_filter_factory;
122+
106123
// If true, the database will be created if it is missing.
107124
// Default: false
108125
bool create_if_missing;
@@ -600,11 +617,6 @@ struct Options {
600617
// Table and TableBuilder.
601618
std::shared_ptr<TableFactory> table_factory;
602619

603-
// This is a factory that provides compaction filter objects which allow
604-
// an application to modify/delete a key-value during background compaction.
605-
// Default: a factory that doesn't provide any object
606-
std::shared_ptr<CompactionFilterFactory> compaction_filter_factory;
607-
608620
// This option allows user to to collect their own interested statistics of
609621
// the tables.
610622
// Default: emtpy vector -- no user-defined statistics collection will be

util/options.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Options::Options()
2525
: comparator(BytewiseComparator()),
2626
merge_operator(nullptr),
2727
compaction_filter(nullptr),
28+
compaction_filter_factory(
29+
std::shared_ptr<CompactionFilterFactory>(
30+
new DefaultCompactionFilterFactory())),
2831
create_if_missing(false),
2932
error_if_exists(false),
3033
paranoid_checks(false),
@@ -97,9 +100,6 @@ Options::Options()
97100
memtable_factory(std::shared_ptr<SkipListFactory>(new SkipListFactory)),
98101
table_factory(
99102
std::shared_ptr<TableFactory>(new BlockBasedTableFactory())),
100-
compaction_filter_factory(
101-
std::shared_ptr<CompactionFilterFactory>(
102-
new DefaultCompactionFilterFactory())),
103103
inplace_update_support(false),
104104
inplace_update_num_locks(10000) {
105105
assert(memtable_factory.get() != nullptr);

0 commit comments

Comments
 (0)