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_numberis 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.
Long(Vec<Lsn>)
IN.entryLsnLongArray — 8 bytes/slot fallback after mutateToLongArray.
Implementations§
Source§impl LsnRep
impl LsnRep
Sourcepub const BYTES_PER_LSN_ENTRY: usize = 4
pub const BYTES_PER_LSN_ENTRY: usize = 4
IN.BYTES_PER_LSN_ENTRY (IN.java:151).
Sourcepub fn new(_n: usize) -> Self
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_lsn
— base_file_number is unknown until then (IN.java:1820, the
baseFileNumber == -1 first-entry case).
Sourcepub fn from_lsns(lsns: &[Lsn]) -> Self
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.
Sourcepub fn set(&mut self, idx: usize, lsn: Lsn, n: usize)
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).
Sourcepub fn insert_shift(&mut self, idx: usize, n: usize)
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.
Sourcepub fn remove_shift(&mut self, idx: usize)
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.
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
IN.computeLsnOverhead analogue: heap bytes of the rep itself.