FSDirectory implements Closeable { INode getInode(final long id) throws IOException { return EntityManager.find(INode.Finder.ByINodeIdFTIS, id); } FSDirectory(FSNamesystem ns, Configuration conf); FSNamesystem getFSNamesystem(); BlockStoragePolicySuite getBlockStoragePolicySuite(); @Override void close(); EnumCounters<StorageType> getStorageTypeDeltas(byte storagePolicyID,
      long dsDelta, short oldRep, short newRep); @VisibleForTesting long getYieldCount(); static boolean isReservedName(INode inode); static boolean isReservedName(String src); final void addToInodeMap(INode inode); final void removeFromInodeMap(List<? extends INode> inodes); INodesInPath getINodesInPath4Write(String src); INode getINode4Write(String src); INodesInPath getINodesInPath(String path, boolean resolveLink); INode getINode(String src); INodeDirectory getRootDir(); boolean isQuotaEnabled(); INodeDirectory createRoot(
      final PermissionStatus ps, final boolean overwrite); boolean hasChildren(final long parentId, final boolean areChildrenRandomlyPartitioned); final static String DOT_RESERVED_STRING; final static String DOT_RESERVED_PATH_PREFIX; final static byte[] DOT_RESERVED; final static String DOT_INODES_STRING; final static byte[] DOT_INODES; @VisibleForTesting
  final EncryptionZoneManager ezManager; }
@Test public void testDumpTree() throws Exception { HopsTransactionalRequestHandler verifyFileBlocksHandler = new HopsTransactionalRequestHandler( HDFSOperationType.VERIFY_FILE_BLOCKS, dir.toString()) { @Override public void acquireLock(TransactionLocks locks) throws IOException { LockFactory lf = LockFactory.getInstance(); INodeLock il = lf.getINodeLock(TransactionLockTypes.INodeLockType.WRITE_ON_TARGET_AND_PARENT, TransactionLockTypes.INodeResolveType.PATH_AND_ALL_CHILDREN_RECURSIVELY, dir.toString()) .setNameNodeID(cluster.getNameNode().getId()) .setActiveNameNodes(cluster.getNameNode().getActiveNameNodes().getActiveNodes()); locks.add(il).add(lf.getLeaseLockAllPaths(TransactionLockTypes.LockType.WRITE, leaseCreationLockRows)) .add(lf.getLeasePathLock(TransactionLockTypes.LockType.READ_COMMITTED)) .add(lf.getBlockLock()).add( lf.getBlockRelated(LockFactory.BLK.RE, LockFactory.BLK.CR, LockFactory.BLK.UC, LockFactory.BLK.UR, LockFactory.BLK.PE, LockFactory.BLK.IV)); } @Override public Object performTask() throws StorageException, IOException { final INode root = fsdir.getINode(dir.toString()); LOG.info("Original tree"); final StringBuffer b1 = root.dumpTreeRecursively(); System.out.println("b1=" + b1); final BufferedReader in = new BufferedReader(new StringReader(b1.toString())); String line = in.readLine(); checkClassName(line); for (; (line = in.readLine()) != null;) { line = line.trim(); assertTrue(line.startsWith(INodeDirectory.DUMPTREE_LAST_ITEM) || line.startsWith(INodeDirectory.DUMPTREE_EXCEPT_LAST_ITEM)); checkClassName(line); } return b1; } }; final StringBuffer b1 = (StringBuffer) verifyFileBlocksHandler.handle(); LOG.info("Create a new file " + file4); DFSTestUtil.createFile(hdfs, file4, 1024, REPLICATION, seed); verifyFileBlocksHandler = new HopsTransactionalRequestHandler( HDFSOperationType.VERIFY_FILE_BLOCKS, dir.toString()) { @Override public void acquireLock(TransactionLocks locks) throws IOException { LockFactory lf = LockFactory.getInstance(); INodeLock il = lf.getINodeLock(TransactionLockTypes.INodeLockType.WRITE_ON_TARGET_AND_PARENT, TransactionLockTypes.INodeResolveType.PATH_AND_ALL_CHILDREN_RECURSIVELY, dir.toString()) .setNameNodeID(cluster.getNameNode().getId()) .setActiveNameNodes(cluster.getNameNode().getActiveNameNodes().getActiveNodes()); locks.add(il).add(lf.getLeaseLockAllPaths(TransactionLockTypes.LockType.WRITE, leaseCreationLockRows)) .add(lf.getLeasePathLock(TransactionLockTypes.LockType.READ_COMMITTED)) .add(lf.getBlockLock()).add( lf.getBlockRelated(LockFactory.BLK.RE, LockFactory.BLK.CR, LockFactory.BLK.UC, LockFactory.BLK.UR, LockFactory.BLK.PE, LockFactory.BLK.IV)); } @Override public Object performTask() throws StorageException, IOException { final INode root = fsdir.getINode(dir.toString()); final StringBuffer b2 = root.dumpTreeRecursively(); System.out.println("b2=" + b2); int i = 0; int j = b1.length() - 1; for (; b1.charAt(i) == b2.charAt(i); i++); int k = b2.length() - 1; for (; b1.charAt(j) == b2.charAt(k); j--, k--); final String diff = b2.substring(i, k + 1); System.out.println("i=" + i + ", j=" + j + ", k=" + k); System.out.println("diff=" + diff); Assert.assertTrue(i > j); Assert.assertTrue(diff.contains(file4.getName())); return null; } }; verifyFileBlocksHandler.handle(); }
@Test public void testINodeXAttrsLimit() throws Exception { String testFile = file1.toString(); XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(new byte[]{0x31, 0x32, 0x33}).build(); XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a2").setValue(new byte[]{0x31, 0x31, 0x31}).build(); addXAttr(testFile, xAttr1); addXAttr(testFile, xAttr2); XAttr newXAttr = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.SYSTEM). setName("a3").setValue(new byte[]{0x33, 0x33, 0x33}).build(); addXAttr(testFile, newXAttr); INode inodeFile = TestUtil.getINode(fsn.getNameNode(), file1); Assert.assertEquals(inodeFile.getNumUserXAttrs(), 2); Assert.assertEquals(inodeFile.getNumSysXAttrs(), 1); XAttr newXAttr1 = (new XAttr.Builder()).setNameSpace( XAttr.NameSpace.TRUSTED).setName("a4"). setValue(new byte[]{0x34, 0x34, 0x34}).build(); try { addXAttr(testFile, newXAttr1); fail("Setting user visible xattr on inode should fail if " + "reaching limit."); } catch (IOException e) { GenericTestUtils.assertExceptionContains("Cannot add additional XAttr " + "to inode, would exceed limit", e); } }
@Test public void testSysXAttrsLimit() throws Exception { String testFile = file1.toString(); int maxNumXAttrs = XAttrStorage.getMaxNumberOfSysXAttrPerInode(); List<XAttr> xAttrs =generateXAttrs(maxNumXAttrs); addXAttr(testFile, xAttrs, EnumSet.of(XAttrSetFlag.CREATE)); INode inodeFile = TestUtil.getINode(fsn.getNameNode(), file1); Assert.assertEquals(inodeFile.getNumUserXAttrs(), 0); Assert.assertEquals(inodeFile.getNumSysXAttrs(), maxNumXAttrs); XAttr newXAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER). setName("a1").setValue(new byte[]{0x31, 0x32, 0x33}).build(); addXAttr(testFile, newXAttr1); inodeFile = TestUtil.getINode(fsn.getNameNode(), file1); Assert.assertEquals(inodeFile.getNumUserXAttrs(), 1); Assert.assertEquals(inodeFile.getNumSysXAttrs(), maxNumXAttrs); XAttr newXAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.SYSTEM). setName("as").setValue(new byte[]{0x34, 0x35, 0x36}).build(); try { addXAttr(testFile, newXAttr2); fail("Setting system xattr on inode should fail if " + "reaching limit."); } catch (IOException e) { GenericTestUtils.assertExceptionContains("Cannot add additional " + "System XAttr to inode, would exceed limit", e); } }