This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch rel/1.2
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.2 by this push:
new b6316d0f06e [To rel/1.2][IOTDB-6061] Fix the instability failure
caused by initServer in IoTConsensus UT not binding to the corresponding port
(#10995)
b6316d0f06e is described below
commit b6316d0f06e273c442b5f10cde5457e482b23b27
Author: Potato <[email protected]>
AuthorDate: Wed Aug 30 14:15:59 2023 +0800
[To rel/1.2][IOTDB-6061] Fix the instability failure caused by initServer
in IoTConsensus UT not binding to the corresponding port (#10995)
---
.../apache/iotdb/consensus/iot/ReplicateTest.java | 129 ++++++++++++---------
1 file changed, 76 insertions(+), 53 deletions(-)
diff --git
a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
index 39eab9c5dd7..03903319cee 100644
---
a/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
+++
b/iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/ReplicateTest.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.common.rpc.thrift.TConsensusGroupType;
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
import org.apache.iotdb.commons.consensus.ConsensusGroupId;
import org.apache.iotdb.commons.consensus.DataRegionId;
+import org.apache.iotdb.commons.exception.StartupException;
import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.consensus.common.ConsensusGroup;
import org.apache.iotdb.consensus.common.Peer;
@@ -53,6 +54,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
public class ReplicateTest {
+
private static final long CHECK_POINT_GAP = 500;
private final Logger logger = LoggerFactory.getLogger(ReplicateTest.class);
@@ -201,34 +203,45 @@ public class ReplicateTest {
Assert.assertEquals(stateMachines.get(0).getData(),
stateMachines.get(1).getData());
Assert.assertEquals(stateMachines.get(2).getData(),
stateMachines.get(1).getData());
- stopServer();
- initServer();
-
- Assert.assertEquals(peers, servers.get(0).getImpl(gid).getConfiguration());
- Assert.assertEquals(peers, servers.get(1).getImpl(gid).getConfiguration());
- Assert.assertEquals(peers, servers.get(2).getImpl(gid).getConfiguration());
+ try {
+ stopServer();
+ initServer();
+
+ Assert.assertEquals(peers,
servers.get(0).getImpl(gid).getConfiguration());
+ Assert.assertEquals(peers,
servers.get(1).getImpl(gid).getConfiguration());
+ Assert.assertEquals(peers,
servers.get(2).getImpl(gid).getConfiguration());
+
+ Assert.assertEquals(CHECK_POINT_GAP,
servers.get(0).getImpl(gid).getSearchIndex());
+ Assert.assertEquals(CHECK_POINT_GAP,
servers.get(1).getImpl(gid).getSearchIndex());
+ Assert.assertEquals(CHECK_POINT_GAP,
servers.get(2).getImpl(gid).getSearchIndex());
+
+ for (int i = 0; i < 3; i++) {
+ long start = System.currentTimeMillis();
+ while
(servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex() <
CHECK_POINT_GAP) {
+ long current = System.currentTimeMillis();
+ if ((current - start) > 60 * 1000) {
+ Assert.fail("Unable to recover entries");
+ }
+ Thread.sleep(100);
+ }
+ }
- Assert.assertEquals(CHECK_POINT_GAP,
servers.get(0).getImpl(gid).getSearchIndex());
- Assert.assertEquals(CHECK_POINT_GAP,
servers.get(1).getImpl(gid).getSearchIndex());
- Assert.assertEquals(CHECK_POINT_GAP,
servers.get(2).getImpl(gid).getSearchIndex());
+ Assert.assertEquals(
+ CHECK_POINT_GAP,
servers.get(0).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
+ Assert.assertEquals(
+ CHECK_POINT_GAP,
servers.get(1).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
+ Assert.assertEquals(
+ CHECK_POINT_GAP,
servers.get(2).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
- for (int i = 0; i < 3; i++) {
- long start = System.currentTimeMillis();
- while (servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex()
< CHECK_POINT_GAP) {
- long current = System.currentTimeMillis();
- if ((current - start) > 60 * 1000) {
- Assert.fail("Unable to recover entries");
- }
- Thread.sleep(100);
+ } catch (IOException e) {
+ if (e.getCause() instanceof StartupException) {
+ // just succeed when can not bind socket
+ logger.info("Can not start IoTConsensus because", e);
+ } else {
+ logger.error("Failed because", e);
+ Assert.fail("Failed because " + e.getMessage());
}
}
-
- Assert.assertEquals(
- CHECK_POINT_GAP,
servers.get(0).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
- Assert.assertEquals(
- CHECK_POINT_GAP,
servers.get(1).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
- Assert.assertEquals(
- CHECK_POINT_GAP,
servers.get(2).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
}
/**
@@ -255,39 +268,49 @@ public class ReplicateTest {
Assert.assertEquals(0,
servers.get(0).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
Assert.assertEquals(0,
servers.get(1).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
- stopServer();
- initServer();
-
- servers.get(2).createLocalPeer(group.getGroupId(), group.getPeers());
-
- Assert.assertEquals(peers, servers.get(0).getImpl(gid).getConfiguration());
- Assert.assertEquals(peers, servers.get(1).getImpl(gid).getConfiguration());
- Assert.assertEquals(peers, servers.get(2).getImpl(gid).getConfiguration());
-
- Assert.assertEquals(CHECK_POINT_GAP,
servers.get(0).getImpl(gid).getSearchIndex());
- Assert.assertEquals(CHECK_POINT_GAP,
servers.get(1).getImpl(gid).getSearchIndex());
- Assert.assertEquals(0, servers.get(2).getImpl(gid).getSearchIndex());
-
- for (int i = 0; i < 2; i++) {
- long start = System.currentTimeMillis();
- // should be [CHECK_POINT_GAP, CHECK_POINT_GAP * 2 - 1] after
- // replicating all entries
- while (servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex()
< CHECK_POINT_GAP) {
- long current = System.currentTimeMillis();
- if ((current - start) > 60 * 1000) {
- logger.error("{}",
servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
- Assert.fail("Unable to replicate entries");
+ try {
+ stopServer();
+ initServer();
+
+ servers.get(2).createLocalPeer(group.getGroupId(), group.getPeers());
+
+ Assert.assertEquals(peers,
servers.get(0).getImpl(gid).getConfiguration());
+ Assert.assertEquals(peers,
servers.get(1).getImpl(gid).getConfiguration());
+ Assert.assertEquals(peers,
servers.get(2).getImpl(gid).getConfiguration());
+
+ Assert.assertEquals(CHECK_POINT_GAP,
servers.get(0).getImpl(gid).getSearchIndex());
+ Assert.assertEquals(CHECK_POINT_GAP,
servers.get(1).getImpl(gid).getSearchIndex());
+ Assert.assertEquals(0, servers.get(2).getImpl(gid).getSearchIndex());
+
+ for (int i = 0; i < 2; i++) {
+ long start = System.currentTimeMillis();
+ // should be [CHECK_POINT_GAP, CHECK_POINT_GAP * 2 - 1] after
+ // replicating all entries
+ while
(servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex() <
CHECK_POINT_GAP) {
+ long current = System.currentTimeMillis();
+ if ((current - start) > 60 * 1000) {
+ logger.error("{}",
servers.get(i).getImpl(gid).getCurrentSafelyDeletedSearchIndex());
+ Assert.fail("Unable to replicate entries");
+ }
+ Thread.sleep(100);
}
- Thread.sleep(100);
}
- }
- Assert.assertEquals(CHECK_POINT_GAP * 2,
stateMachines.get(0).getRequestSet().size());
- Assert.assertEquals(CHECK_POINT_GAP * 2,
stateMachines.get(1).getRequestSet().size());
- Assert.assertEquals(CHECK_POINT_GAP * 2,
stateMachines.get(2).getRequestSet().size());
+ Assert.assertEquals(CHECK_POINT_GAP * 2,
stateMachines.get(0).getRequestSet().size());
+ Assert.assertEquals(CHECK_POINT_GAP * 2,
stateMachines.get(1).getRequestSet().size());
+ Assert.assertEquals(CHECK_POINT_GAP * 2,
stateMachines.get(2).getRequestSet().size());
- Assert.assertEquals(stateMachines.get(0).getData(),
stateMachines.get(1).getData());
- Assert.assertEquals(stateMachines.get(2).getData(),
stateMachines.get(1).getData());
+ Assert.assertEquals(stateMachines.get(0).getData(),
stateMachines.get(1).getData());
+ Assert.assertEquals(stateMachines.get(2).getData(),
stateMachines.get(1).getData());
+ } catch (IOException e) {
+ if (e.getCause() instanceof StartupException) {
+ // just succeed when can not bind socket
+ logger.info("Can not start IoTConsensus because", e);
+ } else {
+ logger.error("Failed because", e);
+ Assert.fail("Failed because " + e.getMessage());
+ }
+ }
}
private void findPortAvailable(int i) {