c abi: allow compaction filter ignore snapshot (#1268)

close #1262
main
Jay 9 years ago committed by Siying Dong
parent 0b63f51fbc
commit 49d88be021
  1. 10
      db/c.cc
  2. 2
      include/rocksdb/c.h
  3. 2
      include/rocksdb/compaction_filter.h

@ -123,6 +123,7 @@ struct rocksdb_compactionfilter_t : public CompactionFilter {
char** new_value, size_t *new_value_length, char** new_value, size_t *new_value_length,
unsigned char* value_changed); unsigned char* value_changed);
const char* (*name_)(void*); const char* (*name_)(void*);
unsigned char ignore_snapshots_;
virtual ~rocksdb_compactionfilter_t() { virtual ~rocksdb_compactionfilter_t() {
(*destructor_)(state_); (*destructor_)(state_);
@ -148,6 +149,8 @@ struct rocksdb_compactionfilter_t : public CompactionFilter {
} }
virtual const char* Name() const override { return (*name_)(state_); } virtual const char* Name() const override { return (*name_)(state_); }
virtual bool IgnoreSnapshots() const override { return ignore_snapshots_; }
}; };
struct rocksdb_compactionfilterfactory_t : public CompactionFilterFactory { struct rocksdb_compactionfilterfactory_t : public CompactionFilterFactory {
@ -1919,10 +1922,17 @@ rocksdb_compactionfilter_t* rocksdb_compactionfilter_create(
result->state_ = state; result->state_ = state;
result->destructor_ = destructor; result->destructor_ = destructor;
result->filter_ = filter; result->filter_ = filter;
result->ignore_snapshots_ = false;
result->name_ = name; result->name_ = name;
return result; 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) { void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t* filter) {
delete filter; delete filter;
} }

@ -729,6 +729,8 @@ rocksdb_compactionfilter_create(
size_t* new_value_length, size_t* new_value_length,
unsigned char* value_changed), unsigned char* value_changed),
const char* (*name)(void*)); 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( extern ROCKSDB_LIBRARY_API void rocksdb_compactionfilter_destroy(
rocksdb_compactionfilter_t*); rocksdb_compactionfilter_t*);

@ -106,7 +106,7 @@ class CompactionFilter {
// By default, compaction will only call Filter() on keys written after the // By default, compaction will only call Filter() on keys written after the
// most recent call to GetSnapshot(). However, if the compaction filter // 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. // 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 // 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 // irrespective of snapshots. In particular, care should be taken

Loading…
Cancel
Save