You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/04/24 13:28:50 UTC

[GitHub] [incubator-ratis] lokeshj1703 opened a new pull request #63: RATIS-882. Implement ExponentialBackoffRetry.

lokeshj1703 opened a new pull request #63:
URL: https://github.com/apache/incubator-ratis/pull/63


   Apache jira
   https://issues.apache.org/jira/browse/RATIS-882


----------------------------------------------------------------
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.

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



[GitHub] [incubator-ratis] lokeshj1703 commented on a change in pull request #63: RATIS-882. Implement ExponentialBackoffRetry.

Posted by GitBox <gi...@apache.org>.
lokeshj1703 commented on a change in pull request #63:
URL: https://github.com/apache/incubator-ratis/pull/63#discussion_r415659683



##########
File path: ratis-common/src/main/java/org/apache/ratis/retry/ExponentialBackoffRetry.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ratis.retry;
+
+import org.apache.ratis.util.Preconditions;
+import org.apache.ratis.util.TimeDuration;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Retry Policy exponentially increases sleep time with randomness on successive
+ * retries. The sleep time is a geometric progression b*2, b*4, b*8, b*16...
+ * bounded by maximum configured duration.
+ *
+ * If sleep time calculated using the progression is s then randomness is added
+ * in the range [s*0.5, s*1.5).
+ */

Review comment:
       "The sleep time is a geometric progression b*2, b*4, b*8, b*16... bounded by maximum configured duration." captures the description for maximum duration.




----------------------------------------------------------------
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.

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



[GitHub] [incubator-ratis] lokeshj1703 commented on pull request #63: RATIS-882. Implement ExponentialBackoffRetry.

Posted by GitBox <gi...@apache.org>.
lokeshj1703 commented on pull request #63:
URL: https://github.com/apache/incubator-ratis/pull/63#issuecomment-619809925


   @bshashikant I dont see the comments.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-ratis] bshashikant commented on a change in pull request #63: RATIS-882. Implement ExponentialBackoffRetry.

Posted by GitBox <gi...@apache.org>.
bshashikant commented on a change in pull request #63:
URL: https://github.com/apache/incubator-ratis/pull/63#discussion_r415584059



##########
File path: ratis-common/src/main/java/org/apache/ratis/retry/ExponentialBackoffRetry.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.ratis.retry;
+
+import org.apache.ratis.util.Preconditions;
+import org.apache.ratis.util.TimeDuration;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * Retry Policy exponentially increases sleep time with randomness on successive
+ * retries. The sleep time is a geometric progression b*2, b*4, b*8, b*16...
+ * bounded by maximum configured duration.
+ *
+ * If sleep time calculated using the progression is s then randomness is added
+ * in the range [s*0.5, s*1.5).
+ */

Review comment:
       Let's also add details on max time out here in the description

##########
File path: ratis-test/src/test/java/org/apache/ratis/retry/TestExponentialBackoffRetry.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.ratis.retry;
+
+import org.apache.ratis.BaseTest;
+import org.apache.ratis.util.TimeDuration;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Tests ExponentialBackoffRetry policy.
+ */
+public class TestExponentialBackoffRetry extends BaseTest {
+
+  @Test
+  public void testExponentialBackoffRetry() {
+    TimeDuration baseSleep = TimeDuration.valueOf(1, TimeUnit.SECONDS);
+    TimeDuration maxSleep = TimeDuration.valueOf(40, TimeUnit.SECONDS);
+
+    // Test maxAttempts
+    ExponentialBackoffRetry retryPolicy = createPolicy(baseSleep, null, 1);
+    Assert.assertFalse(retryPolicy.handleAttemptFailure(() -> 1).shouldRetry());
+
+    try {
+      // baseSleep should not be null
+      createPolicy(null, null, 1);
+      Assert.fail("Policy creation should have failed");
+    } catch (Throwable t) {
+    }
+
+    // test policy with without max sleep

Review comment:
       fix the comment??




----------------------------------------------------------------
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.

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



[GitHub] [incubator-ratis] bshashikant commented on pull request #63: RATIS-882. Implement ExponentialBackoffRetry.

Posted by GitBox <gi...@apache.org>.
bshashikant commented on pull request #63:
URL: https://github.com/apache/incubator-ratis/pull/63#issuecomment-619801228


   looks good with some minor comments.


----------------------------------------------------------------
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.

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