|
@@ -26,14 +26,18 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Options;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.PathIsNotDirectoryException;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
|
|
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
+import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
|
import org.junit.Test;
|
|
|
|
|
@@ -54,9 +58,9 @@ public class TestINodeFile {
|
|
|
public void testReplication () {
|
|
|
replication = 3;
|
|
|
preferredBlockSize = 128*1024*1024;
|
|
|
- INodeFile inf = new INodeFile(new PermissionStatus(userName, null,
|
|
|
- FsPermission.getDefault()), null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
+ INodeFile inf = new INodeFile(INodeId.GRANDFATHER_INODE_ID,
|
|
|
+ new PermissionStatus(userName, null, FsPermission.getDefault()), null,
|
|
|
+ replication, 0L, 0L, preferredBlockSize);
|
|
|
assertEquals("True has to be returned in this case", replication,
|
|
|
inf.getBlockReplication());
|
|
|
}
|
|
@@ -71,9 +75,9 @@ public class TestINodeFile {
|
|
|
throws IllegalArgumentException {
|
|
|
replication = -1;
|
|
|
preferredBlockSize = 128*1024*1024;
|
|
|
- new INodeFile(new PermissionStatus(userName, null,
|
|
|
- FsPermission.getDefault()), null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
+ new INodeFile(INodeId.GRANDFATHER_INODE_ID, new PermissionStatus(userName,
|
|
|
+ null, FsPermission.getDefault()), null, replication, 0L, 0L,
|
|
|
+ preferredBlockSize);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -84,20 +88,20 @@ public class TestINodeFile {
|
|
|
public void testPreferredBlockSize () {
|
|
|
replication = 3;
|
|
|
preferredBlockSize = 128*1024*1024;
|
|
|
- INodeFile inf = new INodeFile(new PermissionStatus(userName, null,
|
|
|
- FsPermission.getDefault()), null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
- assertEquals("True has to be returned in this case", preferredBlockSize,
|
|
|
- inf.getPreferredBlockSize());
|
|
|
- }
|
|
|
+ INodeFile inf = new INodeFile(INodeId.GRANDFATHER_INODE_ID,
|
|
|
+ new PermissionStatus(userName, null, FsPermission.getDefault()), null,
|
|
|
+ replication, 0L, 0L, preferredBlockSize);
|
|
|
+ assertEquals("True has to be returned in this case", preferredBlockSize,
|
|
|
+ inf.getPreferredBlockSize());
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
public void testPreferredBlockSizeUpperBound () {
|
|
|
replication = 3;
|
|
|
preferredBlockSize = BLKSIZE_MAXVALUE;
|
|
|
- INodeFile inf = new INodeFile(new PermissionStatus(userName, null,
|
|
|
- FsPermission.getDefault()), null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
+ INodeFile inf = new INodeFile(INodeId.GRANDFATHER_INODE_ID,
|
|
|
+ new PermissionStatus(userName, null, FsPermission.getDefault()), null,
|
|
|
+ replication, 0L, 0L, preferredBlockSize);
|
|
|
assertEquals("True has to be returned in this case", BLKSIZE_MAXVALUE,
|
|
|
inf.getPreferredBlockSize());
|
|
|
}
|
|
@@ -112,9 +116,9 @@ public class TestINodeFile {
|
|
|
throws IllegalArgumentException {
|
|
|
replication = 3;
|
|
|
preferredBlockSize = -1;
|
|
|
- new INodeFile(new PermissionStatus(userName, null,
|
|
|
- FsPermission.getDefault()), null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
+ new INodeFile(INodeId.GRANDFATHER_INODE_ID, new PermissionStatus(userName,
|
|
|
+ null, FsPermission.getDefault()), null, replication, 0L, 0L,
|
|
|
+ preferredBlockSize);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -127,10 +131,10 @@ public class TestINodeFile {
|
|
|
throws IllegalArgumentException {
|
|
|
replication = 3;
|
|
|
preferredBlockSize = BLKSIZE_MAXVALUE+1;
|
|
|
- new INodeFile(new PermissionStatus(userName, null,
|
|
|
- FsPermission.getDefault()), null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
- }
|
|
|
+ new INodeFile(INodeId.GRANDFATHER_INODE_ID, new PermissionStatus(userName,
|
|
|
+ null, FsPermission.getDefault()), null, replication, 0L, 0L,
|
|
|
+ preferredBlockSize);
|
|
|
+ }
|
|
|
|
|
|
@Test
|
|
|
public void testGetFullPathName() {
|
|
@@ -139,12 +143,14 @@ public class TestINodeFile {
|
|
|
|
|
|
replication = 3;
|
|
|
preferredBlockSize = 128*1024*1024;
|
|
|
- INodeFile inf = new INodeFile(perms, null, replication,
|
|
|
- 0L, 0L, preferredBlockSize);
|
|
|
+ INodeFile inf = new INodeFile(INodeId.GRANDFATHER_INODE_ID, perms, null,
|
|
|
+ replication, 0L, 0L, preferredBlockSize);
|
|
|
inf.setLocalName("f");
|
|
|
|
|
|
- INodeDirectory root = new INodeDirectory(INodeDirectory.ROOT_NAME, perms);
|
|
|
- INodeDirectory dir = new INodeDirectory("d", perms);
|
|
|
+ INodeDirectory root = new INodeDirectory(INodeId.GRANDFATHER_INODE_ID,
|
|
|
+ INodeDirectory.ROOT_NAME, perms);
|
|
|
+ INodeDirectory dir = new INodeDirectory(INodeId.GRANDFATHER_INODE_ID, "d",
|
|
|
+ perms);
|
|
|
|
|
|
assertEquals("f", inf.getFullPathName());
|
|
|
assertEquals("", inf.getLocalParentDir());
|
|
@@ -242,7 +248,7 @@ public class TestINodeFile {
|
|
|
for (int i = 0; i < nCount; i++) {
|
|
|
PermissionStatus perms = new PermissionStatus(userName, null,
|
|
|
FsPermission.getDefault());
|
|
|
- iNodes[i] = new INodeFile(perms, null, replication, 0L, 0L,
|
|
|
+ iNodes[i] = new INodeFile(i, perms, null, replication, 0L, 0L,
|
|
|
preferredBlockSize);
|
|
|
iNodes[i].setLocalName(fileNamePrefix + Integer.toString(i));
|
|
|
BlockInfo newblock = new BlockInfo(replication);
|
|
@@ -293,10 +299,10 @@ public class TestINodeFile {
|
|
|
}
|
|
|
|
|
|
{//cast from INodeFile
|
|
|
- final INode from = new INodeFile(
|
|
|
- perm, null, replication, 0L, 0L, preferredBlockSize);
|
|
|
-
|
|
|
- //cast to INodeFile, should success
|
|
|
+ final INode from = new INodeFile(INodeId.GRANDFATHER_INODE_ID, perm,
|
|
|
+ null, replication, 0L, 0L, preferredBlockSize);
|
|
|
+
|
|
|
+ //cast to INodeFile, should success
|
|
|
final INodeFile f = INodeFile.valueOf(from, path);
|
|
|
assertTrue(f == from);
|
|
|
|
|
@@ -318,8 +324,9 @@ public class TestINodeFile {
|
|
|
|
|
|
{//cast from INodeFileUnderConstruction
|
|
|
final INode from = new INodeFileUnderConstruction(
|
|
|
- perm, replication, 0L, 0L, "client", "machine", null);
|
|
|
-
|
|
|
+ INodeId.GRANDFATHER_INODE_ID, perm, replication, 0L, 0L, "client",
|
|
|
+ "machine", null);
|
|
|
+
|
|
|
//cast to INodeFile, should success
|
|
|
final INodeFile f = INodeFile.valueOf(from, path);
|
|
|
assertTrue(f == from);
|
|
@@ -338,7 +345,8 @@ public class TestINodeFile {
|
|
|
}
|
|
|
|
|
|
{//cast from INodeDirectory
|
|
|
- final INode from = new INodeDirectory(perm, 0L);
|
|
|
+ final INode from = new INodeDirectory(INodeId.GRANDFATHER_INODE_ID, perm,
|
|
|
+ 0L);
|
|
|
|
|
|
//cast to INodeFile, should fail
|
|
|
try {
|
|
@@ -361,4 +369,47 @@ public class TestINodeFile {
|
|
|
assertTrue(d == from);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Verify root always has inode id 1001 and new formated fsimage has last
|
|
|
+ * allocated inode id 1000. Validate correct lastInodeId is persisted.
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void TestInodeId() throws IOException {
|
|
|
+
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY,
|
|
|
+ DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_DEFAULT);
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
|
|
|
+ .build();
|
|
|
+ cluster.waitActive();
|
|
|
+
|
|
|
+ FSNamesystem fsn = cluster.getNamesystem();
|
|
|
+ long lastId = fsn.getLastInodeId();
|
|
|
+
|
|
|
+ assertTrue(lastId == 1001);
|
|
|
+
|
|
|
+ // Create one directory and the last inode id should increase to 1002
|
|
|
+ FileSystem fs = cluster.getFileSystem();
|
|
|
+ Path path = new Path("/test1");
|
|
|
+ assertTrue(fs.mkdirs(path));
|
|
|
+ assertTrue(fsn.getLastInodeId() == 1002);
|
|
|
+
|
|
|
+ Path filePath = new Path("/test1/file");
|
|
|
+ fs.create(filePath);
|
|
|
+ assertTrue(fsn.getLastInodeId() == 1003);
|
|
|
+
|
|
|
+ // Rename doesn't increase inode id
|
|
|
+ Path renamedPath = new Path("/test2");
|
|
|
+ fs.rename(path, renamedPath);
|
|
|
+ assertTrue(fsn.getLastInodeId() == 1003);
|
|
|
+
|
|
|
+ cluster.restartNameNode();
|
|
|
+ cluster.waitActive();
|
|
|
+ // Make sure empty editlog can be handled
|
|
|
+ cluster.restartNameNode();
|
|
|
+ cluster.waitActive();
|
|
|
+ assertTrue(fsn.getLastInodeId() == 1003);
|
|
|
+ }
|
|
|
}
|