@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(INodeId.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.getXAttrs(testFileInodePath); fs.listXAttrs(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(); } } }
@Override public long getPreferredBlockSize() { return HeaderFormat.getPreferredBlockSize(header); }
INodeFile extends INodeWithAdditionalFields implements INodeFileAttributes, BlockCollection { @Override public long getPreferredBlockSize() { return HeaderFormat.getPreferredBlockSize(header); } }
INodeFile extends INodeWithAdditionalFields implements INodeFileAttributes, BlockCollection { @Override public long getPreferredBlockSize() { return HeaderFormat.getPreferredBlockSize(header); } INodeFile(long id, byte[] name, PermissionStatus permissions, long mtime,
            long atime, BlockInfo[] blklist, short replication,
            long preferredBlockSize);   INodeFile(long id, byte[] name, PermissionStatus permissions, long mtime,
      long atime, BlockInfo[] blklist, short replication,
      long preferredBlockSize, byte storagePolicyID);  INodeFile(INodeFile that);  INodeFile(INodeFile that, FileDiffList diffs); }
INodeFile extends INodeWithAdditionalFields implements INodeFileAttributes, BlockCollection { @Override public long getPreferredBlockSize() { return HeaderFormat.getPreferredBlockSize(header); } INodeFile(long id, byte[] name, PermissionStatus permissions, long mtime,
            long atime, BlockInfo[] blklist, short replication,
            long preferredBlockSize);   INodeFile(long id, byte[] name, PermissionStatus permissions, long mtime,
      long atime, BlockInfo[] blklist, short replication,
      long preferredBlockSize, byte storagePolicyID);  INodeFile(INodeFile that);  INodeFile(INodeFile that, FileDiffList diffs); static INodeFile valueOf(INode inode, String path
      ); static INodeFile valueOf(INode inode, String path, boolean acceptNull); @Override final boolean isFile(); @Override final INodeFile asFile(); @Override boolean metadataEquals(INodeFileAttributes other); final FileUnderConstructionFeature getFileUnderConstructionFeature(); @Override // BlockCollection boolean isUnderConstruction(); INodeFile toCompleteFile(long mtime); @Override // BlockCollection void setBlock(int index, BlockInfo blk); @Override // BlockCollection, the file should be under construction BlockInfoUnderConstruction setLastBlock(BlockInfo lastBlock,
      DatanodeStorageInfo[] locations); FileWithSnapshotFeature addSnapshotFeature(FileDiffList diffs); final FileWithSnapshotFeature getFileWithSnapshotFeature(); final boolean isWithSnapshot(); @Override String toDetailString(); @Override INodeFileAttributes getSnapshotINode(final int snapshotId); @Override void recordModification(final int latestSnapshotId); FileDiffList getDiffs(); final short getFileReplication(int snapshot); @Override // INodeFileAttributes final short getFileReplication(); @Override // BlockCollection short getBlockReplication(); final void setFileReplication(short replication); final INodeFile setFileReplication(short replication,
      int latestSnapshotId); @Override long getPreferredBlockSize(); @Override byte getLocalStoragePolicyID(); @Override byte getStoragePolicyID(); final void setStoragePolicyID(byte storagePolicyId,
      int latestSnapshotId); @Override long getHeaderLong(); @Override BlockInfo[] getBlocks(); void setBlocks(BlockInfo[] blocks); @Override Quota.Counts cleanSubtree(final int snapshot, int priorSnapshotId,
      final BlocksMapUpdateInfo collectedBlocks,
      final List<INode> removedINodes, final boolean countDiffChange); @Override void destroyAndCollectBlocks(BlocksMapUpdateInfo collectedBlocks,
      final List<INode> removedINodes); @Override String getName(); @Override final Quota.Counts computeQuotaUsage(Quota.Counts counts,
      boolean useCache, int lastSnapshotId); @Override final ContentSummaryComputationContext computeContentSummary(
      final ContentSummaryComputationContext summary); final long computeFileSize(); final long computeFileSize(int snapshotId); final long computeFileSizeNotIncludingLastUcBlock(); final long computeFileSize(boolean includesLastUcBlock,
      boolean usePreferredBlockSize4LastUcBlock); final long diskspaceConsumed(); final long diskspaceConsumed(int lastSnapshotId); @Override BlockInfo getLastBlock(); @Override int numBlocks(); @VisibleForTesting @Override void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
      final int snapshotId); }
INodeFile extends INodeWithAdditionalFields implements INodeFileAttributes, BlockCollection { @Override public long getPreferredBlockSize() { return HeaderFormat.getPreferredBlockSize(header); } INodeFile(long id, byte[] name, PermissionStatus permissions, long mtime,
            long atime, BlockInfo[] blklist, short replication,
            long preferredBlockSize);   INodeFile(long id, byte[] name, PermissionStatus permissions, long mtime,
      long atime, BlockInfo[] blklist, short replication,
      long preferredBlockSize, byte storagePolicyID);  INodeFile(INodeFile that);  INodeFile(INodeFile that, FileDiffList diffs); static INodeFile valueOf(INode inode, String path
      ); static INodeFile valueOf(INode inode, String path, boolean acceptNull); @Override final boolean isFile(); @Override final INodeFile asFile(); @Override boolean metadataEquals(INodeFileAttributes other); final FileUnderConstructionFeature getFileUnderConstructionFeature(); @Override // BlockCollection boolean isUnderConstruction(); INodeFile toCompleteFile(long mtime); @Override // BlockCollection void setBlock(int index, BlockInfo blk); @Override // BlockCollection, the file should be under construction BlockInfoUnderConstruction setLastBlock(BlockInfo lastBlock,
      DatanodeStorageInfo[] locations); FileWithSnapshotFeature addSnapshotFeature(FileDiffList diffs); final FileWithSnapshotFeature getFileWithSnapshotFeature(); final boolean isWithSnapshot(); @Override String toDetailString(); @Override INodeFileAttributes getSnapshotINode(final int snapshotId); @Override void recordModification(final int latestSnapshotId); FileDiffList getDiffs(); final short getFileReplication(int snapshot); @Override // INodeFileAttributes final short getFileReplication(); @Override // BlockCollection short getBlockReplication(); final void setFileReplication(short replication); final INodeFile setFileReplication(short replication,
      int latestSnapshotId); @Override long getPreferredBlockSize(); @Override byte getLocalStoragePolicyID(); @Override byte getStoragePolicyID(); final void setStoragePolicyID(byte storagePolicyId,
      int latestSnapshotId); @Override long getHeaderLong(); @Override BlockInfo[] getBlocks(); void setBlocks(BlockInfo[] blocks); @Override Quota.Counts cleanSubtree(final int snapshot, int priorSnapshotId,
      final BlocksMapUpdateInfo collectedBlocks,
      final List<INode> removedINodes, final boolean countDiffChange); @Override void destroyAndCollectBlocks(BlocksMapUpdateInfo collectedBlocks,
      final List<INode> removedINodes); @Override String getName(); @Override final Quota.Counts computeQuotaUsage(Quota.Counts counts,
      boolean useCache, int lastSnapshotId); @Override final ContentSummaryComputationContext computeContentSummary(
      final ContentSummaryComputationContext summary); final long computeFileSize(); final long computeFileSize(int snapshotId); final long computeFileSizeNotIncludingLastUcBlock(); final long computeFileSize(boolean includesLastUcBlock,
      boolean usePreferredBlockSize4LastUcBlock); final long diskspaceConsumed(); final long diskspaceConsumed(int lastSnapshotId); @Override BlockInfo getLastBlock(); @Override int numBlocks(); @VisibleForTesting @Override void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
      final int snapshotId);  }