Skip to main content

FileHandleGuard

Struct FileHandleGuard 

Source
pub struct FileHandleGuard<'a> { /* private fields */ }
Expand description

RAII guard providing access to the file while the latch is held.

Implementations§

Source§

impl<'a> FileHandleGuard<'a>

Source

pub fn read_at(&mut self, offset: u64, buf: &mut [u8]) -> Result<usize>

Reads data from the file at the given offset.

§Arguments
  • offset - File offset to read from
  • buf - Buffer to read into
§Returns

Number of bytes read. Reads data from the file at the given offset.

Uses pread64 (one syscall) instead of lseek + read (two syscalls). The JVM lowers to pread64 on Linux.

Source

pub fn read_exact_at(&mut self, offset: u64, buf: &mut [u8]) -> Result<()>

Reads exactly buf.len() bytes from the file at the given offset.

Uses pread64 in a retry loop. Returns an error if fewer bytes are available.

Source

pub fn write_at(&mut self, offset: u64, buf: &[u8]) -> Result<usize>

Writes data to the file at the given offset.

Uses pwrite64 (one syscall) instead of lseek + write (two syscalls). FileChannel.write(ByteBuffer, position) which the JVM lowers to pwrite64 on Linux. This eliminates half the syscalls on the hot write path and removes the need to serialise seek+write under the guard (pwrite64 is inherently positional and thread-safe).

§Arguments
  • offset - File offset to write to (passed directly to pwrite64)
  • buf - Data to write
§Returns

Number of bytes written (always buf.len() on success).

Source

pub fn sync(&mut self) -> Result<()>

Syncs all file data and metadata to disk (fsync).

Use this when the file’s metadata (size, mtime) must also be durable — typically for file-header writes. For log-data writes prefer sync_data() which is faster.

Source

pub fn sync_data(&mut self) -> Result<()>

Syncs only the file data to disk (fdatasync).

Faster than sync() because it does not flush file metadata (mtime etc.). uses FileChannel.force(false) (= fdatasync) for all log-data writes and force(true) (= fsync) only for file-header writes.

/ FileChannel.force(false).

Source

pub fn is_empty(&mut self) -> Result<bool>

Returns true if the file is empty.

Source

pub fn len(&mut self) -> Result<u64>

Returns the file length.

Source

pub fn truncate(&mut self, len: u64) -> Result<()>

Truncates the file to the given length.

Source

pub fn file_num(&self) -> u32

Returns the file number.

Source

pub fn log_version(&self) -> u32

Returns the log version.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for FileHandleGuard<'a>

§

impl<'a> !UnwindSafe for FileHandleGuard<'a>

§

impl<'a> Freeze for FileHandleGuard<'a>

§

impl<'a> Send for FileHandleGuard<'a>

§

impl<'a> Sync for FileHandleGuard<'a>

§

impl<'a> Unpin for FileHandleGuard<'a>

§

impl<'a> UnsafeUnpin for FileHandleGuard<'a>

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.