pub struct WalFile { /* private fields */ }Implementations§
Source§impl WalFile
impl WalFile
pub fn new( io: Arc<dyn IO>, shared: Arc<RwLock<WalFileShared>>, (last_checksum, max_frame): ((u32, u32), u64), buffer_pool: Arc<BufferPool>, ) -> Self
Sourcepub fn try_restart_log_before_write(&self) -> Result<()>
pub fn try_restart_log_before_write(&self) -> Result<()>
attempt to restart WAL header before write in order to keep WAL file size under the control The conditions for WAL restart are following:
- we can do that only under write transaction
- max_frame_read_lock_index == 0 - this means that transaction was initiated to read data from DB file
- nbackfills > 0 - otherwise nothing was backfilled and there is no reason to truncate header
- max_frame == nbackfills - otherwise there are some non-checkpointed frames in the WAL and we can’t truncate the log
Sourcepub fn mvcc_refresh_if_db_changed(&self) -> bool
pub fn mvcc_refresh_if_db_changed(&self) -> bool
MVCC helper: check if WAL state changed and refresh local snapshot without starting a read tx. FIXME: this isn’t TOCTOU safe because we’re not taking WAL read locks.
This is only used to invalidate page cache, so false positives are sort of acceptable since MVCC reads currently don’t read from WAL frames ever. FIXME: MVCC should start using pager read transactions anyway so that we can get rid of the stop-the-world MVCC checkpoint that blocks all reads.
Trait Implementations§
Source§impl Wal for WalFile
impl Wal for WalFile
Source§fn end_read_tx(&self)
fn end_read_tx(&self)
End a read transaction.
Source§fn begin_write_tx(&self, allowed_auto_actions: WalAutoActions) -> Result<()>
fn begin_write_tx(&self, allowed_auto_actions: WalAutoActions) -> Result<()>
Begin a write transaction
Source§fn end_write_tx(&self)
fn end_write_tx(&self)
End a write transaction
Source§fn holds_read_lock(&self) -> bool
fn holds_read_lock(&self) -> bool
Returns true if this WAL instance currently holds a read lock.
Source§fn holds_write_lock(&self) -> bool
fn holds_write_lock(&self) -> bool
Returns true if this WAL instance currently holds the write lock.
Source§fn find_frame(
&self,
page_id: u64,
frame_watermark: Option<u64>,
) -> Result<Option<u64>>
fn find_frame( &self, page_id: u64, frame_watermark: Option<u64>, ) -> Result<Option<u64>>
Find the latest frame containing a page.
Source§fn read_frame(
&self,
frame_id: u64,
page: PageRef,
buffer_pool: Arc<BufferPool>,
) -> Result<Completion>
fn read_frame( &self, frame_id: u64, page: PageRef, buffer_pool: Arc<BufferPool>, ) -> Result<Completion>
Read a frame from the WAL.
Source§fn prepare_frames(
&self,
pages: &[PageRef],
page_sz: PageSize,
db_size_on_commit: Option<u32>,
prev: Option<&PreparedFrames>,
) -> Result<PreparedFrames>
fn prepare_frames( &self, pages: &[PageRef], page_sz: PageSize, db_size_on_commit: Option<u32>, prev: Option<&PreparedFrames>, ) -> Result<PreparedFrames>
Prepares a batch of dirty pages as WAL frames without modifying WAL state.
This is the first phase of a three-phase commit protocol:
- prepare (
prepare_frames) - serialize frames, compute checksums - write + fsync - caller submits I/O and waits for durability
- commit/finalize (
commit_prepared_frames) - update WAL index and page metadata
WAL frames form a checksum chain for corruption detection. When writing
multiple batches in a single transaction, pass the previous batch via prev
to continue the chain. For the first batch, pass None to start from
the committed WAL state.
Source§fn commit_prepared_frames(&self, batches: &[PreparedFrames])
fn commit_prepared_frames(&self, batches: &[PreparedFrames])
For each prepared frame, update in-memory WAL index and rolling checksum. and advance max_frame to make frames visible to readers.
Source§fn finalize_committed_pages(&self, prepared: &[PreparedFrames])
fn finalize_committed_pages(&self, prepared: &[PreparedFrames])
Mark pages clean and set WAL tags after durable commit.
Source§fn append_frames_vectored(
&self,
pages: Vec<PageRef>,
page_sz: PageSize,
) -> Result<Completion>
fn append_frames_vectored( &self, pages: Vec<PageRef>, page_sz: PageSize, ) -> Result<Completion>
Use pwritev to append many frames to the log at once.
§Safety:
this method should only be used for cacheflush/spilling, the commit path should use prepare_frames + commit_prepared_frames instead, as it prevents prematurely modifing WAL state before durability is ensured.
Source§fn begin_read_tx(&self) -> Result<bool>
fn begin_read_tx(&self) -> Result<bool>
Source§fn mvcc_refresh_if_db_changed(&self) -> bool
fn mvcc_refresh_if_db_changed(&self) -> bool
Source§fn should_checkpoint_on_close(&self) -> bool
fn should_checkpoint_on_close(&self) -> bool
Source§fn read_frames_batch(
&self,
start_frame: u64,
pages: &[PageRef],
buffer_pool: Arc<BufferPool>,
scratch_buf: Option<Arc<Buffer>>,
) -> Result<Completion>
fn read_frames_batch( &self, start_frame: u64, pages: &[PageRef], buffer_pool: Arc<BufferPool>, scratch_buf: Option<Arc<Buffer>>, ) -> Result<Completion>
pread.
For each i, pages[i] receives the decoded page body of frame
start_frame + i. This method is a batched version of read_frame. Read moreSource§fn read_frame_raw(&self, frame_id: u64, frame: &mut [u8]) -> Result<Completion>
fn read_frame_raw(&self, frame_id: u64, frame: &mut [u8]) -> Result<Completion>
Source§fn write_frame_raw(
&self,
buffer_pool: Arc<BufferPool>,
frame_id: u64,
page_id: u64,
db_size: u64,
page: &[u8],
sync_type: FileSyncType,
) -> Result<()>
fn write_frame_raw( &self, buffer_pool: Arc<BufferPool>, frame_id: u64, page_id: u64, db_size: u64, page: &[u8], sync_type: FileSyncType, ) -> Result<()>
fn should_checkpoint(&self) -> bool
fn checkpoint( &self, pager: &Pager, mode: CheckpointMode, ) -> Result<IOResult<CheckpointResult>>
Source§fn vacuum_checkpoint_with_held_lock(
&self,
pager: &Pager,
) -> Result<IOResult<CheckpointResult>>
fn vacuum_checkpoint_with_held_lock( &self, pager: &Pager, ) -> Result<IOResult<CheckpointResult>>
fn install_durable_backfill_proof( &self, max_frame: u64, db_size_pages: u32, db_header_crc32c: u32, sync_type: FileSyncType, ) -> Result<Option<Completion>>
fn publish_backfill(&self, max_frame: u64)
fn sync(&self, sync_type: FileSyncType) -> Result<Completion>
fn is_syncing(&self) -> bool
Source§fn is_dirty(&self) -> bool
fn is_dirty(&self) -> bool
fn get_max_frame_in_wal(&self) -> u64
fn get_checkpoint_seq(&self) -> u32
fn get_max_frame(&self) -> u64
Source§fn connection_wal_pos(&self) -> (u32, u64)
fn connection_wal_pos(&self) -> (u32, u64)
(checkpoint_seq, max_frame): for a reader it is the WAL read
mark installed at begin_read_tx; for a writer it is the position after its last commit.
Used by MVCC to gate btree reads on physical reachability (a materialization at WAL
position P is reachable iff P <= this, lexicographically). See RootEntry.Source§fn min_pinned_read_frame(&self) -> Option<u64>
fn min_pinned_read_frame(&self) -> Option<u64>
None if no reader holds a slot. This is the authoritative set of pinned
readers — it includes a reader that has called begin_read_tx but not yet published an
MVCC transaction — so the MVCC checkpoint uses it as the version-store GC floor (a row
whose btree page was materialized past a pinned reader’s frame is invisible in that
reader’s snapshot, so its version-store copy must be retained).fn get_min_frame(&self) -> u64
Source§fn backfill_frame(&self) -> u64
fn backfill_frame(&self) -> u64
fn get_last_checksum(&self) -> (u32, u32)
fn rollback(&self, rollback_to: Option<RollbackTo>)
fn abort_checkpoint(&self)
Source§fn try_begin_vacuum_checkpoint_lock(&self) -> Result<()>
fn try_begin_vacuum_checkpoint_lock(&self) -> Result<()>
Busy if
another checkpointer or VACUUM already holds it. Used by plain VACUUM
to fail fast if a concurrent checkpoint would block later.Source§fn release_vacuum_checkpoint_lock(&self)
fn release_vacuum_checkpoint_lock(&self)
try_begin_vacuum_checkpoint_lock.Source§fn begin_vacuum_blocking_tx(&self) -> Result<()>
fn begin_vacuum_blocking_tx(&self) -> Result<()>
Source§fn release_vacuum_lock(&self)
fn release_vacuum_lock(&self)
begin_vacuum_blocking_tx.
VACUUM calls this once done, after which new
readers and writers may proceed again.Source§fn finish_append_frames_commit(&self) -> Result<()>
fn finish_append_frames_commit(&self) -> Result<()>
Source§fn changed_pages_after(&self, frame_watermark: u64) -> Result<Vec<u32>>
fn changed_pages_after(&self, frame_watermark: u64) -> Result<Vec<u32>>
Source§fn prepare_wal_start(&self, page_size: PageSize) -> Result<Option<Completion>>
fn prepare_wal_start(&self, page_size: PageSize) -> Result<Option<Completion>>
fn prepare_wal_finish(&self, sync_type: FileSyncType) -> Result<Completion>
fn as_any(&self) -> &dyn Any
fn set_io_context(&self, ctx: IOContext)
Source§fn update_max_frame(&self)
fn update_max_frame(&self)
Source§fn truncate_wal(
&self,
result: &mut CheckpointResult,
sync_type: FileSyncType,
) -> Result<IOResult<()>>
fn truncate_wal( &self, result: &mut CheckpointResult, sync_type: FileSyncType, ) -> Result<IOResult<()>>
Auto Trait Implementations§
impl !Freeze for WalFile
impl !RefUnwindSafe for WalFile
impl !UnwindSafe for WalFile
impl Send for WalFile
impl Sync for WalFile
impl Unpin for WalFile
impl UnsafeUnpin for WalFile
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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