From 85584d497e7b354853b72f450683d59fcf6b9c5c Mon Sep 17 00:00:00 2001 From: Sanjay Ghemawat Date: Tue, 17 Apr 2012 08:36:46 -0700 Subject: Added bloom filter support. In particular, we add a new FilterPolicy class. An instance of this class can be supplied in Options when opening a database. If supplied, the instance is used to generate summaries of keys (e.g., a bloom filter) which are placed in sstables. These summaries are consulted by DB::Get() so we can avoid reading sstable blocks that are guaranteed to not contain the key we are looking for. This change provides one implementation of FilterPolicy based on bloom filters. Other changes: - Updated version number to 1.4. - Some build tweaks. - C binding for CompactRange. - A few more benchmarks: deleteseq, deleterandom, readmissing, seekrandom. - Minor .gitignore update. --- include/leveldb/c.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'include/leveldb/c.h') diff --git a/include/leveldb/c.h b/include/leveldb/c.h index 0be993d..70e3cc6 100644 --- a/include/leveldb/c.h +++ b/include/leveldb/c.h @@ -55,6 +55,7 @@ typedef struct leveldb_cache_t leveldb_cache_t; typedef struct leveldb_comparator_t leveldb_comparator_t; typedef struct leveldb_env_t leveldb_env_t; typedef struct leveldb_filelock_t leveldb_filelock_t; +typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t; typedef struct leveldb_iterator_t leveldb_iterator_t; typedef struct leveldb_logger_t leveldb_logger_t; typedef struct leveldb_options_t leveldb_options_t; @@ -127,6 +128,11 @@ extern void leveldb_approximate_sizes( const char* const* range_limit_key, const size_t* range_limit_key_len, uint64_t* sizes); +extern void leveldb_compact_range( + leveldb_t* db, + const char* start_key, size_t start_key_len, + const char* limit_key, size_t limit_key_len); + /* Management operations */ extern void leveldb_destroy_db( @@ -177,6 +183,9 @@ extern void leveldb_options_destroy(leveldb_options_t*); extern void leveldb_options_set_comparator( leveldb_options_t*, leveldb_comparator_t*); +extern void leveldb_options_set_filter_policy( + leveldb_options_t*, + leveldb_filterpolicy_t*); extern void leveldb_options_set_create_if_missing( leveldb_options_t*, unsigned char); extern void leveldb_options_set_error_if_exists( @@ -209,6 +218,26 @@ extern leveldb_comparator_t* leveldb_comparator_create( const char* (*name)(void*)); extern void leveldb_comparator_destroy(leveldb_comparator_t*); +/* Filter policy */ + +extern leveldb_filterpolicy_t* leveldb_filterpolicy_create( + void* state, + void (*destructor)(void*), + char* (*create_filter)( + void*, + const char* const* key_array, const size_t* key_length_array, + int num_keys, + size_t* filter_length), + unsigned char (*key_may_match)( + void*, + const char* key, size_t length, + const char* filter, size_t filter_length), + const char* (*name)(void*)); +extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*); + +extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom( + int bits_per_key); + /* Read options */ extern leveldb_readoptions_t* leveldb_readoptions_create(); -- cgit v1.2.1