Skip to main content

DirBackend

Struct DirBackend 

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

Content in <root>/<hash[..2]>/<hash>. Writes stream into a temporary file beside the target and are renamed into place once complete and hashed, so a reader never sees a partial item under an address that promises whole content; reads verify as they stream.

A durable store (the default) publishes an item behind a barrier: the item is flushed before the rename, and the shard directory after it — and the root too when the write created the shard — so an item put has returned for survives a power loss under its address. DirBackend::regenerable stores skip every flush.

ContentBackend::has hashes a file once per file identity (inode, length, timestamps) per backend: a file replaced or rewritten since is verified again. The quota total is kept in memory between writes and rescanned only when another writer has written since (every writer bumps <root>/.content-store.gen under the root lock), or before refusing a write, since files removed behind the store’s back make the kept total over-count.

Implementations§

Source§

impl DirBackend

Source

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

Source

pub fn with_limits(root: impl Into<PathBuf>, limits: ContentLimits) -> Self

Source

pub fn reading_also(self, dir: impl Into<PathBuf>) -> Self

Source

pub fn regenerable(self) -> Self

Hold content its owner can recreate, such as a cache: writes are not flushed to disk, so a write never waits for the filesystem to flush every other dirty page first. After a crash an item may be missing or torn; reads verify it against its address, so a torn item reads as absent.

Source

pub fn root(&self) -> &Path

Source

pub fn limits(&self) -> ContentLimits

Source§

impl DirBackend

Source

pub fn collect_unreferenced_before( &self, live: &BTreeSet<String>, before: SystemTime, ) -> Result<Collected, ContentError>

Remove every item not in live that was last written before before: what a store collects when an item may be referenced only after it is written (an upload a record names once it is kept). Writing an item that is already here counts as writing it.

§Errors

The store could not be read or changed.

Trait Implementations§

Source§

impl ContentBackend for DirBackend

Source§

fn put_many(&self, items: &[(&[u8], &str)]) -> Vec<Result<Stored, ContentError>>

Store items together: each is received and flushed as Self::put does, and the index, its generation and each shard directory are written once for the whole set instead of once per item.

Source§

fn put( &self, reader: &mut dyn Read, _mime: &str, ) -> Result<Stored, ContentError>

Store everything reader yields, returning its address. Storing content already present is a no-op that succeeds. mime is advisory (a backend may index or serve by it). Read more
Source§

fn open(&self, hash: &str) -> Result<Option<ContentReader>, ContentError>

Source§

fn open_at( &self, hash: &str, offset: u64, ) -> Result<Option<ContentReader>, ContentError>

The content at hash read from offset on: a backend that keeps it in a file seeks there, so serving one piece of a large item reads only that piece. Bytes read so are not checked against the address (that takes the whole item); sealed content is still checked chunk by chunk as it opens. Read more
Source§

fn has(&self, hash: &str) -> bool

Source§

fn size(&self, hash: &str) -> Option<u64>

The length of the content at hash, when the store knows it without reading the bytes: what a reader serving one piece of a large file asks before it seeks there.
Source§

fn state(&self, hash: &str) -> ContentState

Where the content at hash has got to. A backend that can fetch from elsewhere reports ContentState::Pending while it does, and may start fetching when asked.
Source§

fn collect_unreferenced( &self, live: &BTreeSet<String>, ) -> Result<Collected, ContentError>

Remove every item whose address is not in live, which must be complete: the caller asserts nothing outside it is referenced by anything it is responsible for. Read more
Source§

fn release(&self, hash: &str) -> Result<Collected, ContentError>

Remove the item hash, when the one who keeps it here knows nothing it is responsible for references it any longer (a quota letting the oldest item go). Content kept for another reason under the same address goes with it, so a caller sharing a store removes only what it alone keeps. Read more
Source§

fn max_item_bytes(&self) -> usize

The largest item this store accepts: a write that hashes before it seals refuses a larger one as it reads it, rather than holding it whole first (ContentStore::put_reader).
Source§

fn scratch_dir(&self) -> Option<PathBuf>

A directory beside the content this store keeps, where a sealing write may keep the plaintext it hashes in a file rather than in memory. None for a store with no directory of its own: one that keeps content on a host, or holds it in memory.
Source§

fn shared(&self) -> bool

Whether content stored here reaches beyond this device’s own copy: the device content store serves it to the app’s other devices and members. A document may then refer to content by address alone; with a store that is not shared, a member would be left holding an address nothing can resolve.
Source§

fn workspace_scoped(&self) -> bool

Whether this store answers only for content readable in one workspace: the device content store reads through the scope the launcher handed the window, and serves an address only when that workspace references it. A caller’s content reference is resolved only in such a store, so naming a hash never reaches content from elsewhere on this machine.
Source§

fn content_secret(&self) -> Option<SymmetricKey>

The secret the members who read what this store keeps hold, when it is at hand: a sealing store (ContentStore::sealing) then seals each item under a key derived from it and the item’s bytes, rather than a fresh one, so the same bytes stored twice are the same ciphertext under the same reference, kept and carried once. Read more
Source§

fn put_sealed( &self, reader: &mut dyn Read, mime: &str, ) -> Option<Result<Stored, ContentError>>

Seal and keep what reader yields, when the store behind this backend seals what it is handed itself, under the members’ secret it holds and this backend does not (a session’s store, whose device’s daemon holds the workspace’s keys): the sealed reference it answers is what a sealing store hands back. None, reading nothing, when the backend keeps only what is sealed before it reaches it.

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