From 265511f6dee79be1a78112a0a38867efb1ce512f Mon Sep 17 00:00:00 2001 From: Benedict Elliott Smith Date: Fri, 4 Apr 2025 20:12:30 +0100 Subject: [PATCH] Fix CQLSSTableWriterConcurrencyTest patch by Benedict; reviewed by David Capwell for CASSANDRA-20529 --- src/java/org/apache/cassandra/config/Config.java | 2 +- .../apache/cassandra/service/RetryStrategy.java | 14 ++++++++++---- .../service/paxos/ContentionStrategy.java | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/cassandra/config/Config.java b/src/java/org/apache/cassandra/config/Config.java index f5ef9de587..65179fcd7e 100644 --- a/src/java/org/apache/cassandra/config/Config.java +++ b/src/java/org/apache/cassandra/config/Config.java @@ -185,7 +185,7 @@ public class Config public volatile DurationSpec.IntMillisecondsBound cms_default_retry_backoff = null; @Deprecated(since="5.1") public volatile DurationSpec.IntMillisecondsBound cms_default_max_retry_backoff = null; - public String cms_retry_delay = "0 <= 50ms*1*attempts <= 1s,retries=10"; + public String cms_retry_delay = "50ms*attempts <= 500ms ... 100ms*attempts <= 1s,retries=10"; public volatile int epoch_aware_debounce_inflight_tracker_max_size = 100; diff --git a/src/java/org/apache/cassandra/service/RetryStrategy.java b/src/java/org/apache/cassandra/service/RetryStrategy.java index a89f93363d..91c87c520d 100644 --- a/src/java/org/apache/cassandra/service/RetryStrategy.java +++ b/src/java/org/apache/cassandra/service/RetryStrategy.java @@ -97,7 +97,7 @@ public class RetryStrategy implements WaitStrategy static final Pattern PARSE = Pattern.compile( "(\\s*(?0|[0-9]+[mu]?s)\\s*<=)?" + - "(\\s*(?[^=]+)\\s*[.]{3})?" + + "(\\s*(?[^=]+)([(]?\\s*<=\\s*(?0|[0-9]+[mu]?s)\\s*[)]?)?\\s*[.]{3})?" + "(\\s*(?[^=]+))" + "(\\s*<=\\s*(?0|[0-9]+[mu]?s))?"); @@ -198,16 +198,17 @@ public class RetryStrategy implements WaitStrategy } public final WaitRandomizer waitRandomizer; - public final long minMinMicros, maxMaxMicros; + public final long minMinMicros, maxMinMicros, maxMaxMicros; public final @Nullable Wait min; public final @Nonnull Wait max; public final int maxAttempts; - protected RetryStrategy(WaitRandomizer waitRandomizer, long minMinMicros, Wait min, Wait max, long maxMaxMicros, int retries) + protected RetryStrategy(WaitRandomizer waitRandomizer, long minMinMicros, Wait min, long maxMinMicros, Wait max, long maxMaxMicros, int retries) { this.waitRandomizer = waitRandomizer; this.minMinMicros = minMinMicros; this.min = min; + this.maxMinMicros = maxMinMicros; this.max = max; this.maxMaxMicros = maxMaxMicros; this.maxAttempts = retries == Integer.MAX_VALUE ? Integer.MAX_VALUE : retries + 1; @@ -235,6 +236,8 @@ public class RetryStrategy implements WaitStrategy else { long min = this.min.getMicros(attempt); + if (min > maxMinMicros) + min = maxMinMicros; long max = this.max.getMicros(attempt); result = min >= max ? min : waitRandomizer.wait(min, max, attempt); } @@ -294,11 +297,14 @@ public class RetryStrategy implements WaitStrategy throw new IllegalArgumentException("Invalid to specify randomiser when no range specified: '" + original + '\''); if (min instanceof Wait.Constant && minMin != 0) throw new IllegalArgumentException("Invalid to specify an absolute minimum constant when the min bound is itself a constant: '" + original + '\''); + long maxMin = parseInMicros(m.group("maxmin"), Long.MAX_VALUE); + if (min instanceof Wait.Constant && maxMin != Long.MAX_VALUE) + throw new IllegalArgumentException("Invalid to specify an absolute max(min) constant when the min bound is itself a constant: '" + original + '\''); if (max instanceof Wait.Constant && maxMax != Long.MAX_VALUE) throw new IllegalArgumentException("Invalid to specify an absolute maximum constant when the max bound is itself a constant: '" + original + '\''); if (randomizer == null) randomizer = randomizers.uniform(); - return new RetryStrategy(randomizer, minMin, min, max, maxMax, retries); + return new RetryStrategy(randomizer, minMin, min, maxMin, max, maxMax, retries); } @VisibleForTesting diff --git a/src/java/org/apache/cassandra/service/paxos/ContentionStrategy.java b/src/java/org/apache/cassandra/service/paxos/ContentionStrategy.java index 3f983faa8c..63dba970be 100644 --- a/src/java/org/apache/cassandra/service/paxos/ContentionStrategy.java +++ b/src/java/org/apache/cassandra/service/paxos/ContentionStrategy.java @@ -109,7 +109,7 @@ public class ContentionStrategy extends RetryStrategy public ContentionStrategy(WaitRandomizer waitRandomizer, LegacyWait min, LegacyWait max, LegacyWait spread, int retries, int traceAfterAttempts) { - super(waitRandomizer, min.min, min, max, max.max, retries); + super(waitRandomizer, min.min, min, min.max, max, max.max, retries); this.traceAfterAttempts = traceAfterAttempts; this.spread = spread; }