From 3ac3e50b207e27c69e26669c47b1642827c76db0 Mon Sep 17 00:00:00 2001 From: Bharat Viswanadham Date: Tue, 16 Apr 2019 13:49:29 -0700 Subject: [PATCH] HDDS-1374. ContainerStateMap cannot find container while allocating blocks. (#735) --- .../hdds/scm/container/SCMContainerManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java index 1fa839567da..80d7ec10e0c 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/SCMContainerManager.java @@ -246,7 +246,17 @@ public class SCMContainerManager implements ContainerManager { containerStateManager.allocateContainer(pipelineManager, type, replicationFactor, owner); // Add container to DB. - addContainerToDB(containerInfo); + try { + addContainerToDB(containerInfo); + } catch (IOException ex) { + // When adding to DB failed, we are removing from containerStateMap. + // We should also remove from pipeline2Container Map in + // PipelineStateManager. + pipelineManager.removeContainerFromPipeline( + containerInfo.getPipelineID(), + new ContainerID(containerInfo.getContainerID())); + throw ex; + } return containerInfo; } finally { lock.unlock(); @@ -440,6 +450,8 @@ public class SCMContainerManager implements ContainerManager { } catch (IOException ex) { // If adding to containerStore fails, we should remove the container // from in-memory map. + LOG.error("Add Container to DB failed for ContainerID #{}", + containerInfo.getContainerID()); try { containerStateManager.removeContainer(containerInfo.containerID()); } catch (ContainerNotFoundException cnfe) {