Skip to content

Commit da8c387

Browse files
committed
snapshotdir tx_offset method
1 parent 8a2e9c3 commit da8c387

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

crates/paths/src/server.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ impl SnapshotDirPath {
220220
let invalid_path = self.0.with_extension("invalid_snapshot");
221221
fs::rename(self, invalid_path)
222222
}
223+
224+
pub fn tx_offset(&self) -> Option<u64> {
225+
self.0
226+
.file_stem()
227+
.and_then(|s| s.to_str()?.split('.').next()?.parse::<u64>().ok())
228+
}
223229
}
224230

225231
path_type! {
@@ -297,4 +303,14 @@ mod tests {
297303
sdd.pid_file()?;
298304
Ok(())
299305
}
306+
307+
#[test]
308+
fn test_snapshot_parsing() -> Result<()> {
309+
let tempdir = TempDir::new()?;
310+
let sdd = ServerDataDir(tempdir.path().to_path_buf());
311+
const SNAPSHOT_OFFSET: u64 = 123456;
312+
let snapshot_dir = sdd.replica(1).snapshots().snapshot_dir(SNAPSHOT_OFFSET);
313+
assert_eq!(Some(SNAPSHOT_OFFSET), snapshot_dir.tx_offset());
314+
Ok(())
315+
}
300316
}

0 commit comments

Comments
 (0)