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

[v23.1.x] s/segment: fixed tracking offsets of empty segments #11543

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
2 changes: 1 addition & 1 deletion src/v/storage/segment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ ss::future<> segment::do_truncate(

ss::future<bool> segment::materialize_index() {
vassert(
_tracker.base_offset == _tracker.dirty_offset,
_tracker.base_offset == model::next_offset(_tracker.dirty_offset),
"Materializing the index must happen before tracking any data. {}",
*this);
return _idx.materialize_index().then([this](bool yn) {
Expand Down
6 changes: 3 additions & 3 deletions src/v/storage/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class segment {
offset_tracker(model::term_id t, model::offset base)
: term(t)
, base_offset(base)
, committed_offset(base)
, dirty_offset(base)
, stable_offset(base) {}
, committed_offset(model::prev_offset(base))
, dirty_offset(model::prev_offset(base))
, stable_offset(model::prev_offset(base)) {}
model::term_id term;
model::offset base_offset;

Expand Down
1 change: 1 addition & 0 deletions src/v/storage/tests/storage_e2e_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,7 @@ do_compact_test(const compact_test_args args, storage_test_fixture& f) {
append_batch(log, model::term_id(0)); // write single message for final
// segment after last roll

log.flush().get();
auto pre_gaps = analyze(*disk_log);
auto pre_stats = log.offsets();
BOOST_REQUIRE_EQUAL(
Expand Down
71 changes: 71 additions & 0 deletions tests/rptest/tests/log_segment_ms_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,74 @@ def test_segment_timely_rolling_after_change(self):
wait_until(lambda: self._total_segments_count(topic) > middle_count,
timeout_sec=SERVER_HOUSEKEEPING_LOOP * 2,
err_msg=f"failed to roll a segment in a timely manner")

@cluster(num_nodes=3)
def test_segment_rolling_with_retention(self):
self.redpanda.set_cluster_config({
"log_segment_ms": None,
"log_segment_ms_min": 10000
})
topic = TopicSpec(segment_bytes=(1024 * 1024),
replication_factor=1,
partition_count=1)
self.client().create_topic(topic)

producer = VerifiableProducer(context=self.test_context,
num_nodes=1,
redpanda=self.redpanda,
topic=topic.name,
throughput=10000)

producer.start()
wait_until(
lambda: self._total_segments_count(topic) >= 5,
timeout_sec=120,
err_msg=
"producer failed to produce enough messages to create 5 segments")
# stop producer
producer.stop()
producer.clean()
producer.free()
del producer
start_count = self._total_segments_count(topic)
self.client().alter_topic_config(topic.name, "segment.ms", "15000")

# wait for the segment.ms policy to roll the segment
wait_until(lambda: self._total_segments_count(topic) > start_count,
timeout_sec=60,
err_msg=f"failed waiting for the segment to roll")

self.client().alter_topic_config(topic.name,
"retention.local.target.ms", "10000")
self.client().alter_topic_config(topic.name, "retention.ms", "10000")

# wait for retention policy to trigger
wait_until(lambda: self._total_segments_count(topic) <= 1,
timeout_sec=60,
err_msg=f"failed waiting for retention policy")

producer = VerifiableProducer(context=self.test_context,
num_nodes=1,
redpanda=self.redpanda,
topic=topic.name,
throughput=10000)
producer.start()
wait_until(
lambda: self._total_segments_count(topic) >= 2,
timeout_sec=120,
err_msg=
f"producer failed to produce enough messages to create 5 segments")
producer.stop()

consumer = VerifiableConsumer(context=self.test_context,
num_nodes=1,
redpanda=self.redpanda,
topic=topic.name,
group_id="test-group")
consumer.start()