Skip to main content

LsnRep

Enum LsnRep 

Source
pub enum LsnRep {
    Empty,
    Compact {
        base_file_number: u32,
        bytes: Vec<u8>,
    },
    Long(Vec<Lsn>),
}
Expand description

T-3: node-level packed LSN array — IN.entryLsnByteArray / IN.entryLsnLongArray (IN.java:251-289, getLsn/setLsnInternal IN.java:1752-1935).

JE stores one LSN per slot. A naive Lsn (u64) costs 8 bytes/slot even though most LSNs in a node share a file number and have a file offset that fits in 3 bytes. JE’s compact rep is a single byte[] with BYTES_PER_LSN_ENTRY == 4 bytes per slot:

  • base_file_number is the lowest file number of any non-NULL LSN in the node;
  • byte 0 of each slot = file_number - base_file_number (0..=127, Byte.MAX_VALUE);
  • bytes 1..4 = the 3-byte little-endian file offset (max MAX_FILE_OFFSET == 0xff_fffe).

The NULL_LSN blocker (Noxu NULL_LSN == u64::MAX) is solved EXACTLY as JE does it: NULL is NOT stored as the raw u64; the slot’s 3 file-offset bytes are set to 0xff_ffff (THREE_BYTE_NEGATIVE_ONE), a value MAX_FILE_OFFSET can never reach, and get_lsn maps it back to NULL_LSN.

If a file-number difference exceeds 127 or a file offset exceeds MAX_FILE_OFFSET, the rep mutates to Long (one u64 per slot), matching JE’s mutateToLongArray (IN.java:1924). An all-NULL node uses Empty (0 bytes), matching the EMPTY_REP/initial-capacity-free state.

Variants§

§

Empty

All slots NULL — 0 heap bytes (the byteArray == null initial state).

§

Compact

IN.entryLsnByteArray — 4 bytes/slot, base_file_number-relative.

Fields

§base_file_number: u32
§bytes: Vec<u8>
§

Long(Vec<Lsn>)

IN.entryLsnLongArray — 8 bytes/slot fallback after mutateToLongArray.

Implementations§

Source§

impl LsnRep

Source

pub const BYTES_PER_LSN_ENTRY: usize = 4

IN.BYTES_PER_LSN_ENTRY (IN.java:151).

Source

pub fn new(_n: usize) -> Self

A rep sized for n slots, all NULL. Returns Empty (0 bytes); the Compact byte array is lazily allocated by the first non-NULL set_lsnbase_file_number is unknown until then (IN.java:1820, the baseFileNumber == -1 first-entry case).

Source

pub fn from_lsns(lsns: &[Lsn]) -> Self

Build a rep from a per-slot Lsn slice (used by node construction and split, where slots arrive together). Equivalent to new(lsns.len()) followed by set(i, lsns[i]) for each slot.

Source

pub fn get(&self, idx: usize) -> Lsn

IN.getLsn(idx) (IN.java:1752).

Source

pub fn set(&mut self, idx: usize, lsn: Lsn, n: usize)

IN.setLsnInternal(idx, value) (IN.java:1801) — set the LSN of slot idx, mutating Empty→Compact→Long as necessary. n is the node’s slot count (sizes a freshly-allocated Compact array).

Source

pub fn insert_shift(&mut self, idx: usize, n: usize)

INArrayRep.copy analogue: shift LSNs when an entry is inserted at idx (slots >= idx move up one). Mirrors targets.insert_shift.

Source

pub fn remove_shift(&mut self, idx: usize)

INArrayRep.copy analogue: shift LSNs when entry idx is removed (slots > idx move down one). Mirrors targets.remove_shift.

Source

pub fn memory_size(&self) -> usize

IN.computeLsnOverhead analogue: heap bytes of the rep itself.

Trait Implementations§

Source§

impl Debug for LsnRep

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.