|
@@ -677,16 +677,16 @@ public class TestFsck {
|
|
|
conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
|
|
|
ErasureCodingPolicy ecPolicy =
|
|
|
ErasureCodingPolicyManager.getSystemDefaultPolicy();
|
|
|
- int numAllUnits = ecPolicy.getNumDataUnits() + ecPolicy.getNumParityUnits();
|
|
|
+ final int dataBlocks = ecPolicy.getNumDataUnits();
|
|
|
+ final int cellSize = ecPolicy.getCellSize();
|
|
|
+ final int numAllUnits = dataBlocks + ecPolicy.getNumParityUnits();
|
|
|
+ int blockSize = 2 * cellSize;
|
|
|
+ conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize);
|
|
|
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(
|
|
|
numAllUnits + 1).build();
|
|
|
- FileSystem fs = null;
|
|
|
String topDir = "/myDir";
|
|
|
- byte[] randomBytes = new byte[3000000];
|
|
|
- int seed = 42;
|
|
|
- new Random(seed).nextBytes(randomBytes);
|
|
|
cluster.waitActive();
|
|
|
- fs = cluster.getFileSystem();
|
|
|
+ DistributedFileSystem fs = cluster.getFileSystem();
|
|
|
util.createFiles(fs, topDir);
|
|
|
// set topDir to EC when it has replicated files
|
|
|
cluster.getFileSystem().getClient().setErasureCodingPolicy(
|
|
@@ -697,11 +697,12 @@ public class TestFsck {
|
|
|
// Open a EC file for writing and do not close for now
|
|
|
Path openFile = new Path(topDir + "/openECFile");
|
|
|
FSDataOutputStream out = fs.create(openFile);
|
|
|
- int writeCount = 0;
|
|
|
- while (writeCount != 300) {
|
|
|
- out.write(randomBytes);
|
|
|
- writeCount++;
|
|
|
- }
|
|
|
+ int blockGroupSize = dataBlocks * blockSize;
|
|
|
+ // data size is more than 1 block group and less than 2 block groups
|
|
|
+ byte[] randomBytes = new byte[2 * blockGroupSize - cellSize];
|
|
|
+ int seed = 42;
|
|
|
+ new Random(seed).nextBytes(randomBytes);
|
|
|
+ out.write(randomBytes);
|
|
|
|
|
|
// make sure the fsck can correctly handle mixed ec/replicated files
|
|
|
runFsck(conf, 0, true, topDir, "-files", "-blocks", "-openforwrite");
|
|
@@ -723,6 +724,27 @@ public class TestFsck {
|
|
|
assertTrue(outStr.contains("Expected_repl=" + numAllUnits));
|
|
|
assertTrue(outStr.contains("Under Construction Block:"));
|
|
|
|
|
|
+ // check reported blockIDs of internal blocks
|
|
|
+ LocatedStripedBlock lsb = (LocatedStripedBlock)fs.getClient()
|
|
|
+ .getLocatedBlocks(openFile.toString(), 0, cellSize * dataBlocks).get(0);
|
|
|
+ long groupId = lsb.getBlock().getBlockId();
|
|
|
+ byte[] indices = lsb.getBlockIndices();
|
|
|
+ DatanodeInfo[] locs = lsb.getLocations();
|
|
|
+ long blockId;
|
|
|
+ for (int i = 0; i < indices.length; i++) {
|
|
|
+ blockId = groupId + indices[i];
|
|
|
+ String str = "blk_" + blockId + ":" + locs[i];
|
|
|
+ assertTrue(outStr.contains(str));
|
|
|
+ }
|
|
|
+
|
|
|
+ // check the output of under-constructed blocks doesn't include the blockIDs
|
|
|
+ String regex = ".*Expected_repl=" + numAllUnits + "(.*)\nStatus:.*";
|
|
|
+ Pattern p = Pattern.compile(regex, Pattern.DOTALL);
|
|
|
+ Matcher m = p.matcher(outStr);
|
|
|
+ assertTrue(m.find());
|
|
|
+ String ucBlockOutput = m.group(1);
|
|
|
+ assertFalse(ucBlockOutput.contains("blk_"));
|
|
|
+
|
|
|
// Close the file
|
|
|
out.close();
|
|
|
|