Skip to content

Commit

Permalink
Moves CacheHashData test-only methods into tests module (solana-labs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Sep 6, 2023
1 parent 377b600 commit f4816dc
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions accounts-db/src/cache_hash_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,6 @@ impl CacheHashData {
}
}

#[cfg(test)]
/// load from 'file_name' into 'accumulator'
pub(crate) fn load(
&self,
file_name: impl AsRef<Path>,
accumulator: &mut SavedType,
start_bin_index: usize,
bin_calculator: &PubkeyBinCalculator24,
) -> Result<(), std::io::Error> {
let mut m = Measure::start("overall");
let cache_file = self.load_map(file_name)?;
cache_file.load_all(accumulator, start_bin_index, bin_calculator);
m.stop();
self.stats.load_us.fetch_add(m.as_us(), Ordering::Relaxed);
Ok(())
}

/// open a cache hash file, but don't map it.
/// This allows callers to know a file exists, but preserves the # mmapped files.
pub(crate) fn get_file_reference_to_map_later(
Expand Down Expand Up @@ -298,13 +281,6 @@ impl CacheHashData {
})
}

#[cfg(test)]
/// map 'file_name' into memory
fn load_map(&self, file_name: impl AsRef<Path>) -> Result<CacheHashDataFile, std::io::Error> {
let reference = self.get_file_reference_to_map_later(file_name)?;
reference.map()
}

pub(crate) fn pre_existing_cache_file_will_be_used(&self, file_name: impl AsRef<Path>) {
self.pre_existing_cache_files
.lock()
Expand Down Expand Up @@ -382,9 +358,36 @@ impl CacheHashData {
}

#[cfg(test)]
pub mod tests {
mod tests {
use {super::*, rand::Rng};

impl CacheHashData {
/// load from 'file_name' into 'accumulator'
fn load(
&self,
file_name: impl AsRef<Path>,
accumulator: &mut SavedType,
start_bin_index: usize,
bin_calculator: &PubkeyBinCalculator24,
) -> Result<(), std::io::Error> {
let mut m = Measure::start("overall");
let cache_file = self.load_map(file_name)?;
cache_file.load_all(accumulator, start_bin_index, bin_calculator);
m.stop();
self.stats.load_us.fetch_add(m.as_us(), Ordering::Relaxed);
Ok(())
}

/// map 'file_name' into memory
fn load_map(
&self,
file_name: impl AsRef<Path>,
) -> Result<CacheHashDataFile, std::io::Error> {
let reference = self.get_file_reference_to_map_later(file_name)?;
reference.map()
}
}

#[test]
fn test_read_write() {
// generate sample data
Expand Down

0 comments on commit f4816dc

Please sign in to comment.