/// <summary>for snapshot file after deleting the original file.</summary> /// <exception cref="System.Exception"/> public virtual void TestSnapshotPathINodesAfterDeletion() { // Create a snapshot for the dir, and check the inodes for the path // pointing to a snapshot file hdfs.AllowSnapshot(sub1); hdfs.CreateSnapshot(sub1, "s2"); // Delete the original file /TestSnapshot/sub1/file1 hdfs.Delete(file1, false); Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot; { // Resolve the path for the snapshot file // /TestSnapshot/sub1/.snapshot/s2/file1 string snapshotPath = sub1.ToString() + "/.snapshot/s2/file1"; string[] names = INode.GetPathNames(snapshotPath); byte[][] components = INode.GetPathComponents(names); INodesInPath nodesInPath = INodesInPath.Resolve(fsdir.rootDir, components, false); // Length of inodes should be (components.length - 1), since we will ignore // ".snapshot" NUnit.Framework.Assert.AreEqual(nodesInPath.Length(), components.Length - 1); // SnapshotRootIndex should be 3: {root, Testsnapshot, sub1, s2, file1} snapshot = GetSnapshot(nodesInPath, "s2", 3); AssertSnapshot(nodesInPath, true, snapshot, 3); // Check the INode for file1 (snapshot file) INode inode = nodesInPath.GetLastINode(); NUnit.Framework.Assert.AreEqual(file1.GetName(), inode.GetLocalName()); NUnit.Framework.Assert.IsTrue(inode.AsFile().IsWithSnapshot()); } // Check the INodes for path /TestSnapshot/sub1/file1 string[] names_1 = INode.GetPathNames(file1.ToString()); byte[][] components_1 = INode.GetPathComponents(names_1); INodesInPath nodesInPath_1 = INodesInPath.Resolve(fsdir.rootDir, components_1, false ); // The length of inodes should be equal to components.length NUnit.Framework.Assert.AreEqual(nodesInPath_1.Length(), components_1.Length); // The number of non-null elements should be components.length - 1 since // file1 has been deleted NUnit.Framework.Assert.AreEqual(GetNumNonNull(nodesInPath_1), components_1.Length - 1); // The returned nodesInPath should be non-snapshot AssertSnapshot(nodesInPath_1, false, snapshot, -1); // The last INode should be null, and the one before should be associated // with sub1 NUnit.Framework.Assert.IsNull(nodesInPath_1.GetINode(components_1.Length - 1)); NUnit.Framework.Assert.AreEqual(nodesInPath_1.GetINode(components_1.Length - 2).GetFullPathName (), sub1.ToString()); NUnit.Framework.Assert.AreEqual(nodesInPath_1.GetINode(components_1.Length - 3).GetFullPathName (), dir.ToString()); hdfs.DeleteSnapshot(sub1, "s2"); hdfs.DisallowSnapshot(sub1); }
private void AddToParent(INodeDirectory parent, INode child) { if (parent == dir.rootDir && FSDirectory.IsReservedName(child)) { throw new HadoopIllegalArgumentException("File name \"" + child.GetLocalName() + "\" is reserved. Please " + " change the name of the existing file or directory to another " + "name before upgrading to this release."); } // NOTE: This does not update space counts for parents if (!parent.AddChild(child)) { return; } dir.CacheName(child); if (child.IsFile()) { UpdateBlocksMap(child.AsFile(), fsn.GetBlockManager()); } }
/// <summary>for snapshot file while modifying file after snapshot.</summary> /// <exception cref="System.Exception"/> public virtual void TestSnapshotPathINodesAfterModification() { // First check the INode for /TestSnapshot/sub1/file1 string[] names = INode.GetPathNames(file1.ToString()); byte[][] components = INode.GetPathComponents(names); INodesInPath nodesInPath = INodesInPath.Resolve(fsdir.rootDir, components, false); // The number of inodes should be equal to components.length NUnit.Framework.Assert.AreEqual(nodesInPath.Length(), components.Length); // The last INode should be associated with file1 NUnit.Framework.Assert.AreEqual(nodesInPath.GetINode(components.Length - 1).GetFullPathName (), file1.ToString()); // record the modification time of the inode long modTime = nodesInPath.GetINode(nodesInPath.Length() - 1).GetModificationTime (); // Create a snapshot for the dir, and check the inodes for the path // pointing to a snapshot file hdfs.AllowSnapshot(sub1); hdfs.CreateSnapshot(sub1, "s3"); // Modify file1 DFSTestUtil.AppendFile(hdfs, file1, "the content for appending"); // Check the INodes for snapshot of file1 string snapshotPath = sub1.ToString() + "/.snapshot/s3/file1"; names = INode.GetPathNames(snapshotPath); components = INode.GetPathComponents(names); INodesInPath ssNodesInPath = INodesInPath.Resolve(fsdir.rootDir, components, false ); // Length of ssInodes should be (components.length - 1), since we will // ignore ".snapshot" NUnit.Framework.Assert.AreEqual(ssNodesInPath.Length(), components.Length - 1); Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s3 = GetSnapshot(ssNodesInPath , "s3", 3); AssertSnapshot(ssNodesInPath, true, s3, 3); // Check the INode for snapshot of file1 INode snapshotFileNode = ssNodesInPath.GetLastINode(); NUnit.Framework.Assert.AreEqual(snapshotFileNode.GetLocalName(), file1.GetName()); NUnit.Framework.Assert.IsTrue(snapshotFileNode.AsFile().IsWithSnapshot()); // The modification time of the snapshot INode should be the same with the // original INode before modification NUnit.Framework.Assert.AreEqual(modTime, snapshotFileNode.GetModificationTime(ssNodesInPath .GetPathSnapshotId())); // Check the INode for /TestSnapshot/sub1/file1 again names = INode.GetPathNames(file1.ToString()); components = INode.GetPathComponents(names); INodesInPath newNodesInPath = INodesInPath.Resolve(fsdir.rootDir, components, false ); AssertSnapshot(newNodesInPath, false, s3, -1); // The number of inodes should be equal to components.length NUnit.Framework.Assert.AreEqual(newNodesInPath.Length(), components.Length); // The last INode should be associated with file1 int last = components.Length - 1; NUnit.Framework.Assert.AreEqual(newNodesInPath.GetINode(last).GetFullPathName(), file1.ToString()); // The modification time of the INode for file3 should have been changed NUnit.Framework.Assert.IsFalse(modTime == newNodesInPath.GetINode(last).GetModificationTime ()); hdfs.DeleteSnapshot(sub1, "s3"); hdfs.DisallowSnapshot(sub1); }
internal static void AssertINodeFile(INode inode, Path path) { NUnit.Framework.Assert.AreEqual(path.GetName(), inode.GetLocalName()); NUnit.Framework.Assert.AreEqual(typeof(INodeFile), inode.GetType()); }
private static string ToString(INode inode) { return(inode == null ? null : inode.GetLocalName()); }