pub struct SnapshotManager { /* private fields */ }Expand description
Manages a directory of numbered snapshot files.
All operations are synchronous (no async I/O) to keep things simple and
testable. In production the caller is responsible for spawning these calls
onto a blocking thread via tokio::task::spawn_blocking.
Implementations§
Source§impl SnapshotManager
impl SnapshotManager
Sourcepub fn new(snapshot_dir: impl Into<PathBuf>) -> ServerResult<Self>
pub fn new(snapshot_dir: impl Into<PathBuf>) -> ServerResult<Self>
Create a SnapshotManager that stores files in snapshot_dir.
The directory is created if it does not yet exist.
Sourcepub fn write_snapshot(&self, id: u64, data: &[u8]) -> ServerResult<SnapshotMeta>
pub fn write_snapshot(&self, id: u64, data: &[u8]) -> ServerResult<SnapshotMeta>
Compress data with LZ4 and write it to disk as snapshot id.
Returns SnapshotMeta describing the written file.
Sourcepub fn read_snapshot(&self, id: u64) -> ServerResult<Vec<u8>>
pub fn read_snapshot(&self, id: u64) -> ServerResult<Vec<u8>>
Read back the snapshot with the given id and decompress it.
Returns an error if the file is missing, the header is corrupted, the checksum does not match, or LZ4 decompression fails.
Sourcepub fn list_snapshots(&self) -> ServerResult<Vec<SnapshotMeta>>
pub fn list_snapshots(&self) -> ServerResult<Vec<SnapshotMeta>>
List all available snapshots, sorted by ID descending (newest first).
Sourcepub fn delete_snapshot(&self, id: u64) -> ServerResult<()>
pub fn delete_snapshot(&self, id: u64) -> ServerResult<()>
Delete the snapshot file for id.
Returns an error if the file does not exist.
Source§impl SnapshotManager
impl SnapshotManager
Sourcepub fn set_uploader(&mut self, uploader: Arc<dyn SnapshotUploader>)
pub fn set_uploader(&mut self, uploader: Arc<dyn SnapshotUploader>)
Attach an uploader to this manager.
Sourcepub fn upload(&self, id: u64) -> ServerResult<String>
pub fn upload(&self, id: u64) -> ServerResult<String>
Upload the local snapshot with id via the configured uploader.
Returns the remote URI on success, or an error if no uploader is set or the snapshot does not exist locally.
Sourcepub fn restore_from_remote(
&self,
uri: &str,
local_id: u64,
) -> ServerResult<SnapshotMeta>
pub fn restore_from_remote( &self, uri: &str, local_id: u64, ) -> ServerResult<SnapshotMeta>
Download a snapshot from uri and store it locally under local_id.
Returns the SnapshotMeta of the newly written local snapshot.
Auto Trait Implementations§
impl !RefUnwindSafe for SnapshotManager
impl !UnwindSafe for SnapshotManager
impl Freeze for SnapshotManager
impl Send for SnapshotManager
impl Sync for SnapshotManager
impl Unpin for SnapshotManager
impl UnsafeUnpin for SnapshotManager
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.