Summary: This diff is addressing multiple things with a single goal -- to make RocksDB easier to use: * Add some functions to Options that make RocksDB easier to tune. * Add example code for both simple RocksDB and RocksDB with Column Families. * Rewrite our README.md Regarding Options, I took a stab at something we talked about for a long time: * https://www.facebook.com/groups/rocksdb.dev/permalink/563169950448190/ I added functions: * IncreaseParallelism() -- easy, increases the thread pool and max_background_compactions * OptimizeLevelStyleCompaction(memtable_memory_budget) -- the easiest way to optimize rocksdb for less stalls with level style compaction. This is very likely not ideal configuration. Feel free to suggest improvements. I used some of Mark's suggestions from here: https://github.com/facebook/rocksdb/issues/54 * OptimizeUniversalStyleCompaction(memtable_memory_budget) -- optimize for universal compaction. Test Plan: compiled rocksdb. ran examples. Reviewers: dhruba, MarkCallaghan, haobo, sdong, yhchiang Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D18621main
parent
acd17fd002
commit
038a477b53
@ -1,82 +0,0 @@ |
||||
rocksdb: A persistent key-value store for flash storage |
||||
Authors: * The Facebook Database Engineering Team |
||||
* Build on earlier work on leveldb by Sanjay Ghemawat |
||||
(sanjay@google.com) and Jeff Dean (jeff@google.com) |
||||
|
||||
This code is a library that forms the core building block for a fast |
||||
key value server, especially suited for storing data on flash drives. |
||||
It has an Log-Structured-Merge-Database (LSM) design with flexible tradeoffs |
||||
between Write-Amplification-Factor(WAF), Read-Amplification-Factor (RAF) |
||||
and Space-Amplification-Factor(SAF). It has multi-threaded compactions, |
||||
making it specially suitable for storing multiple terabytes of data in a |
||||
single database. |
||||
|
||||
The core of this code has been derived from open-source leveldb. |
||||
|
||||
The code under this directory implements a system for maintaining a |
||||
persistent key/value store. |
||||
|
||||
See doc/index.html and github wiki (https://github.com/facebook/rocksdb/wiki) |
||||
for more explanation. |
||||
|
||||
The public interface is in include/*. Callers should not include or |
||||
rely on the details of any other header files in this package. Those |
||||
internal APIs may be changed without warning. |
||||
|
||||
Guide to header files: |
||||
|
||||
include/rocksdb/db.h |
||||
Main interface to the DB: Start here |
||||
|
||||
include/rocksdb/options.h |
||||
Control over the behavior of an entire database, and also |
||||
control over the behavior of individual reads and writes. |
||||
|
||||
include/rocksdb/comparator.h |
||||
Abstraction for user-specified comparison function. If you want |
||||
just bytewise comparison of keys, you can use the default comparator, |
||||
but clients can write their own comparator implementations if they |
||||
want custom ordering (e.g. to handle different character |
||||
encodings, etc.) |
||||
|
||||
include/rocksdb/iterator.h |
||||
Interface for iterating over data. You can get an iterator |
||||
from a DB object. |
||||
|
||||
include/rocksdb/write_batch.h |
||||
Interface for atomically applying multiple updates to a database. |
||||
|
||||
include/rocksdb/slice.h |
||||
A simple module for maintaining a pointer and a length into some |
||||
other byte array. |
||||
|
||||
include/rocksdb/status.h |
||||
Status is returned from many of the public interfaces and is used |
||||
to report success and various kinds of errors. |
||||
|
||||
include/rocksdb/env.h |
||||
Abstraction of the OS environment. A posix implementation of |
||||
this interface is in util/env_posix.cc |
||||
|
||||
include/rocksdb/table_builder.h |
||||
Lower-level modules that most clients probably won't use directly |
||||
|
||||
include/rocksdb/cache.h |
||||
An API for the block cache. |
||||
|
||||
include/rocksdb/compaction_filter.h |
||||
An API for a application filter invoked on every compaction. |
||||
|
||||
include/rocksdb/filter_policy.h |
||||
An API for configuring a bloom filter. |
||||
|
||||
include/rocksdb/memtablerep.h |
||||
An API for implementing a memtable. |
||||
|
||||
include/rocksdb/statistics.h |
||||
An API to retrieve various database statistics. |
||||
|
||||
include/rocksdb/transaction_log.h |
||||
An API to retrieve transaction logs from a database. |
||||
|
||||
Design discussions are conducted in https://www.facebook.com/groups/rocksdb.dev/ |
@ -0,0 +1,24 @@ |
||||
## RocksDB: A Persistent Key-Value Store for Flash and RAM Storage |
||||
|
||||
RocksDB is developed and maintained by Facebook Database Engineering Team. |
||||
It is built on on earlier work on LevelDB by Sanjay Ghemawat (sanjay@google.com) |
||||
and Jeff Dean (jeff@google.com) |
||||
|
||||
This code is a library that forms the core building block for a fast |
||||
key value server, especially suited for storing data on flash drives. |
||||
It has an Log-Structured-Merge-Database (LSM) design with flexible tradeoffs |
||||
between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF) |
||||
and Space-Amplification-Factor (SAF). It has multi-threaded compactions, |
||||
making it specially suitable for storing multiple terabytes of data in a |
||||
single database. |
||||
|
||||
Start with example usage here: https://github.com/facebook/rocksdb/tree/master/examples |
||||
|
||||
See [doc/index.html](https://github.com/facebook/rocksdb/blob/master/doc/index.html) and |
||||
[github wiki](https://github.com/facebook/rocksdb/wiki) for more explanation. |
||||
|
||||
The public interface is in `include/`. Callers should not include or |
||||
rely on the details of any other header files in this package. Those |
||||
internal APIs may be changed without warning. |
||||
|
||||
Design discussions are conducted in https://www.facebook.com/groups/rocksdb.dev/ |
@ -0,0 +1,2 @@ |
||||
column_families_example |
||||
simple_example |
@ -0,0 +1,9 @@ |
||||
include ../build_config.mk |
||||
|
||||
all: simple_example column_families_example |
||||
|
||||
simple_example: simple_example.cc |
||||
$(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++11 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS)
|
||||
|
||||
column_families_example: column_families_example.cc |
||||
$(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++11 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS)
|
@ -0,0 +1 @@ |
||||
Compile RocksDB first by executing `make static_lib` in parent dir |
@ -0,0 +1,72 @@ |
||||
// Copyright (c) 2013, 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.
|
||||
#include <cstdio> |
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "rocksdb/db.h" |
||||
#include "rocksdb/slice.h" |
||||
#include "rocksdb/options.h" |
||||
|
||||
using namespace rocksdb; |
||||
|
||||
std::string kDBPath = "/tmp/rocksdb_column_families_example"; |
||||
|
||||
int main() { |
||||
// open DB
|
||||
Options options; |
||||
options.create_if_missing = true; |
||||
DB* db; |
||||
Status s = DB::Open(options, kDBPath, &db); |
||||
assert(s.ok()); |
||||
|
||||
// create column family
|
||||
ColumnFamilyHandle* cf; |
||||
s = db->CreateColumnFamily(ColumnFamilyOptions(), "new_cf", &cf); |
||||
assert(s.ok()); |
||||
|
||||
// close DB
|
||||
delete cf; |
||||
delete db; |
||||
|
||||
// open DB with two column families
|
||||
std::vector<ColumnFamilyDescriptor> column_families; |
||||
// have to open default column familiy
|
||||
column_families.push_back(ColumnFamilyDescriptor( |
||||
kDefaultColumnFamilyName, ColumnFamilyOptions())); |
||||
// open the new one, too
|
||||
column_families.push_back(ColumnFamilyDescriptor( |
||||
"new_cf", ColumnFamilyOptions())); |
||||
std::vector<ColumnFamilyHandle*> handles; |
||||
s = DB::Open(DBOptions(), kDBPath, column_families, &handles, &db); |
||||
assert(s.ok()); |
||||
|
||||
// put and get from non-default column family
|
||||
s = db->Put(WriteOptions(), handles[1], Slice("key"), Slice("value")); |
||||
assert(s.ok()); |
||||
std::string value; |
||||
s = db->Get(ReadOptions(), handles[1], Slice("key"), &value); |
||||
assert(s.ok()); |
||||
|
||||
// atomic write
|
||||
WriteBatch batch; |
||||
batch.Put(handles[0], Slice("key2"), Slice("value2")); |
||||
batch.Put(handles[1], Slice("key3"), Slice("value3")); |
||||
batch.Delete(handles[0], Slice("key")); |
||||
s = db->Write(WriteOptions(), &batch); |
||||
assert(s.ok()); |
||||
|
||||
// drop column family
|
||||
s = db->DropColumnFamily(handles[1]); |
||||
assert(s.ok()); |
||||
|
||||
// close db
|
||||
for (auto handle : handles) { |
||||
delete handle; |
||||
} |
||||
delete db; |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,41 @@ |
||||
// Copyright (c) 2013, 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.
|
||||
#include <cstdio> |
||||
#include <string> |
||||
|
||||
#include "rocksdb/db.h" |
||||
#include "rocksdb/slice.h" |
||||
#include "rocksdb/options.h" |
||||
|
||||
using namespace rocksdb; |
||||
|
||||
std::string kDBPath = "/tmp/rocksdb_simple_example"; |
||||
|
||||
int main() { |
||||
DB* db; |
||||
Options options; |
||||
// Optimize RocksDB. This is the easiest way to get RocksDB to perform well
|
||||
options.IncreaseParallelism(); |
||||
options.OptimizeLevelStyleCompaction(); |
||||
// create the DB if it's not already present
|
||||
options.create_if_missing = true; |
||||
|
||||
// open DB
|
||||
Status s = DB::Open(options, kDBPath, &db); |
||||
assert(s.ok()); |
||||
|
||||
// Put key-value
|
||||
s = db->Put(WriteOptions(), "key", "value"); |
||||
assert(s.ok()); |
||||
std::string value; |
||||
// get value
|
||||
s = db->Get(ReadOptions(), "key", &value); |
||||
assert(s.ok()); |
||||
assert(value == "value"); |
||||
|
||||
delete db; |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue