Skip to content

Commit

Permalink
RATIS-2098. RaftLogTruncateTests may fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
szetszwo committed May 22, 2024
1 parent 8c7c444 commit 2c4e01d
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.ratis.statemachine.StateMachine;
import org.apache.ratis.statemachine.TransactionContext;
import org.apache.ratis.statemachine.impl.SimpleStateMachine4Testing;
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.MemoizedSupplier;
import org.apache.ratis.util.Slf4jUtils;
import org.apache.ratis.util.TimeDuration;
Expand Down Expand Up @@ -178,9 +179,11 @@ void runTestLogTruncate(MiniRaftCluster cluster, RaftServer.Division oldLeader,
LOG.info("done");
}

// kill the old leader
// kill remaining peers
LOG.info("Before killServer {}: {}", oldLeader.getId(), cluster.printServers());
cluster.killServer(oldLeader.getId());
for (RaftPeerId p : remainingPeers) {
cluster.killServer(p);
}
LOG.info("After killServer {}: {}", remainingPeers, cluster.printServers());

// restart the earlier followers
Expand All @@ -198,8 +201,10 @@ void runTestLogTruncate(MiniRaftCluster cluster, RaftServer.Division oldLeader,
newLeaderLog.getLastEntryTermIndex());
Assertions.assertTrue(killedPeers.contains(newLeader.getId()));

// restart the old leader
cluster.restartServer(oldLeader.getId(), false);
// restart remaining peers
for (RaftPeerId p : remainingPeers) {
cluster.restartServer(p, false);
}

// check RaftLog truncate
for (RaftPeerId f : remainingPeers) {
Expand All @@ -219,8 +224,11 @@ void runTestLogTruncate(MiniRaftCluster cluster, RaftServer.Division oldLeader,
for (RaftPeer peer : cluster.getGroup().getPeers()) {
final RaftServer.Division division = cluster.getDivision(peer.getId());
assertLogEntries(division, oldLeaderTerm, expectedMessages);
assertEmptyTransactionContextMap(division);
}
final String name = "assertEmptyTransactionContextMap:" + division.getId();
JavaUtils.attempt(() -> assertEmptyTransactionContextMap(division),
10, HUNDRED_MILLIS, name, LOG);

}

if (!exceptions.isEmpty()) {
LOG.info("{} exceptions", exceptions.size());
Expand All @@ -231,9 +239,9 @@ void runTestLogTruncate(MiniRaftCluster cluster, RaftServer.Division oldLeader,
}
}

static void assertEmptyTransactionContextMap(RaftServer.Division division) {
Assertions.assertTrue(RaftServerTestUtil.getTransactionContextMap(division).isEmpty(),
() -> division.getId() + " TransactionContextMap is non-empty");
static void assertEmptyTransactionContextMap(RaftServer.Division d) {
final Map<TermIndex, MemoizedSupplier<TransactionContext>> map = RaftServerTestUtil.getTransactionContextMap(d);
Assertions.assertTrue(map.isEmpty(), () -> d.getId() + " TransactionContextMap is non-empty: " + map);
}

static void assertEntriesInTransactionContextMap(RaftServer.Division division,
Expand Down

0 comments on commit 2c4e01d

Please sign in to comment.