Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage/tests: Adjust step size deviation used in test #18420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/v/storage/segment_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class segment_index {

friend class offset_index_utils_fixture;
friend class log_replayer_fixture;
friend class segment_index_observer;

friend std::ostream& operator<<(std::ostream&, const segment_index&);
};
Expand Down
51 changes: 42 additions & 9 deletions src/v/storage/tests/storage_e2e_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4555,6 +4555,26 @@ FIXTURE_TEST(test_offset_range_size2_compacted, storage_test_fixture) {
== std::nullopt);
};

namespace storage {
class segment_index_observer {
public:
explicit segment_index_observer(segment_index& index)
: _index{index} {}

size_t max_step_size() const {
fragmented_vector<size_t> diffs;
auto& pos = _index._state.position_index;
diffs.reserve(pos.size());
std::adjacent_difference(
pos.begin(), pos.end(), std::back_inserter(diffs));
Copy link
Contributor

Choose a reason for hiding this comment

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

didn't know about adjacent_difference, cool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it does not work on const references to containers, but handy where usable.

return std::ranges::max(diffs);
}

private:
segment_index& _index;
};
} // namespace storage

FIXTURE_TEST(test_offset_range_size_incremental, storage_test_fixture) {
#ifdef NDEBUG
size_t num_segments = 300;
Expand All @@ -4575,15 +4595,14 @@ FIXTURE_TEST(test_offset_range_size_incremental, storage_test_fixture) {
size_t max_size;
};
std::vector<size_target> size_classes = {
// can overshoot quite a lot because of the index step (32KiB)
{100, 0, 50_KiB},
{2000, 1_KiB, 50_KiB},
{10_KiB, 1_KiB, 50_KiB},
{50_KiB, 1_KiB, 100_KiB},
{500_KiB, 1_KiB, 550_KiB},
{1_MiB, 1_KiB, 1_MiB + 50_KiB},
{10_MiB, 1_KiB, 10_MiB + 50_KiB},
{100_MiB, 1_KiB, 100_MiB + 50_KiB},
{100, 0, 100},
{2000, 1_KiB, 2000},
{10_KiB, 1_KiB, 10_KiB},
{50_KiB, 1_KiB, 50_KiB},
{500_KiB, 1_KiB, 500_KiB},
{1_MiB, 1_KiB, 1_MiB},
{10_MiB, 1_KiB, 10_MiB},
{100_MiB, 1_KiB, 100_MiB},
};
auto cfg = default_log_config(test_dir);
ss::abort_source as;
Expand All @@ -4608,6 +4627,7 @@ FIXTURE_TEST(test_offset_range_size_incremental, storage_test_fixture) {
}
log->force_roll(ss::default_priority_class()).get();
}
size_t max_step_size = 0;
for (auto& s : log->segments()) {
if (s->size_bytes() == 0) {
continue;
Expand All @@ -4618,6 +4638,19 @@ FIXTURE_TEST(test_offset_range_size_incremental, storage_test_fixture) {
s->index().path(),
s->index().size());
BOOST_REQUIRE(s->index().size() > 0);
max_step_size = std::max(
max_step_size,
storage::segment_index_observer{s->index()}.max_step_size());
}

BOOST_REQUIRE(max_step_size > 0);
vlog(
e2e_test_log.info,
"Max index step size among all segments: {}",
max_step_size);

for (auto& sc : size_classes) {
sc.max_size += max_step_size + sc.target;
}

std::vector<batch_summary> summaries;
Expand Down
Loading