Skip to content

Commit

Permalink
Add code comments for lowest_cleanup_slot functions (solana-labs#27497)
Browse files Browse the repository at this point in the history
#### Summary of Changes
Add code comments for lowest_cleanup_slot related functions to improve
the code readability for the consistency between blockstore purge logic
and the read side.
  • Loading branch information
yhchiang-sol authored Sep 6, 2022
1 parent ecbd5bb commit c62aef6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,11 @@ impl Blockstore {
self.transaction_memos_cf.put(*signature, &memos)
}

/// Acquires the `lowest_cleanup_slot` lock and returns a tuple of the held lock
/// and lowest available slot.
///
/// The function will return BlockstoreError::SlotCleanedUp if the input
/// `slot` has already been cleaned-up.
fn check_lowest_cleanup_slot(&self, slot: Slot) -> Result<std::sync::RwLockReadGuard<Slot>> {
// lowest_cleanup_slot is the last slot that was not cleaned up by LedgerCleanupService
let lowest_cleanup_slot = self.lowest_cleanup_slot.read().unwrap();
Expand All @@ -2199,10 +2204,13 @@ impl Blockstore {
Ok(lowest_cleanup_slot)
}

/// Acquires the lock of `lowest_cleanup_slot` and returns the tuple of
/// the held lock and the lowest available slot.
///
/// This function ensures a consistent result by using lowest_cleanup_slot
/// as the lower bound for reading columns that do not employ strong read
/// consistency with slot-based delete_range.
fn ensure_lowest_cleanup_slot(&self) -> (std::sync::RwLockReadGuard<Slot>, Slot) {
// Ensures consistent result by using lowest_cleanup_slot as the lower bound
// for reading columns that do not employ strong read consistency with slot-based
// delete_range
let lowest_cleanup_slot = self.lowest_cleanup_slot.read().unwrap();
let lowest_available_slot = (*lowest_cleanup_slot)
.checked_add(1)
Expand Down

0 comments on commit c62aef6

Please sign in to comment.