Skip to content

Commit

Permalink
test(pageserver): add test keyspace into collect_keyspace (#8016)
Browse files Browse the repository at this point in the history
Some test cases add random keys into the timeline, but it is not part of
the `collect_keyspace`, this will cause compaction remove the keys.

The pull request adds a field to supply extra keyspaces during unit
tests.

---------

Signed-off-by: Alex Chi Z <chi@neon.tech>
  • Loading branch information
skyzh committed Jun 12, 2024
1 parent 9dda13e commit 836d1f4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pageserver/src/pgdatadir_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,14 @@ impl Timeline {
result.add_key(AUX_FILES_KEY);
}

#[cfg(test)]
{
let guard = self.extra_test_dense_keyspace.load();
for kr in &guard.ranges {
result.add_range(kr.clone());
}
}

Ok((
result.to_keyspace(),
/* AUX sparse key space */
Expand Down
8 changes: 6 additions & 2 deletions pageserver/src/tenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5264,6 +5264,9 @@ mod tests {
let cancel = CancellationToken::new();

let mut test_key = Key::from_hex("010000000033333333444444445500000000").unwrap();
let mut test_key_end = test_key;
test_key_end.field6 = NUM_KEYS as u32;
tline.add_extra_test_dense_keyspace(KeySpace::single(test_key..test_key_end));

let mut keyspace = KeySpaceAccum::new();

Expand Down Expand Up @@ -6223,8 +6226,8 @@ mod tests {

let cancel = CancellationToken::new();

let mut base_key = Key::from_hex("000000000033333333444444445500000000").unwrap();
base_key.field1 = AUX_KEY_PREFIX;
let base_key = Key::from_hex("620000000033333333444444445500000000").unwrap();
assert_eq!(base_key.field1, AUX_KEY_PREFIX); // in case someone accidentally changed the prefix...
let mut test_key = base_key;
let mut lsn = Lsn(0x10);

Expand Down Expand Up @@ -6329,6 +6332,7 @@ mod tests {
Lsn(0x20), // it's fine to not advance LSN to 0x30 while using 0x30 to get below because `get_vectored_impl` does not wait for LSN
)
.await?;
tline.add_extra_test_dense_keyspace(KeySpace::single(base_key..(base_key_nonexist.next())));

let child = tenant
.branch_timeline_test_with_layers(
Expand Down
18 changes: 18 additions & 0 deletions pageserver/src/tenant/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ pub struct Timeline {

/// Indicate whether aux file v2 storage is enabled.
pub(crate) last_aux_file_policy: AtomicAuxFilePolicy,

/// Some test cases directly place keys into the timeline without actually modifying the directory
/// keys (i.e., DB_DIR). The test cases creating such keys will put the keyspaces here, so that
/// these keys won't get garbage-collected during compaction/GC. This field only modifies the dense
/// keyspace return value of `collect_keyspace`. For sparse keyspaces, use AUX keys for testing, and
/// in the future, add `extra_test_sparse_keyspace` if necessary.
#[cfg(test)]
pub(crate) extra_test_dense_keyspace: ArcSwap<KeySpace>,
}

pub struct WalReceiverInfo {
Expand Down Expand Up @@ -2344,6 +2352,9 @@ impl Timeline {
aux_file_size_estimator: AuxFileSizeEstimator::new(aux_file_metrics),

last_aux_file_policy: AtomicAuxFilePolicy::new(aux_file_policy),

#[cfg(test)]
extra_test_dense_keyspace: ArcSwap::new(Arc::new(KeySpace::default())),
};
result.repartition_threshold =
result.get_checkpoint_distance() / REPARTITION_FREQ_IN_CHECKPOINT_DISTANCE;
Expand Down Expand Up @@ -5562,6 +5573,13 @@ impl Timeline {
}
Ok(layers)
}

#[cfg(test)]
pub(crate) fn add_extra_test_dense_keyspace(&self, ks: KeySpace) {
let mut keyspace = self.extra_test_dense_keyspace.load().as_ref().clone();
keyspace.merge(&ks);
self.extra_test_dense_keyspace.store(Arc::new(keyspace));
}
}

type TraversalPathItem = (ValueReconstructResult, Lsn, TraversalId);
Expand Down

1 comment on commit 836d1f4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3298 tests run: 3144 passed, 3 failed, 151 skipped (full report)


Failures on Postgres 14

  • test_heavy_write_workload[neon_on-github-actions-selfhosted-10-5-5]: release
  • test_download_churn[github-actions-selfhosted-100-std-fs-30]: release
  • test_pageserver_max_throughput_getpage_at_latest_lsn[github-actions-selfhosted-10-6-30]: release
# Run all failed tests locally:
scripts/pytest -vv -n $(nproc) -k "test_heavy_write_workload[neon_on-release-pg14-github-actions-selfhosted-10-5-5] or test_download_churn[release-pg14-github-actions-selfhosted-100-std-fs-30] or test_pageserver_max_throughput_getpage_at_latest_lsn[release-pg14-github-actions-selfhosted-10-6-30]"

Code coverage* (full report)

  • functions: 31.6% (6633 of 20990 functions)
  • lines: 48.6% (51517 of 106058 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
836d1f4 at 2024-06-12T19:03:32.019Z :recycle:

Please sign in to comment.