예제 #1
0
        public virtual void TestSnapshottableDirs()
        {
            cluster.GetNamesystem().GetSnapshotManager().SetAllowNestedSnapshots(true);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 0, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            MetricsAsserts.AssertCounter("AllowSnapshotOps", 0L, MetricsAsserts.GetMetrics(NnMetrics
                                                                                           ));
            MetricsAsserts.AssertCounter("DisallowSnapshotOps", 0L, MetricsAsserts.GetMetrics
                                             (NnMetrics));
            // Allow snapshots for directories, and check the metrics
            hdfs.AllowSnapshot(sub1);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 1, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            MetricsAsserts.AssertCounter("AllowSnapshotOps", 1L, MetricsAsserts.GetMetrics(NnMetrics
                                                                                           ));
            Path sub2 = new Path(dir, "sub2");
            Path file = new Path(sub2, "file");

            DFSTestUtil.CreateFile(hdfs, file, 1024, Replication, seed);
            hdfs.AllowSnapshot(sub2);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 2, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            MetricsAsserts.AssertCounter("AllowSnapshotOps", 2L, MetricsAsserts.GetMetrics(NnMetrics
                                                                                           ));
            Path subsub1 = new Path(sub1, "sub1sub1");
            Path subfile = new Path(subsub1, "file");

            DFSTestUtil.CreateFile(hdfs, subfile, 1024, Replication, seed);
            hdfs.AllowSnapshot(subsub1);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 3, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            MetricsAsserts.AssertCounter("AllowSnapshotOps", 3L, MetricsAsserts.GetMetrics(NnMetrics
                                                                                           ));
            // Set an already snapshottable directory to snapshottable, should not
            // change the metrics
            hdfs.AllowSnapshot(sub1);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 3, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            // But the number of allowSnapshot operations still increases
            MetricsAsserts.AssertCounter("AllowSnapshotOps", 4L, MetricsAsserts.GetMetrics(NnMetrics
                                                                                           ));
            // Disallow the snapshot for snapshottable directories, then check the
            // metrics again
            hdfs.DisallowSnapshot(sub1);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 2, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            MetricsAsserts.AssertCounter("DisallowSnapshotOps", 1L, MetricsAsserts.GetMetrics
                                             (NnMetrics));
            // delete subsub1, snapshottable directories should be 1
            hdfs.Delete(subsub1, true);
            MetricsAsserts.AssertGauge("SnapshottableDirectories", 1, MetricsAsserts.GetMetrics
                                           (NsMetrics));
            // list all the snapshottable directories
            SnapshottableDirectoryStatus[] status = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(1, status.Length);
            MetricsAsserts.AssertCounter("ListSnapshottableDirOps", 1L, MetricsAsserts.GetMetrics
                                             (NnMetrics));
        }
예제 #2
0
        /// <summary>Test allow-snapshot operation.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestAllowSnapshot()
        {
            string pathStr = sub1.ToString();
            INode  before  = fsdir.GetINode(pathStr);

            // Before a directory is snapshottable
            NUnit.Framework.Assert.IsFalse(before.AsDirectory().IsSnapshottable());
            // After a directory is snapshottable
            Path path = new Path(pathStr);

            hdfs.AllowSnapshot(path);
            {
                INode after = fsdir.GetINode(pathStr);
                NUnit.Framework.Assert.IsTrue(after.AsDirectory().IsSnapshottable());
            }
            hdfs.DisallowSnapshot(path);
            {
                INode after = fsdir.GetINode(pathStr);
                NUnit.Framework.Assert.IsFalse(after.AsDirectory().IsSnapshottable());
            }
        }
예제 #3
0
 public virtual void TearDown()
 {
     if (fs.Exists(new Path("/sub1")))
     {
         if (fs.Exists(new Path("/sub1/.snapshot")))
         {
             foreach (FileStatus st in fs.ListStatus(new Path("/sub1/.snapshot")))
             {
                 fs.DeleteSnapshot(new Path("/sub1"), st.GetPath().GetName());
             }
             fs.DisallowSnapshot(new Path("/sub1"));
         }
         fs.Delete(new Path("/sub1"), true);
     }
 }
예제 #4
0
 /// <summary>Disallow snapshot on a directory.</summary>
 /// <param name="path">The path of the snapshottable directory.</param>
 /// <exception cref="System.IO.IOException"/>
 public virtual void DisallowSnapshot(Path path)
 {
     dfs.DisallowSnapshot(path);
 }
예제 #5
0
        /// <summary>Test listing all the snapshottable directories</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestListSnapshottableDir()
        {
            cluster.GetNamesystem().GetSnapshotManager().SetAllowNestedSnapshots(true);
            // Initially there is no snapshottable directories in the system
            SnapshottableDirectoryStatus[] dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.IsNull(dirs);
            // Make root as snapshottable
            Path root = new Path("/");

            hdfs.AllowSnapshot(root);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(1, dirs.Length);
            NUnit.Framework.Assert.AreEqual(string.Empty, dirs[0].GetDirStatus().GetLocalName
                                                ());
            NUnit.Framework.Assert.AreEqual(root, dirs[0].GetFullPath());
            // Make root non-snaphsottable
            hdfs.DisallowSnapshot(root);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.IsNull(dirs);
            // Make dir1 as snapshottable
            hdfs.AllowSnapshot(dir1);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(1, dirs.Length);
            NUnit.Framework.Assert.AreEqual(dir1.GetName(), dirs[0].GetDirStatus().GetLocalName
                                                ());
            NUnit.Framework.Assert.AreEqual(dir1, dirs[0].GetFullPath());
            // There is no snapshot for dir1 yet
            NUnit.Framework.Assert.AreEqual(0, dirs[0].GetSnapshotNumber());
            // Make dir2 as snapshottable
            hdfs.AllowSnapshot(dir2);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(2, dirs.Length);
            NUnit.Framework.Assert.AreEqual(dir1.GetName(), dirs[0].GetDirStatus().GetLocalName
                                                ());
            NUnit.Framework.Assert.AreEqual(dir1, dirs[0].GetFullPath());
            NUnit.Framework.Assert.AreEqual(dir2.GetName(), dirs[1].GetDirStatus().GetLocalName
                                                ());
            NUnit.Framework.Assert.AreEqual(dir2, dirs[1].GetFullPath());
            // There is no snapshot for dir2 yet
            NUnit.Framework.Assert.AreEqual(0, dirs[1].GetSnapshotNumber());
            // Create dir3
            Path dir3 = new Path("/TestSnapshot3");

            hdfs.Mkdirs(dir3);
            // Rename dir3 to dir2
            hdfs.Rename(dir3, dir2, Options.Rename.Overwrite);
            // Now we only have one snapshottable dir: dir1
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(1, dirs.Length);
            NUnit.Framework.Assert.AreEqual(dir1, dirs[0].GetFullPath());
            // Make dir2 snapshottable again
            hdfs.AllowSnapshot(dir2);
            // Create a snapshot for dir2
            hdfs.CreateSnapshot(dir2, "s1");
            hdfs.CreateSnapshot(dir2, "s2");
            dirs = hdfs.GetSnapshottableDirListing();
            // There are now 2 snapshots for dir2
            NUnit.Framework.Assert.AreEqual(dir2, dirs[1].GetFullPath());
            NUnit.Framework.Assert.AreEqual(2, dirs[1].GetSnapshotNumber());
            // Create sub-dirs under dir1
            Path sub1  = new Path(dir1, "sub1");
            Path file1 = new Path(sub1, "file1");
            Path sub2  = new Path(dir1, "sub2");
            Path file2 = new Path(sub2, "file2");

            DFSTestUtil.CreateFile(hdfs, file1, Blocksize, Replication, seed);
            DFSTestUtil.CreateFile(hdfs, file2, Blocksize, Replication, seed);
            // Make sub1 and sub2 snapshottable
            hdfs.AllowSnapshot(sub1);
            hdfs.AllowSnapshot(sub2);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(4, dirs.Length);
            NUnit.Framework.Assert.AreEqual(dir1, dirs[0].GetFullPath());
            NUnit.Framework.Assert.AreEqual(dir2, dirs[1].GetFullPath());
            NUnit.Framework.Assert.AreEqual(sub1, dirs[2].GetFullPath());
            NUnit.Framework.Assert.AreEqual(sub2, dirs[3].GetFullPath());
            // reset sub1
            hdfs.DisallowSnapshot(sub1);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(3, dirs.Length);
            NUnit.Framework.Assert.AreEqual(dir1, dirs[0].GetFullPath());
            NUnit.Framework.Assert.AreEqual(dir2, dirs[1].GetFullPath());
            NUnit.Framework.Assert.AreEqual(sub2, dirs[2].GetFullPath());
            // Remove dir1, both dir1 and sub2 will be removed
            hdfs.Delete(dir1, true);
            dirs = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(1, dirs.Length);
            NUnit.Framework.Assert.AreEqual(dir2.GetName(), dirs[0].GetDirStatus().GetLocalName
                                                ());
            NUnit.Framework.Assert.AreEqual(dir2, dirs[0].GetFullPath());
        }
예제 #6
0
        /// <summary>
        /// Create a snapshot for /test/foo and create another snapshot for
        /// /test/foo/bar.
        /// </summary>
        /// <remarks>
        /// Create a snapshot for /test/foo and create another snapshot for
        /// /test/foo/bar.  Files created before the snapshots should appear in both
        /// snapshots and the files created after the snapshots should not appear in
        /// any of the snapshots.
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual void TestNestedSnapshots()
        {
            cluster.GetNamesystem().GetSnapshotManager().SetAllowNestedSnapshots(true);
            Path foo   = new Path("/testNestedSnapshots/foo");
            Path bar   = new Path(foo, "bar");
            Path file1 = new Path(bar, "file1");

            DFSTestUtil.CreateFile(hdfs, file1, Blocksize, Replication, Seed);
            Print("create file " + file1);
            string s1name = "foo-s1";
            Path   s1path = SnapshotTestHelper.GetSnapshotRoot(foo, s1name);

            hdfs.AllowSnapshot(foo);
            Print("allow snapshot " + foo);
            hdfs.CreateSnapshot(foo, s1name);
            Print("create snapshot " + s1name);
            string s2name = "bar-s2";
            Path   s2path = SnapshotTestHelper.GetSnapshotRoot(bar, s2name);

            hdfs.AllowSnapshot(bar);
            Print("allow snapshot " + bar);
            hdfs.CreateSnapshot(bar, s2name);
            Print("create snapshot " + s2name);
            Path file2 = new Path(bar, "file2");

            DFSTestUtil.CreateFile(hdfs, file2, Blocksize, Replication, Seed);
            Print("create file " + file2);
            AssertFile(s1path, s2path, file1, true, true, true);
            AssertFile(s1path, s2path, file2, true, false, false);
            //test root
            string rootStr  = "/";
            Path   rootPath = new Path(rootStr);

            hdfs.AllowSnapshot(rootPath);
            Print("allow snapshot " + rootStr);
            Path rootSnapshot = hdfs.CreateSnapshot(rootPath);

            Print("create snapshot " + rootSnapshot);
            hdfs.DeleteSnapshot(rootPath, rootSnapshot.GetName());
            Print("delete snapshot " + rootSnapshot);
            hdfs.DisallowSnapshot(rootPath);
            Print("disallow snapshot " + rootStr);
            //change foo to non-snapshottable
            hdfs.DeleteSnapshot(foo, s1name);
            hdfs.DisallowSnapshot(foo);
            //test disallow nested snapshots
            cluster.GetNamesystem().GetSnapshotManager().SetAllowNestedSnapshots(false);
            try
            {
                hdfs.AllowSnapshot(rootPath);
                NUnit.Framework.Assert.Fail();
            }
            catch (SnapshotException se)
            {
                AssertNestedSnapshotException(se, "subdirectory");
            }
            try
            {
                hdfs.AllowSnapshot(foo);
                NUnit.Framework.Assert.Fail();
            }
            catch (SnapshotException se)
            {
                AssertNestedSnapshotException(se, "subdirectory");
            }
            Path sub1Bar = new Path(bar, "sub1");
            Path sub2Bar = new Path(sub1Bar, "sub2");

            hdfs.Mkdirs(sub2Bar);
            try
            {
                hdfs.AllowSnapshot(sub1Bar);
                NUnit.Framework.Assert.Fail();
            }
            catch (SnapshotException se)
            {
                AssertNestedSnapshotException(se, "ancestor");
            }
            try
            {
                hdfs.AllowSnapshot(sub2Bar);
                NUnit.Framework.Assert.Fail();
            }
            catch (SnapshotException se)
            {
                AssertNestedSnapshotException(se, "ancestor");
            }
        }