ldb: support --block_size=<4096|65536|...> and --auto_compaction=<0|1>

Summary: This allows us to use ldb to do more experiments like block_size changes.

Test Plan: run it by hand.

Reviewers: dhruba, sheki, emayanke

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D7431
This commit is contained in:
Zheng Shao 2012-12-15 18:57:31 -08:00
parent c28097538a
commit 7dc8bb710e
2 changed files with 32 additions and 2 deletions

View File

@ -13,13 +13,17 @@ namespace leveldb {
const char* LDBCommand::BLOOM_ARG = "--bloom_bits=";
const char* LDBCommand::COMPRESSION_TYPE_ARG = "--compression_type=";
const char* LDBCommand::BLOCK_SIZE = "--block_size=";
const char* LDBCommand::AUTO_COMPACTION = "--auto_compaction=";
void LDBCommand::parse_open_args(std::vector<std::string>& args) {
std::vector<std::string> rest_of_args;
for (unsigned int i = 0; i < args.size(); i++) {
std::string& arg = args.at(i);
if (arg.find(BLOOM_ARG) == 0
|| arg.find(COMPRESSION_TYPE_ARG) == 0) {
|| arg.find(COMPRESSION_TYPE_ARG) == 0
|| arg.find(BLOCK_SIZE) == 0
|| arg.find(AUTO_COMPACTION) == 0) {
open_args_.push_back(arg);
} else {
rest_of_args.push_back(arg);
@ -42,6 +46,26 @@ leveldb::Options LDBCommand::PrepareOptionsForOpenDB() {
std::string("Badly-formatted bits: ") + bits_string);
}
opt.filter_policy = leveldb::NewBloomFilterPolicy(bits);
} else if (arg.find(BLOCK_SIZE) == 0) {
std::string block_size_string = arg.substr(strlen(BLOCK_SIZE));
int block_size = atoi(block_size_string.c_str());
if (block_size == 0) {
// Badly-formatted bits.
exec_state_ = LDBCommandExecuteResult::FAILED(
std::string("Badly-formatted block size: ") + block_size_string);
}
opt.block_size = block_size;
} else if (arg.find(AUTO_COMPACTION) == 0) {
std::string value = arg.substr(strlen(AUTO_COMPACTION));
if (value == "false") {
opt.disable_auto_compactions = true;
} else if (value == "true") {
opt.disable_auto_compactions = false;
} else {
// Unknown compression.
exec_state_ = LDBCommandExecuteResult::FAILED(
"Unknown auto_compaction value: " + value);
}
} else if (arg.find(COMPRESSION_TYPE_ARG) == 0) {
std::string comp = arg.substr(strlen(COMPRESSION_TYPE_ARG));
if (comp == "no") {

View File

@ -123,7 +123,11 @@ public:
ret.append(LDBCommand::BLOOM_ARG);
ret.append("<int,e.g.:14>] [");
ret.append(LDBCommand::COMPRESSION_TYPE_ARG);
ret.append("<no|snappy|zlib|bzip2>] ");
ret.append("<no|snappy|zlib|bzip2> ");
ret.append(LDBCommand::BLOCK_SIZE);
ret.append("=<block_size_in_bytes> ");
ret.append(LDBCommand::AUTO_COMPACTION);
ret.append("=<true|false>]");
}
/* Run the command, and return the execute result. */
@ -203,6 +207,8 @@ private:
static const char* BLOOM_ARG;
static const char* COMPRESSION_TYPE_ARG;
static const char* BLOCK_SIZE;
static const char* AUTO_COMPACTION;
std::vector<std::string> open_args_;
void parse_open_args(std::vector<std::string>& args);
};