Trait DurableStore
pub trait DurableStore {
// Required methods
fn namespace(&self) -> &str;
fn read(&self, key: &StorageKey) -> Result<Option<Stored>, StoreError>;
fn write(
&self,
key: &StorageKey,
op: WriteOp,
writer: Option<&[u8]>,
) -> Result<Revision, StoreError>;
fn durability(&self, key: &StorageKey, revision: Revision) -> Durability;
fn flush(&self, key: Option<&StorageKey>) -> Result<(), StoreError>;
fn lease(&self, key: &StorageKey) -> Result<Box<dyn Any>, StoreError>;
fn lease_shared(&self, key: &StorageKey) -> Result<SharedLease, StoreError>;
fn claim(
&self,
key: &StorageKey,
claimant: &str,
) -> Result<bool, StoreError>;
// Provided methods
fn local_path(&self, _key: &StorageKey) -> Option<PathBuf> { ... }
fn write_hint(
&self,
_key: &StorageKey,
_hint: &[u8],
) -> Result<(), StoreError> { ... }
fn read_hint(&self, _key: &StorageKey) -> Option<Vec<u8>> { ... }
}Expand description
Keyed, ordered, honestly-acknowledged storage.
A store is shared by every owner in one profile, so each method takes
&self. Writes to one key apply in the order they were accepted.
Required Methods§
fn namespace(&self) -> &str
fn namespace(&self) -> &str
A stable identity for this profile’s storage. Two stores with the same namespace address the same data; history and collaboration use it to tell profiles apart, never to find files.
fn read(&self, key: &StorageKey) -> Result<Option<Stored>, StoreError>
fn read(&self, key: &StorageKey) -> Result<Option<Stored>, StoreError>
The key’s current value, including accepted writes not yet durable.
None when nothing has ever been stored.
§Errors
Reports an invalid key or a failure reading the backing storage.
fn write(
&self,
key: &StorageKey,
op: WriteOp,
writer: Option<&[u8]>,
) -> Result<Revision, StoreError>
fn write( &self, key: &StorageKey, op: WriteOp, writer: Option<&[u8]>, ) -> Result<Revision, StoreError>
fn durability(&self, key: &StorageKey, revision: Revision) -> Durability
fn durability(&self, key: &StorageKey, revision: Revision) -> Durability
Whether the write that returned revision for key has committed.
Never blocks.
fn flush(&self, key: Option<&StorageKey>) -> Result<(), StoreError>
fn flush(&self, key: Option<&StorageKey>) -> Result<(), StoreError>
Make everything read from or accepted for key (or every key) durable
where the store can do so itself, and report whether it now is. A store
that depends on its host returns [StoreError::Pending] instead of
blocking.
§Errors
Reports the latest failed write, or writes still awaiting their host.
fn lease(&self, key: &StorageKey) -> Result<Box<dyn Any>, StoreError>
fn lease(&self, key: &StorageKey) -> Result<Box<dyn Any>, StoreError>
Become the key’s only writer until the returned lease is dropped.
§Errors
[StoreError::Busy] when another owner, in this process or another,
already holds the key.
fn claim(&self, key: &StorageKey, claimant: &str) -> Result<bool, StoreError>
fn claim(&self, key: &StorageKey, claimant: &str) -> Result<bool, StoreError>
Grant custody of key to exactly one claimant, durably: the first
claim wins, and the same claimant may claim again (to resume after a
crash). Used to let exactly one successor adopt a room record under a
new identity.
true when claimant holds custody.
§Errors
A key the store cannot claim, or a failure recording the claim.
Provided Methods§
fn local_path(&self, _key: &StorageKey) -> Option<PathBuf>
fn local_path(&self, _key: &StorageKey) -> Option<PathBuf>
Where a host that keeps the key in a local file keeps it. Only for
diagnostics and tools that work on that file; None elsewhere.
fn write_hint(&self, _key: &StorageKey, _hint: &[u8]) -> Result<(), StoreError>
fn write_hint(&self, _key: &StorageKey, _hint: &[u8]) -> Result<(), StoreError>
Keep hint beside the key’s value on this device: bytes a caller
derived from a value it wrote, to make the next read of that value
cheaper to use. A hint is never part of the value, never leaves the
device and may be dropped at any time, so the caller must recognise
the value it was made for itself; a store that keeps none drops it.
The key must be leased, as for Self::write.
§Errors
An unleased key, or a failure writing the hint.
fn read_hint(&self, _key: &StorageKey) -> Option<Vec<u8>>
fn read_hint(&self, _key: &StorageKey) -> Option<Vec<u8>>
The hint last kept beside the key by Self::write_hint, if the
store still has one.
Implementations on Foreign Types§
§impl DurableStore for FsStore
impl DurableStore for FsStore
§fn write_hint(&self, key: &StorageKey, hint: &[u8]) -> Result<(), StoreError>
fn write_hint(&self, key: &StorageKey, hint: &[u8]) -> Result<(), StoreError>
Kept in the record’s directory, which only this device writes and never syncs. Written at once, unsynced: a hint lost to a crash, or written ahead of a replacement that then fails, names bytes the document no longer holds and the reader ignores it.