Skip to main content

BlockIndexRebuild

Struct BlockIndexRebuild 

Source
pub struct BlockIndexRebuild {
    pub config: RebuildConfig,
    pub scan_entries: Vec<BlockScanEntry>,
    pub index: HashMap<String, IndexEntry>,
    pub progress: RebuildProgress,
    pub existing_index: HashMap<String, IndexEntry>,
}
Expand description

Block index reconstruction engine.

Call BlockIndexRebuild::run_full_rebuild for an all-in-one pipeline, or invoke each phase method individually for fine-grained control.

Fields§

§config: RebuildConfig

Configuration for this rebuild operation.

§scan_entries: Vec<BlockScanEntry>

Scanned block entries accumulated during the scanning phase.

§index: HashMap<String, IndexEntry>

Newly reconstructed index, populated during the rebuilding phase.

§progress: RebuildProgress

Live rebuild progress.

§existing_index: HashMap<String, IndexEntry>

Pre-existing index entries loaded before the rebuild starts.

Implementations§

Source§

impl BlockIndexRebuild

Source

pub fn new(config: RebuildConfig) -> Self

Create a new engine with the given config.

Progress starts at started_at = 0; the timestamp is updated when blocks are first loaded via Self::load_blocks.

Source

pub fn assign_shard(&self, cid: &str) -> u8

Compute the shard number for a given CID using FNV-1a over the CID bytes.

The result is fnv1a_64(cid.as_bytes()) mod shard_count, clamped to a u8.

Source

pub fn assign_offset(idx: usize) -> u64

Compute the page-aligned byte offset for the block at position idx.

The formula is idx as u64 * PAGE_SIZE (4 096 bytes per page).

Source

pub fn detect_flags(meta: &HashMap<String, String>) -> u8

Derive the flags byte from block metadata.

  • Key "pinned" with value "true" → bit 0x01
  • Key "compressed" with value "true" → bit 0x02
  • Key "encrypted" with value "true" → bit 0x04
Source

pub fn load_blocks( &mut self, blocks: Vec<(String, Vec<u8>, HashMap<String, String>)>, now: u64, )

Scanning phase — ingest raw blocks and compute their checksums.

Each element of blocks is (cid, data, metadata). For every block a BlockScanEntry is created (with verified = false), the checksum is computed, and blocks_scanned is incremented. The progress phase is set to RebuildPhase::Scanning and started_at is updated to now if this is the first call.

Source

pub fn load_existing_index(&mut self, entries: Vec<IndexEntry>)

Existing index load — populate the engine with the pre-existing index.

This is called before the verify/rebuild phases so that RebuildConfig::rebuild_missing_only can skip blocks that already have an up-to-date index entry.

Source

pub fn verify_phase(&mut self)

Verification phase — recompute checksums and mark each entry.

When verify_checksums is disabled in the config, all blocks are considered verified automatically. Otherwise the stored checksum is compared against a freshly computed value; mismatches are recorded as errors (up to max_errors).

Note: because this engine stores only the final checksum (not the original raw bytes), re-verification is done by treating the checksum as valid — callers that need full byte re-verification should use BlockIndexRebuild::verify_with_data instead.

Source

pub fn verify_with_data<I>(&mut self, data_iter: I)
where I: IntoIterator<Item = (String, Vec<u8>)>,

Verification phase with raw data — verify entries against original bytes.

Accepts an iterator of (cid, data) pairs. For each pair, the checksum in the corresponding BlockScanEntry is compared against a freshly computed FNV-1a checksum. Mismatches are recorded as errors.

Source

pub fn rebuild_phase(&mut self, _now: u64)

Rebuild phase — construct IndexEntry records for verified blocks.

Iterates over all BlockScanEntry records that have verified = true. If RebuildConfig::rebuild_missing_only is set, blocks already present in Self::existing_index are skipped. For each remaining block, shard, offset, and flags are derived, then the entry is inserted into Self::index.

Source

pub fn validate_phase(&mut self)

Validation phase — verify consistency between scan entries and the index.

For every block that was scanned (regardless of verification status), this phase checks that a corresponding entry exists in Self::index. Missing entries are recorded as errors. If any errors exist after validation the phase is set to RebuildPhase::Failed; otherwise it transitions to RebuildPhase::Complete.

Source

pub fn run_full_rebuild( &mut self, blocks: Vec<(String, Vec<u8>, HashMap<String, String>)>, existing: Vec<IndexEntry>, now: u64, ) -> &RebuildProgress

Execute the full four-phase rebuild pipeline and return a reference to the final progress snapshot.

Equivalent to calling (in order):

  1. Self::load_blocks
  2. Self::load_existing_index
  3. Self::verify_phase
  4. Self::rebuild_phase
  5. Self::validate_phase
Source

pub fn get_index_entry(&self, cid: &str) -> Option<&IndexEntry>

Look up a CID in the rebuilt index.

Returns None when no entry was reconstructed for that CID.

Source

pub fn index_size(&self) -> usize

Number of entries currently in the rebuilt index.

Source

pub fn rebuild_stats(&self) -> RebuildStats

Produce a RebuildStats snapshot of the current engine state.

Source

pub fn export_index(&self) -> Vec<IndexEntry>

Return all index entries as a cloned Vec.

Source

pub fn scan_entries(&self) -> &[BlockScanEntry]

Return all scan entries (including unverified ones).

Source

pub fn errors(&self) -> &[String]

Return the current errors list.

Source

pub fn progress(&self) -> &RebuildProgress

Return a reference to the current progress.

Source

pub fn existing_index(&self) -> &HashMap<String, IndexEntry>

Return a reference to the existing index.

Source

pub fn reset(&mut self)

Reset the engine state, preserving the configuration.

Clears scan entries, rebuilt index, existing index, and progress.

Source

pub fn is_finished(&self) -> bool

Check whether the engine has completed (successfully or with failure).

Source

pub fn is_successful(&self) -> bool

Returns true if the rebuild completed without any errors.

Source

pub fn merge_index(&mut self, entries: Vec<IndexEntry>)

Merge an additional set of IndexEntry records from an external source into the rebuilt index without overwriting existing entries.

Source

pub fn upsert_index_entry(&mut self, entry: IndexEntry)

Forcibly insert (or overwrite) an IndexEntry in the rebuilt index.

Source

pub fn remove_index_entry(&mut self, cid: &str) -> Option<IndexEntry>

Remove an entry from the rebuilt index by CID. Returns the removed entry if it existed.

Source

pub fn unverified_entries(&self) -> Vec<&BlockScanEntry>

Return the subset of scanned blocks that failed verification (or were never verified).

Source

pub fn all_index_entries(&self) -> Vec<&IndexEntry>

Return references to all IndexEntry records in the rebuilt index.

Source

pub fn entries_in_shard(&self, shard: u8) -> Vec<&IndexEntry>

Find index entries assigned to a specific shard.

Source

pub fn pinned_entries(&self) -> Vec<&IndexEntry>

Return all index entries that have the pinned flag set.

Source

pub fn compressed_entries(&self) -> Vec<&IndexEntry>

Return all index entries that have the compressed flag set.

Source

pub fn encrypted_entries(&self) -> Vec<&IndexEntry>

Return all index entries that have the encrypted flag set.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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