Skip to content

Commit

Permalink
Change namespace from leveldb to rocksdb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dhruba committed Oct 4, 2013
1 parent b3ed081 commit a143ef9
Show file tree
Hide file tree
Showing 226 changed files with 871 additions and 815 deletions.
4 changes: 2 additions & 2 deletions db/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "rocksdb/iterator.h"
#include "util/stop_watch.h"

namespace leveldb {
namespace rocksdb {

Status BuildTable(const std::string& dbname,
Env* env,
Expand Down Expand Up @@ -204,4 +204,4 @@ Status BuildTable(const std::string& dbname,
return s;
}

} // namespace leveldb
} // namespace rocksdb
4 changes: 2 additions & 2 deletions db/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "rocksdb/status.h"
#include "rocksdb/types.h"

namespace leveldb {
namespace rocksdb {

struct Options;
struct FileMetaData;
Expand All @@ -36,6 +36,6 @@ extern Status BuildTable(const std::string& dbname,
const SequenceNumber newest_snapshot,
const SequenceNumber earliest_seqno_in_memtable);

} // namespace leveldb
} // namespace rocksdb

#endif // STORAGE_LEVELDB_DB_BUILDER_H_
44 changes: 22 additions & 22 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
#include "rocksdb/status.h"
#include "rocksdb/write_batch.h"

using leveldb::Cache;
using leveldb::Comparator;
using leveldb::CompressionType;
using leveldb::DB;
using leveldb::Env;
using leveldb::FileLock;
using leveldb::FilterPolicy;
using leveldb::Iterator;
using leveldb::Logger;
using leveldb::NewBloomFilterPolicy;
using leveldb::NewLRUCache;
using leveldb::Options;
using leveldb::RandomAccessFile;
using leveldb::Range;
using leveldb::ReadOptions;
using leveldb::SequentialFile;
using leveldb::Slice;
using leveldb::Snapshot;
using leveldb::Status;
using leveldb::WritableFile;
using leveldb::WriteBatch;
using leveldb::WriteOptions;
using rocksdb::Cache;
using rocksdb::Comparator;
using rocksdb::CompressionType;
using rocksdb::DB;
using rocksdb::Env;
using rocksdb::FileLock;
using rocksdb::FilterPolicy;
using rocksdb::Iterator;
using rocksdb::Logger;
using rocksdb::NewBloomFilterPolicy;
using rocksdb::NewLRUCache;
using rocksdb::Options;
using rocksdb::RandomAccessFile;
using rocksdb::Range;
using rocksdb::ReadOptions;
using rocksdb::SequentialFile;
using rocksdb::Slice;
using rocksdb::Snapshot;
using rocksdb::Status;
using rocksdb::WritableFile;
using rocksdb::WriteBatch;
using rocksdb::WriteOptions;

using std::shared_ptr;

Expand Down
8 changes: 4 additions & 4 deletions db/corruption_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "util/testharness.h"
#include "util/testutil.h"

namespace leveldb {
namespace rocksdb {

static const int kValueSize = 1000;

Expand Down Expand Up @@ -68,7 +68,7 @@ class CorruptionTest {
void RepairDB() {
delete db_;
db_ = nullptr;
ASSERT_OK(::leveldb::RepairDB(dbname_, options_));
ASSERT_OK(::rocksdb::RepairDB(dbname_, options_));
}

void Build(int n) {
Expand Down Expand Up @@ -354,8 +354,8 @@ TEST(CorruptionTest, UnrelatedKeys) {
ASSERT_EQ(Value(1000, &tmp2).ToString(), v);
}

} // namespace leveldb
} // namespace rocksdb

int main(int argc, char** argv) {
return leveldb::test::RunAllTests();
return rocksdb::test::RunAllTests();
}
86 changes: 43 additions & 43 deletions db/db_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int FLAGS_min_write_buffer_number_to_merge = 0;
static int FLAGS_max_background_compactions = 0;

// style of compaction: level-based vs universal
static leveldb::CompactionStyle FLAGS_compaction_style = leveldb::kCompactionStyleLevel;
static rocksdb::CompactionStyle FLAGS_compaction_style = rocksdb::kCompactionStyleLevel;

// Percentage flexibility while comparing file size
// (for universal compaction only).
Expand Down Expand Up @@ -201,7 +201,7 @@ static bool FLAGS_verify_checksum = false;

// Database statistics
static bool FLAGS_statistics = false;
static class std::shared_ptr<leveldb::Statistics> dbstats;
static class std::shared_ptr<rocksdb::Statistics> dbstats;

// Number of write operations to do. If negative, do FLAGS_num reads.
static long FLAGS_writes = -1;
Expand Down Expand Up @@ -279,8 +279,8 @@ static int FLAGS_disable_seek_compaction = false;
static uint64_t FLAGS_delete_obsolete_files_period_micros = 0;

// Algorithm used to compress the database
static enum leveldb::CompressionType FLAGS_compression_type =
leveldb::kSnappyCompression;
static enum rocksdb::CompressionType FLAGS_compression_type =
rocksdb::kSnappyCompression;

// If non-negative, compression starts from this level. Levels with number
// < FLAGS_min_level_to_compress are not compressed.
Expand All @@ -290,7 +290,7 @@ static int FLAGS_min_level_to_compress = -1;
static int FLAGS_table_cache_numshardbits = 4;

// posix or hdfs environment
static leveldb::Env* FLAGS_env = leveldb::Env::Default();
static rocksdb::Env* FLAGS_env = rocksdb::Env::Default();

// Stats are reported every N operations when this is greater
// than zero. When 0 the interval grows over time.
Expand Down Expand Up @@ -339,11 +339,11 @@ static bool FLAGS_use_mmap_writes;

// Advise random access on table file open
static bool FLAGS_advise_random_on_open =
leveldb::Options().advise_random_on_open;
rocksdb::Options().advise_random_on_open;

// Access pattern advice when a file is compacted
static auto FLAGS_compaction_fadvice =
leveldb::Options().access_hint_on_compaction_start;
rocksdb::Options().access_hint_on_compaction_start;

// Use multiget to access a series of keys instead of get
static bool FLAGS_use_multiget = false;
Expand All @@ -358,13 +358,13 @@ static bool FLAGS_warn_missing_keys = true;

// Use adaptive mutex
static auto FLAGS_use_adaptive_mutex =
leveldb::Options().use_adaptive_mutex;
rocksdb::Options().use_adaptive_mutex;

// Allows OS to incrementally sync files to disk while they are being
// written, in the background. Issue one request for every bytes_per_sync
// written. 0 turns it off.
static auto FLAGS_bytes_per_sync =
leveldb::Options().bytes_per_sync;
rocksdb::Options().bytes_per_sync;

// On true, deletes use bloom-filter and drop the delete if key not present
static bool FLAGS_filter_deletes = false;
Expand All @@ -387,9 +387,9 @@ static enum RepFactory FLAGS_rep_factory;
static std::string FLAGS_merge_operator = "";

static auto FLAGS_purge_log_after_memtable_flush =
leveldb::Options().purge_log_after_memtable_flush;
rocksdb::Options().purge_log_after_memtable_flush;

namespace leveldb {
namespace rocksdb {

// Helper for quickly generating random data.
class RandomGenerator {
Expand Down Expand Up @@ -691,16 +691,16 @@ class Benchmark {
fprintf(stdout, "Write rate limit: %d\n", FLAGS_writes_per_second);

switch (FLAGS_compression_type) {
case leveldb::kNoCompression:
case rocksdb::kNoCompression:
fprintf(stdout, "Compression: none\n");
break;
case leveldb::kSnappyCompression:
case rocksdb::kSnappyCompression:
fprintf(stdout, "Compression: snappy\n");
break;
case leveldb::kZlibCompression:
case rocksdb::kZlibCompression:
fprintf(stdout, "Compression: zlib\n");
break;
case leveldb::kBZip2Compression:
case rocksdb::kBZip2Compression:
fprintf(stdout, "Compression: bzip2\n");
break;
}
Expand Down Expand Up @@ -735,7 +735,7 @@ class Benchmark {
"WARNING: Assertions are enabled; benchmarks unnecessarily slow\n");
#endif

if (FLAGS_compression_type != leveldb::kNoCompression) {
if (FLAGS_compression_type != rocksdb::kNoCompression) {
// The test string should not be too small.
const int len = FLAGS_block_size;
char* text = (char*) malloc(len+1);
Expand Down Expand Up @@ -2303,24 +2303,24 @@ class Benchmark {
}
};

} // namespace leveldb
} // namespace rocksdb

int main(int argc, char** argv) {
leveldb::InstallStackTraceHandler();
rocksdb::InstallStackTraceHandler();

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;
FLAGS_compaction_style = leveldb::Options().compaction_style;
rocksdb::Options().max_background_compactions;
FLAGS_compaction_style = rocksdb::Options().compaction_style;
// Compression test code above refers to FLAGS_block_size
FLAGS_block_size = leveldb::Options().block_size;
FLAGS_use_os_buffer = leveldb::EnvOptions().use_os_buffer;
FLAGS_use_mmap_reads = leveldb::EnvOptions().use_mmap_reads;
FLAGS_use_mmap_writes = leveldb::EnvOptions().use_mmap_writes;
FLAGS_block_size = rocksdb::Options().block_size;
FLAGS_use_os_buffer = rocksdb::EnvOptions().use_os_buffer;
FLAGS_use_mmap_reads = rocksdb::EnvOptions().use_mmap_reads;
FLAGS_use_mmap_writes = rocksdb::EnvOptions().use_mmap_writes;

std::string default_db_path;

Expand All @@ -2333,7 +2333,7 @@ int main(int argc, char** argv) {
char buf[2048];
char str[512];

if (leveldb::Slice(argv[i]).starts_with("--benchmarks=")) {
if (rocksdb::Slice(argv[i]).starts_with("--benchmarks=")) {
FLAGS_benchmarks = argv[i] + strlen("--benchmarks=");
} else if (sscanf(argv[i], "--compression_ratio=%lf%c", &d, &junk) == 1) {
FLAGS_compression_ratio = d;
Expand Down Expand Up @@ -2384,7 +2384,7 @@ int main(int argc, char** argv) {
== 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) {
Expand Down Expand Up @@ -2424,7 +2424,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();
FLAGS_statistics = true;
}
} else if (sscanf(argv[i], "--writes=%lld%c", &ll, &junk) == 1) {
Expand Down Expand Up @@ -2456,7 +2456,7 @@ int main(int argc, char** argv) {
(n == 0 || n == 1)) {
FLAGS_get_approx = n;
} else if (sscanf(argv[i], "--hdfs=%s", buf) == 1) {
FLAGS_env = new leveldb::HdfsEnv(buf);
FLAGS_env = new rocksdb::HdfsEnv(buf);
} else if (sscanf(argv[i], "--num_levels=%d%c",
&n, &junk) == 1) {
FLAGS_num_levels = n;
Expand All @@ -2478,7 +2478,7 @@ int main(int argc, char** argv) {
} else if (sscanf(argv[i],
"--max_bytes_for_level_multiplier_additional=%s%c",
str, &junk) == 1) {
std::vector<std::string> fanout = leveldb::stringSplit(str, ',');
std::vector<std::string> fanout = rocksdb::stringSplit(str, ',');
for (unsigned int j= 0; j < fanout.size(); j++) {
FLAGS_max_bytes_for_level_multiplier_additional.push_back(
std::stoi(fanout[j]));
Expand All @@ -2492,13 +2492,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]);
}
Expand Down Expand Up @@ -2561,13 +2561,13 @@ int main(int argc, char** argv) {
FLAGS_advise_random_on_open = n;
} else if (sscanf(argv[i], "--compaction_fadvice=%s", buf) == 1) {
if (!strcasecmp(buf, "NONE"))
FLAGS_compaction_fadvice = leveldb::Options::NONE;
FLAGS_compaction_fadvice = rocksdb::Options::NONE;
else if (!strcasecmp(buf, "NORMAL"))
FLAGS_compaction_fadvice = leveldb::Options::NORMAL;
FLAGS_compaction_fadvice = rocksdb::Options::NORMAL;
else if (!strcasecmp(buf, "SEQUENTIAL"))
FLAGS_compaction_fadvice = leveldb::Options::SEQUENTIAL;
FLAGS_compaction_fadvice = rocksdb::Options::SEQUENTIAL;
else if (!strcasecmp(buf, "WILLNEED"))
FLAGS_compaction_fadvice = leveldb::Options::WILLNEED;
FLAGS_compaction_fadvice = rocksdb::Options::WILLNEED;
else {
fprintf(stdout, "Unknown compaction fadvice:%s\n", buf);
}
Expand Down Expand Up @@ -2615,12 +2615,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 += "/dbbench";
FLAGS_db = default_db_path.c_str();
}

leveldb::Benchmark benchmark;
rocksdb::Benchmark benchmark;
benchmark.Run();
return 0;
}
2 changes: 1 addition & 1 deletion db/db_filesnapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "port/port.h"
#include "util/mutexlock.h"

namespace leveldb {
namespace rocksdb {

Status DBImpl::DisableFileDeletions() {
MutexLock l(&mutex_);
Expand Down
4 changes: 2 additions & 2 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "util/mutexlock.h"
#include "util/stop_watch.h"

namespace leveldb {
namespace rocksdb {

void dumpLeveldbBuildVersion(Logger * log);

Expand Down Expand Up @@ -3294,4 +3294,4 @@ void dumpLeveldbBuildVersion(Logger * log) {
leveldb_build_compile_time, leveldb_build_compile_date);
}

} // namespace leveldb
} // namespace rocksdb
4 changes: 2 additions & 2 deletions db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "scribe/scribe_logger.h"
#endif

namespace leveldb {
namespace rocksdb {

class MemTable;
class TableCache;
Expand Down Expand Up @@ -444,6 +444,6 @@ extern Options SanitizeOptions(const std::string& db,
const InternalFilterPolicy* ipolicy,
const Options& src);

} // namespace leveldb
} // namespace rocksdb

#endif // STORAGE_LEVELDB_DB_DB_IMPL_H_
Loading

0 comments on commit a143ef9

Please sign in to comment.