Skip to main content

FlatFileStore

Struct FlatFileStore 

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

Content-addressed flat-file blob store keyed by BLAKE3.

An in-memory cache of (meta_hash, node_id) pairs and known meta_hash values is maintained to avoid O(n) linear scans of index.ndjson on the indexer hot path. The cache is populated during [init] and updated by [append_index].

Implementations§

Source§

impl FlatFileStore

Source

pub fn open(root: impl Into<PathBuf>) -> Self

Open (or create) a store rooted at root.

Directories are created lazily by [init].

Source

pub async fn init(&self) -> Result<(), StoreError>

Create the required directory structure and populate the in-memory dedup cache from any existing index.ndjson.

Source

pub fn resolve_path( &self, blake3_hex: &str, ) -> Result<Option<PathBuf>, StoreError>

Return the filesystem path for a blob without reading it.

Returns Some(path) if the blob exists locally, None otherwise.

Source

pub async fn put(&self, bytes: &[u8]) -> Result<Blake3Hex, StoreError>

Hash bytes with BLAKE3 and store under blobs/.

Returns the 64-char hex key. Idempotent: if the blob already exists the write is skipped (content-addressable deduplication).

Source

pub async fn get(&self, blake3_hex: &str) -> Result<Option<Vec<u8>>, StoreError>

Read a blob by its 64-char BLAKE3 hex key. Returns None if not found.

Source

pub fn contains(&self, blake3_hex: &str) -> Result<bool, StoreError>

Check existence without reading the full blob.

Source

pub async fn append_index(&self, record: &IndexRecord) -> Result<(), StoreError>

Append one record to index.ndjson (one JSON object per line).

Also updates the in-memory dedup and meta_hash caches.

Source

pub async fn append_index_if_absent( &self, record: &IndexRecord, ) -> Result<bool, StoreError>

Append one record only if the (meta_hash, node_id) pair is absent.

Returns true when a new record was appended, false when the record was already present in the dedup cache.

Source

pub fn iter_index( &self, ) -> Result<impl Iterator<Item = Result<IndexRecord, StoreError>>, StoreError>

Iterate all records from the in-memory index cache.

Source

pub fn has_index_record( &self, meta_hash: &str, node_id: &str, ) -> Result<bool, StoreError>

True if the exact (meta_hash, node_id) pair is already recorded.

Uses the in-memory dedup cache — O(1) after [init].

Source

pub fn has_meta_hash(&self, meta_hash: &str) -> Result<bool, StoreError>

True if any record is known for this metadata blob.

Uses the in-memory meta_hash cache — O(1) after [init].

Source

pub fn discovery_events_since( &self, since_seq: u64, ) -> Result<Vec<(u64, IndexRecord)>, StoreError>

Return all RemoteAnnouncement index records at or after position since_seq.

since_seq is a 0-based line number in index.ndjson. The discovery worker persists the last processed seq and resumes from there on restart, providing at-least-once delivery across restarts.

Returns (seq, record) pairs ordered by ascending seq.

Source

pub fn latest_local_publish( &self, igc_hash: &Blake3Hex, node_id: &NodeIdHex, ) -> Result<Option<IndexRecord>, StoreError>

Return the latest local publish record for an IGC hash from this node.

Source

pub fn load_key_bytes(&self) -> Result<Option<[u8; 32]>, StoreError>

Load the raw 32-byte secret key from node.key, or return None if the file does not exist.

Source

pub fn save_key_bytes(&self, bytes: &[u8; 32]) -> Result<(), StoreError>

Persist a 32-byte secret key to node.key with mode 0600.

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<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<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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> 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