pub struct Target {
pub space_id: String,
/* private fields */
}Expand description
See the module docs.
Fields§
§space_id: StringImplementations§
Source§impl Target
impl Target
pub fn new( space_id: &str, stores: Stores, on_change: impl Fn(&BTreeSet<String>) + Send + Sync + 'static, ) -> Target
Sourcepub fn on_files(
self,
f: impl Fn(Origin, &[FileState]) + Send + Sync + 'static,
) -> Target
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).
Sourcepub fn load(&self) -> Result<()>
pub fn load(&self) -> Result<()>
Loads the cursor, schemas and outbox, and replays the outbox into the DataStore (crash recovery).
Sourcepub fn close(&self)
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.
pub fn cursor(&self) -> i64
pub fn schemas(&self) -> BTreeMap<String, TableSchema>
pub fn outbox(&self) -> Vec<PendingMutation>
pub fn pending(&self) -> (usize, usize, Option<String>)
pub fn max_hlc(&self) -> Option<String>
pub fn abort_snapshot(&self)
pub fn reset_cursor(&self) -> Result<()>
Sourcepub fn apply_ops(&self, ops: &[Op]) -> Result<bool>
pub fn apply_ops(&self, ops: &[Op]) -> Result<bool>
Applies committed ops. Returns true when a schema op needs a re-snapshot.
Sourcepub fn apply_snapshot(&self, frame: &Snapshot) -> Result<bool>
pub fn apply_snapshot(&self, frame: &Snapshot) -> Result<bool>
Feeds one snapshot chunk. True once the complete chunk is applied.
Sourcepub fn acked(&self, ids: &[String], max_seq: Option<i64>) -> Result<()>
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.
Sourcepub fn hold(&self, ids: &[String], code: &str) -> Result<()>
pub fn hold(&self, ids: &[String], code: &str) -> Result<()>
Keeps these mutations queued but held back (e.g. quota_exceeded).
Sourcepub fn release_held(&self) -> Result<()>
pub fn release_held(&self) -> Result<()>
Clears the hold on every held entry (usage dropped, or a retry).
Sourcepub fn mark_uploaded(&self, mutation_id: &str, done: bool) -> Result<()>
pub fn mark_uploaded(&self, mutation_id: &str, done: bool) -> Result<()>
Records whether a pending file put’s bytes are on the server.
Sourcepub fn rollback(
&self,
rejected: &[Rejection],
fetch: &dyn Fetcher,
) -> Result<()>
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.
Sourcepub fn write(
&self,
entries: Vec<PendingMutation>,
file_states: Vec<FileState>,
) -> Result<()>
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.
Sourcepub fn seed(&self, rows: Vec<Mutation>, clock: Arc<Clock>) -> Result<()>
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.
Sourcepub fn pending_seed(&self) -> usize
pub fn pending_seed(&self) -> usize
Seed rows waiting for the first snapshot.
Sourcepub fn record_in(&self, view: &dyn TxView, m: Mutation) -> Result<()>
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).
Sourcepub fn refresh_outbox(&self) -> Result<()>
pub fn refresh_outbox(&self) -> Result<()>
Re-reads the outbox from the SyncStore (after record-mode writes).
Sourcepub fn enqueue(&self, entries: &[Mutation]) -> Result<()>
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.
Sourcepub fn drain_queue(&self, limit: usize) -> Result<usize>
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.