ascherbakoff commented on a change in pull request #481:
URL: https://github.com/apache/ignite-3/pull/481#discussion_r790509150



##########
File path: 
modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/ExponentialBackoffTimeoutStrategy.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.ignite.raft.jraft.util;
+
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Timeout generation strategy.
+ * Increases provided timeout based on exponential backoff algorithm. Max 
timeout equals to {@link DEFAULT_TIMEOUT_MS_MAX}
+ */
+public class ExponentialBackoffTimeoutStrategy implements TimeoutStrategy {
+    /** Default backoff coefficient to calculate next timeout based on backoff 
strategy. */
+    private static final double DEFAULT_BACKOFF_COEFFICIENT = 2.0;
+
+    /** Default max timeout that strategy could generate, ms. */
+    private static final int DEFAULT_TIMEOUT_MS_MAX = 11_000;
+
+    /** Default max number of a round after which timeout will be adjusted. */
+    public static final long DEFAULT_ROUNDS_WITHOUT_ADJUSTING = 3;

Review comment:
       Why is this public ?

##########
File path: 
modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java
##########
@@ -608,6 +614,48 @@ private void handleElectionTimeout() {
         }
     }
 
+    /**
+     * Method that adjusts election timeout after several consecutive 
unsuccessful leader elections according to {@link TimeoutStrategy}
+     * <p>
+     * Notes about general algorithm: The main idea is that in a stable 
cluster election timeout should be relatively small, but when
+     * something is preventing elections from completion, like an unstable 
network or long GC pauses, we don't want to have a lot of
+     * elections, so election timeout is adjusted. Hence, the upper bound of 
the election timeout adjusting is the value, which is enough to
+     * elect a leader or handle problems that prevent a successful leader 
election.
+     * <p>
+     * Leader election timeout is set to an initial value after a successful 
election of a leader.
+     */
+    private void adjustElectionTimeout() {
+        electionRound++;
+
+        if (!electionAdjusted) {
+            initialElectionTimeout = options.getElectionTimeoutMs();
+        }
+
+        long timeout = 
options.getElectionTimeoutStrategy().nextTimeout(options.getElectionTimeoutMs(),
 electionRound);
+
+        if (timeout != options.getElectionTimeoutMs()) {
+            LOG.info("Election timeout was adjusted according to {} ", 
options.getElectionTimeoutStrategy().toString());
+            resetElectionTimeoutMs((int) timeout);
+            electionAdjusted = true;
+            electionRound = 0;

Review comment:
       Why do we reset electionRound to zero after each succesful adjustment ?
   It doesn't seem correct to me. Additionally, I would log this value on each 
election attempt

##########
File path: 
modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/ExponentialBackoffTimeoutStrategy.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.ignite.raft.jraft.util;
+
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Timeout generation strategy.
+ * Increases provided timeout based on exponential backoff algorithm. Max 
timeout equals to {@link DEFAULT_TIMEOUT_MS_MAX}
+ */
+public class ExponentialBackoffTimeoutStrategy implements TimeoutStrategy {
+    /** Default backoff coefficient to calculate next timeout based on backoff 
strategy. */
+    private static final double DEFAULT_BACKOFF_COEFFICIENT = 2.0;
+
+    /** Default max timeout that strategy could generate, ms. */
+    private static final int DEFAULT_TIMEOUT_MS_MAX = 11_000;
+
+    /** Default max number of a round after which timeout will be adjusted. */
+    public static final long DEFAULT_ROUNDS_WITHOUT_ADJUSTING = 3;
+
+    /** Max timeout that strategy could generate, ms. */
+    private int maxTimeout = DEFAULT_TIMEOUT_MS_MAX;
+
+    /** Max number of a round after which timeout will be adjusted. */
+    private long roundsWithoutAdjusting = DEFAULT_ROUNDS_WITHOUT_ADJUSTING;
+
+    public ExponentialBackoffTimeoutStrategy() {
+

Review comment:
       call to **this** with defaults is missing

##########
File path: 
modules/raft/src/main/java/org/apache/ignite/raft/jraft/core/NodeImpl.java
##########
@@ -608,6 +614,48 @@ private void handleElectionTimeout() {
         }
     }
 
+    /**
+     * Method that adjusts election timeout after several consecutive 
unsuccessful leader elections according to {@link TimeoutStrategy}
+     * <p>
+     * Notes about general algorithm: The main idea is that in a stable 
cluster election timeout should be relatively small, but when
+     * something is preventing elections from completion, like an unstable 
network or long GC pauses, we don't want to have a lot of
+     * elections, so election timeout is adjusted. Hence, the upper bound of 
the election timeout adjusting is the value, which is enough to
+     * elect a leader or handle problems that prevent a successful leader 
election.
+     * <p>
+     * Leader election timeout is set to an initial value after a successful 
election of a leader.
+     */
+    private void adjustElectionTimeout() {
+        electionRound++;
+
+        if (!electionAdjusted) {
+            initialElectionTimeout = options.getElectionTimeoutMs();
+        }
+
+        long timeout = 
options.getElectionTimeoutStrategy().nextTimeout(options.getElectionTimeoutMs(),
 electionRound);
+
+        if (timeout != options.getElectionTimeoutMs()) {
+            LOG.info("Election timeout was adjusted according to {} ", 
options.getElectionTimeoutStrategy().toString());

Review comment:
       toString is not needed




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


Reply via email to