ldb: support --fix_prefix_len

Summary:
ldb to support --fix_prefix_len to allow us to verify more cases.
Also fix a small issue that --bloom_bits might not be applied if --block_size is not given.

Test Plan: run ldb tool against an example DB.

Reviewers: ljin, yhchiang, rven, igor

Reviewed By: igor

Subscribers: leveldb

Differential Revision: https://reviews.facebook.net/D24819
This commit is contained in:
sdong 2014-10-13 16:08:02 -07:00
parent ca250d71a1
commit 6a150c0118
3 changed files with 26 additions and 4 deletions

View File

@ -40,6 +40,7 @@ const string LDBCommand::ARG_FROM = "from";
const string LDBCommand::ARG_TO = "to"; const string LDBCommand::ARG_TO = "to";
const string LDBCommand::ARG_MAX_KEYS = "max_keys"; const string LDBCommand::ARG_MAX_KEYS = "max_keys";
const string LDBCommand::ARG_BLOOM_BITS = "bloom_bits"; const string LDBCommand::ARG_BLOOM_BITS = "bloom_bits";
const string LDBCommand::ARG_FIX_PREFIX_LEN = "fix_prefix_len";
const string LDBCommand::ARG_COMPRESSION_TYPE = "compression_type"; const string LDBCommand::ARG_COMPRESSION_TYPE = "compression_type";
const string LDBCommand::ARG_BLOCK_SIZE = "block_size"; const string LDBCommand::ARG_BLOCK_SIZE = "block_size";
const string LDBCommand::ARG_AUTO_COMPACTION = "auto_compaction"; const string LDBCommand::ARG_AUTO_COMPACTION = "auto_compaction";
@ -221,9 +222,11 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
map<string, string>::const_iterator itr; map<string, string>::const_iterator itr;
BlockBasedTableOptions table_options; BlockBasedTableOptions table_options;
bool use_table_options = false;
int bits; int bits;
if (ParseIntOption(option_map_, ARG_BLOOM_BITS, bits, exec_state_)) { if (ParseIntOption(option_map_, ARG_BLOOM_BITS, bits, exec_state_)) {
if (bits > 0) { if (bits > 0) {
use_table_options = true;
table_options.filter_policy.reset(NewBloomFilterPolicy(bits)); table_options.filter_policy.reset(NewBloomFilterPolicy(bits));
} else { } else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOOM_BITS + exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOOM_BITS +
@ -234,14 +237,18 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
int block_size; int block_size;
if (ParseIntOption(option_map_, ARG_BLOCK_SIZE, block_size, exec_state_)) { if (ParseIntOption(option_map_, ARG_BLOCK_SIZE, block_size, exec_state_)) {
if (block_size > 0) { if (block_size > 0) {
use_table_options = true;
table_options.block_size = block_size; table_options.block_size = block_size;
opt.table_factory.reset(NewBlockBasedTableFactory(table_options));
} else { } else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOCK_SIZE + exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOCK_SIZE +
" must be > 0."); " must be > 0.");
} }
} }
if (use_table_options) {
opt.table_factory.reset(NewBlockBasedTableFactory(table_options));
}
itr = option_map_.find(ARG_AUTO_COMPACTION); itr = option_map_.find(ARG_AUTO_COMPACTION);
if (itr != option_map_.end()) { if (itr != option_map_.end()) {
opt.disable_auto_compactions = ! StringToBool(itr->second); opt.disable_auto_compactions = ! StringToBool(itr->second);
@ -294,6 +301,18 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
opt.db_paths.emplace_back(db_path_, std::numeric_limits<uint64_t>::max()); opt.db_paths.emplace_back(db_path_, std::numeric_limits<uint64_t>::max());
} }
int fix_prefix_len;
if (ParseIntOption(option_map_, ARG_FIX_PREFIX_LEN, fix_prefix_len,
exec_state_)) {
if (fix_prefix_len > 0) {
opt.prefix_extractor.reset(
NewFixedPrefixTransform(static_cast<size_t>(fix_prefix_len)));
} else {
exec_state_ =
LDBCommandExecuteResult::FAILED(ARG_FIX_PREFIX_LEN + " must be > 0.");
}
}
return opt; return opt;
} }

View File

@ -46,6 +46,7 @@ public:
static const string ARG_TO; static const string ARG_TO;
static const string ARG_MAX_KEYS; static const string ARG_MAX_KEYS;
static const string ARG_BLOOM_BITS; static const string ARG_BLOOM_BITS;
static const string ARG_FIX_PREFIX_LEN;
static const string ARG_COMPRESSION_TYPE; static const string ARG_COMPRESSION_TYPE;
static const string ARG_BLOCK_SIZE; static const string ARG_BLOCK_SIZE;
static const string ARG_AUTO_COMPACTION; static const string ARG_AUTO_COMPACTION;
@ -284,9 +285,10 @@ protected:
* passed in. * passed in.
*/ */
vector<string> BuildCmdLineOptions(vector<string> options) { vector<string> BuildCmdLineOptions(vector<string> options) {
vector<string> ret = {ARG_DB, ARG_BLOOM_BITS, ARG_BLOCK_SIZE, vector<string> ret = {ARG_DB, ARG_BLOOM_BITS,
ARG_AUTO_COMPACTION, ARG_COMPRESSION_TYPE, ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION,
ARG_WRITE_BUFFER_SIZE, ARG_FILE_SIZE}; ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE,
ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN};
ret.insert(ret.end(), options.begin(), options.end()); ret.insert(ret.end(), options.begin(), options.end());
return ret; return ret;
} }

View File

@ -47,6 +47,7 @@ public:
" with 'put','get','scan','dump','query','batchput'" " with 'put','get','scan','dump','query','batchput'"
" : DB supports ttl and value is internally timestamp-suffixed\n"); " : DB supports ttl and value is internally timestamp-suffixed\n");
ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n"); ret.append(" --" + LDBCommand::ARG_BLOOM_BITS + "=<int,e.g.:14>\n");
ret.append(" --" + LDBCommand::ARG_FIX_PREFIX_LEN + "=<int,e.g.:14>\n");
ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE + ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE +
"=<no|snappy|zlib|bzip2>\n"); "=<no|snappy|zlib|bzip2>\n");
ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE + ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE +