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
impl NodeStoreHeader
Sourcepub const SIZE: u64 = 2048
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
Sourcepub fn read_from_storage<S: ReadableStorage>(
storage: &S,
) -> Result<Self, FileIoError>
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.
Sourcepub fn new(node_hash_algorithm: NodeHashAlgorithm) -> Self
pub fn new(node_hash_algorithm: NodeHashAlgorithm) -> Self
Creates a new header with default values and no root address.
Sourcepub fn validate(
&self,
expected_node_hash_algorithm: NodeHashAlgorithm,
) -> Result<(), Error>
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.
Sourcepub const fn free_lists(&self) -> &[Option<LinearAddress>; 23]
pub const fn free_lists(&self) -> &[Option<LinearAddress>; 23]
Get the free lists
Sourcepub const fn free_lists_mut(&mut self) -> &mut [Option<LinearAddress>; 23]
pub const fn free_lists_mut(&mut self) -> &mut [Option<LinearAddress>; 23]
Get mutable access to the free lists
Sourcepub const fn root_address(&self) -> Option<LinearAddress>
pub const fn root_address(&self) -> Option<LinearAddress>
Get the root address
Sourcepub fn set_root_location(
&mut self,
root_location: Option<(LinearAddress, TrieHash)>,
)
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.
Sourcepub const fn free_lists_offset() -> u64
pub const fn free_lists_offset() -> u64
Get the offset of the free_lists field for use with offset_of!
Sourcepub const fn cargo_version(&self) -> Option<&CargoVersion>
pub const fn cargo_version(&self) -> Option<&CargoVersion>
Get the cargo version of firewood-storage used to create this database,
if available.
Sourcepub const fn git_describe(&self) -> Option<&GitDescribe>
pub const fn git_describe(&self) -> Option<&GitDescribe>
Get the git describe string of firewood used to create this database,
Source§impl NodeStoreHeader
impl NodeStoreHeader
Sourcepub fn flush_to<S: WritableStorage>(
&self,
storage: &S,
) -> Result<(), FileIoError>
pub fn flush_to<S: WritableStorage>( &self, storage: &S, ) -> Result<(), FileIoError>
Trait Implementations§
Source§impl Clone for NodeStoreHeader
impl Clone for NodeStoreHeader
Source§fn clone(&self) -> NodeStoreHeader
fn clone(&self) -> NodeStoreHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NodeStoreHeader
impl Debug for NodeStoreHeader
Source§impl PartialEq for NodeStoreHeader
impl PartialEq for NodeStoreHeader
impl Copy for NodeStoreHeader
impl Eq for NodeStoreHeader
impl Pod for NodeStoreHeader
impl StructuralPartialEq for NodeStoreHeader
Auto Trait Implementations§
impl Freeze for NodeStoreHeader
impl RefUnwindSafe for NodeStoreHeader
impl Send for NodeStoreHeader
impl Sync for NodeStoreHeader
impl Unpin for NodeStoreHeader
impl UnsafeUnpin for NodeStoreHeader
impl UnwindSafe for NodeStoreHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.