Skip to content

Commit

Permalink
[TieredStorage] Add capacity() API and limit file size to 16GB (#401)
Browse files Browse the repository at this point in the history
#### Problem
The TieredStorage has not yet implemented the AccountsFile::capacity()
API.

#### Summary of Changes
Implement capacity() API for TieredStorage and limit file size to 16GB,
same as the append-vec file.
  • Loading branch information
yhchiang-sol authored Mar 24, 2024
1 parent b6d2237 commit 6024712
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions accounts-db/src/tiered_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ use {

pub type TieredStorageResult<T> = Result<T, TieredStorageError>;

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)]
Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions accounts-db/src/tiered_storage/readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6024712

Please sign in to comment.