pub struct Replica { /* private fields */ }Expand description
One workspace root and its replica store.
Implementations§
Source§impl Replica
impl Replica
pub fn open(config: ReplicaConfig, clock: Arc<dyn Clock>) -> Result<Self>
pub fn replica_id(&self) -> ReplicaId
pub fn vv(&self) -> &VersionVector
pub fn config(&self) -> &ReplicaConfig
pub fn state(&self, path: &str) -> Result<Option<PathState>>
pub fn states(&self) -> Result<Vec<(String, PathState)>>
Sourcepub fn pause_reason(&self) -> Result<Option<PauseReason>>
pub fn pause_reason(&self) -> Result<Option<PauseReason>>
Why this replica must not scan or apply right now. A root or marker that is missing while files were written would otherwise read as “everything deleted”.
Sourcepub fn scan(&mut self) -> Result<ScanOutcome>
pub fn scan(&mut self) -> Result<ScanOutcome>
Record every unrecorded edit under the root and finish pending writes.
Sourcepub fn delta_for(&self, peer: &VersionVector) -> Result<Vec<PathUpdate>>
pub fn delta_for(&self, peer: &VersionVector) -> Result<Vec<PathUpdate>>
Path states the peer with version vector peer has not merged.
Sourcepub fn apply(
&mut self,
updates: &[PathUpdate],
source: &dyn ContentSource,
) -> Result<Report>
pub fn apply( &mut self, updates: &[PathUpdate], source: &dyn ContentSource, ) -> Result<Report>
Join updates received from a peer, fetching content from source.
Every update is joined before any file is written, so that the joined states go to the store in one transaction and what the files then hold in another, rather than several transactions per path.
Sourcepub fn commit_session(&mut self, peer: &VersionVector) -> Result<()>
pub fn commit_session(&mut self, peer: &VersionVector) -> Result<()>
Declare that every update of a session with peer has been applied.
Sourcepub fn fetch_missing(&mut self, source: &dyn ContentSource) -> Result<Report>
pub fn fetch_missing(&mut self, source: &dyn ContentSource) -> Result<Report>
Retry writes that were waiting for content.
Content this replica wants written and does not have: the winner of a path whose file does not hold it yet, and each loser still waiting for its conflict copy.
A session asks its peer for these whatever the peer sends: committing a session takes in the peer’s version vector even when some content never arrived, so no later delta carries those paths again. Content the replica would not write anyway — an ignored or unrepresentable path, a case collision, a file over the size limit — is left out.
Sourcepub fn collect_staging(&self) -> Result<usize>
pub fn collect_staging(&self) -> Result<usize>
Remove staged content nothing needs any more, returning how many files went.
Staged content is kept while some stored version refers to it and no workspace file holds it: the replica may still write it, or be asked for it. Placing content moves it out of staging, so what this removes is content staged and never placed — a version superseded first, a second copy from another session, inline content of a page that never came. A workspace file counts as holding the content only when its recorded stamp still matches and is not racy; nothing is re-hashed here.
Files younger than [STAGING_GRACE] are kept whatever they hold: a session stages
inline content before the page that refers to it arrives, and runs alongside this.
Sourcepub fn content_path(&self, hash: &ContentHash) -> Result<Option<(PathBuf, u64)>>
pub fn content_path(&self, hash: &ContentHash) -> Result<Option<(PathBuf, u64)>>
A file holding the content hash, and its length: a synced file on disk, else
finished staged content. A file whose length and mtime still match what was
recorded (and are not racy) is trusted; any other is re-hashed first.
Sourcepub fn content_paths(
&self,
hashes: &[ContentHash],
) -> Result<HashMap<ContentHash, (PathBuf, u64)>>
pub fn content_paths( &self, hashes: &[ContentHash], ) -> Result<HashMap<ContentHash, (PathBuf, u64)>>
Self::content_path for each of hashes, building the store index once for
all of them rather than once per hash. A hash no file or staged content holds is
left out of the map.