Skip to main content

ChunkStore

Struct ChunkStore 

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

Content-addressed chunk storage.

Implementations§

Source§

impl ChunkStore

Source

pub async fn new(config: ChunkStoreConfig) -> Result<Self>

Open the store under config.root_dir.

Opens the legacy environment only if one is already on disk. A fresh node never creates one, so it never pays for a memory map it will not use.

§Errors

Returns Error::Storage if either store cannot be opened.

Source

pub async fn put(&self, address: &XorName, content: &[u8]) -> Result<bool>

Store a chunk.

While a legacy environment exists and dual-writing is on, the chunk goes there first. A chunk uploaded during the bridge to holders that all revert to a pre-migration build would otherwise be gone from every one of them, and that is real client data, not a replica.

§Returns

true if the chunk was newly stored, false if either store already had it.

§Errors

Returns Error::Storage if the content does not hash to address, the disk is too full, or the write fails.

Source

pub async fn get(&self, address: &XorName) -> Result<Option<Vec<u8>>>

Retrieve a chunk, verifying it against its address when configured to.

§Errors

Returns Error::Storage on an I/O failure, or when verification fails and no intact copy is available.

Source

pub async fn get_raw(&self, address: &XorName) -> Result<Option<Vec<u8>>>

Retrieve raw chunk bytes without content-address verification.

§Errors

Returns Error::Storage on an I/O failure.

Source

pub fn exists(&self, address: &XorName) -> Result<bool>

Check whether a chunk is stored, in either backing.

An in-memory lookup: no syscall, no I/O, in both phases.

§Errors

Never fails. The signature is kept because callers treat an error as “absent”.

Source

pub async fn holds_verified(&self, address: &XorName, content: &[u8]) -> bool

Does this node already hold address with exactly these bytes, and if it holds a damaged copy, replace it with these?

The question a responder has to answer before turning away an offered copy. Plain Self::exists answers from names alone, and a name can outlive the bytes under it: off Unix a chunk is created under its final name before it is written, so a crash leaves a short file that exists reports as a chunk, and bit rot leaves a full-length one. Acknowledging a client on the strength of either throws away the copy that would repair it, and nothing offers it again.

So this reads. It is affordable because the only caller is the client-facing PUT path, reached when a client offers a chunk this node already has, and because the alternative is keeping a chunk this node cannot serve and being penalised for it at the next audit.

content must already hash to address; the caller checks that before this is reached, and a repair from bytes that do not would be worse than the damage.

§Errors

Never fails. An unreadable chunk answers false, so the offered copy is stored through the ordinary path rather than refused.

Source

pub async fn delete(&self, address: &XorName) -> Result<bool>

Delete a chunk from both backings.

A logical delete has to reach the legacy environment too, or the union view would resurrect the key on the next read. It frees no space there — only removing the environment whole does that — but it keeps the two views honest.

§Errors

Returns Error::Storage if a file exists but cannot be removed.

Source

pub async fn all_keys(&self) -> Result<Vec<XorName>>

Every stored key, in ascending order, across both backings.

The order is a correctness requirement: the commitment builder truncates the responsible subset with take(cap) before the Merkle tree sorts it, so an unstable order would make the node’s published commitment depend on iteration luck rather than on what it holds.

§Errors

Returns Error::Storage if the file index cannot be read.

Source

pub async fn committable_keys(&self) -> Result<Vec<XorName>>

The keys the commitment builder should commit to.

While the node is still bridging this is the whole union, because it can still serve all of it and dropping the claim early would collapse its commitment (and with it its quoted price) for no reason. Once it has settled on what it will keep, this narrows to the file-backed set, which is exactly the point at which the node stops claiming keys it is about to give up.

§Errors

Returns Error::Storage if the file index cannot be read.

Source

pub fn current_chunks(&self) -> Result<u64>

Number of chunks currently stored, counted across both backings without double-counting a chunk that is in each.

§Errors

Never fails.

Source

pub fn stats(&self) -> StorageStats

Operation statistics.

The cumulative counters are the file store’s; current_chunks is the union.

Source

pub fn compute_address(content: &[u8]) -> XorName

Compute a content address (BLAKE3 hash).

Source

pub fn root_dir(&self) -> &Path

The node root directory.

Source

pub fn check_capacity(&self) -> Result<()>

Reject work early when the disk cannot take another chunk at all.

§Errors

Returns Error::Storage when free space is below the configured reserve.

Source

pub fn check_capacity_for(&self, bytes: u64) -> Result<()>

Reject work early when the disk cannot take bytes more.

Free bytes alone stopped being a sufficient answer once chunks became files.

§Errors

Returns Error::Storage when the write would not fit above the reserve.

Source

pub async fn wait_idle(&self)

Wait until every blocking task in either backing has finished.

Source

pub fn migration_phase(&self) -> MigrationPhase

Where the node is in the migration.

Source

pub fn migration_state(&self) -> MigrationState

A snapshot of the persisted migration marker.

Source

pub fn migration_config(&self) -> &MigrationConfig

The migration settings this store was built with.

Source

pub fn has_legacy(&self) -> bool

Whether a legacy environment is still open.

Source

pub fn legacy_only_keys(&self) -> Vec<XorName> ⓘ

The keys the legacy environment still holds alone, ascending.

Source

pub fn legacy_bytes(&self) -> u64

Bytes the legacy environment occupies, as the filesystem sees it.

Source

pub async fn copy_batch( &self, keys: &[XorName], slack: u64, throttle_mib_per_sec: u64, shutdown: &CancellationToken, ) -> Result<CopyReport>

Copy up to keys.len() chunks out of the legacy environment into files.

Stops as soon as free space would fall below slack above the configured reserve, so a migration never fills the disk it is trying to free.

§Errors

Returns Error::Storage only for failures that are not per-key: a per-key problem is counted in the report and the pass continues.

Source

pub fn commit_to_files(&self) -> Result<()>

Settle on the file-backed set: from now on the node commits only to what it will keep, while still serving everything it ever committed to.

§Errors

Returns Error::Storage if the marker cannot be persisted.

Source

pub fn note_commitment_rebuilt(&self)

Record that the commitment builder has read and published the committable set.

The retirement gate counts these: one proves the builder saw the new set, two prove it survived a rotation, which is what makes the answerability window meaningful rather than notional.

Source

pub fn retirement_blocker<F>(&self, still_answerable: F) -> Option<String>
where F: Fn(&XorName) -> bool,

Whether every gate on deleting the legacy environment is satisfied.

still_answerable is asked of each key the node is about to give up: the pruner’s existing retention contract, reused verbatim. A key still covered by a retained commitment slot vetoes the delete, because the node could still be challenged on it.

Source

pub async fn verify_before_retire( &self, throttle_mib_per_sec: u64, shutdown: &CancellationToken, ) -> Result<VerifyReport>

Re-hash every chunk that both stores hold, repairing the file from the legacy copy when they disagree.

A filename is not proof the bytes behind it are good. The startup scan reads names only, so a file that was truncated or that rotted while the node was down is indexed, counted as copied, committed to, and would have its intact legacy copy deleted underneath it. The first verified read would then find the corruption with nothing left to repair from. This pass is what turns “a file with that name exists” into “those bytes are that chunk”, and it is why it runs before retirement rather than after.

§Errors

Returns Error::Storage if the legacy key set cannot be read.

Source

pub async fn retire_legacy<F>( &self, proof: &VerifyReport, still_answerable: &F, approved_to_shed: &BTreeSet<XorName>, ) -> Result<u64>
where F: Fn(&XorName) -> bool + Send + Sync,

Close the legacy environment and remove it, returning the bytes freed.

This is the only destructive step in the migration and the only one that cannot be undone. It is also the only moment the disk comes back.

Takes a VerifyReport rather than a flag so the verification pass cannot be skipped: there is no way to call this without having produced one.

§Errors

Returns Error::Storage if verification did not pass or no longer describes the store, if a write has not reported back, if the handle is still shared (the caller should retry on the next tick), or if the directory cannot be removed.

Source

pub async fn recover_lost_legacy_handle(&self) -> bool

Try again to open a legacy environment this node has lost its handle to.

A rename that failed and then could not be reopened leaves the directory on disk with no way to read it, and every chunk that lives only there unserved. Saying so once and waiting for a restart is not enough: the reason is usually transient, and a node that is otherwise healthy should not stay half-blind until somebody notices.

Returns whether it came back. Does nothing when there is a handle already, or when there is nothing on disk to open.

Source

pub fn has_cleanup_pending(&self) -> bool

Is there a retired directory still waiting to be deleted?

Separate from having a legacy environment: a node whose removal was interrupted has no handle and nothing to migrate, but its disk has not come back. Something has to keep trying during this uptime rather than leaving it until the next restart.

Source

pub fn retry_cleanup(&self)

Try again to finish a removal a previous attempt left behind.

Safe to call at any time: it only ever moves or deletes a directory that carries its own retirement mark.

Source

pub async fn reconcile_pending_writes(&self)

Resolve writes whose outcome was never recorded.

A write announces itself before it starts and clears the note when both halves have returned. A note still there afterwards belongs to a write nobody waited for, and only the disk can say what became of it: the file store has the chunk, or the environment does and nothing else, or neither and there was never anything to protect.

Source

pub fn has_pending_writes(&self) -> bool

Are there writes in flight whose outcome nothing has recorded?

Source

pub fn legacy_dir_is_on_disk(&self) -> bool

Is there anything at the legacy environment’s path at all?

Asked without a handle, and answered conservatively: a path this node cannot even look at counts as present. The migration is not finished while something is there, whether or not this node can currently read it.

Is the legacy environment a link this node must not delete?

Copying out of it works; only the removal is refused. Callers use this to stop waiting for a retirement that is never going to happen.

Source

pub fn writes_without_a_rollback_copy(&self) -> u64

How many writes this node made without a rollback copy, cumulatively.

Zero on a node that is not bridging, and zero on a bridging node whose environment has room. A number that is climbing says this node would lose those chunks on a rollback to a pre-migration build, which is a fleet question the second release turns on and which a per-chunk log line cannot answer.

Attempts rather than distinct chunks, for the reason given on the field: it is a rate, not an inventory.

Source

pub fn legacy_cannot_be_classified(&self) -> bool

Is there an environment on disk this node cannot classify at all?

Neither removable nor openable, which is not a state waiting will clear: something about the path has to change first, and until it does the node will refuse to touch it in either direction. The driver treats this the way it treats a lost handle or a link, by standing down from the shared volume and saying so where an operator looks, because holding a disk exclusively to wait for a person is a disk nobody else can use.

Source

pub fn has_lost_its_legacy_handle(&self) -> bool

Is there an environment on disk this node can no longer read?

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> 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, 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