pub struct WriteHandle { /* private fields */ }Expand description
One destination file, open for concurrent positional writes.
Implementations§
Source§impl WriteHandle
impl WriteHandle
Sourcepub fn open_cloned(
final_path: &Path,
size: u64,
preallocate: bool,
) -> Result<Self>
pub fn open_cloned( final_path: &Path, size: u64, preallocate: bool, ) -> Result<Self>
Open the partial file, seeding it from an existing copy where the filesystem can do that for free.
Delta sync reuses most blocks of an unchanged file, and the receiver would otherwise copy every one of them out of the old file and into the new one — gigabytes of local I/O to reproduce bytes that are already on the disk. A copy-on-write clone shares the extents instead, so the seeding is O(1) and only the chunks that genuinely differ are written. Where the filesystem cannot clone, this falls back to the ordinary path and the per-chunk copies happen as before.
Sourcepub fn open(final_path: &Path, size: u64, preallocate: bool) -> Result<Self>
pub fn open(final_path: &Path, size: u64, preallocate: bool) -> Result<Self>
Open (or reopen) the partial file for final_path, sized to size.
pub fn size(&self) -> u64
pub fn part_path(&self) -> &Path
Sourcepub fn created_new(&self) -> bool
pub fn created_new(&self) -> bool
Whether this session created the partial file, and can therefore assume unwritten regions read as zeros.
Sourcepub fn write_zeros_at(&self, offset: u64, len: usize) -> Result<()>
pub fn write_zeros_at(&self, offset: u64, len: usize) -> Result<()>
Write len zero bytes at offset without allocating a buffer that big.
Sourcepub fn write_at(&self, offset: u64, buf: &[u8]) -> Result<()>
pub fn write_at(&self, offset: u64, buf: &[u8]) -> Result<()>
Write buf at offset. Safe to call concurrently from many threads.
pub fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize>
Sourcepub fn matches_at(&self, offset: u64, want: &[u8]) -> Result<bool>
pub fn matches_at(&self, offset: u64, want: &[u8]) -> Result<bool>
Is want already what the file holds at offset?
Used to avoid rewriting bytes a copy-on-write clone already shares: writing them would break the sharing and cost the very I/O the clone was there to avoid.
Sourcepub fn sync(&self) -> Result<()>
pub fn sync(&self) -> Result<()>
Flush to stable storage. Called once per file, not per chunk — an fsync per chunk would dominate the cost of the transfer.
Sourcepub fn commit(
&self,
mode: u32,
mtime: i64,
preserve_metadata: bool,
) -> Result<()>
pub fn commit( &self, mode: u32, mtime: i64, preserve_metadata: bool, ) -> Result<()>
Rename the partial file into place and apply metadata.
Takes &self rather than self because several workers may still hold
a clone of the Arc around this handle when the last chunk lands.
Renaming a file that is still open is safe on unix, and on Windows too:
Rust’s OpenOptions opens with FILE_SHARE_DELETE. Callers guarantee
this runs once per file.
Auto Trait Implementations§
impl Freeze for WriteHandle
impl RefUnwindSafe for WriteHandle
impl Send for WriteHandle
impl Sync for WriteHandle
impl Unpin for WriteHandle
impl UnsafeUnpin for WriteHandle
impl UnwindSafe for WriteHandle
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