Skip to content

Commit

Permalink
tests: fix test_changing_topic_retention_with_restart
Browse files Browse the repository at this point in the history
This test was assuming that segment sizes apply exactly,
but they are actually subject to a +/- 5% jitter.  To reliably
remove the expected number of segments, we must set our retention
bytes to 5% less than the amount we really expect to retain.

Fixes redpanda-data#2406
  • Loading branch information
jcsp committed Jul 4, 2022
1 parent 197b12f commit 20949e3
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tests/rptest/tests/retention_policy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
segments_count)


def bytes_for_segments(want_segments, segment_size):
"""
Work out what to set retention.bytes to in order to retain
just this number of segments (assuming all segments are written
to their size limit).
"""

# When predicting segment sizes, we must account for segment_size_jitter
# which adjusts segment sizes up or down by 5%. We must handle the case
# where segments are the smallest they can be.
# (see `jitter_segment_size` in segment_utils.cc)
segment_size_jitter_factor = 0.95

return int((want_segments * segment_size) * segment_size_jitter_factor)


class RetentionPolicyTest(RedpandaTest):
topics = (TopicSpec(partition_count=1,
replication_factor=3,
Expand Down Expand Up @@ -94,7 +110,8 @@ def test_changing_topic_retention_with_restart(self):
# change retention bytes to preserve 15 segments
self.client().alter_topic_configs(
self.topic, {
TopicSpec.PROPERTY_RETENTION_BYTES: 15 * segment_size,
TopicSpec.PROPERTY_RETENTION_BYTES:
bytes_for_segments(15, segment_size)
})
wait_for_segments_removal(redpanda=self.redpanda,
topic=self.topic,
Expand All @@ -104,7 +121,8 @@ def test_changing_topic_retention_with_restart(self):
# change retention bytes again to preserve 10 segments
self.client().alter_topic_configs(
self.topic, {
TopicSpec.PROPERTY_RETENTION_BYTES: 10 * segment_size,
TopicSpec.PROPERTY_RETENTION_BYTES:
bytes_for_segments(10, segment_size),
})
wait_for_segments_removal(redpanda=self.redpanda,
topic=self.topic,
Expand All @@ -114,7 +132,8 @@ def test_changing_topic_retention_with_restart(self):
# change retention bytes again to preserve 5 segments
self.client().alter_topic_configs(
self.topic, {
TopicSpec.PROPERTY_RETENTION_BYTES: 4 * segment_size,
TopicSpec.PROPERTY_RETENTION_BYTES:
bytes_for_segments(4, segment_size),
})
wait_for_segments_removal(redpanda=self.redpanda,
topic=self.topic,
Expand Down Expand Up @@ -148,7 +167,8 @@ def test_timequery_after_segments_eviction(self):
# change retention bytes to preserve 15 segments
self.client().alter_topic_configs(
self.topic, {
TopicSpec.PROPERTY_RETENTION_BYTES: 2 * segment_size,
TopicSpec.PROPERTY_RETENTION_BYTES:
bytes_for_segments(2, segment_size),
})

def validate_time_query_until_deleted():
Expand Down

0 comments on commit 20949e3

Please sign in to comment.