From f35e1648b4f2a1d3f46b95b05c3bfafb2b4a40d8 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 4 Jul 2022 11:42:20 +0100 Subject: [PATCH] tests: fix test_changing_topic_retention_with_restart 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 https://github.com/redpanda-data/redpanda/issues/2406 --- tests/rptest/tests/retention_policy_test.py | 26 +++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/rptest/tests/retention_policy_test.py b/tests/rptest/tests/retention_policy_test.py index 3bd2315440403..cd9c2e6238de0 100644 --- a/tests/rptest/tests/retention_policy_test.py +++ b/tests/rptest/tests/retention_policy_test.py @@ -19,6 +19,20 @@ 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% + segment_size_jitter_factor = 1.05 + + return int((want_segments * segment_size) / segment_size_jitter_factor) + + class RetentionPolicyTest(RedpandaTest): topics = (TopicSpec(partition_count=1, replication_factor=3, @@ -94,7 +108,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, @@ -104,7 +119,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, @@ -114,7 +130,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, @@ -148,7 +165,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():