solana_accounts_db/tiered_storage/
readable.rs1use {
2 crate::{
3 account_info::Offset,
4 account_storage::stored_account_info::{StoredAccountInfo, StoredAccountInfoWithoutData},
5 tiered_storage::{
6 file::TieredReadableFile,
7 footer::{AccountMetaFormat, TieredStorageFooter},
8 hot::HotStorageReader,
9 index::IndexOffset,
10 TieredStorageResult,
11 },
12 },
13 solana_account::AccountSharedData,
14 solana_pubkey::Pubkey,
15 std::path::Path,
16};
17
18#[derive(Debug)]
20pub enum TieredStorageReader {
21 Hot(HotStorageReader),
22}
23
24impl TieredStorageReader {
25 pub fn new_from_path(path: impl AsRef<Path>) -> TieredStorageResult<Self> {
27 let file = TieredReadableFile::new(&path)?;
28 let footer = TieredStorageFooter::new_from_footer_block(&file)?;
29 match footer.account_meta_format {
30 AccountMetaFormat::Hot => Ok(Self::Hot(HotStorageReader::new(file)?)),
31 }
32 }
33
34 pub fn len(&self) -> usize {
36 match self {
37 Self::Hot(hot) => hot.len(),
38 }
39 }
40
41 pub fn is_empty(&self) -> bool {
43 match self {
44 Self::Hot(hot) => hot.is_empty(),
45 }
46 }
47
48 pub fn capacity(&self) -> u64 {
49 match self {
50 Self::Hot(hot) => hot.capacity(),
51 }
52 }
53
54 pub fn footer(&self) -> &TieredStorageFooter {
56 match self {
57 Self::Hot(hot) => hot.footer(),
58 }
59 }
60
61 pub fn num_accounts(&self) -> usize {
63 match self {
64 Self::Hot(hot) => hot.num_accounts(),
65 }
66 }
67
68 pub fn get_account_shared_data(
70 &self,
71 index_offset: IndexOffset,
72 ) -> TieredStorageResult<Option<AccountSharedData>> {
73 match self {
74 Self::Hot(hot) => hot.get_account_shared_data(index_offset),
75 }
76 }
77
78 pub fn get_stored_account_without_data_callback<Ret>(
86 &self,
87 index_offset: IndexOffset,
88 callback: impl for<'local> FnMut(StoredAccountInfoWithoutData<'local>) -> Ret,
89 ) -> TieredStorageResult<Option<Ret>> {
90 match self {
91 Self::Hot(hot) => hot.get_stored_account_without_data_callback(index_offset, callback),
92 }
93 }
94
95 pub fn get_stored_account_callback<Ret>(
103 &self,
104 index_offset: IndexOffset,
105 callback: impl for<'local> FnMut(StoredAccountInfo<'local>) -> Ret,
106 ) -> TieredStorageResult<Option<Ret>> {
107 match self {
108 Self::Hot(hot) => hot.get_stored_account_callback(index_offset, callback),
109 }
110 }
111
112 pub fn scan_pubkeys(&self, callback: impl FnMut(&Pubkey)) -> TieredStorageResult<()> {
114 match self {
115 Self::Hot(hot) => hot.scan_pubkeys(callback),
116 }
117 }
118
119 pub fn scan_accounts_without_data(
127 &self,
128 callback: impl for<'local> FnMut(Offset, StoredAccountInfoWithoutData<'local>),
129 ) -> TieredStorageResult<()> {
130 match self {
131 Self::Hot(hot) => hot.scan_accounts_without_data(callback),
132 }
133 }
134
135 pub fn scan_accounts(
144 &self,
145 callback: impl for<'local> FnMut(Offset, StoredAccountInfo<'local>),
146 ) -> TieredStorageResult<()> {
147 match self {
148 Self::Hot(hot) => hot.scan_accounts(callback),
149 }
150 }
151
152 pub(crate) fn calculate_stored_size(&self, data_len: usize) -> usize {
155 match self {
156 Self::Hot(hot) => hot.calculate_stored_size(data_len),
157 }
158 }
159
160 pub(crate) fn get_account_data_lens(
162 &self,
163 sorted_offsets: &[usize],
164 ) -> TieredStorageResult<Vec<usize>> {
165 match self {
166 Self::Hot(hot) => hot.get_account_data_lens(sorted_offsets),
167 }
168 }
169
170 pub fn data_for_archive(&self) -> &[u8] {
172 match self {
173 Self::Hot(hot) => hot.data_for_archive(),
174 }
175 }
176}