forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it easier to start using RocksDB
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: facebook#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/D18621
- Loading branch information
1 parent
acd17fd
commit 038a477
Showing
9 changed files
with
246 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ([email protected]) | ||
and Jeff Dean ([email protected]) | ||
|
||
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
column_families_example | ||
simple_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Compile RocksDB first by executing `make static_lib` in parent dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters