diff --git a/accounts-db/src/tiered_storage.rs b/accounts-db/src/tiered_storage.rs index a0d8eea4010b94..cbca5c93d0041e 100644 --- a/accounts-db/src/tiered_storage.rs +++ b/accounts-db/src/tiered_storage.rs @@ -38,6 +38,8 @@ use { pub type TieredStorageResult = Result; +const MAX_TIERED_STORAGE_FILE_SIZE: u64 = 16 * 1024 * 1024 * 1024; // 16 GiB; + /// The struct that defines the formats of all building blocks of a /// TieredStorage. #[derive(Clone, Debug, PartialEq)] @@ -163,6 +165,11 @@ impl TieredStorage { pub fn is_empty(&self) -> bool { self.len() == 0 } + + pub fn capacity(&self) -> u64 { + self.reader() + .map_or(MAX_TIERED_STORAGE_FILE_SIZE, |reader| reader.capacity()) + } } #[cfg(test)] diff --git a/accounts-db/src/tiered_storage/hot.rs b/accounts-db/src/tiered_storage/hot.rs index 414d74b2eb81b7..260548897f66e2 100644 --- a/accounts-db/src/tiered_storage/hot.rs +++ b/accounts-db/src/tiered_storage/hot.rs @@ -369,6 +369,10 @@ impl HotStorageReader { self.len() == 0 } + pub fn capacity(&self) -> u64 { + self.len() as u64 + } + /// Returns the footer of the underlying tiered-storage accounts file. pub fn footer(&self) -> &TieredStorageFooter { &self.footer diff --git a/accounts-db/src/tiered_storage/readable.rs b/accounts-db/src/tiered_storage/readable.rs index 008e805689df57..0191dad4903578 100644 --- a/accounts-db/src/tiered_storage/readable.rs +++ b/accounts-db/src/tiered_storage/readable.rs @@ -44,6 +44,12 @@ impl TieredStorageReader { } } + pub fn capacity(&self) -> u64 { + match self { + Self::Hot(hot) => hot.capacity(), + } + } + /// Returns the footer of the associated HotAccountsFile. pub fn footer(&self) -> &TieredStorageFooter { match self {