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
impl DirBackend
pub fn new(root: impl Into<PathBuf>) -> Self
pub fn with_limits(root: impl Into<PathBuf>, limits: ContentLimits) -> Self
pub fn reading_also(self, dir: impl Into<PathBuf>) -> Self
Sourcepub fn regenerable(self) -> Self
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.
pub fn root(&self) -> &Path
pub fn limits(&self) -> ContentLimits
Source§impl DirBackend
impl DirBackend
Sourcepub fn collect_unreferenced_before(
&self,
live: &BTreeSet<String>,
before: SystemTime,
) -> Result<Collected, ContentError>
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
impl ContentBackend for DirBackend
Source§fn put_many(&self, items: &[(&[u8], &str)]) -> Vec<Result<Stored, ContentError>>
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>
fn put( &self, reader: &mut dyn Read, _mime: &str, ) -> Result<Stored, ContentError>
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 morefn open(&self, hash: &str) -> Result<Option<ContentReader>, ContentError>
Source§fn open_at(
&self,
hash: &str,
offset: u64,
) -> Result<Option<ContentReader>, ContentError>
fn open_at( &self, hash: &str, offset: u64, ) -> Result<Option<ContentReader>, ContentError>
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 morefn has(&self, hash: &str) -> bool
Source§fn size(&self, hash: &str) -> Option<u64>
fn size(&self, hash: &str) -> Option<u64>
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
fn state(&self, hash: &str) -> ContentState
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>
fn collect_unreferenced( &self, live: &BTreeSet<String>, ) -> Result<Collected, ContentError>
live, which must be complete: the caller
asserts nothing outside it is referenced by anything it is responsible for. Read moreSource§fn release(&self, hash: &str) -> Result<Collected, ContentError>
fn release(&self, hash: &str) -> Result<Collected, ContentError>
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 moreSource§fn max_item_bytes(&self) -> usize
fn max_item_bytes(&self) -> usize
ContentStore::put_reader).Source§fn scratch_dir(&self) -> Option<PathBuf>
fn scratch_dir(&self) -> Option<PathBuf>
None for a store with no directory
of its own: one that keeps content on a host, or holds it in memory.Source§fn workspace_scoped(&self) -> bool
fn workspace_scoped(&self) -> bool
Source§fn content_secret(&self) -> Option<SymmetricKey>
fn content_secret(&self) -> Option<SymmetricKey>
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 moreSource§fn put_sealed(
&self,
reader: &mut dyn Read,
mime: &str,
) -> Option<Result<Stored, ContentError>>
fn put_sealed( &self, reader: &mut dyn Read, mime: &str, ) -> Option<Result<Stored, ContentError>>
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.