1. Each RocksDB database will now automatically persist its current set of options into a file on every successful call of DB::Open(), SetOptions(), and CreateColumnFamily() / DropColumnFamily().

  2. LoadLatestOptions() / LoadOptionsFromFile(): A function that constructs RocksDB options object from an options file.

With the above options file support, developers no longer need to maintain the full set of options of a previously-created RocksDB instance. In addition, when changing options is needed, CheckOptionsCompatibility() can further make sure the resulting set of Options can successfully open the same RocksDB database without corrupting the underlying data.

Suppose we open a RocksDB database, create a new column family on-the-fly while the database is running, and then close the database:

Since in RocksDB 4.3 or later, each RocksDB instance will automatically store its latest set of options into a options file, we can use that file to construct the options next time when we want to open the DB. This is different from RocksDB 4.2 or older version where we need to remember all the options of each the column families in order to successfully open a DB. Now let’s see how it works.

First, we call LoadLatestOptions() to load the latest set of options used by the target RocksDB database:

  1. DBOptions loaded_db_opt;
  2. std::vector<ColumnFamilyDescriptor> loaded_cf_descs;
  3. LoadLatestOptions(cfg_opts, path_to_db, &loaded_db_opt, &loaded_cf_descs);

Since C++ does not have reflection, the following user-defined functions and pointer-typed options will only be initialized with default values. Detailed information can be found in rocksdb/utilities/options_util.h:

  1. loaded_bbt_opt->block_cache = cache;
  2. }
  3. loaded_cf_descs[0].options.compaction_filter = new MyCompactionFilter();

Now we perform sanity check to make sure the set of options is safe to open the target database:

If the return value indicates OK status, we can proceed and use the loaded set of options to open the target RocksDB database:

  1. s = DB::Open(loaded_db_opt, kDBPath, loaded_cf_descs, &handles, &db);

In cases where an options file of a newer version is used with an older RocksDB version (say, when downgrading due to a bug), the older RocksDB version might not know about some newer options. ignore_unknown_options flag can be used to handle such cases. By setting the , unknown options will be ignored. By default it is set to false.

RocksDB Options File Format

RocksDB options file is a text file that follows the . Each RocksDB options file has one Version section, one DBOptions section, and one CFOptions and TableOptions section for each column family. Below is an example RocksDB options file. A complete example can be found in examples/rocksdb_option_file_example.ini: