You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "nivykani (via GitHub)" <gi...@apache.org> on 2026/01/07 18:18:45 UTC

[PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

nivykani opened a new pull request, #4549:
URL: https://github.com/apache/cassandra/pull/4549

   Thanks for sending a pull request! Here are some tips if you're new here:
    
    * Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
    * Be sure to keep the PR description updated to reflect all changes.
    * Write your PR title to summarize what this PR proposes.
    * If possible, provide a concise example to reproduce the issue for a faster review.
    * Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
    * If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
    
   Commit messages should follow the following format:
   
   ```
   <One sentence description, usually Jira title or CHANGES.txt summary>
   
   <Optional lengthier description (context on patch)>
   
   patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
   
   Co-authored-by: Name1 <email1>
   Co-authored-by: Name2 <email2>
   
   ```
   
   The [Cassandra Jira](https://issues.apache.org/jira/browse/CASSANDRA-21102)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on PR #4549:
URL: https://github.com/apache/cassandra/pull/4549#issuecomment-3731134081

   ```
   commit 386183fce11707f176b736d92e50cb75ad0680b8
   Author: Nivy Kani <ni...@apple.com>
   Date:   Thu Jan 8 14:27:36 2026 -0800
   
       Fix off-by-one bug in exponential backoff for repair retry config
   
       patch by Nivy Kani; reviewed by David Capwell, Jyothsna Konisa for CASSANDRA-21102
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "nivykani (via GitHub)" <gi...@apache.org>.
nivykani commented on code in PR #4549:
URL: https://github.com/apache/cassandra/pull/4549#discussion_r2670315876


##########
test/unit/org/apache/cassandra/service/TimeoutStrategyTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeoutStrategyTest {
+
+    @Test
+    public void testParseLatencyModifierExponential() {

Review Comment:
   Great catch with the overflows; Integer.MIN_VALUE would break this logic so I added a max(a, 0). For Integer.MAX_VALUE, the maximum number of retries has to be specified in the input string. Also added a case for fractional bases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4549:
URL: https://github.com/apache/cassandra/pull/4549#discussion_r2674064326


##########
test/unit/org/apache/cassandra/service/TimeoutStrategyTest.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeoutStrategyTest {

Review Comment:
   style: `{` are always on a new line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4549:
URL: https://github.com/apache/cassandra/pull/4549#discussion_r2674061499


##########
src/java/org/apache/cassandra/service/TimeoutStrategy.java:
##########
@@ -97,7 +97,8 @@ interface LatencyModifierFactory
         default LatencyModifier identity() { return (l, a) -> l; }
         default LatencyModifier multiply(double constant) { return (l, a) -> saturatedCast(l * constant); }
         default LatencyModifier multiplyByAttempts(double multiply) { return (l, a) -> saturatedCast(l * multiply * a); }
-        default LatencyModifier multiplyByAttemptsExp(double base) { return (l, a) -> saturatedCast(l * pow(base, a)); }
+        // Ensure attempts is non-negative before subtracting 1.
+        default LatencyModifier multiplyByAttemptsExp(double base) { return (l, a) -> saturatedCast(l * pow(base, max(0, (max(a, 0) - 1)))); }

Review Comment:
   this looks safe
   
   ```
   $ rg '\^attempts' src
   src/java/org/apache/cassandra/config/RetrySpec.java
   164:        return RetryStrategy.parse(spec.baseSleepTime.toMilliseconds() + "ms * 2^attempts <= " + spec.maxSleepTime.toMilliseconds() + "ms,retries=" + (spec.maxAttempts.value - 1), LatencySourceFactory.none());
   
   src/java/org/apache/cassandra/service/RetryStrategy.java
   72: * <li> {@code 10ms <= p95(rw)*1.8^attempts <= 100ms}
   
   src/java/org/apache/cassandra/service/TimeoutStrategy.java
   73: * <li> {@code 10ms <= p95(rw)*1.8^attempts <= 100ms}
   ```
   
   The only user is repair, so not really a breaking change to paxos.  If anyone was using this in paxos v2, the only impact is that it would have the first retry respect the min value rather than do `min * 2`, so LGTM



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell closed pull request #4549: [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config
URL: https://github.com/apache/cassandra/pull/4549


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "jyothsnakonisa (via GitHub)" <gi...@apache.org>.
jyothsnakonisa commented on code in PR #4549:
URL: https://github.com/apache/cassandra/pull/4549#discussion_r2670026516


##########
test/unit/org/apache/cassandra/service/TimeoutStrategyTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeoutStrategyTest {
+
+    @Test
+    public void testParseLatencyModifierExponential() {
+        long expectedBaseLatencyMicros = TimeUnit.MILLISECONDS.toMicros(30);
+        String spec = "30ms * 2^attempts";
+        TimeoutStrategy.Wait w = org.apache.cassandra.service.TimeoutStrategy.parseWait(spec, TimeoutStrategy.LatencySourceFactory.none());
+
+        // Attempt 1: baseLatency * 2^(1-1) = baseLatency * 1
+        Assertions.assertThat(w.getMicros(1))
+                .isEqualTo(expectedBaseLatencyMicros);
+
+        // Attempt 2: baseLatency * 2^(2-1) = baseLatency * 2
+        Assertions.assertThat(w.getMicros(2))
+                .isEqualTo(expectedBaseLatencyMicros * 2);
+
+        // Attempt 3: baseLatency * 2^(3-1) = baseLatency * 4
+        Assertions.assertThat(w.getMicros(3))
+                .isEqualTo(expectedBaseLatencyMicros * 4);
+
+        // Edge case to check for 0 attempts: max(0, -1) = 0
+        Assertions.assertThat(w.getMicros(0))
+                .isEqualTo(expectedBaseLatencyMicros);
+    }
+}

Review Comment:
   Please add new line



##########
src/java/org/apache/cassandra/service/TimeoutStrategy.java:
##########
@@ -97,7 +97,7 @@ interface LatencyModifierFactory
         default LatencyModifier identity() { return (l, a) -> l; }
         default LatencyModifier multiply(double constant) { return (l, a) -> saturatedCast(l * constant); }
         default LatencyModifier multiplyByAttempts(double multiply) { return (l, a) -> saturatedCast(l * multiply * a); }
-        default LatencyModifier multiplyByAttemptsExp(double base) { return (l, a) -> saturatedCast(l * pow(base, a)); }
+        default LatencyModifier multiplyByAttemptsExp(double base) { return (l, a) -> saturatedCast(l * pow(base, max(0, a-1))); }

Review Comment:
   ```suggestion
           default LatencyModifier multiplyByAttemptsExp(double base) { return (l, a) -> saturatedCast(l * pow(base, max(0, a - 1))); }
   ```
   Please fix formatting



##########
test/unit/org/apache/cassandra/service/TimeoutStrategyTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeoutStrategyTest {
+
+    @Test
+    public void testParseLatencyModifierExponential() {

Review Comment:
   How about checking for Integer.MAX_VALUE & Integer.MIN_VALUE number of attempts for checking overflows?
   Also, can you add another case for fractional base like `0.5`



##########
test/unit/org/apache/cassandra/service/TimeoutStrategyTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.service;
+
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeoutStrategyTest {
+
+    @Test
+    public void testParseLatencyModifierExponential() {
+        long expectedBaseLatencyMicros = TimeUnit.MILLISECONDS.toMicros(30);
+        String spec = "30ms * 2^attempts";
+        TimeoutStrategy.Wait w = org.apache.cassandra.service.TimeoutStrategy.parseWait(spec, TimeoutStrategy.LatencySourceFactory.none());

Review Comment:
   ```suggestion
           TimeoutStrategy.Wait w = TimeoutStrategy.parseWait(spec, TimeoutStrategy.LatencySourceFactory.none());
   ```
   We don't need fully qualified class name



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-21102] Fix off-by-one bug in exponential backoff for repair retry config [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on PR #4549:
URL: https://github.com/apache/cassandra/pull/4549#issuecomment-3726436511

   checkstyles fails
   
   File Name	Line Number	Message
   /workspace/cassandra/test/unit/org/apache/cassandra/service/TimeoutStrategyTest.java	24	Wrong order for 'java.util.concurrent.TimeUnit' import.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org