maedhroz commented on code in PR #2660:
URL: https://github.com/apache/cassandra/pull/2660#discussion_r1317743179


##########
src/java/org/apache/cassandra/config/RetrySpec.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.config;
+
+import java.util.Objects;
+
+import javax.annotation.Nullable;
+
+import org.apache.cassandra.config.DurationSpec.LongNanosecondsBound;
+
+public class RetrySpec
+{
+    public enum Type { Expoential }
+
+    public static class MaxAttempt
+    {
+        public static final MaxAttempt DISABLED = new MaxAttempt();
+
+        public int value;
+
+        public MaxAttempt(int value)
+        {
+            if (value < 1)
+                throw new IllegalArgumentException("max attempt must be 
positive; but given " + value);
+            this.value = value;
+        }
+
+        private MaxAttempt()
+        {
+            value = 0;
+        }
+
+        @Override
+        public boolean equals(Object o)
+        {
+            if (this == o) return true;
+            if (o == null) return false;
+            if (o instanceof Integer) return this.value == ((Integer) 
o).intValue();
+            if (getClass() != o.getClass()) return false;
+            MaxAttempt that = (MaxAttempt) o;
+            return value == that.value;
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return Objects.hash(value);
+        }
+
+        @Override
+        public String toString()
+        {
+            return Integer.toString(value);
+        }
+    }
+
+    public static class Partial extends RetrySpec
+    {
+        public Partial()
+        {
+            this.type = null;
+            this.maxAttempts = null;
+            this.baseSleepTime = null;
+            this.maxSleepTime = null;
+        }
+
+        public RetrySpec withDefaults(RetrySpec defaultValues)
+        {
+            Type type = nonNull(this.type, defaultValues.getType(), 
DEFAULT_TYPE);
+            MaxAttempt maxAttempts = nonNull(this.maxAttempts, 
defaultValues.getMaxAttempts(), DEFAULT_MAX_ATTEMPTS);
+            LongNanosecondsBound baseSleepTime = nonNull(this.baseSleepTime, 
defaultValues.getBaseSleepTime(), DEFAULT_BASE_SLEEP);
+            LongNanosecondsBound maxSleepTime = nonNull(this.maxSleepTime, 
defaultValues.getMaxSleepTime(), DEFAULT_MAX_SLEEP);
+            return new RetrySpec(type, maxAttempts, baseSleepTime, 
maxSleepTime);
+        }
+
+        private static <T> T nonNull(@Nullable T left, @Nullable T right, T 
defaultValue)
+        {
+            if (left != null)
+                return left;
+            if (right != null)
+                return right;
+            return defaultValue;
+        }
+    }
+
+    private static final Type DEFAULT_TYPE = Type.Expoential;
+    private static final MaxAttempt DEFAULT_MAX_ATTEMPTS = MaxAttempt.DISABLED;
+    private static final LongNanosecondsBound DEFAULT_BASE_SLEEP = new 
LongNanosecondsBound("200ms");
+    private static final LongNanosecondsBound DEFAULT_MAX_SLEEP = new 
LongNanosecondsBound("1s");
+
+    public Type type = DEFAULT_TYPE;
+    /**
+     * Represents how many retry attempts are allowed.  If the value is 2, 
this will cause 2 retries + 1 original request, for a total of 3 requests!
+     * <p/>
+     * To disable, set to 0.
+     * <p/>
+     * To make it unbound, used -1

Review Comment:
   We talked about this a bit, but I'd consider just avoiding `-1` and using 
some very large value (TM) if we need to effectively make it unbound.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to