HDFS-10569. A bug causes OutOfIndex error in BlockListAsLongs. Contributed by Weiwei Yang.

This commit is contained in:
Kihwal Lee 2016-08-03 15:19:31 -05:00
parent c82745432a
commit 6f63566694
2 changed files with 20 additions and 3 deletions

View File

@ -468,8 +468,8 @@ public long[] getBlockListAsLongs() {
long[] longs = new long[2+values.size()];
longs[0] = finalizedBlocks;
longs[1] = numBlocks - finalizedBlocks;
for (int i=0; i < longs.length; i++) {
longs[i] = values.get(i);
for(int i=0; i<values.size(); i++) {
longs[2+i] = values.get(i);
}
return longs;
}

View File

@ -188,6 +188,20 @@ private void checkReplicas(Map<Long,Replica> expectedReplicas,
assertTrue(reportReplicas.isEmpty());
}
private BlockListAsLongs getBlockList(Replica ... replicas) {
int numBlocks = replicas.length;
List<Long> longs = new ArrayList<Long>(2 + numBlocks);
longs.add(Long.valueOf(numBlocks));
longs.add(0L);
for(Replica r : replicas) {
longs.add(r.getBlockId());
longs.add(r.getBytesOnDisk());
longs.add(r.getGenerationStamp());
}
BlockListAsLongs blockList = BlockListAsLongs.decodeLongs(longs);
return blockList;
}
@Test
public void testCapabilitiesInited() {
NamespaceInfo nsInfo = new NamespaceInfo();
@ -237,7 +251,10 @@ public BlockReportResponseProto answer(InvocationOnMock invocation) {
// back up to prior version and check DN sends old-style BR
request.set(null);
nsInfo.setCapabilities(Capability.UNKNOWN.getMask());
nn.blockReport(reg, "pool", sbr,
BlockListAsLongs blockList = getBlockList(r);
StorageBlockReport[] obp = new StorageBlockReport[] {
new StorageBlockReport(new DatanodeStorage("s1"), blockList) };
nn.blockReport(reg, "pool", obp,
new BlockReportContext(1, 0, System.nanoTime(), 0L, true));
proto = request.get();
assertNotNull(proto);