From 932a70e1f170e6bb7c76dc6e241920e021600229 Mon Sep 17 00:00:00 2001 From: Ilya Bogdanov Date: Sat, 7 Sep 2019 16:26:40 +0300 Subject: [PATCH] Add `DB::latest_sequence_number` method. (#326) --- CHANGELOG.md | 1 + src/db.rs | 5 +++++ tests/test_db.rs | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de46e50..85e2c0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Bumped RocksDB to 6.1.2 (lispy) * Added `Sync` and `Send` implementations to `Snapshot` (pavel-mukhanov) * Added `raw_iterator_cf_opt` to the DB API (rnarubin) +* Added `DB::latest_sequence_number` method (vitvakatu) ## 0.12.2 (2019-05-03) diff --git a/src/db.rs b/src/db.rs index 2fd59c5..6e5959e 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1560,6 +1560,11 @@ impl DB { Err(e) => Err(e), } } + + /// The sequence number of the most recent transaction. + pub fn latest_sequence_number(&self) -> u64 { + unsafe { ffi::rocksdb_get_latest_sequence_number(self.inner) } + } } impl WriteBatch { diff --git a/tests/test_db.rs b/tests/test_db.rs index 4240d96..a2da749 100644 --- a/tests/test_db.rs +++ b/tests/test_db.rs @@ -240,3 +240,14 @@ fn set_option_test() { db.set_options(&multiple_options).unwrap(); } } + +#[test] +fn test_sequence_number() { + let path = DBPath::new("_rust_rocksdb_test_sequence_number"); + { + let db = DB::open_default(&path).unwrap(); + assert_eq!(db.latest_sequence_number(), 0); + db.put(b"key", b"value"); + assert_eq!(db.latest_sequence_number(), 1); + } +}