|
@@ -190,12 +190,23 @@ public class BlockInfoContiguousUnderConstruction extends BlockInfoContiguous {
|
|
|
|
|
|
/** Set expected locations */
|
|
|
public void setExpectedLocations(DatanodeStorageInfo[] targets) {
|
|
|
- int numLocations = targets == null ? 0 : targets.length;
|
|
|
+ if (targets == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int numLocations = 0;
|
|
|
+ for (DatanodeStorageInfo target : targets) {
|
|
|
+ if (target != null) {
|
|
|
+ numLocations++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.replicas = new ArrayList<ReplicaUnderConstruction>(numLocations);
|
|
|
- for(int i = 0; i < numLocations; i++)
|
|
|
+ for(int i = 0; i < targets.length; i++) {
|
|
|
+ // Only store non-null DatanodeStorageInfo.
|
|
|
if (targets[i] != null) {
|
|
|
replicas.add(new ReplicaUnderConstruction(this, targets[i], ReplicaState.RBW));
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -286,10 +297,15 @@ public class BlockInfoContiguousUnderConstruction extends BlockInfoContiguous {
|
|
|
* Initialize lease recovery for this block.
|
|
|
* Find the first alive data-node starting from the previous primary and
|
|
|
* make it primary.
|
|
|
+ * @param recoveryId Recovery ID (new gen stamp)
|
|
|
+ * @param startRecovery Issue recovery command to datanode if true.
|
|
|
*/
|
|
|
- public void initializeBlockRecovery(long recoveryId) {
|
|
|
+ public void initializeBlockRecovery(long recoveryId, boolean startRecovery) {
|
|
|
setBlockUCState(BlockUCState.UNDER_RECOVERY);
|
|
|
blockRecoveryId = recoveryId;
|
|
|
+ if (!startRecovery) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (replicas.size() == 0) {
|
|
|
NameNode.blockStateChangeLog.warn("BLOCK*"
|
|
|
+ " BlockInfoUnderConstruction.initLeaseRecovery:"
|
|
@@ -337,27 +353,33 @@ public class BlockInfoContiguousUnderConstruction extends BlockInfoContiguous {
|
|
|
void addReplicaIfNotPresent(DatanodeStorageInfo storage,
|
|
|
Block block,
|
|
|
ReplicaState rState) {
|
|
|
- Iterator<ReplicaUnderConstruction> it = replicas.iterator();
|
|
|
- while (it.hasNext()) {
|
|
|
- ReplicaUnderConstruction r = it.next();
|
|
|
- DatanodeStorageInfo expectedLocation = r.getExpectedStorageLocation();
|
|
|
- if(expectedLocation == storage) {
|
|
|
- // Record the gen stamp from the report
|
|
|
- r.setGenerationStamp(block.getGenerationStamp());
|
|
|
- return;
|
|
|
- } else if (expectedLocation != null &&
|
|
|
- expectedLocation.getDatanodeDescriptor() ==
|
|
|
- storage.getDatanodeDescriptor()) {
|
|
|
-
|
|
|
- // The Datanode reported that the block is on a different storage
|
|
|
- // than the one chosen by BlockPlacementPolicy. This can occur as
|
|
|
- // we allow Datanodes to choose the target storage. Update our
|
|
|
- // state by removing the stale entry and adding a new one.
|
|
|
- it.remove();
|
|
|
- break;
|
|
|
+ if (replicas == null) {
|
|
|
+ replicas = new ArrayList<ReplicaUnderConstruction>(1);
|
|
|
+ replicas.add(new ReplicaUnderConstruction(block, storage,
|
|
|
+ rState));
|
|
|
+ } else {
|
|
|
+ Iterator<ReplicaUnderConstruction> it = replicas.iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ ReplicaUnderConstruction r = it.next();
|
|
|
+ DatanodeStorageInfo expectedLocation = r.getExpectedStorageLocation();
|
|
|
+ if (expectedLocation == storage) {
|
|
|
+ // Record the gen stamp from the report
|
|
|
+ r.setGenerationStamp(block.getGenerationStamp());
|
|
|
+ return;
|
|
|
+ } else if (expectedLocation != null
|
|
|
+ && expectedLocation.getDatanodeDescriptor() ==
|
|
|
+ storage.getDatanodeDescriptor()) {
|
|
|
+
|
|
|
+ // The Datanode reported that the block is on a different storage
|
|
|
+ // than the one chosen by BlockPlacementPolicy. This can occur as
|
|
|
+ // we allow Datanodes to choose the target storage. Update our
|
|
|
+ // state by removing the stale entry and adding a new one.
|
|
|
+ it.remove();
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ replicas.add(new ReplicaUnderConstruction(block, storage, rState));
|
|
|
}
|
|
|
- replicas.add(new ReplicaUnderConstruction(block, storage, rState));
|
|
|
}
|
|
|
|
|
|
@Override // BlockInfo
|