Skip to content

Commit

Permalink
fix test case
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi Z <chi@neon.tech>
  • Loading branch information
skyzh committed May 17, 2024
1 parent ea9d775 commit 849c05b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
55 changes: 34 additions & 21 deletions pageserver/src/tenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5732,23 +5732,11 @@ mod tests {
lsn: Lsn,
ctx: &RequestContext,
) -> anyhow::Result<(BTreeMap<Key, Result<Bytes, PageReconstructError>>, usize)> {
let begin_files_accessed = ctx
.vectored_access_delta_file_cnt
.load(std::sync::atomic::Ordering::SeqCst);
let mut reconstruct_state = ValuesReconstructState::default();
let res = tline
.get_vectored_impl(
keyspace.clone(),
lsn,
ValuesReconstructState::default(),
ctx,
)
.get_vectored_impl(keyspace.clone(), lsn, &mut reconstruct_state, ctx)
.await?;
Ok((
res,
ctx.vectored_access_delta_file_cnt
.load(std::sync::atomic::Ordering::SeqCst)
- begin_files_accessed,
))
Ok((res, reconstruct_state.get_delta_layers_visited() as usize))
}

#[allow(clippy::needless_range_loop)]
Expand Down Expand Up @@ -5827,6 +5815,8 @@ mod tests {
.create_test_timeline(TIMELINE_ID, Lsn(0x10), DEFAULT_PG_VERSION, &ctx)
.await?;

let cancel = CancellationToken::new();

let base_key = Key::from_hex("000000000033333333444444445500000000").unwrap();
let base_key_child = Key::from_hex("000000000033333333444444445500000001").unwrap();
let base_key_nonexist = Key::from_hex("000000000033333333444444445500000002").unwrap();
Expand All @@ -5841,7 +5831,7 @@ mod tests {
writer.finish_write(lsn);
drop(writer);

tline.freeze_and_flush().await?; // this will create an image layer
tline.freeze_and_flush().await?; // this will create a image layer
}

let child = tenant
Expand All @@ -5864,7 +5854,30 @@ mod tests {
writer.finish_write(lsn);
drop(writer);

child.freeze_and_flush().await?; // this will create an image layer
child.freeze_and_flush().await?; // this will create a delta

{
// update the partitioning to include the test key space, otherwise they
// will be dropped by image layer creation
let mut guard = child.partitioning.lock().await;
let ((partitioning, _), partition_lsn) = &mut *guard;
partitioning
.parts
.push(KeySpace::single(base_key..base_key_nonexist)); // exclude the nonexist key
*partition_lsn = lsn;
}

child
.compact(
&cancel,
{
let mut set = EnumSet::empty();
set.insert(CompactFlags::ForceImageLayerCreation);
set
},
&ctx,
)
.await?; // force create an image layer for the keys
}

async fn get_vectored_impl_wrapper(
Expand All @@ -5873,12 +5886,12 @@ mod tests {
lsn: Lsn,
ctx: &RequestContext,
) -> Result<Option<Bytes>, GetVectoredError> {
let reconstruct_state = ValuesReconstructState::new();
let mut reconstruct_state = ValuesReconstructState::new();
let mut res = tline
.get_vectored_impl(
KeySpace::single(key..key.next()),
lsn,
reconstruct_state,
&mut reconstruct_state,
ctx,
)
.await?;
Expand Down Expand Up @@ -6019,12 +6032,12 @@ mod tests {
lsn: Lsn,
ctx: &RequestContext,
) -> Result<Option<Bytes>, GetVectoredError> {
let reconstruct_state = ValuesReconstructState::new();
let mut reconstruct_state = ValuesReconstructState::new();
let mut res = tline
.get_vectored_impl(
KeySpace::single(key..key.next()),
lsn,
reconstruct_state,
&mut reconstruct_state,
ctx,
)
.await?;
Expand Down
5 changes: 4 additions & 1 deletion pageserver/src/tenant/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ pub struct Timeline {
pub initdb_lsn: Lsn,

/// When did we last calculate the partitioning?
partitioning: tokio::sync::Mutex<((KeyPartitioning, SparseKeyPartitioning), Lsn)>,
pub(crate) partitioning: tokio::sync::Mutex<((KeyPartitioning, SparseKeyPartitioning), Lsn)>,

/// Configuration: how often should the partitioning be recalculated.
repartition_threshold: u64,
Expand Down Expand Up @@ -4161,6 +4161,8 @@ impl Timeline {
}; // no partitioning for metadata keys for now
*partitioning_guard = ((dense_partitioning, sparse_partitioning), lsn);

info!("repartitioning!");

Ok((partitioning_guard.0.clone(), partitioning_guard.1))
}

Expand Down Expand Up @@ -4230,6 +4232,7 @@ impl Timeline {

let mut key_request_accum = KeySpaceAccum::new();
for range in &partition.ranges {
info!("partition: {}..{}", range.start, range.end);
let mut key = range.start;
while key < range.end {
// Decide whether to retain this key: usually we do, but sharded tenants may
Expand Down

0 comments on commit 849c05b

Please sign in to comment.