INodeFile extends INodeWithAdditionalFields implements BlockCollection { @Override public long getPreferredBlockSize() { return HeaderFormat.getPreferredBlockSize(header); } INodeFile(long id, PermissionStatus permissions, BlockInfoContiguous[] blklist,
      short replication, long modificationTime, long atime,
      long preferredBlockSize, byte storagePolicyID);  INodeFile(long id, PermissionStatus permissions, BlockInfoContiguous[] blklist,
      short replication, long modificationTime, long atime,
      long preferredBlockSize, byte storagePolicyID, boolean inTree);  INodeFile(long id, PermissionStatus permissions, long header,
      long modificationTime, long atime, boolean isFileStoredInDB, byte storagepolicy, boolean inTree);  INodeFile(INodeFile other); static INodeFile valueOf(INode inode, String path
      ); static INodeFile valueOf(INode inode, String path, boolean acceptNull); @Override final boolean isFile(); @Override final INodeFile asFile(); final FileUnderConstructionFeature getFileUnderConstructionFeature(); @Override // BlockCollection boolean isUnderConstruction(); @Override short getBlockReplication(); @Override byte getStoragePolicyID(); @Override long getPreferredBlockSize(); @Override BlockInfoContiguous getBlock(int index); @Override BlockInfoContiguous[] getBlocks(); void storeFileDataInDB(byte[] data); byte[] getFileDataInDB(); void deleteFileDataStoredInDB(); void setBlock(int idx, BlockInfoContiguous blk); @Override void destroyAndCollectBlocks(BlockStoragePolicySuite bsps,
      BlocksMapUpdateInfo collectedBlocks, final List<INode> removedINodes); @Override String getName(); @Override final ContentSummaryComputationContext computeContentSummary(
      final ContentSummaryComputationContext summary); final long computeFileSizeNotIncludingLastUcBlock(); long computeFileSize(); final long computeFileSize(boolean includesLastUcBlock,
      boolean usePreferredBlockSize4LastUcBlock); final long storagespaceConsumed(); final long storagespaceConsumedNoReplication(); @Override BlockInfoContiguous getLastBlock(); @Override int numBlocks(); INodeFile toUnderConstruction(String clientName, String clientMachine); INodeFile toCompleteFile(long mtime); @Override BlockInfoContiguousUnderConstruction setLastBlock(
      BlockInfoContiguous lastBlock, DatanodeStorageInfo[] locations); void removeBlock(BlockInfoContiguous block); BlockInfoContiguous findMaxBlk(); int getGenerationStamp(); void setGenerationStampNoPersistence(int generationStamp); int nextGenerationStamp(); long getSize(); boolean isFileStoredInDB(); void setFileStoredInDB(boolean isFileStoredInDB); void setFileStoredInDBNoPersistence(boolean isFileStoredInDB); void setSizeNoPersistence(long size); void setSize(long size); void recomputeFileSize(); @Override INode cloneInode(); long collectBlocksBeyondMax(final long max,
      final BlocksMapUpdateInfo collectedBlocks);  }
@Test public void testPreferredBlockSize() throws IOException { replication = 3; preferredBlockSize = 128 * 1024 * 1024; INodeFile inf = createINodeFile(replication, preferredBlockSize); assertEquals("True has to be returned in this case", preferredBlockSize, inf.getPreferredBlockSize()); }
@Test public void testPreferredBlockSizeUpperBound() throws IOException { replication = 3; preferredBlockSize = BLKSIZE_MAXVALUE; INodeFile inf = createINodeFile(replication, preferredBlockSize); assertEquals("True has to be returned in this case", BLKSIZE_MAXVALUE, inf.getPreferredBlockSize()); }
@Test public void testInodeIdBasedPaths() throws Exception { Configuration conf = new Configuration(); conf.setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_DEFAULT); conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem fs = cluster.getFileSystem(); NamenodeProtocols nnRpc = cluster.getNameNodeRpc(); Path baseDir = getInodePath(INode.ROOT_INODE_ID, "testInodeIdBasedPaths"); Path baseDirRegPath = new Path("/testInodeIdBasedPaths"); fs.mkdirs(baseDir); fs.exists(baseDir); long baseDirFileId = nnRpc.getFileInfo(baseDir.toString()).getFileId(); Path testFileInodePath = getInodePath(baseDirFileId, "test1"); Path testFileRegularPath = new Path(baseDir, "test1"); final int testFileBlockSize = 1024; FileSystemTestHelper.createFile(fs, testFileInodePath, 1, testFileBlockSize); assertTrue(fs.exists(testFileInodePath)); FsPermission perm = new FsPermission((short) 0666); fs.setPermission(testFileInodePath, perm); FileStatus fileStatus = fs.getFileStatus(testFileInodePath); assertEquals(perm, fileStatus.getPermission()); fs.setOwner(testFileInodePath, fileStatus.getOwner(), fileStatus.getGroup()); fs.setTimes(testFileInodePath, 0, 0); fileStatus = fs.getFileStatus(testFileInodePath); assertEquals(0, fileStatus.getModificationTime()); assertEquals(0, fileStatus.getAccessTime()); fs.setReplication(testFileInodePath, (short) 3); fileStatus = fs.getFileStatus(testFileInodePath); assertEquals(3, fileStatus.getReplication()); fs.setReplication(testFileInodePath, (short) 1); assertEquals(testFileBlockSize, nnRpc.getPreferredBlockSize(testFileInodePath.toString())); { fs.isFileClosed(testFileInodePath); fs.getAclStatus(testFileInodePath); fs.access(testFileInodePath, FsAction.READ_WRITE); } String invalidTarget = new Path(baseDir, "invalidTarget").toString(); String link = new Path(baseDir, "link").toString(); testInvalidSymlinkTarget(nnRpc, invalidTarget, link); String validTarget = "/validtarget"; testValidSymlinkTarget(nnRpc, validTarget, link); fs.append(testFileInodePath); fs.recoverLease(testFileInodePath); LocatedBlocks l1 = nnRpc.getBlockLocations(testFileInodePath.toString(), 0, Long.MAX_VALUE); LocatedBlocks l2 = nnRpc.getBlockLocations(testFileRegularPath.toString(), 0, Long.MAX_VALUE); checkEquals(l1, l2); Path renameDst = getInodePath(baseDirFileId, "test2"); fileStatus = fs.getFileStatus(testFileInodePath); fs.rename(testFileInodePath, renameDst); fs.rename(renameDst, testFileInodePath); assertEquals(fileStatus, fs.getFileStatus(testFileInodePath)); fs.rename(testFileInodePath, renameDst, Rename.OVERWRITE); fs.rename(renameDst, testFileInodePath, Rename.OVERWRITE); assertEquals(fileStatus, fs.getFileStatus(testFileInodePath)); assertEquals(fs.getContentSummary(testFileRegularPath).toString(), fs.getContentSummary(testFileInodePath).toString()); checkEquals(fs.listFiles(baseDirRegPath, false), fs.listFiles(baseDir, false)); fs.delete(testFileInodePath, true); assertFalse(fs.exists(testFileInodePath)); } finally { if (cluster != null) { cluster.shutdown(); } } }