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:
parent
ca250d71a1
commit
6a150c0118
@ -40,6 +40,7 @@ const string LDBCommand::ARG_FROM = "from";
|
||||
const string LDBCommand::ARG_TO = "to";
|
||||
const string LDBCommand::ARG_MAX_KEYS = "max_keys";
|
||||
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_BLOCK_SIZE = "block_size";
|
||||
const string LDBCommand::ARG_AUTO_COMPACTION = "auto_compaction";
|
||||
@ -221,9 +222,11 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
|
||||
map<string, string>::const_iterator itr;
|
||||
|
||||
BlockBasedTableOptions table_options;
|
||||
bool use_table_options = false;
|
||||
int bits;
|
||||
if (ParseIntOption(option_map_, ARG_BLOOM_BITS, bits, exec_state_)) {
|
||||
if (bits > 0) {
|
||||
use_table_options = true;
|
||||
table_options.filter_policy.reset(NewBloomFilterPolicy(bits));
|
||||
} else {
|
||||
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOOM_BITS +
|
||||
@ -234,14 +237,18 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
|
||||
int block_size;
|
||||
if (ParseIntOption(option_map_, ARG_BLOCK_SIZE, block_size, exec_state_)) {
|
||||
if (block_size > 0) {
|
||||
use_table_options = true;
|
||||
table_options.block_size = block_size;
|
||||
opt.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
} else {
|
||||
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOCK_SIZE +
|
||||
" must be > 0.");
|
||||
}
|
||||
}
|
||||
|
||||
if (use_table_options) {
|
||||
opt.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
}
|
||||
|
||||
itr = option_map_.find(ARG_AUTO_COMPACTION);
|
||||
if (itr != option_map_.end()) {
|
||||
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());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
static const string ARG_TO;
|
||||
static const string ARG_MAX_KEYS;
|
||||
static const string ARG_BLOOM_BITS;
|
||||
static const string ARG_FIX_PREFIX_LEN;
|
||||
static const string ARG_COMPRESSION_TYPE;
|
||||
static const string ARG_BLOCK_SIZE;
|
||||
static const string ARG_AUTO_COMPACTION;
|
||||
@ -284,9 +285,10 @@ protected:
|
||||
* passed in.
|
||||
*/
|
||||
vector<string> BuildCmdLineOptions(vector<string> options) {
|
||||
vector<string> ret = {ARG_DB, ARG_BLOOM_BITS, ARG_BLOCK_SIZE,
|
||||
ARG_AUTO_COMPACTION, ARG_COMPRESSION_TYPE,
|
||||
ARG_WRITE_BUFFER_SIZE, ARG_FILE_SIZE};
|
||||
vector<string> ret = {ARG_DB, ARG_BLOOM_BITS,
|
||||
ARG_BLOCK_SIZE, ARG_AUTO_COMPACTION,
|
||||
ARG_COMPRESSION_TYPE, ARG_WRITE_BUFFER_SIZE,
|
||||
ARG_FILE_SIZE, ARG_FIX_PREFIX_LEN};
|
||||
ret.insert(ret.end(), options.begin(), options.end());
|
||||
return ret;
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
" with 'put','get','scan','dump','query','batchput'"
|
||||
" : 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_FIX_PREFIX_LEN + "=<int,e.g.:14>\n");
|
||||
ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE +
|
||||
"=<no|snappy|zlib|bzip2>\n");
|
||||
ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE +
|
||||
|
Loading…
Reference in New Issue
Block a user