HDDS-1374. ContainerStateMap cannot find container while allocating blocks. (#735)

This commit is contained in:
Bharat Viswanadham 2019-04-16 13:49:29 -07:00 committed by GitHub
parent f2ab2795db
commit 3ac3e50b20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -246,7 +246,17 @@ public ContainerInfo allocateContainer(final ReplicationType type,
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 @@ private void addContainerToDB(ContainerInfo containerInfo)
} 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) {