Change namespace from leveldb to rocksdb

Summary:
Change namespace from leveldb to rocksdb. This allows a single
application to link in open-source leveldb code as well as
rocksdb code into the same process.

Test Plan: compile rocksdb

Reviewers: emayanke

Reviewed By: emayanke

CC: leveldb

Differential Revision: https://reviews.facebook.net/D13287
This commit is contained in:
Dhruba Borthakur
2013-10-03 21:49:15 -07:00
parent b3ed08129b
commit a143ef9b38
226 changed files with 871 additions and 815 deletions

View File

@@ -13,7 +13,7 @@
// --num_inserts = the num of inserts the first thread should perform.
// --wal_ttl = the wal ttl for the run.
using namespace leveldb;
using namespace rocksdb;
struct DataPumpThread {
size_t no_records;

View File

@@ -103,7 +103,7 @@ static int FLAGS_min_write_buffer_number_to_merge = 0;
static int FLAGS_max_background_compactions = 0;
// This is initialized to default value of false
static leveldb::CompactionStyle FLAGS_compaction_style = leveldb::kCompactionStyleLevel;
static rocksdb::CompactionStyle FLAGS_compaction_style = rocksdb::kCompactionStyleLevel;
// The ratio of file sizes that trigger compaction in universal style
static unsigned int FLAGS_universal_size_ratio = 0;
@@ -140,10 +140,10 @@ static const char* FLAGS_db = nullptr;
static bool FLAGS_verify_checksum = false;
// Allow reads to occur via mmap-ing files
static bool FLAGS_use_mmap_reads = leveldb::EnvOptions().use_mmap_reads;
static bool FLAGS_use_mmap_reads = rocksdb::EnvOptions().use_mmap_reads;
// Database statistics
static std::shared_ptr<leveldb::Statistics> dbstats;
static std::shared_ptr<rocksdb::Statistics> dbstats;
// Sync all writes to disk
static bool FLAGS_sync = false;
@@ -206,11 +206,11 @@ static int FLAGS_disable_seek_compaction = false;
static uint64_t FLAGS_delete_obsolete_files_period_micros = 0;
// Algorithm to use to compress the database
static enum leveldb::CompressionType FLAGS_compression_type =
leveldb::kSnappyCompression;
static enum rocksdb::CompressionType FLAGS_compression_type =
rocksdb::kSnappyCompression;
// posix or hdfs environment
static leveldb::Env* FLAGS_env = leveldb::Env::Default();
static rocksdb::Env* FLAGS_env = rocksdb::Env::Default();
// Number of operations per thread.
static uint32_t FLAGS_ops_per_thread = 600000;
@@ -242,7 +242,7 @@ static bool FLAGS_prefix_size = 0;
// On true, replaces all writes with a Merge that behaves like a Put
static bool FLAGS_use_merge_put = false;
namespace leveldb {
namespace rocksdb {
// convert long to a big-endian slice key
static std::string Key(long val) {
@@ -1206,16 +1206,16 @@ class StressTest {
const char* compression = "";
switch (FLAGS_compression_type) {
case leveldb::kNoCompression:
case rocksdb::kNoCompression:
compression = "none";
break;
case leveldb::kSnappyCompression:
case rocksdb::kSnappyCompression:
compression = "snappy";
break;
case leveldb::kZlibCompression:
case rocksdb::kZlibCompression:
compression = "zlib";
break;
case leveldb::kBZip2Compression:
case rocksdb::kBZip2Compression:
compression = "bzip2";
break;
}
@@ -1380,26 +1380,26 @@ class StressTest {
int num_times_reopened_;
};
} // namespace leveldb
} // namespace rocksdb
int main(int argc, char** argv) {
FLAGS_write_buffer_size = leveldb::Options().write_buffer_size;
FLAGS_max_write_buffer_number = leveldb::Options().max_write_buffer_number;
FLAGS_write_buffer_size = rocksdb::Options().write_buffer_size;
FLAGS_max_write_buffer_number = rocksdb::Options().max_write_buffer_number;
FLAGS_min_write_buffer_number_to_merge =
leveldb::Options().min_write_buffer_number_to_merge;
FLAGS_open_files = leveldb::Options().max_open_files;
rocksdb::Options().min_write_buffer_number_to_merge;
FLAGS_open_files = rocksdb::Options().max_open_files;
FLAGS_max_background_compactions =
leveldb::Options().max_background_compactions;
rocksdb::Options().max_background_compactions;
FLAGS_compaction_style =
leveldb::Options().compaction_style;
rocksdb::Options().compaction_style;
FLAGS_level0_file_num_compaction_trigger =
leveldb::Options().level0_file_num_compaction_trigger;
rocksdb::Options().level0_file_num_compaction_trigger;
FLAGS_level0_slowdown_writes_trigger =
leveldb::Options().level0_slowdown_writes_trigger;
rocksdb::Options().level0_slowdown_writes_trigger;
FLAGS_level0_stop_writes_trigger =
leveldb::Options().level0_stop_writes_trigger;
rocksdb::Options().level0_stop_writes_trigger;
// Compression test code above refers to FLAGS_block_size
FLAGS_block_size = leveldb::Options().block_size;
FLAGS_block_size = rocksdb::Options().block_size;
std::string default_db_path;
for (int i = 1; i < argc; i++) {
@@ -1448,7 +1448,7 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i], "--max_background_compactions=%d%c", &n, &junk) == 1) {
FLAGS_max_background_compactions = n;
} else if (sscanf(argv[i], "--compaction_style=%d%c", &n, &junk) == 1) {
FLAGS_compaction_style = (leveldb::CompactionStyle)n;
FLAGS_compaction_style = (rocksdb::CompactionStyle)n;
} else if (sscanf(argv[i], "--cache_size=%ld%c", &l, &junk) == 1) {
FLAGS_cache_size = l;
} else if (sscanf(argv[i], "--block_size=%d%c", &n, &junk) == 1) {
@@ -1470,7 +1470,7 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i], "--statistics=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
if (n == 1) {
dbstats = leveldb::CreateDBStatistics();
dbstats = rocksdb::CreateDBStatistics();
}
} else if (sscanf(argv[i], "--sync=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
@@ -1505,7 +1505,7 @@ int main(int argc, char** argv) {
(n == 0 || n == 1)) {
FLAGS_disable_wal = n;
} else if (sscanf(argv[i], "--hdfs=%s", hdfsname) == 1) {
FLAGS_env = new leveldb::HdfsEnv(hdfsname);
FLAGS_env = new rocksdb::HdfsEnv(hdfsname);
} else if (sscanf(argv[i], "--target_file_size_base=%d%c",
&n, &junk) == 1) {
FLAGS_target_file_size_base = n;
@@ -1530,13 +1530,13 @@ int main(int argc, char** argv) {
} else if (strncmp(argv[i], "--compression_type=", 19) == 0) {
const char* ctype = argv[i] + 19;
if (!strcasecmp(ctype, "none"))
FLAGS_compression_type = leveldb::kNoCompression;
FLAGS_compression_type = rocksdb::kNoCompression;
else if (!strcasecmp(ctype, "snappy"))
FLAGS_compression_type = leveldb::kSnappyCompression;
FLAGS_compression_type = rocksdb::kSnappyCompression;
else if (!strcasecmp(ctype, "zlib"))
FLAGS_compression_type = leveldb::kZlibCompression;
FLAGS_compression_type = rocksdb::kZlibCompression;
else if (!strcasecmp(ctype, "bzip2"))
FLAGS_compression_type = leveldb::kBZip2Compression;
FLAGS_compression_type = rocksdb::kBZip2Compression;
else {
fprintf(stdout, "Cannot parse %s\n", argv[i]);
}
@@ -1613,12 +1613,12 @@ int main(int argc, char** argv) {
// Choose a location for the test database if none given with --db=<path>
if (FLAGS_db == nullptr) {
leveldb::Env::Default()->GetTestDirectory(&default_db_path);
rocksdb::Env::Default()->GetTestDirectory(&default_db_path);
default_db_path += "/dbstress";
FLAGS_db = default_db_path.c_str();
}
leveldb::StressTest stress;
rocksdb::StressTest stress;
stress.Run();
return 0;
}

View File

@@ -5,7 +5,7 @@
#include "rocksdb/ldb_tool.h"
int main(int argc, char** argv) {
leveldb::LDBTool tool;
rocksdb::LDBTool tool;
tool.Run(argc, argv);
return 0;
}

View File

@@ -11,7 +11,7 @@
#include "util/testharness.h"
#include "util/ldb_cmd.h"
namespace leveldb {
namespace rocksdb {
class ReduceLevelTest {
public:
@@ -72,11 +72,11 @@ private:
Status ReduceLevelTest::OpenDB(bool create_if_missing, int num_levels,
int mem_table_compact_level) {
leveldb::Options opt;
rocksdb::Options opt;
opt.num_levels = num_levels;
opt.create_if_missing = create_if_missing;
opt.max_mem_compaction_level = mem_table_compact_level;
leveldb::Status st = leveldb::DB::Open(opt, dbname_, &db_);
rocksdb::Status st = rocksdb::DB::Open(opt, dbname_, &db_);
if (!st.ok()) {
fprintf(stderr, "Can't open the db:%s\n", st.ToString().c_str());
}
@@ -84,7 +84,7 @@ Status ReduceLevelTest::OpenDB(bool create_if_missing, int num_levels,
}
bool ReduceLevelTest::ReduceLevels(int target_level) {
std::vector<std::string> args = leveldb::ReduceDBLevelsCommand::PrepareArgs(
std::vector<std::string> args = rocksdb::ReduceDBLevelsCommand::PrepareArgs(
dbname_, target_level, false);
LDBCommand* level_reducer = LDBCommand::InitFromCmdLineArgs(args);
level_reducer->Run();
@@ -193,5 +193,5 @@ TEST(ReduceLevelTest, All_Levels) {
}
int main(int argc, char** argv) {
return leveldb::test::RunAllTests();
return rocksdb::test::RunAllTests();
}

View File

@@ -16,7 +16,7 @@ using namespace Tleveldb;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
namespace leveldb {
namespace rocksdb {
DBClientProxy::DBClientProxy(const string & host, int port) :
host_(host),

View File

@@ -18,7 +18,7 @@
* it's client codes' responsibility to catch all possible exceptions.
*/
namespace leveldb {
namespace rocksdb {
class DBClientProxy : private boost::noncopyable {
public:
@@ -52,12 +52,12 @@ class DBClientProxy : private boost::noncopyable {
// some internal help functions
void cleanUp(void);
void open(const std::string & db);
std::map<std::string, Tleveldb::DBHandle>::iterator getHandle(const std::string & db);
std::map<std::string, Trocksdb::DBHandle>::iterator getHandle(const std::string & db);
const std::string host_;
const int port_;
std::map<std::string, Tleveldb::DBHandle> dbToHandle_;
boost::shared_ptr<Tleveldb::DBClient> dbClient_;
std::map<std::string, Trocksdb::DBHandle> dbToHandle_;
boost::shared_ptr<Trocksdb::DBClient> dbClient_;
};
} // namespace

View File

@@ -16,7 +16,7 @@
using namespace std;
using namespace boost;
using namespace Tleveldb;
using namespace leveldb;
using namespace rocksdb;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;

View File

@@ -45,7 +45,7 @@ class ShellContext : private boost::noncopyable {
int argc_;
char ** argv_;
int port_;
boost::shared_ptr<leveldb::DBClientProxy> clientProxy_;
boost::shared_ptr<rocksdb::DBClientProxy> clientProxy_;
};
#endif

View File

@@ -19,7 +19,7 @@
#include "../DBClientProxy.h"
using namespace leveldb;
using namespace rocksdb;
using namespace apache::thrift;

View File

@@ -19,7 +19,7 @@
#include "util/testharness.h"
#include "util/testutil.h"
namespace leveldb {
namespace rocksdb {
class SstFileReader {
public:
@@ -119,7 +119,7 @@ Status SstFileReader::ReadSequential(bool print_kv,
return ret;
}
} // namespace leveldb
} // namespace rocksdb
static void print_help() {
fprintf(stderr,
@@ -206,8 +206,8 @@ int main(int argc, char** argv) {
}
std::vector<std::string> filenames;
leveldb::Env* env = leveldb::Env::Default();
leveldb::Status st = env->GetChildren(dir_or_file, &filenames);
rocksdb::Env* env = rocksdb::Env::Default();
rocksdb::Status st = env->GetChildren(dir_or_file, &filenames);
bool dir = true;
if (!st.ok()) {
filenames.clear();
@@ -215,8 +215,8 @@ int main(int argc, char** argv) {
dir = false;
}
std::cout << "from [" << leveldb::Slice(from_key).ToString(true)
<< "] to [" << leveldb::Slice(to_key).ToString(true) << "]\n";
std::cout << "from [" << rocksdb::Slice(from_key).ToString(true)
<< "] to [" << rocksdb::Slice(to_key).ToString(true) << "]\n";
uint64_t total_read = 0;
for (size_t i = 0; i < filenames.size(); i++) {
@@ -229,9 +229,9 @@ int main(int argc, char** argv) {
if(dir) {
filename = std::string(dir_or_file) + "/" + filename;
}
leveldb::SstFileReader reader(filename, verify_checksum,
rocksdb::SstFileReader reader(filename, verify_checksum,
output_hex);
leveldb::Status st;
rocksdb::Status st;
// scan all files in give file path.
if (command == "" || command == "scan" || command == "check") {
st = reader.ReadSequential(command != "check",