Skip to content

Conversation

@andrwng
Copy link
Contributor

@andrwng andrwng commented Feb 3, 2026

Saw an instance where we failed to allocate ~800KB because one of the containers in s3_imposters grew to be large. It isn't unreasonable to expect a test to bombard s3_imposter with requests, especially when trying to stress certain subsystems.

This replaces the containers in s3_imposter with chunked_vector and absl::btree_multimap, which are more aligned with best practices of our codebase.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v25.3.x
  • v25.2.x
  • v25.1.x

Release Notes

  • None

Copilot AI review requested due to automatic review settings February 3, 2026 23:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces standard library containers in s3_imposter with more memory-efficient alternatives to prevent allocation failures during high-volume testing. The motivation stems from a test failure where ~800KB could not be allocated due to container growth in s3_imposter.

Changes:

  • Replaced std::vector with chunked_vector for various collections in s3_imposter and related test utilities
  • Replaced std::map/std::multimap with absl::btree_map/absl::btree_multimap for ordered collections
  • Updated function signatures and call sites throughout test code to use the new container types

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/v/cloud_io/tests/s3_imposter.h Updated s3_imposter interface to use chunked_vector and absl::btree_multimap
src/v/cloud_io/tests/s3_imposter.cc Implemented container type changes in s3_imposter, replacing std containers
src/v/cloud_io/tests/BUILD Added dependencies for chunked_vector and absl::btree containers
src/v/cloud_storage/tests/util.h Changed return types of make_imposter_expectations to chunked_vector
src/v/cloud_storage/tests/util.cc Updated implementations to use chunked_vector and std::move semantics
src/v/cloud_storage/tests/BUILD Added chunked_vector dependency
src/v/cloud_storage/tests/remote_test.cc Changed local variables to const references to avoid copies
src/v/cloud_storage/tests/remote_partition_test.cc Updated expectation handling to use chunked_vector with std::move
src/v/cloud_storage/tests/async_manifest_view_test.cc Changed _expectations field to chunked_vector and added std::move
src/v/cloud_storage/tests/topic_mount_handler_test.cc Refactored expectation construction to use chunked_vector
src/v/datalake/coordinator/tests/iceberg_snapshot_remover_test.cc Updated remove_expectations call to use chunked_vector::single
src/v/iceberg/tests/table_io_test.cc Updated add_expectations call to use chunked_vector::single
src/v/lsm/io/tests/persistence_test.cc Updated remove_expectations call to use chunked_vector::single

Comment on lines +593 to +599
// Build new vector excluding manifest expectation
chunked_vector<cloud_storage_fixture::expectation> expectations;
for (auto& e : all_expectations) {
if (e.url != manifest_url) {
expectations.push_back(std::move(e));
}
}
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The loop constructs a new chunked_vector by copying/moving elements from all_expectations except the manifest. This is less efficient than removing the manifest element directly. Consider using std::remove_if or erase-remove idiom on all_expectations instead of creating a new vector.

Copilot uses AI. Check for mistakes.
s3_imposter_fixture::req_pred_t predicate) const {
std::vector<http_test_utils::request_info> matching_requests;
matching_requests.reserve(_requests.size());
chunked_vector<http_test_utils::request_info> matching_requests;
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The reserve() call was removed when converting from std::vector to chunked_vector. While chunked_vector has different memory characteristics, pre-allocating capacity when the upper bound is known (_requests.size()) could still improve performance by reducing reallocations.

Suggested change
chunked_vector<http_test_utils::request_info> matching_requests;
chunked_vector<http_test_utils::request_info> matching_requests;
matching_requests.reserve(_requests.size());

Copilot uses AI. Check for mistakes.
Saw an instance where we failed to allocate ~800KB because one of the
containers in s3_imposters grew to be large. It isn't unreasonable to
expect a test to bombard s3_imposter with requests, especially when
trying to stress certain subsystems.

This replaces the containers in s3_imposter with chunked_vector and
absl::btree_multimap, which are more aligned with best practices of our
codebase.
Saw one instance of this test using ~1GB which contributed to it
crashing.
@andrwng andrwng force-pushed the s3-imposter-chunked branch from 2b04ff8 to faf9722 Compare February 4, 2026 00:19
@vbotbuildovich
Copy link
Collaborator

CI test results

test results on build#80060
test_class test_method test_arguments test_kind job_url test_status passed reason test_history
RpkDebugBundleTest test_debug_bundle null integration https://buildkite.com/redpanda/redpanda/builds/80060#019c2614-c527-4f7f-80bc-5cb2fdb309f2 FLAKY 10/11 Test PASSES after retries.No significant increase in flaky rate(baseline=0.0027, p0=1.0000, reject_threshold=0.0100. adj_baseline=0.1000, p1=0.3487, trust_threshold=0.5000) https://redpanda.metabaseapp.com/dashboard/87-tests?tab=142-dt-individual-test-history&test_class=RpkDebugBundleTest&test_method=test_debug_bundle

}

void listen() { set_expectations_and_listen(_expectations); }
void listen() { set_expectations_and_listen(std::move(_expectations)); }
Copy link
Member

Choose a reason for hiding this comment

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

this ok? just happens once and then no more uses of expectations member var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, this is only used to set up expectations at the beginning of certain tests

@andrwng andrwng merged commit ac4015c into redpanda-data:dev Feb 4, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants