HDDS-1451 : SCMBlockManager findPipeline and createPipeline are not lock protected. (#799)

* HDDS-1451 : SCMBlockManager findPipeline and createPipeline are not lock protected.

* HDDS-1451 : Address review comments.
This commit is contained in:
avijayanhwx 2019-05-20 13:02:56 -07:00 committed by Anu Engineer
parent 24c53e057a
commit f63300228e

View File

@ -182,18 +182,27 @@ public AllocatedBlock allocateBlock(final long size, ReplicationType type,
pipelineManager pipelineManager
.getPipelines(type, factor, Pipeline.PipelineState.OPEN, .getPipelines(type, factor, Pipeline.PipelineState.OPEN,
excludeList.getDatanodes(), excludeList.getPipelineIds()); excludeList.getDatanodes(), excludeList.getPipelineIds());
Pipeline pipeline; Pipeline pipeline = null;
if (availablePipelines.size() == 0) { if (availablePipelines.size() == 0) {
try { try {
// TODO: #CLUTIL Remove creation logic when all replication types and // TODO: #CLUTIL Remove creation logic when all replication types and
// factors are handled by pipeline creator // factors are handled by pipeline creator
pipeline = pipelineManager.createPipeline(type, factor); pipeline = pipelineManager.createPipeline(type, factor);
} catch (IOException e) { } catch (IOException e) {
LOG.error("Pipeline creation failed for type:{} factor:{}", LOG.warn("Pipeline creation failed for type:{} factor:{}. Retrying " +
type, factor, e); "get pipelines call once.", type, factor, e);
break; availablePipelines = pipelineManager
.getPipelines(type, factor, Pipeline.PipelineState.OPEN,
excludeList.getDatanodes(), excludeList.getPipelineIds());
if (availablePipelines.size() == 0) {
LOG.info("Could not find available pipeline of type:{} and " +
"factor:{} even after retrying", type, factor);
break;
}
} }
} else { }
if (null == pipeline) {
// TODO: #CLUTIL Make the selection policy driven. // TODO: #CLUTIL Make the selection policy driven.
pipeline = availablePipelines pipeline = availablePipelines
.get((int) (Math.random() * availablePipelines.size())); .get((int) (Math.random() * availablePipelines.size()));