diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index 8eda39bf9..70f0c6a94 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -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::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::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(fix_prefix_len))); + } else { + exec_state_ = + LDBCommandExecuteResult::FAILED(ARG_FIX_PREFIX_LEN + " must be > 0."); + } + } + return opt; } diff --git a/util/ldb_cmd.h b/util/ldb_cmd.h index 0553fe64a..9ffe0eabc 100644 --- a/util/ldb_cmd.h +++ b/util/ldb_cmd.h @@ -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 BuildCmdLineOptions(vector options) { - vector ret = {ARG_DB, ARG_BLOOM_BITS, ARG_BLOCK_SIZE, - ARG_AUTO_COMPACTION, ARG_COMPRESSION_TYPE, - ARG_WRITE_BUFFER_SIZE, ARG_FILE_SIZE}; + vector 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; } diff --git a/util/ldb_tool.cc b/util/ldb_tool.cc index 271dba350..bb6c8ffca 100644 --- a/util/ldb_tool.cc +++ b/util/ldb_tool.cc @@ -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 + "=\n"); + ret.append(" --" + LDBCommand::ARG_FIX_PREFIX_LEN + "=\n"); ret.append(" --" + LDBCommand::ARG_COMPRESSION_TYPE + "=\n"); ret.append(" --" + LDBCommand::ARG_BLOCK_SIZE +