Skip to main content

NodeStoreHeader

Struct NodeStoreHeader 

Source
pub struct NodeStoreHeader { /* private fields */ }
Expand description

Persisted metadata for a NodeStore. The NodeStoreHeader is at the start of the ReadableStorage.

root_hash, cargo_version and git_describe were added between v0.0.18 and v0.1.0. If version is not equal to firewood-v1, this field may contain “uninitialized” data and must be ignored. Uninitialized data in this context means whatever the filesystem returns when reading from the sparse region of the file where there previously was no data written. This does not mean uninitialized memory with respect to memory safety, but does mean that the data may be garbage.

Implementations§

Source§

impl NodeStoreHeader

Source

pub const SIZE: u64 = 2048

The first SIZE bytes of the ReadableStorage are reserved for the NodeStoreHeader. We also want it aligned to a disk block

Source

pub fn read_from_storage<S: ReadableStorage>( storage: &S, ) -> Result<Self, FileIoError>

Reads the NodeStoreHeader from the start of the given storage.

§Errors

Returns an error if unable to read the header from storage or if there’s a node hash algorithm mismatch.

Source

pub fn new(node_hash_algorithm: NodeHashAlgorithm) -> Self

Creates a new header with default values and no root address.

Source

pub fn validate( &self, expected_node_hash_algorithm: NodeHashAlgorithm, ) -> Result<(), Error>

Validates the header fields to ensure correctness and compatibility with the current build of firewood.

Checks performed:

  • Magic number / version string is valid. The first 16 bytes must match an expected magic number.
  • Endianness test matches expected value (1). If not, reading from the database will produce incorrect results from mis-interpreted byte order.
  • Area size hash matches the expected hash for the current build. This prevents corrupting the allocation structures by changing area sizes.
  • Node hash algorithm flag matches the expected algorithm for this storage.
§Errors

Returns an error if validation fails.

Source

pub const fn size(&self) -> u64

Get the size of the nodestore

Source

pub const fn set_size(&mut self, size: u64)

Set the size of the nodestore

Source

pub const fn free_lists(&self) -> &[Option<LinearAddress>; 23]

Get the free lists

Source

pub const fn free_lists_mut(&mut self) -> &mut [Option<LinearAddress>; 23]

Get mutable access to the free lists

Source

pub const fn root_address(&self) -> Option<LinearAddress>

Get the root address

Source

pub fn set_root_location( &mut self, root_location: Option<(LinearAddress, TrieHash)>, )

Update the root location, both address and hash.

Note that this does not overwrite the version field, so it is possible the root hash will be ignored when set.

Source

pub const fn free_lists_offset() -> u64

Get the offset of the free_lists field for use with offset_of!

Source

pub const fn cargo_version(&self) -> Option<&CargoVersion>

Get the cargo version of firewood-storage used to create this database, if available.

Source

pub const fn git_describe(&self) -> Option<&GitDescribe>

Get the git describe string of firewood used to create this database,

Source§

impl NodeStoreHeader

Source

pub fn flush_to<S: WritableStorage>( &self, storage: &S, ) -> Result<(), FileIoError>

Persist this header to storage.

§Errors

Returns a FileIoError if the header cannot be written.

Trait Implementations§

Source§

impl Clone for NodeStoreHeader

Source§

fn clone(&self) -> NodeStoreHeader

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeStoreHeader

Source§

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

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

impl PartialEq for NodeStoreHeader

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Zeroable for NodeStoreHeader

Source§

fn zeroed() -> Self

Source§

impl Copy for NodeStoreHeader

Source§

impl Eq for NodeStoreHeader

Source§

impl Pod for NodeStoreHeader

Source§

impl StructuralPartialEq for NodeStoreHeader

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ValueSize for T

Source§

fn value_size(&self) -> usize

The size of this value in bytes, excluding allocated data. Read more
Source§

fn value_size_sum_iter<'item>(iterator: impl Iterator<Item = &'item T>) -> usize
where T: 'item,

The total sum of the sizes of all values in the given iterator, in bytes. This is default-implemented by computing ValueSize::value_size on every element and summing them. For Sized types, a more potentially efficient implementation using Iterator::count is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more
Source§

fn value_size_sum_exact_size_iter<'item>( iterator: impl ExactSizeIterator<Item = &'item T>, ) -> usize
where T: 'item,

The total sum of the sizes of all values in the given exact-size-iterator, in bytes. This is default-implemented by using ValueSize::value_size_sum_iter. For Sized types, a usually more efficient implementation using ExactSizeIterator::len is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,