Skip to main content

PointerStore

Struct PointerStore 

Source
pub struct PointerStore { /* private fields */ }
Expand description

A store of pointer records.

Implementations§

Source§

impl PointerStore

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn contains(&self, address: &XorName) -> bool

Whether a record is held at address.

Source

pub fn len(&self) -> usize

How many records the store holds.

Source

pub fn is_empty(&self) -> bool

Whether the store holds nothing.

Source

pub fn dir(&self) -> &Path

Directory holding the records.

Source

pub fn file_for(&self, address: &XorName) -> PathBuf

The file the record at address is kept in.

Source

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.

Source

pub fn stats(&self) -> PointerStoreStats

What the store has done since it was opened.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PointerStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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