|
@@ -30,6 +30,8 @@ import org.apache.hadoop.hdfs.server.datanode.DNConf;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.DataBlockScanner;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.DataStorage;
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.FinalizedReplica;
|
|
|
+import org.apache.hadoop.hdfs.server.datanode.ReplicaInfo;
|
|
|
import org.apache.hadoop.hdfs.server.datanode.StorageLocation;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
@@ -46,6 +48,8 @@ import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertNull;
|
|
|
+import static org.junit.Assert.assertSame;
|
|
|
import static org.junit.Assert.fail;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Matchers.anyString;
|
|
@@ -186,4 +190,35 @@ public class TestFsDatasetImpl {
|
|
|
verify(scanner, times(BLOCK_POOL_IDS.length))
|
|
|
.deleteBlocks(anyString(), any(Block[].class));
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDuplicateReplicaResolution() throws IOException {
|
|
|
+ FsVolumeImpl fsv1 = Mockito.mock(FsVolumeImpl.class);
|
|
|
+ FsVolumeImpl fsv2 = Mockito.mock(FsVolumeImpl.class);
|
|
|
+
|
|
|
+ File f1 = new File("d1/block");
|
|
|
+ File f2 = new File("d2/block");
|
|
|
+
|
|
|
+ ReplicaInfo replicaOlder = new FinalizedReplica(1,1,1,fsv1,f1);
|
|
|
+ ReplicaInfo replica = new FinalizedReplica(1,2,2,fsv1,f1);
|
|
|
+ ReplicaInfo replicaSame = new FinalizedReplica(1,2,2,fsv1,f1);
|
|
|
+ ReplicaInfo replicaNewer = new FinalizedReplica(1,3,3,fsv1,f1);
|
|
|
+
|
|
|
+ ReplicaInfo replicaOtherOlder = new FinalizedReplica(1,1,1,fsv2,f2);
|
|
|
+ ReplicaInfo replicaOtherSame = new FinalizedReplica(1,2,2,fsv2,f2);
|
|
|
+ ReplicaInfo replicaOtherNewer = new FinalizedReplica(1,3,3,fsv2,f2);
|
|
|
+
|
|
|
+ // equivalent path so don't remove either
|
|
|
+ assertNull(BlockPoolSlice.selectReplicaToDelete(replicaSame, replica));
|
|
|
+ assertNull(BlockPoolSlice.selectReplicaToDelete(replicaOlder, replica));
|
|
|
+ assertNull(BlockPoolSlice.selectReplicaToDelete(replicaNewer, replica));
|
|
|
+
|
|
|
+ // keep latest found replica
|
|
|
+ assertSame(replica,
|
|
|
+ BlockPoolSlice.selectReplicaToDelete(replicaOtherSame, replica));
|
|
|
+ assertSame(replicaOtherOlder,
|
|
|
+ BlockPoolSlice.selectReplicaToDelete(replicaOtherOlder, replica));
|
|
|
+ assertSame(replica,
|
|
|
+ BlockPoolSlice.selectReplicaToDelete(replicaOtherNewer, replica));
|
|
|
+ }
|
|
|
}
|