diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java index 6b40f28fc0b1..5db887b6742d 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java @@ -106,9 +106,9 @@ void addContainerToPipeline(PipelineID pipelineID, ContainerID containerID) Pipeline pipeline = getPipeline(pipelineID); if (pipeline.isClosed()) { - throw new IOException(String - .format("Cannot add container to pipeline=%s in closed state", - pipelineID)); + LOG.warn("Adding container {} to pipeline={} in CLOSED state." + + " This happens only for some exceptional cases." + + " Check for the previous exceptions.", containerID, pipelineID); } pipeline2container.get(pipelineID).add(containerID); } diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java index 1ed9b845ac25..c75cb937e5b6 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java @@ -762,7 +762,7 @@ public void testSafeModeUpdatedOnSafemodeExit() throws Exception { } @Test - public void testAddContainerWithClosedPipeline() throws Exception { + public void testAddContainerWithClosedPipelineScmStart() throws Exception { GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer. captureLogs(LoggerFactory.getLogger(PipelineStateMap.class)); SCMHADBTransactionBuffer buffer = new SCMHADBTransactionBufferStub(dbStore); @@ -786,6 +786,30 @@ public void testAddContainerWithClosedPipeline() throws Exception { pipelineID + " in closed state")); } + @Test + public void testAddContainerWithClosedPipeline() throws Exception { + GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer. + captureLogs(LoggerFactory.getLogger(PipelineStateMap.class)); + SCMHADBTransactionBuffer buffer = new SCMHADBTransactionBufferStub(dbStore); + PipelineManagerImpl pipelineManager = + createPipelineManager(true, buffer); + Table pipelineStore = + SCMDBDefinition.PIPELINES.getTable(dbStore); + Pipeline pipeline = pipelineManager.createPipeline( + RatisReplicationConfig + .getInstance(HddsProtos.ReplicationFactor.THREE)); + PipelineID pipelineID = pipeline.getId(); + pipelineManager.addContainerToPipeline(pipelineID, ContainerID.valueOf(1)); + pipelineManager.getStateManager().updatePipelineState( + pipelineID.getProtobuf(), HddsProtos.PipelineState.PIPELINE_CLOSED); + buffer.flush(); + Assertions.assertTrue(pipelineStore.get(pipelineID).isClosed()); + pipelineManager.addContainerToPipeline(pipelineID, + ContainerID.valueOf(2)); + assertTrue(logCapturer.getOutput().contains( + "Adding container #2 to pipeline=" + pipelineID + " in CLOSED state.")); + } + @Test public void testPipelineCloseFlow() throws IOException, TimeoutException { GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer