Skip to main content

ShardedSyncIndex

Struct ShardedSyncIndex 

Source
pub struct ShardedSyncIndex {
    index_file: PathBuf,
    shards: [RwLock<Shard>; 16],
}
Expand description

Thread-safe sync index that distributes entries across 16 RwLock shards keyed by path hash. This eliminates the single-lock bottleneck when parallel producers (startup scan, watcher workers) and consumers (library UI sync-state lookups) all contend on the index simultaneously.

The public API is identical to the old SyncIndex but methods are inherent – callers no longer wrap this in Arc<Mutex<_>>.

Fields§

§index_file: PathBuf

Absolute path of index JSON on disk.

§shards: [RwLock<Shard>; 16]

Array of RwLock-wrapped entry shards.

Implementations§

Source§

impl ShardedSyncIndex

Source

pub fn new() -> Self

Load existing indices from persistent path, migrating cache if necessary.

Source

pub fn sync_decision( &self, path: &Path, target: &SyncTarget, ) -> Result<SyncDecision>

Decide whether a file is already current, needs a new upload, or only needs reassociation.

Source

pub fn record_synced( &self, path: &str, checksum: &str, target: &SyncTarget, ) -> Result<()>

Save the latest synced fingerprint and album target for a file.

Source

pub fn prune_missing(&self, seen_paths: &HashSet<String>) -> Result<()>

Drop records for files that no longer exist under any configured watch path.

Source

pub fn stored_checksum(&self, path: &str) -> Option<String>

Reuse the previous checksum when a file only needs album reassociation.

Source

pub fn fresh_checksum(&self, path: &Path) -> Option<String>

Return the cached checksum only if the file’s current size + mtime still match the stored fingerprint. Returns None when the file is missing, untracked, or has been modified since the last index update — callers must re-hash in that case.

Source

pub fn record_for_path(&self, path: &str) -> Option<SyncedFileRecord>

Return a synced record for a specific path without touching the filesystem.

Source

pub fn remove_path(&self, path: &str) -> Result<bool>

Remove one synced path from the index after a deliberate delete sync.

Source

pub fn records_under_path(&self, root: &Path) -> Vec<(String, SyncedFileRecord)>

Return synced records rooted under a watch path.

Source

pub fn paths_for_checksum(&self, checksum: &str) -> Vec<String>

All synced paths that share a checksum. Used to detect when an asset is referenced from more than one watch folder before trashing it.

Source

pub fn local_path_for_checksum(&self, checksum: &str) -> Option<String>

Reverse-lookup a local path by checksum for library sync-state indicators.

Source

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

Force a flush to disk if there are unwritten changes. Dirty markers are only cleared after a successful write, so a failed write leaves the data marked dirty for the next flush attempt.

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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
§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more