feat: add blocks_per_file field to StaticFileProvider (#11043)

This commit is contained in:
joshieDo
2024-09-19 18:36:23 +01:00
committed by GitHub
parent 9f23443029
commit 69c8ddb330
8 changed files with 63 additions and 41 deletions

View File

@ -16,7 +16,7 @@ pub use compression::Compression;
pub use segment::{SegmentConfig, SegmentHeader, SegmentRangeInclusive, StaticFileSegment};
/// Default static file block count.
pub const BLOCKS_PER_STATIC_FILE: u64 = 500_000;
pub const DEFAULT_BLOCKS_PER_STATIC_FILE: u64 = 500_000;
/// Highest static file block numbers, per data segment.
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq)]
@ -64,7 +64,10 @@ impl HighestStaticFiles {
/// Each static file has a fixed number of blocks. This gives out the range where the requested
/// block is positioned. Used for segment filename.
pub const fn find_fixed_range(block: BlockNumber) -> SegmentRangeInclusive {
let start = (block / BLOCKS_PER_STATIC_FILE) * BLOCKS_PER_STATIC_FILE;
SegmentRangeInclusive::new(start, start + BLOCKS_PER_STATIC_FILE - 1)
pub const fn find_fixed_range(
block: BlockNumber,
blocks_per_static_file: u64,
) -> SegmentRangeInclusive {
let start = (block / blocks_per_static_file) * blocks_per_static_file;
SegmentRangeInclusive::new(start, start + blocks_per_static_file - 1)
}