pub struct PackWriter {
pub len: u64,
pub entry_count: u64,
pub offsets: HashMap<Hash, u64>,
/* private fields */
}Expand description
An open, append-only pack. Entries are appended one at a time; the
trailer is written only at seal() time.
Fields§
§len: u64Byte length of the file so far (header + entries written).
entry_count: u64§offsets: HashMap<Hash, u64>In-memory offset index for entries written this process — avoids a
re-scan to serve a get() against data not yet sealed.
Implementations§
Source§impl PackWriter
impl PackWriter
Sourcepub fn open_active(path: &Path, partition_id: PartitionId) -> Result<Self>
pub fn open_active(path: &Path, partition_id: PartitionId) -> Result<Self>
Open (creating if absent) the active pack at path for partition_id,
rebuilding in-memory state by scanning any bytes already there
(resuming after a crash or a prior process exit).
Sourcepub fn append(
&mut self,
hash: Hash,
codec: Codec,
uncompressed_len: u64,
payload: &[u8],
) -> Result<u64>
pub fn append( &mut self, hash: Hash, codec: Codec, uncompressed_len: u64, payload: &[u8], ) -> Result<u64>
Append one entry (dedup is the caller’s responsibility — this always
writes). Returns the byte offset the entry starts at. Always emits
the reserved values for flags/key_epoch — there is no parameter
to supply anything else; that is the writer-side half of the
fail-closed rule (module docs).
Sourcepub fn append_raw(&mut self, meta: &EntryMeta, payload: &[u8]) -> Result<u64>
pub fn append_raw(&mut self, meta: &EntryMeta, payload: &[u8]) -> Result<u64>
Append one entry with an arbitrary, caller-supplied EntryMeta —
the byte-exact primitive a meta-preserving copy (GC’s repack) needs
to relocate an entry without re-deriving flags/key_epoch from
scratch. Not a route for ordinary callers to set reserved
fields: PartitionStore::put
only ever reaches this through PackWriter::append, which hard-codes
the reserved values. packfile is implementation, explicitly
outside the interface lock (see lib.rs); this is the escape hatch
that exists for exactly one job.
pub fn read_payload_at(&self, offset: u64) -> Result<(EntryMeta, Vec<u8>)>
Sourcepub fn seal(self, packs_dir: &Path) -> Result<(Hash, PathBuf)>
pub fn seal(self, packs_dir: &Path) -> Result<(Hash, PathBuf)>
Seal this pack: write the trailer, rename to its content-addressed
final name (<pack_content_hash>.pack), and return the new id +
path. The writer is consumed — callers open a fresh PackWriter for
the next active pack.
pub fn partition_id(&self) -> PartitionId
Auto Trait Implementations§
impl Forget for PackWriter
impl Freeze for PackWriter
impl Move for PackWriter
impl RefUnwindSafe for PackWriter
impl Send for PackWriter
impl Sync for PackWriter
impl Unpin for PackWriter
impl UnsafeUnpin for PackWriter
impl UnwindSafe for PackWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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