@Override void addTaskToDatanode(NumberReplicas numberReplicas) { final DatanodeStorageInfo[] targets = getTargets(); assert targets.length > 0; BlockInfoStriped stripedBlk = (BlockInfoStriped) getBlock(); if (hasNotEnoughRack()) { // if we already have all the internal blocks, but not enough racks, // we only need to replicate one internal block to a new rack int sourceIndex = chooseSource4SimpleReplication(); createReplicationWork(sourceIndex, targets[0]); } else if ((numberReplicas.decommissioning() > 0 || numberReplicas.liveEnteringMaintenanceReplicas() > 0) && hasAllInternalBlocks()) { List<Integer> leavingServiceSources = findLeavingServiceSources(); // decommissioningSources.size() should be >= targets.length final int num = Math.min(leavingServiceSources.size(), targets.length); for (int i = 0; i < num; i++) { createReplicationWork(leavingServiceSources.get(i), targets[i]); } } else { targets[0].getDatanodeDescriptor().addBlockToBeErasureCoded( new ExtendedBlock(blockPoolId, stripedBlk), getSrcNodes(), targets, getLiveBlockIndicies(), stripedBlk.getErasureCodingPolicy()); } }