62 lines
2.1 KiB
Diff
62 lines
2.1 KiB
Diff
# UNDF: UNDF-2026-000000096
|
|
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/PendingReconstructionBlocks.java
|
|
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/PendingReconstructionBlocks.java
|
|
@@ -22,9 +22,11 @@ import java.io.PrintWriter;
|
|
import java.sql.Time;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
+import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
+import java.util.LinkedHashSet;
|
|
|
|
/**
|
|
* PendingReconstructionBlocks does the bookkeeping of all
|
|
@@ -208,22 +210,22 @@ class PendingReconstructionBlocks {
|
|
static class PendingBlockInfo {
|
|
private long timeStamp;
|
|
- private final List<DatanodeStorageInfo> targets;
|
|
+ private final LinkedHashSet<DatanodeStorageInfo> targets;
|
|
|
|
PendingBlockInfo(DatanodeStorageInfo[] targets) {
|
|
this.timeStamp = monotonicNow();
|
|
- this.targets = targets == null ? new ArrayList<DatanodeStorageInfo>()
|
|
- : new ArrayList<>(Arrays.asList(targets));
|
|
+ this.targets = targets == null ? new LinkedHashSet<>()
|
|
+ : new LinkedHashSet<>(Arrays.asList(targets));
|
|
}
|
|
|
|
long getTimeStamp() {
|
|
return timeStamp;
|
|
}
|
|
|
|
void setTimeStamp() {
|
|
timeStamp = monotonicNow();
|
|
}
|
|
|
|
void incrementReplicas(DatanodeStorageInfo... newTargets) {
|
|
if (newTargets != null) {
|
|
for (DatanodeStorageInfo newTarget : newTargets) {
|
|
- if (!targets.contains(newTarget)) {
|
|
- targets.add(newTarget);
|
|
- }
|
|
+ targets.add(newTarget); // LinkedHashSet.add() is O(1) — dedup implicit
|
|
}
|
|
}
|
|
}
|
|
|
|
void decrementReplicas(DatanodeStorageInfo dn) {
|
|
Iterator<DatanodeStorageInfo> iterator = targets.iterator();
|
|
@@ -254,7 +256,7 @@ class PendingReconstructionBlocks {
|
|
int getNumReplicas() {
|
|
return targets.size();
|
|
}
|
|
|
|
- List<DatanodeStorageInfo> getTargets() {
|
|
- return targets;
|
|
+ List<DatanodeStorageInfo> getTargets() {
|
|
+ return new ArrayList<>(targets);
|
|
}
|
|
}
|