]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/docs/_posts/2015-02-24-reading-rocksdb-options-from-a-file.markdown
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / docs / _posts / 2015-02-24-reading-rocksdb-options-from-a-file.markdown
1 ---
2 title: Reading RocksDB options from a file
3 layout: post
4 author: lgalanis
5 category: blog
6 redirect_from:
7 - /blog/1883/reading-rocksdb-options-from-a-file/
8 ---
9
10 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:
11
12 <!--truncate-->
13
14 ```c++
15 #include <string>
16 #include "rocksdb/db.h"
17 #include "rocksdb/table.h"
18 #include "rocksdb/utilities/convenience.h"
19
20 using namespace rocksdb;
21
22 int main(int argc, char** argv) {
23 DB *db;
24
25 Options opt;
26
27 std::string options_string =
28 "create_if_missing=true;max_open_files=1000;"
29 "block_based_table_factory={block_size=4096}";
30
31 Status s = GetDBOptionsFromString(opt, options_string, &opt);
32
33 s = DB::Open(opt, "/tmp/mydb_rocks", &db);
34
35 // use db
36
37 delete db;
38 }
39 ```
40
41 Using `GetDBOptionsFromString` is a convenient way of changing options for your RocksDB application without needing to resort to recompilation or tedious command line parsing.