Added CompatibleOptions for compatibility with LevelDB Options
Summary: Created a CompatibleOptions object that can be used as a LevelDB Options object and then converted to a RocksDB Options object using the ConvertOptions() method. Test Plan: Unit test included in diff. Reviewers: ljin Reviewed By: ljin Subscribers: sdong, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D28893
This commit is contained in:
parent
353307758b
commit
9e285d4238
144
include/rocksdb/utilities/leveldb_options.h
Normal file
144
include/rocksdb/utilities/leveldb_options.h
Normal file
@ -0,0 +1,144 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
class Cache;
|
||||
class Comparator;
|
||||
class Env;
|
||||
class FilterPolicy;
|
||||
class Logger;
|
||||
class Options;
|
||||
class Snapshot;
|
||||
|
||||
enum CompressionType : char;
|
||||
|
||||
// Options to control the behavior of a database (passed to
|
||||
// DB::Open). A LevelDBOptions object can be initialized as though
|
||||
// it were a LevelDB Options object, and then it can be converted into
|
||||
// a RocksDB Options object.
|
||||
struct LevelDBOptions {
|
||||
// -------------------
|
||||
// Parameters that affect behavior
|
||||
|
||||
// Comparator used to define the order of keys in the table.
|
||||
// Default: a comparator that uses lexicographic byte-wise ordering
|
||||
//
|
||||
// REQUIRES: The client must ensure that the comparator supplied
|
||||
// here has the same name and orders keys *exactly* the same as the
|
||||
// comparator provided to previous open calls on the same DB.
|
||||
const Comparator* comparator;
|
||||
|
||||
// If true, the database will be created if it is missing.
|
||||
// Default: false
|
||||
bool create_if_missing;
|
||||
|
||||
// If true, an error is raised if the database already exists.
|
||||
// Default: false
|
||||
bool error_if_exists;
|
||||
|
||||
// If true, the implementation will do aggressive checking of the
|
||||
// data it is processing and will stop early if it detects any
|
||||
// errors. This may have unforeseen ramifications: for example, a
|
||||
// corruption of one DB entry may cause a large number of entries to
|
||||
// become unreadable or for the entire DB to become unopenable.
|
||||
// Default: false
|
||||
bool paranoid_checks;
|
||||
|
||||
// Use the specified object to interact with the environment,
|
||||
// e.g. to read/write files, schedule background work, etc.
|
||||
// Default: Env::Default()
|
||||
Env* env;
|
||||
|
||||
// Any internal progress/error information generated by the db will
|
||||
// be written to info_log if it is non-NULL, or to a file stored
|
||||
// in the same directory as the DB contents if info_log is NULL.
|
||||
// Default: NULL
|
||||
Logger* info_log;
|
||||
|
||||
// -------------------
|
||||
// Parameters that affect performance
|
||||
|
||||
// Amount of data to build up in memory (backed by an unsorted log
|
||||
// on disk) before converting to a sorted on-disk file.
|
||||
//
|
||||
// Larger values increase performance, especially during bulk loads.
|
||||
// Up to two write buffers may be held in memory at the same time,
|
||||
// so you may wish to adjust this parameter to control memory usage.
|
||||
// Also, a larger write buffer will result in a longer recovery time
|
||||
// the next time the database is opened.
|
||||
//
|
||||
// Default: 4MB
|
||||
size_t write_buffer_size;
|
||||
|
||||
// Number of open files that can be used by the DB. You may need to
|
||||
// increase this if your database has a large working set (budget
|
||||
// one open file per 2MB of working set).
|
||||
//
|
||||
// Default: 1000
|
||||
int max_open_files;
|
||||
|
||||
// Control over blocks (user data is stored in a set of blocks, and
|
||||
// a block is the unit of reading from disk).
|
||||
|
||||
// If non-NULL, use the specified cache for blocks.
|
||||
// If NULL, leveldb will automatically create and use an 8MB internal cache.
|
||||
// Default: NULL
|
||||
Cache* block_cache;
|
||||
|
||||
// Approximate size of user data packed per block. Note that the
|
||||
// block size specified here corresponds to uncompressed data. The
|
||||
// actual size of the unit read from disk may be smaller if
|
||||
// compression is enabled. This parameter can be changed dynamically.
|
||||
//
|
||||
// Default: 4K
|
||||
size_t block_size;
|
||||
|
||||
// Number of keys between restart points for delta encoding of keys.
|
||||
// This parameter can be changed dynamically. Most clients should
|
||||
// leave this parameter alone.
|
||||
//
|
||||
// Default: 16
|
||||
int block_restart_interval;
|
||||
|
||||
// Compress blocks using the specified compression algorithm. This
|
||||
// parameter can be changed dynamically.
|
||||
//
|
||||
// Default: kSnappyCompression, which gives lightweight but fast
|
||||
// compression.
|
||||
//
|
||||
// Typical speeds of kSnappyCompression on an Intel(R) Core(TM)2 2.4GHz:
|
||||
// ~200-500MB/s compression
|
||||
// ~400-800MB/s decompression
|
||||
// Note that these speeds are significantly faster than most
|
||||
// persistent storage speeds, and therefore it is typically never
|
||||
// worth switching to kNoCompression. Even if the input data is
|
||||
// incompressible, the kSnappyCompression implementation will
|
||||
// efficiently detect that and will switch to uncompressed mode.
|
||||
CompressionType compression;
|
||||
|
||||
// If non-NULL, use the specified filter policy to reduce disk reads.
|
||||
// Many applications will benefit from passing the result of
|
||||
// NewBloomFilterPolicy() here.
|
||||
//
|
||||
// Default: NULL
|
||||
const FilterPolicy* filter_policy;
|
||||
|
||||
// Create a LevelDBOptions object with default values for all fields.
|
||||
LevelDBOptions();
|
||||
};
|
||||
|
||||
// Converts a LevelDBOptions object into a RocksDB Options object.
|
||||
Options ConvertOptions(const LevelDBOptions& leveldb_options);
|
||||
|
||||
} // namespace rocksdb
|
@ -139,6 +139,10 @@ std::string BlockBasedTableFactory::GetPrintableTableOptions() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
const BlockBasedTableOptions& BlockBasedTableFactory::GetTableOptions() const {
|
||||
return table_options_;
|
||||
}
|
||||
|
||||
TableFactory* NewBlockBasedTableFactory(
|
||||
const BlockBasedTableOptions& table_options) {
|
||||
return new BlockBasedTableFactory(table_options);
|
||||
|
@ -51,6 +51,8 @@ class BlockBasedTableFactory : public TableFactory {
|
||||
|
||||
std::string GetPrintableTableOptions() const override;
|
||||
|
||||
const BlockBasedTableOptions& GetTableOptions() const;
|
||||
|
||||
private:
|
||||
BlockBasedTableOptions table_options_;
|
||||
};
|
||||
|
@ -16,7 +16,11 @@
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include "rocksdb/options.h"
|
||||
#include "rocksdb/table.h"
|
||||
#include "table/block_based_table_factory.h"
|
||||
#include "util/testharness.h"
|
||||
#include "rocksdb/cache.h"
|
||||
#include "rocksdb/utilities/leveldb_options.h"
|
||||
#include "rocksdb/utilities/convenience.h"
|
||||
|
||||
using GFLAGS::ParseCommandLineFlags;
|
||||
@ -322,6 +326,34 @@ TEST(OptionsTest, GetOptionsFromStringTest) {
|
||||
ASSERT_EQ(new_cf_opt.arena_block_size, 21*1024UL*1024UL*1024UL*1024UL);
|
||||
}
|
||||
|
||||
TEST(OptionsTest, ConvertOptionsTest) {
|
||||
LevelDBOptions leveldb_opt;
|
||||
Options converted_opt = ConvertOptions(leveldb_opt);
|
||||
|
||||
ASSERT_EQ(converted_opt.create_if_missing, leveldb_opt.create_if_missing);
|
||||
ASSERT_EQ(converted_opt.error_if_exists, leveldb_opt.error_if_exists);
|
||||
ASSERT_EQ(converted_opt.paranoid_checks, leveldb_opt.paranoid_checks);
|
||||
ASSERT_EQ(converted_opt.env, leveldb_opt.env);
|
||||
ASSERT_EQ(converted_opt.info_log.get(), leveldb_opt.info_log);
|
||||
ASSERT_EQ(converted_opt.write_buffer_size, leveldb_opt.write_buffer_size);
|
||||
ASSERT_EQ(converted_opt.max_open_files, leveldb_opt.max_open_files);
|
||||
ASSERT_EQ(converted_opt.compression, leveldb_opt.compression);
|
||||
|
||||
std::shared_ptr<BlockBasedTableFactory> table_factory =
|
||||
std::dynamic_pointer_cast<BlockBasedTableFactory>(
|
||||
converted_opt.table_factory);
|
||||
|
||||
ASSERT_TRUE(table_factory.get() != nullptr);
|
||||
|
||||
const BlockBasedTableOptions table_opt = table_factory->GetTableOptions();
|
||||
|
||||
ASSERT_EQ(table_opt.block_cache->GetCapacity(), 8UL << 20);
|
||||
ASSERT_EQ(table_opt.block_size, leveldb_opt.block_size);
|
||||
ASSERT_EQ(table_opt.block_restart_interval,
|
||||
leveldb_opt.block_restart_interval);
|
||||
ASSERT_EQ(table_opt.filter_policy.get(), leveldb_opt.filter_policy);
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
56
utilities/leveldb_options/leveldb_options.cc
Normal file
56
utilities/leveldb_options/leveldb_options.cc
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
//
|
||||
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
|
||||
#include "rocksdb/utilities/leveldb_options.h"
|
||||
#include "rocksdb/cache.h"
|
||||
#include "rocksdb/comparator.h"
|
||||
#include "rocksdb/env.h"
|
||||
#include "rocksdb/filter_policy.h"
|
||||
#include "rocksdb/options.h"
|
||||
#include "rocksdb/table.h"
|
||||
|
||||
namespace rocksdb {
|
||||
|
||||
LevelDBOptions::LevelDBOptions()
|
||||
: comparator(BytewiseComparator()),
|
||||
create_if_missing(false),
|
||||
error_if_exists(false),
|
||||
paranoid_checks(false),
|
||||
env(Env::Default()),
|
||||
info_log(nullptr),
|
||||
write_buffer_size(4 << 20),
|
||||
max_open_files(1000),
|
||||
block_cache(nullptr),
|
||||
block_size(4096),
|
||||
block_restart_interval(16),
|
||||
compression(kSnappyCompression),
|
||||
filter_policy(nullptr) {}
|
||||
|
||||
Options ConvertOptions(const LevelDBOptions& leveldb_options) {
|
||||
Options options = Options();
|
||||
options.create_if_missing = leveldb_options.create_if_missing;
|
||||
options.error_if_exists = leveldb_options.error_if_exists;
|
||||
options.paranoid_checks = leveldb_options.paranoid_checks;
|
||||
options.env = leveldb_options.env;
|
||||
options.info_log.reset(leveldb_options.info_log);
|
||||
options.write_buffer_size = leveldb_options.write_buffer_size;
|
||||
options.max_open_files = leveldb_options.max_open_files;
|
||||
options.compression = leveldb_options.compression;
|
||||
|
||||
BlockBasedTableOptions table_options;
|
||||
table_options.block_cache.reset(leveldb_options.block_cache);
|
||||
table_options.block_size = leveldb_options.block_size;
|
||||
table_options.block_restart_interval = leveldb_options.block_restart_interval;
|
||||
table_options.filter_policy.reset(leveldb_options.filter_policy);
|
||||
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
Loading…
x
Reference in New Issue
Block a user