Skip to content

Commit 939053a

Browse files
committed
compaction fuzz test changes
1 parent 979c792 commit 939053a

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/v/storage/tests/compaction_fuzz_test.cc

+37-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "base/vlog.h"
1111
#include "container/fragmented_vector.h"
12+
#include "model/namespace.h"
1213
#include "model/record_batch_types.h"
1314
#include "model/timeout_clock.h"
1415
#include "random/generators.h"
@@ -122,11 +123,24 @@ struct ot_state_consumer {
122123
/// by the set of segment base offset values.
123124
ss::future<ot_state> arrange_and_compact(
124125
const fragmented_vector<model::record_batch>& batches,
125-
std::deque<model::offset> arrangement) {
126+
std::deque<model::offset> arrangement,
127+
bool simulate_internal_topic_compaction = false) {
126128
std::sort(arrangement.begin(), arrangement.end());
127-
storage::disk_log_builder b1;
129+
storage::log_config cfg = storage::log_builder_config();
130+
auto offset_translator_types = model::offset_translator_batch_types();
131+
auto raft_group_id = raft::group_id{0};
132+
storage::disk_log_builder b1(cfg, offset_translator_types, raft_group_id);
133+
134+
auto ns = simulate_internal_topic_compaction
135+
? model::kafka_internal_namespace
136+
: model::kafka_namespace;
137+
model::ntp log_ntp(
138+
ns,
139+
model::topic_partition(
140+
model::topic(random_generators::gen_alphanum_string(8)),
141+
model::partition_id{0}));
128142
std::exception_ptr error = nullptr;
129-
co_await b1.start();
143+
co_await b1.start(log_ntp);
130144
try {
131145
for (const auto& b : batches) {
132146
co_await b1.add_batch(b.copy());
@@ -138,11 +152,13 @@ ss::future<ot_state> arrange_and_compact(
138152
}
139153
}
140154
ss::abort_source as;
141-
co_await b1.apply_compaction(storage::compaction_config(
155+
auto compact_cfg = storage::compaction_config(
142156
batches.back().last_offset(),
143157
std::nullopt,
144158
ss::default_priority_class(),
145-
as));
159+
as);
160+
co_await b1.apply_sliding_window_compaction(compact_cfg);
161+
co_await b1.apply_adjacent_merge_compaction(compact_cfg);
146162
} catch (...) {
147163
error = std::current_exception();
148164
}
@@ -185,11 +201,25 @@ std::deque<model::offset> generate_random_arrangement(
185201
SEASTAR_THREAD_TEST_CASE(test_compaction_with_different_segment_arrangements) {
186202
auto batches = generate_random_record_batches(1000, 10);
187203
auto expected_ot
188-
= arrange_and_compact(batches, std::deque<model::offset>{}).get();
204+
= arrange_and_compact(batches, std::deque<model::offset>{}, false).get();
205+
std::vector<size_t> num_segments = {10, 100, 1000};
206+
for (auto num : num_segments) {
207+
auto arrangement = generate_random_arrangement(batches, num);
208+
auto actual_ot = arrange_and_compact(batches, arrangement, false).get();
209+
BOOST_REQUIRE(expected_ot.gap_offset == actual_ot.gap_offset);
210+
BOOST_REQUIRE(expected_ot.gap_length == actual_ot.gap_length);
211+
}
212+
}
213+
214+
SEASTAR_THREAD_TEST_CASE(
215+
test_compaction_with_different_segment_arrangements_simulate_internal_topic) {
216+
auto batches = generate_random_record_batches(1000, 10);
217+
auto expected_ot
218+
= arrange_and_compact(batches, std::deque<model::offset>{}, true).get();
189219
std::vector<size_t> num_segments = {10, 100, 1000};
190220
for (auto num : num_segments) {
191221
auto arrangement = generate_random_arrangement(batches, num);
192-
auto actual_ot = arrange_and_compact(batches, arrangement).get();
222+
auto actual_ot = arrange_and_compact(batches, arrangement, true).get();
193223
BOOST_REQUIRE(expected_ot.gap_offset == actual_ot.gap_offset);
194224
BOOST_REQUIRE(expected_ot.gap_length == actual_ot.gap_length);
195225
}

0 commit comments

Comments
 (0)