Skip to main content

NetworkRestore

Struct NetworkRestore 

Source
pub struct NetworkRestore { /* private fields */ }
Expand description

A network restore operation that copies database files from a peer node.

Manages the lifecycle of a restore: starting the transfer, tracking progress, and completing or failing.

Implementations§

Source§

impl NetworkRestore

Source

pub fn new(config: NetworkRestoreConfig) -> Self

Create a new network restore with the given configuration.

Source

pub fn with_local_dir(self, dir: impl Into<PathBuf>) -> Self

Set the local directory where restored .ndb files will be written.

If not set, the current working directory is used.

Source

pub fn get_state(&self) -> RestoreState

Get the current restore state.

Source

pub fn get_progress(&self) -> RestoreProgress

Get a snapshot of the current progress.

Source

pub fn get_config(&self) -> &NetworkRestoreConfig

Get the restore configuration.

Source

pub fn execute(&self) -> Result<()>

Execute a full network restore: connect to the source node, transfer all .ndb log files, and write them to the local log directory.

§Wire protocol (simple restore protocol)
Client → Server: [magic: u32 LE]            (4 bytes)  "NRST"
Server → Client: [file_count: u32 LE]        (4 bytes)
For each file:
  Server → Client: [name_len: u16 LE]        (2 bytes)
                   [name: UTF-8 bytes]        (name_len bytes)
                   [file_size: u64 LE]        (8 bytes)
                   [data: file_size bytes]
Source

pub fn execute_via_dispatcher(&self) -> Result<()>

Execute a network restore against a peer’s RESTORE service running on the TcpServiceDispatcher.

Closes findings F2 / F4 of the 2026 review.

execute() (above) connects raw TCP and writes RESTORE_MAGIC, which works only against the standalone NetworkRestoreServer::start path. Production replicated environments register the NetworkRestoreServer as a ServiceHandler on the dispatcher; the dispatcher first reads a length-prefixed service-name handshake, then delegates to the handler. The handler reads RESTORE_MAGIC over the channel framing (not raw stream bytes) and replies with a single framed payload.

This method speaks that protocol: it goes through connect_to_service(RESTORE), sends the magic over the channel, then receives one framed payload containing the entire [count][file_records...] structure and decodes it into local files.

Source

pub fn start(&self) -> Result<()>

Mark the restore as in-progress.

State-transition helper that moves the restore from RestoreState::NotStarted to RestoreState::InProgress and updates the public progress snapshot to match. It performs no I/O — the actual file transfer is driven by execute.

Callers that drive the restore via execute() do not need to invoke this directly; execute() performs the same state transition internally before any work begins.

Source

pub fn update_progress(&self, bytes: u64, files: u32)

Update the progress of an in-progress restore.

§Arguments
  • bytes - Total bytes transferred so far.
  • files - Total files transferred so far.
Source

pub fn update_elapsed(&self, elapsed: Duration)

Update the elapsed time for progress tracking.

Source

pub fn complete(&self) -> Result<()>

Mark the restore as completed successfully.

Source

pub fn fail(&self) -> Result<()>

Mark the restore as failed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V