2023-07-25 10:51:56 -07:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2023-05-30 14:14:29 -07:00
|
|
|
pub mod byte_block;
|
2023-05-23 15:06:55 -07:00
|
|
|
pub mod error;
|
2023-05-07 13:18:10 -07:00
|
|
|
pub mod file;
|
|
|
|
pub mod footer;
|
2023-06-23 10:25:54 -07:00
|
|
|
pub mod hot;
|
2023-07-15 16:23:08 -07:00
|
|
|
pub mod index;
|
2023-06-01 14:48:27 -07:00
|
|
|
pub mod meta;
|
2023-05-07 13:18:10 -07:00
|
|
|
pub mod mmap_utils;
|
2023-07-06 09:08:09 -07:00
|
|
|
pub mod readable;
|
2023-05-23 15:06:55 -07:00
|
|
|
|
2023-07-25 10:51:56 -07:00
|
|
|
use {
|
|
|
|
error::TieredStorageError,
|
|
|
|
footer::{AccountBlockFormat, AccountMetaFormat, OwnersBlockFormat},
|
|
|
|
index::AccountIndexFormat,
|
|
|
|
std::path::{Path, PathBuf},
|
|
|
|
};
|
2023-05-23 15:06:55 -07:00
|
|
|
|
|
|
|
pub type TieredStorageResult<T> = Result<T, TieredStorageError>;
|
2023-07-25 10:51:56 -07:00
|
|
|
|
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
}
|