@Override public String toString() { final StringBuilder b = new StringBuilder(50); appendStringTo(b); return b.toString(); }
/** * Create array of expected replica locations * (as has been assigned by chooseTargets()). */ public DatanodeStorageInfo[] getExpectedStorageLocations() { int numLocations = getNumExpectedLocations(); DatanodeStorageInfo[] storages = new DatanodeStorageInfo[numLocations]; for (int i = 0; i < numLocations; i++) { storages[i] = replicas[i].getExpectedStorageLocation(); } return storages; }
List<ReplicaUnderConstruction> getStaleReplicas(long genStamp) { List<ReplicaUnderConstruction> staleReplicas = new ArrayList<>(); // Remove replicas with wrong gen stamp. The replica list is unchanged. for (ReplicaUnderConstruction r : replicas) { if (genStamp != r.getGenerationStamp()) { staleReplicas.add(r); } } return staleReplicas; }
for (ReplicaUnderConstruction replica : replicas) { if (replica.isAlive()) { allLiveReplicasTriedAsPrimary = allLiveReplicasTriedAsPrimary && replica.getChosenAsPrimary(); replica.setChosenAsPrimary(false); for (int i = 0; i < replicas.length; i++) { if (!(replicas[i].isAlive() && !replicas[i].getChosenAsPrimary())) { continue; final long lastUpdate = ruc.getExpectedStorageLocation() .getDatanodeDescriptor().getLastUpdateMonotonic(); if (lastUpdate > mostRecentLastUpdate) { primary.getExpectedStorageLocation().getDatanodeDescriptor() .addBlockToBeRecovered(blockInfo); primary.setChosenAsPrimary(true); NameNode.blockStateChangeLog.debug( "BLOCK* {} recovery started, primary={}", this, primary);
if (replicas.length == 0) { replicas = new ReplicaUnderConstruction[1]; replicas[0] = new ReplicaUnderConstruction(reportedBlock, storage, rState); } else { for (int i = 0; i < replicas.length; i++) { DatanodeStorageInfo expected = replicas[i].getExpectedStorageLocation(); if (expected == storage) { replicas[i].setGenerationStamp(reportedBlock.getGenerationStamp()); return; } else if (expected != null && expected.getDatanodeDescriptor() == replicas[i] = new ReplicaUnderConstruction(reportedBlock, storage, rState); return; new ReplicaUnderConstruction[replicas.length + 1]; System.arraycopy(replicas, 0, newReplicas, 0, replicas.length); newReplicas[newReplicas.length - 1] = new ReplicaUnderConstruction( reportedBlock, storage, rState); replicas = newReplicas;
/** Set expected locations */ public void setExpectedLocations(Block block, DatanodeStorageInfo[] targets, BlockType blockType) { if (targets == null) { return; } int numLocations = 0; for (DatanodeStorageInfo target : targets) { if (target != null) { numLocations++; } } this.replicas = new ReplicaUnderConstruction[numLocations]; int offset = 0; for(int i = 0; i < targets.length; i++) { if (targets[i] != null) { // when creating a new striped block we simply sequentially assign block // index to each storage Block replicaBlock = blockType == BlockType.STRIPED ? new Block(block.getBlockId() + i, 0, block.getGenerationStamp()) : block; replicas[offset++] = new ReplicaUnderConstruction(replicaBlock, targets[i], ReplicaState.RBW); } } }
public void appendUCPartsConcise(StringBuilder sb) { sb.append("replicas="); int i = 0; for (ReplicaUnderConstruction r : replicas) { sb.append(r.getExpectedStorageLocation().getDatanodeDescriptor()); if (++i < replicas.length) { sb.append(", "); } } } }
private void appendUCParts(StringBuilder sb) { sb.append("{UCState=").append(blockUCState) .append(", truncateBlock=").append(truncateBlock) .append(", primaryNodeIndex=").append(primaryNodeIndex) .append(", replicas=["); int i = 0; for (ReplicaUnderConstruction r : replicas) { r.appendStringTo(sb); if (++i < replicas.length) { sb.append(", "); } } sb.append("]}"); }
@Override public DatanodeStorageInfo next() { if (!hasNext()) { throw new NoSuchElementException(); } return replicas[index++].getExpectedStorageLocation(); } };
private void removeStaleReplicas(List<ReplicaUnderConstruction> staleReplicas, BlockInfo block) { for (ReplicaUnderConstruction r : staleReplicas) { removeStoredBlock(block, r.getExpectedStorageLocation().getDatanodeDescriptor()); NameNode.blockStateChangeLog .debug("BLOCK* Removing stale replica {}" + " of {}", r, Block.toString(r)); } } /**
/** * when committing a striped block whose size is less than a stripe, we need * to decrease the scheduled block size of the DataNodes that do not store * any internal block. */ void updateStorageScheduledSize(BlockInfoStriped storedBlock) { assert storedBlock.getUnderConstructionFeature() == this; if (replicas.length == 0) { return; } final int dataBlockNum = storedBlock.getDataBlockNum(); final int realDataBlockNum = storedBlock.getRealDataBlockNum(); if (realDataBlockNum < dataBlockNum) { for (ReplicaUnderConstruction replica : replicas) { int index = BlockIdManager.getBlockIndex(replica); if (index >= realDataBlockNum && index < dataBlockNum) { final DatanodeStorageInfo storage = replica.getExpectedStorageLocation(); storage.getDatanodeDescriptor() .decrementBlocksScheduled(storage.getStorageType()); } } } }