Skip to main content

Meta

Struct Meta 

Source
pub struct Meta {
    pub format_version: u16,
    pub roots: [u32; 8],
    pub next_lsn: u64,
    pub generation: u64,
}

Fields§

§format_version: u16§roots: [u32; 8]§next_lsn: u64

LSN high-water mark, persisted so a rotation followed by a restart does not renumber log records from 1. Nothing today compares a page’s lsn against a record’s, but a later idempotence check would be silently wrong if LSNs repeated, and that is not a defect worth discovering from a corrupted store.

§generation: u64

Monotone publication counter (2f). Chooses the live slot on open and the victim slot on write. 0 = the create-time publication.

Implementations§

Source§

impl Meta

Source

pub fn write(&self, pool: &BufferPool) -> Result<()>

Source

pub fn write_slot(&self, pool: &BufferPool) -> Result<()>

Write this Meta into the slot its generation selects (2f). The caller flushes data pages and BARRIERS before calling, and flushes again after: the flip must reach the medium only once everything it names is already there.

Source

pub fn from_page(p: &PageRef<'_>) -> Result<Meta>

Decode a Meta from an already-verified page. Pure – no BufferPool involved – so a caller holding a raw, already-CRC- checked PageRef over a single buffer can read it without needing a whole pool wrapped around one page. read below is a thin wrapper over this.

Fallible (Task 17 re-review, R2): a page can CRC-verify – its own bytes are exactly what was last written – while still holding zero slots, which Meta::write’s own error path can produce (see its doc comment) and nothing stops a future writer from producing another way. PageRef::slot(0) on such a page returns an EMPTY slice, not an error – verification and “has a slot 0 at all” are different questions – so the previous, infallible version of this function indexed straight into it and panicked. A malformed superblock is exactly the kind of damage this crate’s own recover() exists to repair; a decoder that panics on it instead of returning Err takes that repair path down with it, which is precisely what R2 measured.

Source

pub fn read(pool: &BufferPool) -> Result<Meta>

Source

pub fn read_latest(pool: &BufferPool) -> Result<Meta>

2f: read BOTH slots, adopt the newest valid one. A slot that fails its page checksum or does not parse is normally the loser – a torn flip leaves the previous publication standing. An intact unsupported logical version must refuse instead of falling back to stale metadata. A page-1 slot that is a valid page of any OTHER kind is a pre-2f file and is refused outright: silently adopting slot 0 would let the next checkpoint overwrite a live tree page.

Source

pub fn init_slot_b(pool: &BufferPool) -> Result<()>

Initialise slot B as an EMPTY Meta page (valid page, no record): recognisably a slot – so read_latest never mistakes this for a pre-2f file – but never adoptable until a real flip writes it.

Trait Implementations§

Source§

impl Clone for Meta

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Meta

Source§

impl Debug for Meta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Meta

§

impl RefUnwindSafe for Meta

§

impl Send for Meta

§

impl Sync for Meta

§

impl Unpin for Meta

§

impl UnsafeUnpin for Meta

§

impl UnwindSafe for Meta

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.