Skip to main content

SyncRuntime

Struct SyncRuntime 

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

Replication for one application’s workspaces.

Implementations§

Source§

impl SyncRuntime

Source

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.

Source

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.

Source

pub fn with_connector(self, connector: BridgeConnector) -> SyncRuntime

Reach the bridge again with connector once the connection closes.

Source

pub fn is_connected(&self) -> bool

Whether the runtime has a live connection to the bridge.

Source

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.

Source

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.

Source

pub fn set_backfill_timing(&self, timing: BackfillTiming)

Pace the primary device’s backfill differently: for tests, which cannot wait ten minutes.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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).

Source

pub async fn status(&self, root: &Path) -> SyncStatus

What sync.status answers with.

Source

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.

Source

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.

Source

pub async fn sync_now(self: &Arc<Self>, root: &Path) -> Result<()>

Open a session with every peer that will take one.

Source

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.

Source

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.

Source

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.

Source

pub async fn roots(&self) -> Vec<PathBuf>

Every synced root, for the watcher.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Fruit for T
where T: Send + Downcast,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more