Skip to main content

Superblock

Struct Superblock 

Source
pub struct Superblock {
Show 19 fields pub format_version: u32, pub min_reader_version: u32, pub page_size: u32, pub shard_count: u32, pub seq: u64, pub file_size: u64, pub file_uuid: [u8; 16], pub created_unix_ms: u64, pub checkpoint_unix_ms: u64, pub db_count: u32, pub flags: u32, pub replid_hi: u64, pub replid_lo: u64, pub replid_ext: u32, pub shard_table_off: u32, pub shard_table_len: u16, pub catalog_addr: u64, pub free_list_addr: u64, pub archival_root: u64,
}
Expand description

The header half of a superblock slot, decoded.

The shard table and the checkpoint entries are not in here on purpose. They are variable length, they live further into the same 16 KiB, and a caller that only wants to know the page size should not pay to decode 16384 slot assignments to find out.

Fields§

§format_version: u32

The format this slot was written by.

§min_reader_version: u32

The lowest reader version that may read it.

§page_size: u32

Segment size, fixed at creation.

§shard_count: u32

Shard count, fixed at creation.

§seq: u64

Monotonic. The higher of the two valid slots wins.

§file_size: u64

Segments times page_size plus DATA_START.

§file_uuid: [u8; 16]

Identifies this database across copies of the file.

§created_unix_ms: u64

When the file was created.

§checkpoint_unix_ms: u64

When this checkpoint was taken.

§db_count: u32

Logical databases, default 16.

§flags: u32§replid_hi: u64

The replication id, high 64 bits of the 40 hex characters.

§replid_lo: u64

The replication id, next 64 bits.

§replid_ext: u32

The replication id, last 32 bits.

§shard_table_off: u32

Offset within the slot of the run length encoded shard table.

§shard_table_len: u16

Length in bytes of that encoding.

§catalog_addr: u64

Address of the collection catalogue, or 0 if there are no collections.

§free_list_addr: u64

Address of the free segment list.

§archival_root: u64

Address of the archival root, or 0.

Implementations§

Source§

impl Superblock

Source

pub fn encode(&self, slot: &mut [u8])

Writes the header fields into the first 160 bytes of slot.

Leaves the checksum alone, because the bytes it covers have not all been written yet. Call seal once the table and the entries are in.

§Panics

If slot is not exactly SUPERBLOCK_LEN bytes. That is a programmer error rather than a corrupt file, so it is not an Err.

Source

pub fn decode(slot: &[u8]) -> Result<Superblock>

Reads the header fields, checking everything that makes the file ours.

In order: the length, the magic, the checksum, then the version. The checksum comes before the version check so that a corrupt slot is reported as corrupt rather than as a version from the future, which is what happens if a flipped bit lands in the version field.

Source

pub const fn checkpoint_off(&self) -> usize

Where the checkpoint entries begin, which is right after the table.

Source

pub fn checkpoints_fit(&self) -> bool

Whether every checkpoint entry fits inside the slot.

A file whose shard count and table length do not leave room for the entries is corrupt in a way that would otherwise show up as a checkpoint full of zeroes, which reads as a valid empty database.

Trait Implementations§

Source§

impl Clone for Superblock

Source§

fn clone(&self) -> Superblock

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 Debug for Superblock

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Superblock

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Superblock

Source§

impl PartialEq for Superblock

Source§

fn eq(&self, other: &Superblock) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Superblock

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> 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.