Skip to content

Commit

Permalink
blockstore: Move delete_file_in_range() to go through LedgerColumn (#…
Browse files Browse the repository at this point in the history
…3712)

Shift delete_file_in_range() from Database to LedgerColumn to keep key
serialization in LedgerColumn
  • Loading branch information
steviez authored Nov 20, 2024
1 parent 6918c40 commit 41e94dd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
72 changes: 36 additions & 36 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
pub struct PurgeStats {
delete_range: u64,
write_batch: u64,
delete_files_in_range: u64,
delete_file_in_range: u64,
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -50,8 +50,8 @@ impl Blockstore {
("delete_range_us", purge_stats.delete_range as i64, i64),
("write_batch_us", purge_stats.write_batch as i64, i64),
(
"delete_files_in_range_us",
purge_stats.delete_files_in_range as i64,
"delete_file_in_range_us",
purge_stats.delete_file_in_range as i64,
i64
)
);
Expand Down Expand Up @@ -241,7 +241,7 @@ impl Blockstore {

purge_stats.delete_range += delete_range_timer.as_us();
purge_stats.write_batch += write_timer.as_us();
purge_stats.delete_files_in_range += purge_files_in_range_timer.as_us();
purge_stats.delete_file_in_range += purge_files_in_range_timer.as_us();

Ok(columns_purged)
}
Expand Down Expand Up @@ -334,68 +334,68 @@ impl Blockstore {
}

fn purge_files_in_range(&self, from_slot: Slot, to_slot: Slot) -> bool {
self.db
.delete_file_in_range_cf::<cf::SlotMeta>(from_slot, to_slot)
self.meta_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::BankHash>(from_slot, to_slot)
.bank_hash_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::Root>(from_slot, to_slot)
.roots_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::ShredData>(from_slot, to_slot)
.data_shred_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::ShredCode>(from_slot, to_slot)
.code_shred_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::DeadSlots>(from_slot, to_slot)
.dead_slots_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::DuplicateSlots>(from_slot, to_slot)
.duplicate_slots_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::ErasureMeta>(from_slot, to_slot)
.erasure_meta_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::Orphans>(from_slot, to_slot)
.orphans_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::Index>(from_slot, to_slot)
.index_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::Rewards>(from_slot, to_slot)
.rewards_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::Blocktime>(from_slot, to_slot)
.blocktime_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::PerfSamples>(from_slot, to_slot)
.perf_samples_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::BlockHeight>(from_slot, to_slot)
.block_height_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::OptimisticSlots>(from_slot, to_slot)
.optimistic_slots_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
& self
.db
.delete_file_in_range_cf::<cf::MerkleRootMeta>(from_slot, to_slot)
.merkle_root_meta_cf
.delete_file_in_range(from_slot, to_slot)
.is_ok()
}

Expand Down
24 changes: 12 additions & 12 deletions ledger/src/blockstore_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,18 +1477,6 @@ impl Database {
Ok(fs_extra::dir::get_size(&self.path)?)
}

/// Delete files whose slot range is within \[`from`, `to`\].
pub fn delete_file_in_range_cf<C>(&self, from: Slot, to: Slot) -> Result<()>
where
C: Column + ColumnName,
{
self.backend.delete_file_in_range_cf(
self.cf_handle::<C>(),
&C::key(C::as_index(from)),
&C::key(C::as_index(to)),
)
}

pub fn is_primary_access(&self) -> bool {
self.backend.is_primary_access()
}
Expand Down Expand Up @@ -1670,6 +1658,18 @@ where
let to_key = C::key(C::as_index(to.saturating_add(1)));
batch.delete_range_cf(self.handle(), &from_key, &to_key)
}

/// Delete files whose slot range is within \[`from`, `to`\].
pub fn delete_file_in_range(&self, from: Slot, to: Slot) -> Result<()>
where
C: Column + ColumnName,
{
self.backend.delete_file_in_range_cf(
self.handle(),
&C::key(C::as_index(from)),
&C::key(C::as_index(to)),
)
}
}

impl<C> LedgerColumn<C>
Expand Down

0 comments on commit 41e94dd

Please sign in to comment.