Skip to main content

Target

Struct Target 

Source
pub struct Target {
    pub space_id: String,
    /* private fields */
}
Expand description

See the module docs.

Fields§

§space_id: String

Implementations§

Source§

impl Target

Source

pub fn new( space_id: &str, stores: Stores, on_change: impl Fn(&BTreeSet<String>) + Send + Sync + 'static, ) -> Target

Source

pub fn on_files( self, f: impl Fn(Origin, &[FileState]) + Send + Sync + 'static, ) -> Target

Also calls f with the file states of every batch that carries Change::Files, and the batch’s origin (the file mirror listens here).

Source

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

Loads the cursor, schemas and outbox, and replays the outbox into the DataStore (crash recovery).

Source

pub fn close(&self)

Stops server-driven writes (snapshots, ops, acks) once the space is closed, and waits for one in progress, so nothing lands in the SyncStore after SyncStore::forget_space. Local writes still work.

Source

pub fn cursor(&self) -> i64

Source

pub fn schemas(&self) -> BTreeMap<String, TableSchema>

Source

pub fn outbox(&self) -> Vec<PendingMutation>

Source

pub fn pending(&self) -> (usize, usize, Option<String>)

Source

pub fn max_hlc(&self) -> Option<String>

Source

pub fn abort_snapshot(&self)

Source

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

Source

pub fn apply_ops(&self, ops: &[Op]) -> Result<bool>

Applies committed ops. Returns true when a schema op needs a re-snapshot.

Source

pub fn apply_snapshot(&self, frame: &Snapshot) -> Result<bool>

Feeds one snapshot chunk. True once the complete chunk is applied.

Source

pub fn acked(&self, ids: &[String], max_seq: Option<i64>) -> Result<()>

Applied and duplicate results: clocks were set when the write was queued and the DataStore already has the values, so an ack only removes the entries.

The cursor moves to the largest acked seq when that is larger (PROTOCOL.md §7.4), never to ack.head_seq.

Source

pub fn hold(&self, ids: &[String], code: &str) -> Result<()>

Keeps these mutations queued but held back (e.g. quota_exceeded).

Source

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

Clears the hold on every held entry (usage dropped, or a retry).

Source

pub fn mark_uploaded(&self, mutation_id: &str, done: bool) -> Result<()>

Records whether a pending file put’s bytes are on the server.

Source

pub fn rollback( &self, rejected: &[Rejection], fetch: &dyn Fetcher, ) -> Result<()>

Permanent rejections (ADR 0017 §2): re-read the affected rows from the server, hand them to the DataStore as an origin: rollback batch (a purge when the server has no such row), and reset their clocks. Later queued writes to the same rows are laid back on top.

A row whose every clock comes from this client’s own unacknowledged writes has never reached the server, so it is rolled back without a network read.

Source

pub fn write( &self, entries: Vec<PendingMutation>, file_states: Vec<FileState>, ) -> Result<()>

Queues local mutations (write-through): clocks and outbox first, then the DataStore with origin: local. If the DataStore fails, the queue entries and clocks are reverted and the error is returned.

Source

pub fn seed(&self, rows: Vec<Mutation>, clock: Arc<Clock>) -> Result<()>

Seeds the space with rows the app already had before it linked the space: queues an upsert for each row the space doesn’t have and skips the rest, so the space’s values win over older local copies.

“The space has it” means the row has clocks. Before the first snapshot since the bookkeeping was created (a fresh link, or after SyncStore::forget_space) the clocks are empty, so the rows wait and are decided in the same transaction as the snapshot’s last change. Once synced, they are decided now, in one transaction. Rows are stamped when they are queued. Calling it again with the same rows queues nothing new.

Source

pub fn pending_seed(&self) -> usize

Seed rows waiting for the first snapshot.

Source

pub fn record_in(&self, view: &dyn TxView, m: Mutation) -> Result<()>

Record mode: queues a write the app has already made to its own rows, inside the app’s own open transaction (view runs on that connection).

Source

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

Re-reads the outbox from the SyncStore (after record-mode writes).

Source

pub fn enqueue(&self, entries: &[Mutation]) -> Result<()>

Space::queue: stores writes in the SyncStore’s durable queue, in one transaction. Takes neither the merge lock nor the DataStore: safe to call while the app holds its own locks.

Source

pub fn queued(&self) -> Result<usize>

Writes queued and not yet merged.

Source

pub fn drain_queue(&self, limit: usize) -> Result<usize>

Merges up to limit queued writes (the queue worker): clocks and outbox, then the DataStore with origin: local, then drops them from the queue. Returns how many it took.

Unlike Target::write, a queued write is merged like a remote op: a field only wins where its stamp is newer than the row’s, because a remote change may have landed between queue and this. Deletes and restores of rows Kovlet doesn’t know are dropped (logged), and so is a write that wins no field (nothing to apply, nothing the server would keep). Entries already in the outbox, or already merged and acked (a crash after the commit but before the queue was trimmed), are skipped.

Auto Trait Implementations§

§

impl !Freeze for Target

§

impl !RefUnwindSafe for Target

§

impl !UnwindSafe for Target

§

impl Forget for Target

§

impl Move for Target

§

impl Send for Target
where RawVecInner: Send, Arc<dyn DataStore>: Send, Arc<dyn SyncStore>: Send, Mutex<State>: Send, Mutex<()>: Send, Atomic<bool>: Send, BoxRaw<dyn Fn(&BTreeSet<String>) + Sync + Send>: Send, BoxRaw<dyn Fn(Origin, &[FileState]) + Sync + Send>: Send,

§

impl Sync for Target
where RawVecInner: Sync, Arc<dyn DataStore>: Sync, Arc<dyn SyncStore>: Sync, Mutex<State>: Sync, Mutex<()>: Sync, Atomic<bool>: Sync, BoxRaw<dyn Fn(&BTreeSet<String>) + Sync + Send>: Sync, BoxRaw<dyn Fn(Origin, &[FileState]) + Sync + Send>: Sync,

§

impl Unpin for Target
where *const u8 is !null: Unpin, Arc<dyn DataStore>: Unpin, Arc<dyn SyncStore>: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, *const LeafNode<String, TableSchema> is !null: Unpin, Box<(String, TableSchema)>: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Arc<Clock>: Unpin, *const LeafNode<String, Sub> is !null: Unpin, Box<(String, Sub)>: Unpin, *const LeafNode<RowRef, BTreeSet<String>> is !null: Unpin, Box<(RowRef, BTreeSet<String>)>: Unpin, *const LeafNode<RowRef, i64> is !null: Unpin, Box<(RowRef, i64)>: Unpin, *const LeafNode<String, Pages> is !null: Unpin, Box<(String, Pages)>: Unpin, Box<dyn Fn(&BTreeSet<String>) + Sync + Send>: Unpin, Box<dyn Fn(Origin, &[FileState]) + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Target

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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