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.
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.
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
already be a workspace of this application — the directory is placed, not made.
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 until the connection closes.
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 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.
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