C API: Add support for compaction filter factories (v1)
This commit is contained in:
parent
0bf5589c74
commit
91bede79cc
54
db/c.cc
54
db/c.cc
@ -35,6 +35,7 @@ using rocksdb::ColumnFamilyDescriptor;
|
|||||||
using rocksdb::ColumnFamilyHandle;
|
using rocksdb::ColumnFamilyHandle;
|
||||||
using rocksdb::ColumnFamilyOptions;
|
using rocksdb::ColumnFamilyOptions;
|
||||||
using rocksdb::CompactionFilter;
|
using rocksdb::CompactionFilter;
|
||||||
|
using rocksdb::CompactionFilterFactory;
|
||||||
using rocksdb::Comparator;
|
using rocksdb::Comparator;
|
||||||
using rocksdb::CompressionType;
|
using rocksdb::CompressionType;
|
||||||
using rocksdb::DB;
|
using rocksdb::DB;
|
||||||
@ -84,6 +85,10 @@ struct rocksdb_cache_t { shared_ptr<Cache> rep; };
|
|||||||
struct rocksdb_livefiles_t { std::vector<LiveFileMetaData> rep; };
|
struct rocksdb_livefiles_t { std::vector<LiveFileMetaData> rep; };
|
||||||
struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; };
|
struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; };
|
||||||
|
|
||||||
|
struct rocksdb_compactionfiltercontext_t {
|
||||||
|
CompactionFilter::Context rep;
|
||||||
|
};
|
||||||
|
|
||||||
struct rocksdb_compactionfilter_t : public CompactionFilter {
|
struct rocksdb_compactionfilter_t : public CompactionFilter {
|
||||||
void* state_;
|
void* state_;
|
||||||
void (*destructor_)(void*);
|
void (*destructor_)(void*);
|
||||||
@ -127,6 +132,26 @@ struct rocksdb_compactionfilter_t : public CompactionFilter {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct rocksdb_compactionfilterfactory_t : public CompactionFilterFactory {
|
||||||
|
void* state_;
|
||||||
|
void (*destructor_)(void*);
|
||||||
|
rocksdb_compactionfilter_t* (*create_compaction_filter_)(
|
||||||
|
void*, rocksdb_compactionfiltercontext_t* context);
|
||||||
|
const char* (*name_)(void*);
|
||||||
|
|
||||||
|
virtual ~rocksdb_compactionfilterfactory_t() { (*destructor_)(state_); }
|
||||||
|
|
||||||
|
virtual std::unique_ptr<CompactionFilter> CreateCompactionFilter(
|
||||||
|
const CompactionFilter::Context& context) {
|
||||||
|
rocksdb_compactionfiltercontext_t ccontext;
|
||||||
|
ccontext.rep = context;
|
||||||
|
CompactionFilter* cf = (*create_compaction_filter_)(state_, &ccontext);
|
||||||
|
return std::unique_ptr<CompactionFilter>(cf);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const char* Name() const { return (*name_)(state_); }
|
||||||
|
};
|
||||||
|
|
||||||
struct rocksdb_comparator_t : public Comparator {
|
struct rocksdb_comparator_t : public Comparator {
|
||||||
void* state_;
|
void* state_;
|
||||||
void (*destructor_)(void*);
|
void (*destructor_)(void*);
|
||||||
@ -1445,6 +1470,35 @@ void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t* filter) {
|
|||||||
delete filter;
|
delete filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char rocksdb_compactionfiltercontext_is_full_compaction(
|
||||||
|
rocksdb_compactionfiltercontext_t* context) {
|
||||||
|
return context->rep.is_full_compaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char rocksdb_compactionfiltercontext_is_manual_compaction(
|
||||||
|
rocksdb_compactionfiltercontext_t* context) {
|
||||||
|
return context->rep.is_manual_compaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
rocksdb_compactionfilterfactory_t* rocksdb_compactionfilterfactory_create(
|
||||||
|
void* state, void (*destructor)(void*),
|
||||||
|
rocksdb_compactionfilter_t* (*create_compaction_filter)(
|
||||||
|
void*, rocksdb_compactionfiltercontext_t* context),
|
||||||
|
const char* (*name)(void*)) {
|
||||||
|
rocksdb_compactionfilterfactory_t* result =
|
||||||
|
new rocksdb_compactionfilterfactory_t;
|
||||||
|
result->state_ = state;
|
||||||
|
result->destructor_ = destructor;
|
||||||
|
result->create_compaction_filter_ = create_compaction_filter;
|
||||||
|
result->name_ = name;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rocksdb_compactionfilterfactory_destroy(
|
||||||
|
rocksdb_compactionfilterfactory_t* factory) {
|
||||||
|
delete factory;
|
||||||
|
}
|
||||||
|
|
||||||
rocksdb_comparator_t* rocksdb_comparator_create(
|
rocksdb_comparator_t* rocksdb_comparator_create(
|
||||||
void* state,
|
void* state,
|
||||||
void (*destructor)(void*),
|
void (*destructor)(void*),
|
||||||
|
@ -57,6 +57,10 @@ extern "C" {
|
|||||||
typedef struct rocksdb_t rocksdb_t;
|
typedef struct rocksdb_t rocksdb_t;
|
||||||
typedef struct rocksdb_cache_t rocksdb_cache_t;
|
typedef struct rocksdb_cache_t rocksdb_cache_t;
|
||||||
typedef struct rocksdb_compactionfilter_t rocksdb_compactionfilter_t;
|
typedef struct rocksdb_compactionfilter_t rocksdb_compactionfilter_t;
|
||||||
|
typedef struct rocksdb_compactionfiltercontext_t
|
||||||
|
rocksdb_compactionfiltercontext_t;
|
||||||
|
typedef struct rocksdb_compactionfilterfactory_t
|
||||||
|
rocksdb_compactionfilterfactory_t;
|
||||||
typedef struct rocksdb_comparator_t rocksdb_comparator_t;
|
typedef struct rocksdb_comparator_t rocksdb_comparator_t;
|
||||||
typedef struct rocksdb_env_t rocksdb_env_t;
|
typedef struct rocksdb_env_t rocksdb_env_t;
|
||||||
typedef struct rocksdb_filelock_t rocksdb_filelock_t;
|
typedef struct rocksdb_filelock_t rocksdb_filelock_t;
|
||||||
@ -531,6 +535,25 @@ extern rocksdb_compactionfilter_t* rocksdb_compactionfilter_create(
|
|||||||
const char* (*name)(void*));
|
const char* (*name)(void*));
|
||||||
extern void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t*);
|
extern void rocksdb_compactionfilter_destroy(rocksdb_compactionfilter_t*);
|
||||||
|
|
||||||
|
/* Compaction Filter Context */
|
||||||
|
|
||||||
|
extern unsigned char rocksdb_compactionfiltercontext_is_full_compaction(
|
||||||
|
rocksdb_compactionfiltercontext_t* context);
|
||||||
|
|
||||||
|
extern unsigned char rocksdb_compactionfiltercontext_is_manual_compaction(
|
||||||
|
rocksdb_compactionfiltercontext_t* context);
|
||||||
|
|
||||||
|
/* Compaction Filter Factory */
|
||||||
|
|
||||||
|
extern rocksdb_compactionfilterfactory_t*
|
||||||
|
rocksdb_compactionfilterfactory_create(
|
||||||
|
void* state, void (*destructor)(void*),
|
||||||
|
rocksdb_compactionfilter_t* (*create_compaction_filter)(
|
||||||
|
void*, rocksdb_compactionfiltercontext_t* context),
|
||||||
|
const char* (*name)(void*));
|
||||||
|
extern void rocksdb_compactionfilterfactory_destroy(
|
||||||
|
rocksdb_compactionfilterfactory_t*);
|
||||||
|
|
||||||
/* Comparator */
|
/* Comparator */
|
||||||
|
|
||||||
extern rocksdb_comparator_t* rocksdb_comparator_create(
|
extern rocksdb_comparator_t* rocksdb_comparator_create(
|
||||||
|
Loading…
Reference in New Issue
Block a user