cchung100m commented on code in PR #11505:
URL: https://github.com/apache/ozone/pull/11505#discussion_r4310289290


##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/ha/TestSCMRatisServerImpl.java:
##########
@@ -224,4 +243,51 @@ public void testGetRatisRolesKeepsHostname() throws 
Exception {
     }
   }
 
+  @Test
+  public void testInitializeSkipEntriesOfStaleGroup() throws Exception {
+    final int port;
+    try (ServerSocket socket = new ServerSocket(0)) {
+      port = socket.getLocalPort();
+    }
+    final OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(ScmConfigKeys.OZONE_SCM_HA_RATIS_STORAGE_DIR, 
tempDir.resolve("ratis").toString());
+    conf.setInt(ScmConfigKeys.OZONE_SCM_RATIS_PORT_KEY, port);
+    final SCMNodeDetails details = new SCMNodeDetails.Builder()
+        .setRpcAddress(new InetSocketAddress("localhost", 0))
+        .setRatisPort(port)
+        .setSCMNodeId("scm1")
+        .build();
+
+    // A previous SCM initialized its group and committed a data entry.
+    final String oldClusterId = "CID-" + UUID.randomUUID();
+    final String oldScmId = UUID.randomUUID().toString();
+    SCMRatisServerImpl.initialize(oldClusterId, oldScmId, details, conf);
+    final RaftGroup oldGroup = 
RaftGroup.valueOf(SCMRatisServerImpl.buildRaftGroupId(oldClusterId),
+        
RaftPeer.newBuilder().setId(RaftPeerId.getRaftPeerId(oldScmId)).setAddress("localhost:"
 + port).build());
+    final RaftProperties properties = RatisUtil.newRaftProperties(conf);
+    try (RaftServer server = 
RaftServer.newBuilder().setServerId(RaftPeerId.getRaftPeerId(oldScmId))
+        .setProperties(properties).setGroup(oldGroup).setStateMachine(new 
BaseStateMachine())
+        .setOption(RaftStorage.StartupOption.RECOVER).build();
+         RaftClient client = 
RaftClient.newBuilder().setProperties(properties).setRaftGroup(oldGroup)
+             .setClientRpc(new GrpcFactory(new 
Parameters()).newRaftClientRpc(ClientId.randomId(), properties))
+             .build()) {
+      server.start();
+      assertTrue(client.io().send(SCMRatisRequest.of(RequestType.CONTAINER, 
"op", new Class<?>[0]).encode())
+          .isSuccess());
+    }
+
+    // The Ratis directory is kept while the SCM is initialized again with a 
new cluster ID and SCM ID.
+    final LogCapturer logs = LogCapturer.captureLogs(
+        
LoggerFactory.getLogger("org.apache.ratis.server.impl.StateMachineUpdater"));
+    final LogCapturer smLogs = LogCapturer.captureLogs(SCMStateMachine.class);
+    try {
+      SCMRatisServerImpl.initialize("CID-" + UUID.randomUUID(), 
UUID.randomUUID().toString(), details, conf);
+
+      assertThat(smLogs.getOutput()).contains("Skipping applyTransaction");

Review Comment:
   Hi @priyeshkaratha 
   
   Thanks, you were right that this could be flaky. The window was not after 
`initialize()` (`RaftServer.close()` joins `StateMachineUpdater` up to the 
committed index), but in the test setup: the stale group's commit index is 
restored from the last persisted metadata entry, and closing the Ratis log 
worker does not drain queued writes. The test now waits for the old log to be 
flushed before closing the first server. The second comment is addressed too: 
the result is now asserted to be `Message.EMPTY`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to