implement scan_pubkeys for hot storage (#666)
This commit is contained in:
parent
8e0a55fe64
commit
c0be86d0e1
|
@ -2418,8 +2418,24 @@ impl AccountsDb {
|
||||||
AccountsDb::new_for_tests(Vec::new(), &ClusterType::Development)
|
AccountsDb::new_for_tests(Vec::new(), &ClusterType::Development)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_single_for_tests_with_provider(file_provider: AccountsFileProvider) -> Self {
|
||||||
|
AccountsDb::new_for_tests_with_provider(
|
||||||
|
Vec::new(),
|
||||||
|
&ClusterType::Development,
|
||||||
|
file_provider,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_for_tests(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
|
pub fn new_for_tests(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
|
||||||
AccountsDb::new_with_config(
|
Self::new_for_tests_with_provider(paths, cluster_type, AccountsFileProvider::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_for_tests_with_provider(
|
||||||
|
paths: Vec<PathBuf>,
|
||||||
|
cluster_type: &ClusterType,
|
||||||
|
accounts_file_provider: AccountsFileProvider,
|
||||||
|
) -> Self {
|
||||||
|
let mut db = AccountsDb::new_with_config(
|
||||||
paths,
|
paths,
|
||||||
cluster_type,
|
cluster_type,
|
||||||
AccountSecondaryIndexes::default(),
|
AccountSecondaryIndexes::default(),
|
||||||
|
@ -2427,7 +2443,9 @@ impl AccountsDb {
|
||||||
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
|
Some(ACCOUNTS_DB_CONFIG_FOR_TESTING),
|
||||||
None,
|
None,
|
||||||
Arc::default(),
|
Arc::default(),
|
||||||
)
|
);
|
||||||
|
db.accounts_file_provider = accounts_file_provider;
|
||||||
|
db
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_config(
|
pub fn new_with_config(
|
||||||
|
@ -15328,10 +15346,11 @@ pub mod tests {
|
||||||
/// - ensure Account1 has *not* been purged
|
/// - ensure Account1 has *not* been purged
|
||||||
/// - call `clean_accounts()` with `last_full_snapshot_slot` set to 3
|
/// - call `clean_accounts()` with `last_full_snapshot_slot` set to 3
|
||||||
/// - ensure Account1 *has* been purged
|
/// - ensure Account1 *has* been purged
|
||||||
#[test]
|
#[test_case(AccountsFileProvider::AppendVec)]
|
||||||
fn test_clean_accounts_with_last_full_snapshot_slot() {
|
#[test_case(AccountsFileProvider::HotStorage)]
|
||||||
|
fn test_clean_accounts_with_last_full_snapshot_slot(file_provider: AccountsFileProvider) {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let accounts_db = AccountsDb::new_single_for_tests();
|
let accounts_db = AccountsDb::new_single_for_tests_with_provider(file_provider);
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
let pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let owner = solana_sdk::pubkey::new_rand();
|
let owner = solana_sdk::pubkey::new_rand();
|
||||||
let space = 0;
|
let space = 0;
|
||||||
|
|
|
@ -197,7 +197,11 @@ impl AccountsFile {
|
||||||
pub(crate) fn scan_pubkeys(&self, callback: impl FnMut(&Pubkey)) {
|
pub(crate) fn scan_pubkeys(&self, callback: impl FnMut(&Pubkey)) {
|
||||||
match self {
|
match self {
|
||||||
Self::AppendVec(av) => av.scan_pubkeys(callback),
|
Self::AppendVec(av) => av.scan_pubkeys(callback),
|
||||||
Self::TieredStorage(_) => unimplemented!(),
|
Self::TieredStorage(ts) => {
|
||||||
|
if let Some(reader) = ts.reader() {
|
||||||
|
_ = reader.scan_pubkeys(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -554,6 +554,14 @@ impl HotStorageReader {
|
||||||
Ok(accounts)
|
Ok(accounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn scan_pubkeys(&self, mut callback: impl FnMut(&Pubkey)) -> TieredStorageResult<()> {
|
||||||
|
for i in 0..self.footer.account_entry_count {
|
||||||
|
let address = self.get_account_address(IndexOffset(i))?;
|
||||||
|
callback(address);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a slice suitable for use when archiving hot storages
|
/// Returns a slice suitable for use when archiving hot storages
|
||||||
pub fn data_for_archive(&self) -> &[u8] {
|
pub fn data_for_archive(&self) -> &[u8] {
|
||||||
self.mmap.as_ref()
|
self.mmap.as_ref()
|
||||||
|
|
|
@ -109,6 +109,12 @@ impl TieredStorageReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn scan_pubkeys(&self, callback: impl FnMut(&Pubkey)) -> TieredStorageResult<()> {
|
||||||
|
match self {
|
||||||
|
Self::Hot(hot) => hot.scan_pubkeys(callback),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a slice suitable for use when archiving tiered storages
|
/// Returns a slice suitable for use when archiving tiered storages
|
||||||
pub fn data_for_archive(&self) -> &[u8] {
|
pub fn data_for_archive(&self) -> &[u8] {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in New Issue