Skip to content

Commit 9a698af

Browse files
evanjzaidoon1
authored andcommitted
Options: Add set_track_and_verify_wals_in_manifest (#954)
This was added to the C API in RocksDB 9.7.0. The RocksDB wiki recommends setting this option to true: "We recommend to set track_and_verify_wals_in_manifest to true for production, it has been enabled in production for the entire database cluster serving the social graph for all Meta apps." See: https://github.com/facebook/rocksdb/wiki/Track-WAL-in-MANIFEST
1 parent 4a3716a commit 9a698af

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Diff for: src/db_options.rs

+29
Original file line numberDiff line numberDiff line change
@@ -3774,6 +3774,35 @@ impl Options {
37743774
}
37753775
}
37763776

3777+
/// If true, the log numbers and sizes of the synced WALs are tracked
3778+
/// in MANIFEST. During DB recovery, if a synced WAL is missing
3779+
/// from disk, or the WAL's size does not match the recorded size in
3780+
/// MANIFEST, an error will be reported and the recovery will be aborted.
3781+
///
3782+
/// This is one additional protection against WAL corruption besides the
3783+
/// per-WAL-entry checksum.
3784+
///
3785+
/// Note that this option does not work with secondary instance.
3786+
/// Currently, only syncing closed WALs are tracked. Calling `DB::SyncWAL()`,
3787+
/// etc. or writing with `WriteOptions::sync=true` to sync the live WAL is not
3788+
/// tracked for performance/efficiency reasons.
3789+
///
3790+
/// See: <https://github.com/facebook/rocksdb/wiki/Track-WAL-in-MANIFEST>
3791+
///
3792+
/// Default: false (disabled)
3793+
pub fn set_track_and_verify_wals_in_manifest(&mut self, val: bool) {
3794+
unsafe {
3795+
ffi::rocksdb_options_set_track_and_verify_wals_in_manifest(self.inner, u8::from(val));
3796+
}
3797+
}
3798+
3799+
/// Returns the value of the `track_and_verify_wals_in_manifest` option.
3800+
pub fn get_track_and_verify_wals_in_manifest(&self) -> bool {
3801+
let val_u8 =
3802+
unsafe { ffi::rocksdb_options_get_track_and_verify_wals_in_manifest(self.inner) };
3803+
val_u8 != 0
3804+
}
3805+
37773806
/// The DB unique ID can be saved in the DB manifest (preferred, this option)
37783807
/// or an IDENTITY file (historical, deprecated), or both. If this option is
37793808
/// set to false (old behavior), then `write_identity_file` must be set to true.

Diff for: tests/test_rocksdb_options.rs

+21
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,27 @@ fn test_set_avoid_unnecessary_blocking_io() {
299299
}
300300
}
301301

302+
#[test]
303+
fn test_set_track_and_verify_wals_in_manifest() {
304+
let path = DBPath::new("_set_track_and_verify_wals_in_manifest");
305+
306+
// test the defaults and the setter/accessor
307+
let mut opts = Options::default();
308+
assert!(!opts.get_track_and_verify_wals_in_manifest());
309+
opts.set_track_and_verify_wals_in_manifest(true);
310+
assert!(opts.get_track_and_verify_wals_in_manifest());
311+
opts.set_track_and_verify_wals_in_manifest(false);
312+
assert!(!opts.get_track_and_verify_wals_in_manifest());
313+
314+
// verify that a database created with this option works
315+
// TODO: Check that the MANIFEST actually contains WalAddition/WalDeletion records
316+
opts.create_if_missing(true);
317+
opts.set_track_and_verify_wals_in_manifest(true);
318+
let db = DB::open(&opts, &path).unwrap();
319+
db.put(b"k1", b"a").expect("put must work");
320+
assert_eq!(db.get(b"k1").unwrap().unwrap(), b"a");
321+
}
322+
302323
#[test]
303324
fn test_set_periodic_compaction_seconds() {
304325
let path = DBPath::new("_set_periodic_compaction_seconds");

0 commit comments

Comments
 (0)