rocksdb/docs/_posts/2015-02-24-reading-rocksdb-options-from-a-file.markdown
Joel Marcey 3c2262400f Migrate the RocksDB Worpdress blog over to Jekyll
Summary:
Tried to:

- preserve existing links
- move existing images over (there were 2)
- preserve codeblocks (modified where apprporiate)
- etc.

Also as agreed upon:

- All blog posts are preserved.
- Comments are not preserved.
- Not turning on comments for future blog posts (use the FB developer group instead).
- Like button at the end of the blog post.

Depends on https://reviews.facebook.net/D63051

Test Plan: Visual

Reviewers: IslamAbdelRahman, lgalanis

Reviewed By: lgalanis

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D63105
2016-09-01 17:28:49 -07:00

1.7 KiB

title layout author category
Reading RocksDB options from a file post lgalanis blog

RocksDB options can be provided using a file or any string to RocksDB. The format is straightforward: write_buffer_size=1024;max_write_buffer_number=2. Any whitespace around = and ; is OK. Moreover, options can be nested as necessary. For example BlockBasedTableOptions can be nested as follows: write_buffer_size=1024; max_write_buffer_number=2; block_based_table_factory={block_size=4k};. Similarly any white space around { or } is ok. Here is what it looks like in code:

#include <string>
#include "rocksdb/db.h"
#include "rocksdb/table.h"
#include "rocksdb/utilities/convenience.h"

using namespace rocksdb;                                                                                           

int main(int argc, char** argv) {                                                                                  
  DB *db;

  Options opt;

  std::string options_string =                                                                                     
    "create_if_missing=true;max_open_files=1000;"                                                                  
    "block_based_table_factory={block_size=4096}";                                                                 

  Status s = GetDBOptionsFromString(opt, options_string, &opt);

  s = DB::Open(opt, "/tmp/mydb_rocks", &db);                                                                       

  // use db

  delete db;
}

Using GetDBOptionsFromString is a convenient way of changing options for your RocksDB application without needing to resort to recompilation or tedious command line parsing.