adoroszlai commented on code in PR #7706:
URL: https://github.com/apache/ozone/pull/7706#discussion_r1920687859


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestStorageContainerManager.java:
##########
@@ -289,153 +339,74 @@ public void testBlockDeletionTransactions() throws 
Exception {
     conf.setInt(ScmConfigKeys.OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 5);
     // Reset container provision size, otherwise only one container
     // is created by default.
-    conf.setInt(ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT,
-        numKeys);
-
-    try (MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(conf)
-        .build()) {
-      cluster.waitForClusterToBeReady();
-      DeletedBlockLog delLog = cluster.getStorageContainerManager()
-          .getScmBlockManager().getDeletedBlockLog();
-      assertEquals(0, delLog.getNumOfValidTransactions());
-
-      Map<String, OmKeyInfo> keyLocations = TestDataUtil.createKeys(cluster, 
numKeys);
-      // Wait for container report
-      Thread.sleep(1000);
-      for (OmKeyInfo keyInfo : keyLocations.values()) {
-        OzoneTestUtils.closeContainers(keyInfo.getKeyLocationVersions(),
-            cluster.getStorageContainerManager());
-      }
-      Map<Long, List<Long>> containerBlocks = createDeleteTXLog(
-          cluster.getStorageContainerManager(),
-          delLog, keyLocations, cluster, conf);
-
-      // Verify a few TX gets created in the TX log.
-      assertThat(delLog.getNumOfValidTransactions()).isGreaterThan(0);
-
-      // Once TXs are written into the log, SCM starts to fetch TX
-      // entries from the log and schedule block deletions in HB interval,
-      // after sometime, all the TX should be proceed and by then
-      // the number of containerBlocks of all known containers will be
-      // empty again.
-      OzoneTestUtils.waitBlockDeleted(cluster.getStorageContainerManager());
-      assertTrue(verifyBlocksWithTxnTable(cluster, conf, containerBlocks));
-      // Continue the work, add some TXs that with known container names,
-      // but unknown block IDs.
-      for (Long containerID : containerBlocks.keySet()) {
-        // Add 2 TXs per container.
-        Map<Long, List<Long>> deletedBlocks = new HashMap<>();
-        List<Long> blocks = new ArrayList<>();
-        blocks.add(RandomUtils.nextLong());
-        blocks.add(RandomUtils.nextLong());
-        deletedBlocks.put(containerID, blocks);
-        addTransactions(cluster.getStorageContainerManager(), delLog,
-            deletedBlocks);
-      }
-
-      // Verify a few TX gets created in the TX log.
-      assertThat(delLog.getNumOfValidTransactions()).isGreaterThan(0);
-
-      // These blocks cannot be found in the container, skip deleting them
-      // eventually these TX will success.
-      GenericTestUtils.waitFor(() -> {
-        try {
-          if (SCMHAUtils.isSCMHAEnabled(cluster.getConf())) {
-            cluster.getStorageContainerManager().getScmHAManager()
-                .asSCMHADBTransactionBuffer().flush();
-          }
-          return delLog.getFailedTransactions(-1, 0).size() == 0;
-        } catch (IOException e) {
-          return false;
-        }
-      }, 1000, 20000);
-    }
+    conf.setInt(ScmConfigKeys.OZONE_SCM_PIPELINE_OWNER_CONTAINER_COUNT, 10 * 
KEY_COUNT);
   }
 
-  @Test
-  public void testOldDNRegistersToReInitialisedSCM() throws Exception {
-    OzoneConfiguration conf = new OzoneConfiguration();
-    conf.setTimeDuration(HDDS_HEARTBEAT_INTERVAL, 1000, TimeUnit.MILLISECONDS);
-    conf.setTimeDuration(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 
3000, TimeUnit.MILLISECONDS);
-
-
-
-    try (MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(conf)
-        .setNumDatanodes(1)
-        .build()) {
-      cluster.waitForClusterToBeReady();
-      HddsDatanodeService datanode = cluster.getHddsDatanodes().get(0);
-      StorageContainerManager scm = cluster.getStorageContainerManager();
-      File dbDir = scm.getScmMetadataStore().getStore().getDbLocation();
-      scm.stop();
-
-      // re-initialise SCM with new clusterID
-
-      GenericTestUtils.deleteDirectory(new 
File(SCMHAUtils.getRatisStorageDir(conf)));
-      GenericTestUtils.deleteDirectory(dbDir);
-      GenericTestUtils.deleteDirectory(
-          new File(scm.getScmStorageConfig().getStorageDir()));
-      String newClusterId = UUID.randomUUID().toString();
-      StorageContainerManager.scmInit(scm.getConfiguration(), newClusterId);
-      scm = HddsTestUtils.getScmSimple(scm.getConfiguration());
-
-      DatanodeStateMachine dsm = datanode.getDatanodeStateMachine();
+  // assumes SCM is already stopped
+  private void testOldDNRegistersToReInitialisedSCM(MiniOzoneCluster cluster) 
throws Exception {
+    HddsDatanodeService datanode = cluster.getHddsDatanodes().get(0);
+
+    // re-initialise SCM with new clusterID
+    String newClusterId = UUID.randomUUID().toString();
+    StorageContainerManager.scmInit(cluster.getConf(), newClusterId);
+    StorageContainerManager scm = 
HddsTestUtils.getScmSimple(cluster.getConf());
+
+    DatanodeStateMachine dsm = datanode.getDatanodeStateMachine();
+    assertEquals(DatanodeStateMachine.DatanodeStates.RUNNING,
+        dsm.getContext().getState());
+    // DN Endpoint State has already gone through GetVersion and Register,
+    // so it will be in HEARTBEAT state.
+    for (EndpointStateMachine endpoint : dsm.getConnectionManager()
+        .getValues()) {
+      assertEquals(EndpointStateMachine.EndPointStates.HEARTBEAT,
+          endpoint.getState());
+    }
+    GenericTestUtils.LogCapturer scmDnHBDispatcherLog =
+        GenericTestUtils.LogCapturer.captureLogs(
+            SCMDatanodeHeartbeatDispatcher.LOG);
+    LogManager.getLogger(HeartbeatEndpointTask.class).setLevel(Level.DEBUG);
+    GenericTestUtils.LogCapturer heartbeatEndpointTaskLog =
+        GenericTestUtils.LogCapturer.captureLogs(HeartbeatEndpointTask.LOG);
+    GenericTestUtils.LogCapturer versionEndPointTaskLog =
+        GenericTestUtils.LogCapturer.captureLogs(VersionEndpointTask.LOG);
+    // Initially empty
+    assertThat(scmDnHBDispatcherLog.getOutput()).isEmpty();
+    assertThat(versionEndPointTaskLog.getOutput()).isEmpty();
+    // start the new SCM
+    try {
+      scm.start();
+      // Initially DatanodeStateMachine will be in Running state
       assertEquals(DatanodeStateMachine.DatanodeStates.RUNNING,

Review Comment:
   Good point, thanks.



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