pub struct SyncRuntime { /* private fields */ }Expand description
Replication for one application’s workspaces.
Implementations§
Source§impl SyncRuntime
impl SyncRuntime
Sourcepub fn new(
ctx: &'static AppContext,
bridge: Arc<BridgeClient>,
exe_path: PathBuf,
managed_by: ManagedBy,
) -> SyncRuntime
pub fn new( ctx: &'static AppContext, bridge: Arc<BridgeClient>, exe_path: PathBuf, managed_by: ManagedBy, ) -> SyncRuntime
A runtime for ctx’s application, syncing through bridge.
It has no way to reach the bridge again: when the connection closes, sync stops until
the runtime is given a connector.
Sourcepub fn connecting(
ctx: &'static AppContext,
connector: BridgeConnector,
exe_path: PathBuf,
managed_by: ManagedBy,
) -> SyncRuntime
pub fn connecting( ctx: &'static AppContext, connector: BridgeConnector, exe_path: PathBuf, managed_by: ManagedBy, ) -> SyncRuntime
A runtime for ctx’s application that reaches the bridge with connector, and again
whenever it loses it (#244).
Not connected yet: connect makes the first attempt, and
keep_connected the rest. AppServer::run does both.
Sourcepub fn with_connector(self, connector: BridgeConnector) -> SyncRuntime
pub fn with_connector(self, connector: BridgeConnector) -> SyncRuntime
Reach the bridge again with connector once the connection closes.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the runtime has a live connection to the bridge.
Sourcepub fn with_open_timeout(self, timeout: Duration) -> SyncRuntime
pub fn with_open_timeout(self, timeout: Duration) -> SyncRuntime
Give up on opening a stream to a peer after timeout rather than OPEN_TIMEOUT:
for tests, which cannot wait that long for a peer that never answers.
Sourcepub fn with_bridge_endpoint(self, endpoint: Endpoint) -> SyncRuntime
pub fn with_bridge_endpoint(self, endpoint: Endpoint) -> SyncRuntime
Tell the runtime which app server owns these workspaces’ caches.
Called by AppServer::sync. First writer wins: a runtime
belongs to the server that wired it.
Embed through the bridge at endpoint rather than the host’s standard one: for a
fixture running several hosts in one process.
Sourcepub fn set_backfill_timing(&self, timing: BackfillTiming)
pub fn set_backfill_timing(&self, timing: BackfillTiming)
Pace the primary device’s backfill differently: for tests, which cannot wait ten minutes.
Sourcepub async fn enable(self: &Arc<Self>, root: &Path) -> Result<GrainId>
pub async fn enable(self: &Arc<Self>, root: &Path) -> Result<GrainId>
Start syncing root, returning its identity across devices.
Idempotent: enabling an already-synced workspace returns the same id and changes nothing.
Sourcepub async fn disable(&self, root: &Path) -> Result<()>
pub async fn disable(&self, root: &Path) -> Result<()>
Stop syncing root. Files and the sync id stay, so re-enabling rejoins the same
workspace rather than creating a second one.
Something that began before — a scan, a session, the first dial — may still hold the
replica open; a re-enable meanwhile takes it back (see reclaim).
Sourcepub async fn release(&self, root: &Path, limit: Duration) -> Result<()>
pub async fn release(&self, root: &Path, limit: Duration) -> Result<()>
Stop syncing root, like disable, then wait up to limit until
nothing holds its replica store open any more — a session, a scan or an embedding
pass that started before may still have it. A store about to be moved or deleted
must be closed first.
Only a store still in use at limit is an error. The bridge not hearing of it is
logged, not returned: the store is closed all the same, and the next registration
replaces the bridge’s view.
Sourcepub async fn workspaces(&self) -> Result<WorkspacesResult>
pub async fn workspaces(&self) -> Result<WorkspacesResult>
The workspaces the workgroup knows about.
Read straight from the bridge, so it reflects every device’s registrations. The
bridge being down is not an empty answer — that would read as “nothing to map” — so
it is an error, and sync.map reports it.
Sourcepub async fn place(&self, selector: &str, dir: &Path) -> Result<PathBuf>
pub async fn place(&self, selector: &str, dir: &Path) -> Result<PathBuf>
Place a workgroup workspace at a directory of this host: write its identity and
map there, returning the canonical root. Current::map
then selects it and syncs it.
selector is the workspace’s name or id, as workspaces lists it; dir must
exist. Its marker is made when it has none, and nothing else: the marker’s
config.toml is the application’s, and arrives with the first sync — a local one
written first would meet it as a conflict (#253).
Sourcepub async fn status(&self, root: &Path) -> SyncStatus
pub async fn status(&self, root: &Path) -> SyncStatus
What sync.status answers with.
Sourcepub async fn scan(&self, root: &Path) -> Result<()>
pub async fn scan(&self, root: &Path) -> Result<()>
Bring the replica’s view of the files up to date.
Called straight after the app server’s own writes, and by the watcher for everything else. A scan that finds nothing is cheap; a scan that is skipped loses an edit until the next one.
Sourcepub fn request_embed(self: &Arc<Self>, root: &Path)
pub fn request_embed(self: &Arc<Self>, root: &Path)
Run an embedding pass over root in the background, after the pass already
waiting for it if there is one (#187).
The pass reads the vector files that arrived, and computes the missing ones this host is responsible for: the files whose winning version this replica wrote, and — on the primary device — every other one. It never holds up the caller.
Sourcepub async fn sync_now(self: &Arc<Self>, root: &Path) -> Result<()>
pub async fn sync_now(self: &Arc<Self>, root: &Path) -> Result<()>
Open a session with every peer that will take one.
Sourcepub async fn run(self: Arc<Self>) -> Result<()>
pub async fn run(self: Arc<Self>) -> Result<()>
Answer the bridge’s announcements, following the connection across reconnections (#244). Runs until the task is aborted.
Sourcepub async fn connect(self: &Arc<Self>) -> Result<()>
pub async fn connect(self: &Arc<Self>) -> Result<()>
Make the first attempt to reach the bridge, when the runtime has a
BridgeConnector and is not connected yet.
No bridge running is not an error: the server serves without sync, and
keep_connected picks the bridge up once it starts. Any
other failure — a bridge of another API version, say — is, and stops the start.
Sourcepub async fn keep_connected(self: Arc<Self>)
pub async fn keep_connected(self: Arc<Self>)
Stay connected to the bridge: wait for the connection to close, then reach the
bridge again with the runtime’s BridgeConnector, backing off from
RECONNECT_BACKOFF to RECONNECT_BACKOFF_MAX while it cannot (#244).
reconnect_now ends a wait early and starts the backoff over.
Runs until the task is aborted, which is what the app server’s shutdown does with it. Without a connector it only marks the runtime disconnected once the connection closes, and returns.
Sourcepub async fn after_commit(&self, root: &Path, updates: Vec<PathUpdate>)
pub async fn after_commit(&self, root: &Path, updates: Vec<PathUpdate>)
Push updates to every open session for root.
Called with what a scan recorded. from is always None here: a local commit came
from this host, so no session is excluded. The forwarding path, which does name a
source, is LivePeers::fan_out called directly by the
reader side of a session.
Best-effort by contract: the commit already happened, and a peer that is gone is the dialer’s problem, not the writer’s.
Sourcepub async fn live_session_devices(&self, root: &Path) -> Vec<GrainId>
pub async fn live_session_devices(&self, root: &Path) -> Vec<GrainId>
The devices with an open live session for root.
Used by tests to wait for the dialer; empty for a workspace this server does not hold.
Sourcepub async fn stop_dials(&self)
pub async fn stop_dials(&self)
End the first dials enable left running, waiting until
they are gone.
For the app server’s shutdown: each one pins the runtime, and with it the replica stores, which are redb databases that stay locked — a dial outliving its server would lock the next one out.
Sourcepub async fn stop_background(&self)
pub async fn stop_background(&self)
End the runtime’s background work — inbound sessions, live-session readers and embedding passes — and wait until it has let go.
The server’s shutdown calls this, so a server restarted in the same process can open the replica stores again at once rather than whenever the last straggler finished (#235). An embedding pass already inside its blocking section runs that section to the end; it holds the workspace’s index, never a replica.
Sourcepub async fn drop_connections(&self)
pub async fn drop_connections(&self)
Close every open live session, as if the connections had been cut.
Called for a workspace being disabled, and by tests that want to watch the dialer rebuild what was dropped.
Sourcepub async fn dial_loop(self: Arc<Self>) -> Result<()>
pub async fn dial_loop(self: Arc<Self>) -> Result<()>
Keep a live session open to every peer, for every synced workspace.
One walk per DIAL_INTERVAL: for each synced workspace, ask
the bridge who is in the workgroup, and open a session to every peer that is connected
and does not already have one.
A peer that cannot be reached is retried on a per-peer exponential backoff capped at
DIAL_BACKOFF_MAX — one failed attempt per walk, not one per spin — and the counter
resets when a session opens. An unreachable peer is therefore no obstacle to the
others: its dial fails, the walk moves on, and the next workspace is dialled.
Runs until the task is aborted, which is what the app server’s shutdown does with it.
It is allowed to fail like run: only sync stops, and the app
server keeps serving files (spec §10).
Sourcepub async fn watch_changes(self: Arc<Self>) -> Result<()>
pub async fn watch_changes(self: Arc<Self>) -> Result<()>
Watch the synced roots and, on a debounced report, scan and dial.
This is the safety net for everything the app server did not do itself — a file
edited in an editor, a git checkout. The exact path is scan called from
handlers.rs right after a write the server made. A scan that finds nothing is
cheap; a scan that is skipped loses an edit until the next one.
Returns when the reporting channel closes — that is, when the Watcher this
runtime holds is dropped, which happens when the runtime itself is.
Sourcepub async fn is_primary(&self, workspace_id: GrainId) -> bool
pub async fn is_primary(&self, workspace_id: GrainId) -> bool
Whether this host is workspace_id’s primary device, by the last roles the
bridge reported. false when the bridge has not answered yet, or when this host’s
device id is not known yet (no workspace was enabled). Reads the cached id only:
asking the bridge here would register with an empty workspace list, racing
enable’s registration.
Sourcepub fn this_device(&self) -> Option<GrainId>
pub fn this_device(&self) -> Option<GrainId>
This host’s device id, once the bridge has told it (#250).
None until this runtime first registered — no workspace was enabled yet, or the
bridge was not connected when one was. Never asks the bridge: a registration made
only to learn the id would carry an empty workspace list, and briefly clear this
application’s routes.
Sourcepub async fn peers(&self) -> Result<PeersResult>
pub async fn peers(&self) -> Result<PeersResult>
The workgroup’s devices, this host’s included, and the roles the bridge assigns per
workspace (#250). Asked of the bridge each time; is_primary
reads the answer afterwards.
Error::BridgeDisconnected while there is no connection to the bridge.
Auto Trait Implementations§
impl !Freeze for SyncRuntime
impl !RefUnwindSafe for SyncRuntime
impl !UnwindSafe for SyncRuntime
impl Send for SyncRuntime
impl Sync for SyncRuntime
impl Unpin for SyncRuntime
impl UnsafeUnpin for SyncRuntime
Blanket Implementations§
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
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 more