bharatviswa504 commented on a change in pull request #2847:
URL: https://github.com/apache/ozone/pull/2847#discussion_r752530129



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineManagerImpl.java
##########
@@ -341,6 +341,9 @@ protected void closeContainersForPipeline(final PipelineID 
pipelineId)
   public void closePipeline(Pipeline pipeline, boolean onTimeout)
       throws IOException {
     PipelineID pipelineID = pipeline.getId();
+    // close containers.
+    closeContainersForPipeline(pipelineID);

Review comment:
       Current logic of closeContainersForpipeline is just firing events, so 
lets say events have not completed and pipeline closed or removed we will be in 
situation like containers open with out a pipeline.
   
   So, I think we should update closeContainersForPipeline as below. 
   With this approach we are making sure containers are in closing before 
pipeline remove/close log in ratis.
   ```
     protected void closeContainersForPipeline(final PipelineID pipelineId)
         throws IOException {
       Set<ContainerID> containerIDs = stateManager.getContainers(pipelineId);
       for (ContainerID containerID : containerIDs) {
         if (scmContext.getScm().getContainerManager()
             .getContainer(containerID).getState()
             == HddsProtos.LifeCycleState.OPEN) {
           try {
             scmContext.getScm().getContainerManager().updateContainerState(
                 containerID, HddsProtos.LifeCycleEvent.FINALIZE);
           } catch (InvalidNodeStateException ex) {
             throw new IOException(ex);
           }
         }
   
         eventPublisher.fireEvent(SCMEvents.CLOSE_CONTAINER, containerID);
       }
     }
   ```
   

##########
File path: 
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java
##########
@@ -650,6 +650,30 @@ public void testAddContainerWithClosedPipeline() throws 
Exception {
             pipelineID + " in closed state"));
   }
 
+  @Test
+  public void testPipelineCloseFlow() throws IOException {
+    GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer
+            .captureLogs(LoggerFactory.getLogger(PipelineManagerImpl.class));
+    PipelineManagerImpl pipelineManager = createPipelineManager(true);
+    Pipeline pipeline = pipelineManager.createPipeline(
+            new RatisReplicationConfig(HddsProtos.ReplicationFactor.THREE));
+    PipelineID pipelineID = pipeline.getId();
+    pipelineManager.addContainerToPipeline(pipelineID, ContainerID.valueOf(1));
+    pipelineManager.closePipeline(pipeline, false);
+
+    String containerExpectedOutput =
+        "Containers closed for pipeline=" + pipeline;
+    String pipelineExpectedOutput =
+        "Pipeline " + pipeline + " moved to CLOSED state";
+    String logOutput = logCapturer.getOutput();
+    assertTrue(logOutput.contains(containerExpectedOutput));
+    assertTrue(logOutput.contains(pipelineExpectedOutput));
+
+    int containerLogIdx = logOutput.indexOf(containerExpectedOutput);

Review comment:
       We can put a log in closeContainers for pipeline, instead of adding 
generic log like mentioning 
   Containers closed for pipeline={}, We can change it as
   LOG.info("Container {} closed for pipeline={}, containerID, pipelineID) we 
can add this to closeContainersForPipeline.




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