This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch remove_cluster_environmentutil
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/remove_cluster_environmentutil
by this push:
new c7dc942 reduce election timeout in tests
c7dc942 is described below
commit c7dc9420d7a3c481a8f0f0c218a0d4bc0cc45d2c
Author: jt <[email protected]>
AuthorDate: Tue Jan 5 14:23:00 2021 +0800
reduce election timeout in tests
---
.../iotdb/cluster/config/ClusterConstant.java | 31 +++++++++++++++++-----
.../cluster/server/heartbeat/HeartbeatThread.java | 8 +++---
.../server/heartbeat/HeartbeatThreadTest.java | 3 +++
.../iotdb/db/query/control/QueryFileManager.java | 2 --
4 files changed, 32 insertions(+), 12 deletions(-)
diff --git
a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
index 55fe6b4..1de6d4d 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConstant.java
@@ -19,15 +19,12 @@
package org.apache.iotdb.cluster.config;
import org.apache.iotdb.cluster.rpc.thrift.Node;
+import org.apache.iotdb.db.utils.TestOnly;
public class ClusterConstant {
- /**
- * a failed election will restart in 2s~5s, this should be at least as long
as a heartbeat
- * interval, or a stale node may frequently issue elections and thus makes
the leader step down
- */
- public static final long ELECTION_LEAST_TIME_OUT_MS = 2 * 1000L;
- public static final long ELECTION_RANDOM_TIME_OUT_MS = 3 * 1000L;
+ private static long ELECTION_LEAST_TIME_OUT_MS = 2 * 1000L;
+ private static long ELECTION_RANDOM_TIME_OUT_MS = 3 * 1000L;
public static final int SLOT_NUM = 10000;
public static final int HASH_SALT = 2333;
public static final int CHECK_ALIVE_TIME_OUT_MS = 1000;
@@ -41,4 +38,26 @@ public class ClusterConstant {
}
static final String CLUSTER_CONF = "CLUSTER_CONF";
+
+ /**
+ * a failed election will restart in 2s~5s, this should be at least as long
as a heartbeat
+ * interval, or a stale node may frequently issue elections and thus makes
the leader step down
+ */
+ public static long getElectionLeastTimeOutMs() {
+ return ELECTION_LEAST_TIME_OUT_MS;
+ }
+
+ public static long getElectionRandomTimeOutMs() {
+ return ELECTION_RANDOM_TIME_OUT_MS;
+ }
+
+ @TestOnly
+ public static void setElectionLeastTimeOutMs(long electionLeastTimeOutMs) {
+ ELECTION_LEAST_TIME_OUT_MS = electionLeastTimeOutMs;
+ }
+
+ @TestOnly
+ public static void setElectionRandomTimeOutMs(long electionRandomTimeOutMs) {
+ ELECTION_RANDOM_TIME_OUT_MS = electionRandomTimeOutMs;
+ }
}
diff --git
a/cluster/src/main/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThread.java
b/cluster/src/main/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThread.java
index 0bfefee..514be50 100644
---
a/cluster/src/main/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThread.java
+++
b/cluster/src/main/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThread.java
@@ -67,8 +67,8 @@ public class HeartbeatThread implements Runnable {
public void run() {
logger.info("{}: Heartbeat thread starts...", memberName);
// sleep random time to reduce first election conflicts
- long electionWait = ClusterConstant.ELECTION_LEAST_TIME_OUT_MS
- + Math.abs(random.nextLong() %
ClusterConstant.ELECTION_RANDOM_TIME_OUT_MS);
+ long electionWait = ClusterConstant.getElectionLeastTimeOutMs()
+ + Math.abs(random.nextLong() %
ClusterConstant.getElectionRandomTimeOutMs());
try {
logger.info("{}: Sleep {}ms before first election", memberName,
electionWait);
Thread.sleep(electionWait);
@@ -246,8 +246,8 @@ public class HeartbeatThread implements Runnable {
startElection();
if (localMember.getCharacter() == NodeCharacter.ELECTOR) {
// sleep random time to reduce election conflicts
- long electionWait = ClusterConstant.ELECTION_LEAST_TIME_OUT_MS
- + Math.abs(random.nextLong() %
ClusterConstant.ELECTION_RANDOM_TIME_OUT_MS);
+ long electionWait = ClusterConstant.getElectionLeastTimeOutMs()
+ + Math.abs(random.nextLong() %
ClusterConstant.getElectionRandomTimeOutMs());
logger.info("{}: Sleep {}ms until next election", memberName,
electionWait);
Thread.sleep(electionWait);
}
diff --git
a/cluster/src/test/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThreadTest.java
b/cluster/src/test/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThreadTest.java
index ea2af1e..717f6e1 100644
---
a/cluster/src/test/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThreadTest.java
+++
b/cluster/src/test/java/org/apache/iotdb/cluster/server/heartbeat/HeartbeatThreadTest.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;
+import org.apache.iotdb.cluster.config.ClusterConstant;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.cluster.common.TestAsyncClient;
import org.apache.iotdb.cluster.common.TestLogManager;
@@ -143,6 +144,8 @@ public class HeartbeatThreadTest {
@Before
public void setUp() throws Exception {
+ ClusterConstant.setElectionLeastTimeOutMs(20);
+ ClusterConstant.setElectionRandomTimeOutMs(30);
prevUseAsyncServer =
ClusterDescriptor.getInstance().getConfig().isUseAsyncServer();
ClusterDescriptor.getInstance().getConfig().setUseAsyncServer(true);
logManager = new TestLogManager(1);
diff --git
a/server/src/main/java/org/apache/iotdb/db/query/control/QueryFileManager.java
b/server/src/main/java/org/apache/iotdb/db/query/control/QueryFileManager.java
index 942ed7f..20ebc10 100644
---
a/server/src/main/java/org/apache/iotdb/db/query/control/QueryFileManager.java
+++
b/server/src/main/java/org/apache/iotdb/db/query/control/QueryFileManager.java
@@ -97,7 +97,6 @@ public class QueryFileManager {
if (tsFiles != null) {
for (TsFileResource tsFile : sealedFilePathsMap.get(queryId)) {
FileReaderManager.getInstance().decreaseFileReaderReference(tsFile,
true);
- logger.warn("{} is read-unlocked by {}", tsFile, queryId, new
Exception());
}
sealedFilePathsMap.remove(queryId);
}
@@ -105,7 +104,6 @@ public class QueryFileManager {
if (tsFiles != null) {
for (TsFileResource tsFile : unsealedFilePathsMap.get(queryId)) {
FileReaderManager.getInstance().decreaseFileReaderReference(tsFile,
false);
- logger.warn("{} is read-unlocked by {}", tsFile, queryId, new
Exception());
}
unsealedFilePathsMap.remove(queryId);
}