Skip to content

Commit

Permalink
c abi: allow compaction filter ignore snapshot (facebook#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
BusyJay authored and siying committed Aug 18, 2016
1 parent 0b63f51 commit 49d88be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct rocksdb_compactionfilter_t : public CompactionFilter {
char** new_value, size_t *new_value_length,
unsigned char* value_changed);
const char* (*name_)(void*);
unsigned char ignore_snapshots_;

virtual ~rocksdb_compactionfilter_t() {
(*destructor_)(state_);
Expand All @@ -148,6 +149,8 @@ struct rocksdb_compactionfilter_t : public CompactionFilter {
}

virtual const char* Name() const override { return (*name_)(state_); }

virtual bool IgnoreSnapshots() const override { return ignore_snapshots_; }
};

struct rocksdb_compactionfilterfactory_t : public CompactionFilterFactory {
Expand Down Expand Up @@ -1919,10 +1922,17 @@ rocksdb_compactionfilter_t* rocksdb_compactionfilter_create(
result->state_ = state;
result->destructor_ = destructor;
result->filter_ = filter;
result->ignore_snapshots_ = false;
result->name_ = name;
return result;
}

void rocksdb_compactionfilter_set_ignore_snapshots(
rocksdb_compactionfilter_t* filter,
unsigned char whether_ignore) {
filter->ignore_snapshots_ = whether_ignore;
}

void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t* filter) {
delete filter;
}
Expand Down
2 changes: 2 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ rocksdb_compactionfilter_create(
size_t* new_value_length,
unsigned char* value_changed),
const char* (*name)(void*));
extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilter_set_ignore_snapshots(
rocksdb_compactionfilter_t*, unsigned char);
extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilter_destroy(
rocksdb_compactionfilter_t*);

Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/compaction_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CompactionFilter {

// By default, compaction will only call Filter() on keys written after the
// most recent call to GetSnapshot(). However, if the compaction filter
// overrides IgnoreSnapshots to make it return false, the compaction filter
// overrides IgnoreSnapshots to make it return true, the compaction filter
// will be called even if the keys were written before the last snapshot.
// This behavior is to be used only when we want to delete a set of keys
// irrespective of snapshots. In particular, care should be taken
Expand Down

0 comments on commit 49d88be

Please sign in to comment.