TieredStorage struct (1/N) -- new_writable() (#32538)

#### Summary of Changes
This PR initiates the implementation of the main struct for the
tiered accounts storage --- TieredStorage.  Specifically,
it defines the TieredStorage struct, TieredStorageFormat,
and skeleton implementation of new_writable().

#### Test Plan
Unit tests are included in this PR.
This commit is contained in:
Yueh-Hsuan Chiang 2023-07-26 01:51:56 +08:00 committed by GitHub
parent cd39a6afd3
commit 28d7e59cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 1 deletions

View File

@ -1,3 +1,5 @@
#![allow(dead_code)]
pub mod byte_block;
pub mod error;
pub mod file;
@ -8,6 +10,60 @@ pub mod meta;
pub mod mmap_utils;
pub mod readable;
use crate::tiered_storage::error::TieredStorageError;
use {
error::TieredStorageError,
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
index::AccountIndexFormat,
std::path::{Path, PathBuf},
};
pub type TieredStorageResult<T> = Result<T, TieredStorageError>;
/// The struct that defines the formats of all building blocks of a
/// TieredStorage.
#[derive(Clone, Debug)]
pub struct TieredStorageFormat {
pub meta_entry_size: usize,
pub account_meta_format: AccountMetaFormat,
pub owners_block_format: OwnersBlockFormat,
pub account_index_format: AccountIndexFormat,
pub account_block_format: AccountBlockFormat,
}
#[derive(Debug)]
pub struct TieredStorage {
format: Option<TieredStorageFormat>,
path: PathBuf,
}
impl TieredStorage {
/// Creates a new writable instance of TieredStorage based on the
/// specified path and TieredStorageFormat.
///
/// Note that the actual file will not be created until append_accounts
/// is called.
pub fn new_writable(path: impl Into<PathBuf>, format: TieredStorageFormat) -> Self {
Self {
format: Some(format),
path: path.into(),
}
}
/// Returns the path to this TieredStorage.
pub fn path(&self) -> &Path {
self.path.as_path()
}
}
#[cfg(test)]
mod tests {
use {super::*, hot::HOT_FORMAT};
#[test]
fn test_new_writable() {
let path = PathBuf::default();
let ts = TieredStorage::new_writable(&path, HOT_FORMAT.clone());
assert_eq!(ts.path(), path);
}
}

View File

@ -6,7 +6,10 @@ use {
account_storage::meta::StoredMetaWriteVersion,
tiered_storage::{
byte_block,
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
index::AccountIndexFormat,
meta::{AccountMetaFlags, AccountMetaOptionalFields, TieredAccountMeta},
TieredStorageFormat,
},
},
modular_bitfield::prelude::*,
@ -14,6 +17,14 @@ use {
std::option::Option,
};
pub const HOT_FORMAT: TieredStorageFormat = TieredStorageFormat {
meta_entry_size: std::mem::size_of::<HotAccountMeta>(),
account_meta_format: AccountMetaFormat::Hot,
owners_block_format: OwnersBlockFormat::LocalIndex,
account_index_format: AccountIndexFormat::AddressAndOffset,
account_block_format: AccountBlockFormat::AlignedRaw,
};
/// The maximum number of padding bytes used in a hot account entry.
const MAX_HOT_PADDING: u8 = 7;