HDFS-1776 Bug in Bug in Concat code. Contributed by Bharath Mundlapudi

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1150247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dmytro Molkov 2011-07-24 01:43:05 +00:00
parent 598b85c9e2
commit c316d43a0a
3 changed files with 56 additions and 1 deletions

View File

@ -879,6 +879,8 @@ Trunk (unreleased changes)
HDFS-2114. re-commission of a decommissioned node does not delete
excess replicas. (John George via mattf)
HDFS-1776. Bug in Concat code. (Bharath Mundlapudi via Dmytro Molkov)
Release 0.22.0 - Unreleased
INCOMPATIBLE CHANGES

View File

@ -127,7 +127,7 @@ public class INodeFile extends INode {
size += in.blocks.length;
}
for(BlockInfo bi: this.blocks) {
for(BlockInfo bi: newlist) {
bi.setINode(this);
}
this.blocks = newlist;

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.permission.PermissionStatus;
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
import org.junit.Test;
@ -150,4 +151,56 @@ public class TestINodeFile {
assertEquals(Path.SEPARATOR, root.getLocalParentDir());
}
@Test
public void testAppendBlocks() {
INodeFile origFile = createINodeFiles(1, "origfile")[0];
assertEquals("Number of blocks didn't match", origFile.numBlocks(), 1L);
INodeFile[] appendFiles = createINodeFiles(4, "appendfile");
origFile.appendBlocks(appendFiles, getTotalBlocks(appendFiles));
assertEquals("Number of blocks didn't match", origFile.numBlocks(), 5L);
for(int i=0; i< origFile.numBlocks(); i++) {
assertSame("INodeFiles didn't Match", origFile, origFile.getBlocks()[i].getINode());
}
}
/**
* Gives the count of blocks for a given number of files
* @param files Array of INode files
* @return total count of blocks
*/
private int getTotalBlocks(INodeFile[] files) {
int nBlocks=0;
for(int i=0; i < files.length; i++) {
nBlocks += files[i].numBlocks();
}
return nBlocks;
}
/**
* Creates the required number of files with one block each
* @param nCount Number of INodes to create
* @return Array of INode files
*/
private INodeFile[] createINodeFiles(int nCount, String fileNamePrefix) {
if(nCount <= 0)
return new INodeFile[1];
replication = 3;
preferredBlockSize = 128 * 1024 * 1024;
INodeFile[] iNodes = new INodeFile[nCount];
for (int i = 0; i < nCount; i++) {
PermissionStatus perms = new PermissionStatus(userName, null,
FsPermission.getDefault());
iNodes[i] = new INodeFile(perms, null, replication, 0L, 0L,
preferredBlockSize);
iNodes[i].setLocalName(fileNamePrefix + Integer.toString(i));
BlockInfo newblock = new BlockInfo(replication);
iNodes[i].addBlock(newblock);
}
return iNodes;
}
}