|
@@ -21,6 +21,7 @@ package org.apache.hadoop.hdfs.server.blockmanagement;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
|
import org.apache.hadoop.hdfs.StripedFileTestUtil;
|
|
import org.apache.hadoop.hdfs.StripedFileTestUtil;
|
|
import org.apache.hadoop.hdfs.protocol.Block;
|
|
import org.apache.hadoop.hdfs.protocol.Block;
|
|
@@ -41,6 +42,7 @@ import static org.junit.Assert.fail;
|
|
public class TestLowRedundancyBlockQueues {
|
|
public class TestLowRedundancyBlockQueues {
|
|
|
|
|
|
private final ErasureCodingPolicy ecPolicy;
|
|
private final ErasureCodingPolicy ecPolicy;
|
|
|
|
+ private static AtomicLong mockINodeId = new AtomicLong(0);
|
|
|
|
|
|
public TestLowRedundancyBlockQueues(ErasureCodingPolicy policy) {
|
|
public TestLowRedundancyBlockQueues(ErasureCodingPolicy policy) {
|
|
ecPolicy = policy;
|
|
ecPolicy = policy;
|
|
@@ -52,7 +54,15 @@ public class TestLowRedundancyBlockQueues {
|
|
}
|
|
}
|
|
|
|
|
|
private BlockInfo genBlockInfo(long id) {
|
|
private BlockInfo genBlockInfo(long id) {
|
|
- return new BlockInfoContiguous(new Block(id), (short) 3);
|
|
|
|
|
|
+ return genBlockInfo(id, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private BlockInfo genBlockInfo(long id, boolean isCorruptBlock) {
|
|
|
|
+ BlockInfo bInfo = new BlockInfoContiguous(new Block(id), (short) 3);
|
|
|
|
+ if (!isCorruptBlock) {
|
|
|
|
+ bInfo.setBlockCollectionId(mockINodeId.incrementAndGet());
|
|
|
|
+ }
|
|
|
|
+ return bInfo;
|
|
}
|
|
}
|
|
|
|
|
|
private BlockInfo genStripedBlockInfo(long id, long numBytes) {
|
|
private BlockInfo genStripedBlockInfo(long id, long numBytes) {
|
|
@@ -93,6 +103,41 @@ public class TestLowRedundancyBlockQueues {
|
|
queues.getHighestPriorityECBlockCount());
|
|
queues.getHighestPriorityECBlockCount());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Tests that deleted blocks should not be returned by
|
|
|
|
+ * {@link LowRedundancyBlocks#chooseLowRedundancyBlocks(int, boolean)}.
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testDeletedBlocks() throws Exception {
|
|
|
|
+ int numBlocks = 5;
|
|
|
|
+ LowRedundancyBlocks queues = new LowRedundancyBlocks();
|
|
|
|
+ // create 5 blockinfos. The first one is corrupt.
|
|
|
|
+ for (int ind = 0; ind < numBlocks; ind++) {
|
|
|
|
+ BlockInfo blockInfo = genBlockInfo(ind, ind == 0);
|
|
|
|
+ queues.add(blockInfo, 2, 0, 0, 3);
|
|
|
|
+ }
|
|
|
|
+ List<List<BlockInfo>> blocks;
|
|
|
|
+ // Get two blocks from the queue, but we should only get one because first
|
|
|
|
+ // block is deleted.
|
|
|
|
+ blocks = queues.chooseLowRedundancyBlocks(2, false);
|
|
|
|
+
|
|
|
|
+ assertEquals(1, blocks.get(2).size());
|
|
|
|
+ assertEquals(1, blocks.get(2).get(0).getBlockId());
|
|
|
|
+
|
|
|
|
+ // Get the next blocks - should be ID 2
|
|
|
|
+ blocks = queues.chooseLowRedundancyBlocks(1, false);
|
|
|
|
+ assertEquals(2, blocks.get(2).get(0).getBlockId());
|
|
|
|
+
|
|
|
|
+ // Get the next block, but also reset this time - should be ID 3 returned
|
|
|
|
+ blocks = queues.chooseLowRedundancyBlocks(1, true);
|
|
|
|
+ assertEquals(3, blocks.get(2).get(0).getBlockId());
|
|
|
|
+
|
|
|
|
+ // Get one more block and due to resetting the queue it will be block id 1
|
|
|
|
+ blocks = queues.chooseLowRedundancyBlocks(1, false);
|
|
|
|
+ assertEquals(1, blocks.get(2).get(0).getBlockId());
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testQueuePositionCanBeReset() throws Throwable {
|
|
public void testQueuePositionCanBeReset() throws Throwable {
|
|
LowRedundancyBlocks queues = new LowRedundancyBlocks();
|
|
LowRedundancyBlocks queues = new LowRedundancyBlocks();
|