Skip to content

Commit

Permalink
feat(pageserver): generate image layers for sparse keyspace
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi Z <chi@neon.tech>

collect read bytes

Signed-off-by: Alex Chi Z <chi@neon.tech>
  • Loading branch information
skyzh committed May 14, 2024
1 parent 30d15ad commit 03c5484
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 121 deletions.
6 changes: 6 additions & 0 deletions pageserver/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
//! [`RequestContext`] argument. Functions in the middle of the call chain
//! only need to pass it on.
use std::sync::atomic::AtomicUsize;

use crate::task_mgr::TaskKind;

pub(crate) mod optional_counter;
Expand All @@ -98,6 +100,8 @@ pub struct RequestContext {
access_stats_behavior: AccessStatsBehavior,
page_content_kind: PageContentKind,
pub micros_spent_throttled: optional_counter::MicroSecondsCounterU32,
/// Total number of kilobytes of layer files processed in this request.
pub vectored_access_delta_file_size_kb: AtomicUsize,
}

/// The kind of access to the page cache.
Expand Down Expand Up @@ -154,6 +158,7 @@ impl RequestContextBuilder {
access_stats_behavior: AccessStatsBehavior::Update,
page_content_kind: PageContentKind::Unknown,
micros_spent_throttled: Default::default(),
vectored_access_delta_file_size_kb: AtomicUsize::new(0),
},
}
}
Expand All @@ -168,6 +173,7 @@ impl RequestContextBuilder {
access_stats_behavior: original.access_stats_behavior,
page_content_kind: original.page_content_kind,
micros_spent_throttled: Default::default(),
vectored_access_delta_file_size_kb: AtomicUsize::new(0),
},
}
}
Expand Down
31 changes: 23 additions & 8 deletions pageserver/src/tenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5534,7 +5534,7 @@ mod tests {
.await?;

const NUM_KEYS: usize = 1000;
const STEP: usize = 100; // random update + scan base_key + idx * STEP
const STEP: usize = 10000; // random update + scan base_key + idx * STEP

let cancel = CancellationToken::new();

Expand Down Expand Up @@ -5567,7 +5567,7 @@ mod tests {

let keyspace = KeySpace::single(base_key..base_key.add((NUM_KEYS * STEP) as u32));

for _ in 0..10 {
for iter in 0..=10 {
// Read all the blocks
for (blknum, last_lsn) in updated.iter().enumerate() {
test_key.field6 = (blknum * STEP) as u32;
Expand Down Expand Up @@ -5618,12 +5618,27 @@ mod tests {
updated[blknum] = lsn;
}

// Perform a cycle of flush, compact, and GC
tline.freeze_and_flush().await?;
tline.compact(&cancel, EnumSet::empty(), &ctx).await?;
tenant
.gc_iteration(Some(tline.timeline_id), 0, Duration::ZERO, &cancel, &ctx)
.await?;
// Perform two cycles of flush, compact, and GC
for round in 0..2 {
tline.freeze_and_flush().await?;
tline
.compact(
&cancel,
if iter % 5 == 0 && round == 0 {
let mut flags = EnumSet::new();
flags.insert(CompactFlags::ForceImageLayerCreation);
flags.insert(CompactFlags::ForceRepartition);
flags
} else {
EnumSet::empty()
},
&ctx,
)
.await?;
tenant
.gc_iteration(Some(tline.timeline_id), 0, Duration::ZERO, &cancel, &ctx)
.await?;
}
}

Ok(())
Expand Down
13 changes: 12 additions & 1 deletion pageserver/src/tenant/storage_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub(crate) struct ValuesReconstructState {

keys_done: KeySpaceRandomAccum,
layers_visited: u32,
delta_file_kb_visited: usize,
}

impl ValuesReconstructState {
Expand All @@ -127,6 +128,7 @@ impl ValuesReconstructState {
keys: HashMap::new(),
keys_done: KeySpaceRandomAccum::new(),
layers_visited: 0,
delta_file_kb_visited: 0,
}
}

Expand All @@ -140,8 +142,17 @@ impl ValuesReconstructState {
}
}

pub(crate) fn on_layer_visited(&mut self) {
pub(crate) fn on_layer_visited(&mut self, layer: &ReadableLayer) {
self.layers_visited += 1;
if let ReadableLayer::PersistentLayer(layer) = layer {
if layer.layer_desc().is_delta() {
self.delta_file_kb_visited += layer.layer_desc().file_size as usize / 1024;
}
}
}

pub(crate) fn get_vectored_access_delta_file_size_kb(&self) -> usize {
self.delta_file_kb_visited
}

pub(crate) fn get_layers_visited(&self) -> u32 {
Expand Down
Loading

0 comments on commit 03c5484

Please sign in to comment.