diff --git a/crates/paths/src/server.rs b/crates/paths/src/server.rs index 745f173f206..5da628544d5 100644 --- a/crates/paths/src/server.rs +++ b/crates/paths/src/server.rs @@ -220,6 +220,12 @@ impl SnapshotDirPath { let invalid_path = self.0.with_extension("invalid_snapshot"); fs::rename(self, invalid_path) } + + pub fn tx_offset(&self) -> Option { + self.0 + .file_stem() + .and_then(|s| s.to_str()?.split('.').next()?.parse::().ok()) + } } path_type! { @@ -297,4 +303,14 @@ mod tests { sdd.pid_file()?; Ok(()) } + + #[test] + fn test_snapshot_parsing() -> Result<()> { + let tempdir = TempDir::new()?; + let sdd = ServerDataDir(tempdir.path().to_path_buf()); + const SNAPSHOT_OFFSET: u64 = 123456; + let snapshot_dir = sdd.replica(1).snapshots().snapshot_dir(SNAPSHOT_OFFSET); + assert_eq!(Some(SNAPSHOT_OFFSET), snapshot_dir.tx_offset()); + Ok(()) + } }