[−][src]Struct grin_store::types::AppendOnlyFile
Wrapper for a file that can be read at any position (random read) but for which writes are append only. Reads are backed by a memory map (mmap(2)), relying on the operating system for fast access and caching. The memory map is reallocated to expand it when new writes are flushed.
Despite being append-only, the file can still be pruned and truncated. The former simply happens by rewriting it, ignoring some of the data. The latter by truncating the underlying file and re-creating the mmap.
Methods
impl<T> AppendOnlyFile<T> where
T: Debug + Readable + Writeable,
[src]
T: Debug + Readable + Writeable,
pub fn open<P>(
path: P,
size_info: SizeInfo,
version: ProtocolVersion
) -> Result<AppendOnlyFile<T>> where
P: AsRef<Path> + Debug,
[src]
path: P,
size_info: SizeInfo,
version: ProtocolVersion
) -> Result<AppendOnlyFile<T>> where
P: AsRef<Path> + Debug,
Open a file (existing or not) as append-only, backed by a mmap.
pub fn init(&mut self) -> Result<()>
[src]
(Re)init an underlying file and its associated memmap. Taking care to initialize the mmap_offset_cache for each element.
pub fn append(&mut self, bytes: &mut [u8]) -> Result<()>
[src]
Append data to the file. Until the append-only file is synced, data is only written to memory.
pub fn rewind(&mut self, pos: u64)
[src]
Rewinds the data file back to a previous position. We simply "rewind" the buffer_start_pos to the specified position. Note: We do not currently support rewinding within the buffer itself.
pub fn flush(&mut self) -> Result<()>
[src]
Syncs all writes (fsync), reallocating the memory map to make the newly written data accessible.
pub fn discard(&mut self)
[src]
Discard the current non-flushed data.
pub fn read(&self, pos: u64) -> Result<&[u8]>
[src]
Read the bytes representing the element at the given position (0-indexed). Uses the offset cache to determine the offset to read from and the size in bytes to actually read. Leverages the memory map.
pub fn as_temp_file(&self) -> Result<File>
[src]
Create a new tempfile containing the contents of this append only file. This allows callers to see a consistent view of the data without locking the append only file.
pub fn save_prune(&mut self, prune_pos: &[u64]) -> Result<()>
[src]
Saves a copy of the current file content, skipping data at the provided prune positions. prune_pos must be ordered.
pub fn release(&mut self)
[src]
Release underlying file handles.
pub fn size(&self) -> Result<u64>
[src]
Current size of the file in bytes.
pub fn path(&self) -> &Path
[src]
Path of the underlying file
Auto Trait Implementations
impl<T> Send for AppendOnlyFile<T> where
T: Send,
T: Send,
impl<T> Sync for AppendOnlyFile<T> where
T: Sync,
T: Sync,
impl<T> Unpin for AppendOnlyFile<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for AppendOnlyFile<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for AppendOnlyFile<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> UnsafeAny for T where
T: Any,
T: Any,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Erased for T
impl<T> SafeBorrow<T> for T where
T: ?Sized,
T: ?Sized,
fn borrow_replacement(ptr: &T) -> &T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,