pub struct PointerStore { /* private fields */ }Expand description
A store of pointer records.
Implementations§
Source§impl PointerStore
impl PointerStore
Sourcepub async fn new(root_dir: &Path) -> Result<Self>
pub async fn new(root_dir: &Path) -> Result<Self>
Open a store under root_dir, rebuilding its index from disk.
Takes an exclusive lock on the directory. Two stores over one directory would each keep their own index, and the one with the staler view would happily overwrite the other’s newer record.
A file that does not parse as a valid pointer, or that is not at the address its owner derives, is skipped and logged rather than deleted: a store that prunes what it cannot read destroys the evidence of its own bug.
§Errors
Returns Error::Storage if the directory cannot be created, locked or
read.
Sourcepub async fn put_bytes(&self, bytes: &[u8]) -> Result<PutOutcome>
pub async fn put_bytes(&self, bytes: &[u8]) -> Result<PutOutcome>
Validate and store in one step, with no payment gate.
For callers that have already settled payment, and for tests. The request path runs the same three steps with its admission and payment gates between them.
§Errors
As the three steps it runs: a malformed record, a signature that does not verify, or a write that fails.
Sourcepub async fn get(&self, address: &XorName) -> Result<Option<Pointer>>
pub async fn get(&self, address: &XorName) -> Result<Option<Pointer>>
Read the record held at address, if any.
Re-validates on the way out: the signature is checked and the record must belong at the address asked for, so a file corrupted under the node is reported as missing rather than served as authentic, and the entry is disowned so the node will take a fresh copy instead of answering “unchanged” to its own repair.
The file is what is served, not the index. A file replaced under the
node by a different record that is genuinely signed for this address
is served as held — it is a real record, the reader verifies it, and the
read quorum is what decides between replicas that disagree. What the
index is not allowed to do is claim a state the file does not have —
that check guards inspect’s two early answers, the ones that
assert this node already holds something.
§Errors
Returns Error::Storage if the file cannot be read for a reason other
than its absence.
Sourcepub fn state_id(&self, address: &XorName) -> Option<XorName>
pub fn state_id(&self, address: &XorName) -> Option<XorName>
The authenticated-state identifier held at address, if any.
This is what a sync hint carries and what a fetch decision compares. It names the state, not the encoding, so two replicas holding one state under different signatures agree and do not refetch each other forever.
Sourcepub fn superseded(&self, address: &XorName) -> Option<Vec<u8>>
pub fn superseded(&self, address: &XorName) -> Option<Vec<u8>>
The record the last update at address replaced, within the last
SUPERSEDED_RETENTION, if any. See Self::superseded_all for
every one kept.
Sourcepub fn superseded_all(&self, address: &XorName) -> Vec<Bytes>
pub fn superseded_all(&self, address: &XorName) -> Vec<Bytes>
Every record updates at address replaced within the last
SUPERSEDED_RETENTION, newest first: what a storage audit that bound
one of them before the updates is still owed (ADR-0019).
Sourcepub fn drop_expired_superseded(&self)
pub fn drop_expired_superseded(&self)
Forget every replaced record older than SUPERSEDED_RETENTION.
Updates do this as they keep a record; this is for when none come, so memory goes back within a pass of the retention running out rather than at the next update, which may never come.
Sourcepub async fn record_bytes(&self, address: &XorName) -> Result<Option<Vec<u8>>>
pub async fn record_bytes(&self, address: &XorName) -> Result<Option<Vec<u8>>>
The bytes of the record held at address, read from disk without
verifying them.
For a caller that only binds the bytes and has them verified later, by whoever they are served to: verifying here would cost a signature check per record for nothing.
§Errors
Returns Error::Storage if the file exists but cannot be read.
Sourcepub fn state(&self, address: &XorName) -> Option<PointerState>
pub fn state(&self, address: &XorName) -> Option<PointerState>
The state held at address, as the index records it, if this node can
serve one.
What a peer asking “which state do you hold?” is told. Taken from the index rather than the file, so answering costs no disk read; a file lost since is caught by the first read, which stops the index claiming it.
Sourcepub fn admits(&self, state: &PointerState) -> bool
pub fn admits(&self, state: &PointerState) -> bool
Whether a paid PUT of state may be taken.
Any state the merge rule prefers to what is held, whatever its counter. The counter orders states; it does not meter them, since each state is paid for on its own. That is also what lets a node catch up: a write ends once its quorum has answered, so a node can miss an update, and one that joins the group later holds nothing at all. Either takes the next update, however far ahead of it that is.
A record this node knew and lost admits the lost state itself as well, so the arrival that restores it is not mistaken for a resubmission. It admits nothing older, so a node that lost its copy cannot be rolled back by a replay.
Sourcepub fn file_for(&self, address: &XorName) -> PathBuf
pub fn file_for(&self, address: &XorName) -> PathBuf
The file the record at address is kept in.
Sourcepub fn held_states(&self) -> Vec<PointerState>
pub fn held_states(&self) -> Vec<PointerState>
Every state this node can serve, sorted by address.
Taken from the index, which every other answer the store gives is also based on. A record whose file has gone is left out: it is not something this node can offer to anyone.
Sourcepub fn stats(&self) -> PointerStoreStats
pub fn stats(&self) -> PointerStoreStats
What the store has done since it was opened.
Sourcepub async fn delete(&self, address: &XorName) -> Result<bool>
pub async fn delete(&self, address: &XorName) -> Result<bool>
Remove the record at address and forget it entirely.
For a node that is no longer responsible for the address. Unlike a record lost to the disk, nothing about it is remembered, because the node is not meant to take it back. Returns whether a file was removed, so the caller can give its space back to the disk budget.
§Errors
Returns Error::Storage if the file exists and cannot be removed; the
record is then still held and still indexed.
Trait Implementations§
Source§impl Clone for PointerStore
impl Clone for PointerStore
Auto Trait Implementations§
impl !RefUnwindSafe for PointerStore
impl !UnwindSafe for PointerStore
impl Freeze for PointerStore
impl Send for PointerStore
impl Sync for PointerStore
impl Unpin for PointerStore
impl UnsafeUnpin for PointerStore
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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