linyiqun commented on a change in pull request #1611:
URL: https://github.com/apache/ozone/pull/1611#discussion_r529190587



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
##########
@@ -1166,4 +1172,107 @@ public String getClusterId() {
   public HDDSLayoutVersionManager getLayoutVersionManager() {
     return scmLayoutVersionManager;
   }
+
+  private void waitForAllContainersToClose() {
+    boolean containersFound = true;
+    while (containersFound) {
+      containersFound = false;
+      for (DatanodeDetails datanodeDetails : scmNodeManager.getAllNodes()) {
+        try {
+          for (ContainerID id : scmNodeManager.getContainers(datanodeDetails)) 
{
+            try {
+              final ContainerInfo container = 
containerManager.getContainer(id);
+              if (container.getState() == HddsProtos.LifeCycleState.OPEN ||
+                  container.getState() == HddsProtos.LifeCycleState.CLOSING) {
+                containersFound = true;
+                if (container.getState() == HddsProtos.LifeCycleState.OPEN) {
+                  eventQueue.fireEvent(SCMEvents.CLOSE_CONTAINER, id);
+                }
+              }
+            } catch (ContainerNotFoundException cnfe) {
+              LOG.warn("Container {} is not managed by ContainerManager.",
+                  id, cnfe);
+              continue;
+            }
+          }
+        } catch (NodeNotFoundException e) {
+          continue;
+        }
+      }
+      try {
+        if (containersFound) {
+          LOG.info("Waiting for all containers to close.");
+          Thread.sleep(5000);
+        }
+      } catch (InterruptedException e) {
+        continue;
+      }
+    }
+  }
+
+  private void waitForAllPipelinesToDestroy() throws IOException {
+    boolean pipelineFound = true;
+    while (pipelineFound) {
+      pipelineFound = false;
+      for (Pipeline pipeline : pipelineManager.getPipelines()) {
+        if (pipeline.getPipelineState() != CLOSED) {
+          pipelineFound = true;
+          pipelineManager.finalizeAndDestroyPipeline(pipeline, false);
+        }
+      }
+      try {
+        if (pipelineFound) {
+          LOG.info("Waiting for all pipelines to close.");
+          Thread.sleep(5000);
+        }
+      } catch (InterruptedException e) {
+        continue;
+      }
+    }
+  }
+
+  // This should be called in the context of a separate finalize upgrade 
thread.
+  // This function can block indefinitely till the conditions are met to safely
+  // finalize Upgrade.
+
+  public void preFinalizeUpgrade() throws IOException {
+    /**
+     * Ask pipeline manager to not create any new pipelines. Pipeline
+     * creation will remain frozen until postFinalizeUpgrade().
+     */
+    pipelineManager.freezePipelineCreation();
+

Review comment:
       Can we also reset SCMSafeModeManager#setInSafeMode to true? In some 
scenarios, we alreadt use safemode status check to reject some create type 
operations for new containers/pipelines.




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

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