public virtual void TestClearQuota()
        {
            Path dir = new Path("/TestSnapshot");

            hdfs.Mkdirs(dir);
            hdfs.AllowSnapshot(dir);
            hdfs.SetQuota(dir, HdfsConstants.QuotaDontSet, HdfsConstants.QuotaDontSet);
            INodeDirectory dirNode = fsdir.GetINode4Write(dir.ToString()).AsDirectory();

            NUnit.Framework.Assert.IsTrue(dirNode.IsSnapshottable());
            NUnit.Framework.Assert.AreEqual(0, dirNode.GetDiffs().AsList().Count);
            hdfs.SetQuota(dir, HdfsConstants.QuotaDontSet - 1, HdfsConstants.QuotaDontSet - 1
                          );
            dirNode = fsdir.GetINode4Write(dir.ToString()).AsDirectory();
            NUnit.Framework.Assert.IsTrue(dirNode.IsSnapshottable());
            NUnit.Framework.Assert.AreEqual(0, dirNode.GetDiffs().AsList().Count);
            hdfs.SetQuota(dir, HdfsConstants.QuotaReset, HdfsConstants.QuotaReset);
            dirNode = fsdir.GetINode4Write(dir.ToString()).AsDirectory();
            NUnit.Framework.Assert.IsTrue(dirNode.IsSnapshottable());
            NUnit.Framework.Assert.AreEqual(0, dirNode.GetDiffs().AsList().Count);
            // allow snapshot on dir and create snapshot s1
            SnapshotTestHelper.CreateSnapshot(hdfs, dir, "s1");
            // clear quota of dir
            hdfs.SetQuota(dir, HdfsConstants.QuotaReset, HdfsConstants.QuotaReset);
            // dir should still be a snapshottable directory
            dirNode = fsdir.GetINode4Write(dir.ToString()).AsDirectory();
            NUnit.Framework.Assert.IsTrue(dirNode.IsSnapshottable());
            NUnit.Framework.Assert.AreEqual(1, dirNode.GetDiffs().AsList().Count);
            SnapshottableDirectoryStatus[] status = hdfs.GetSnapshottableDirListing();
            NUnit.Framework.Assert.AreEqual(1, status.Length);
            NUnit.Framework.Assert.AreEqual(dir, status[0].GetFullPath());
            Path subDir = new Path(dir, "sub");

            hdfs.Mkdirs(subDir);
            hdfs.CreateSnapshot(dir, "s2");
            Path file = new Path(subDir, "file");

            DFSTestUtil.CreateFile(hdfs, file, Blocksize, Replication, seed);
            hdfs.SetQuota(dir, HdfsConstants.QuotaReset, HdfsConstants.QuotaReset);
            INode subNode = fsdir.GetINode4Write(subDir.ToString());

            NUnit.Framework.Assert.IsTrue(subNode.AsDirectory().IsWithSnapshot());
            IList <DirectoryWithSnapshotFeature.DirectoryDiff> diffList = subNode.AsDirectory(
                ).GetDiffs().AsList();

            NUnit.Framework.Assert.AreEqual(1, diffList.Count);
            Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s2 = dirNode.GetSnapshot
                                                                              (DFSUtil.String2Bytes("s2"));
            NUnit.Framework.Assert.AreEqual(s2.GetId(), diffList[0].GetSnapshotId());
            IList <INode> createdList = diffList[0].GetChildrenDiff().GetList(Diff.ListType.Created
                                                                              );

            NUnit.Framework.Assert.AreEqual(1, createdList.Count);
            NUnit.Framework.Assert.AreSame(fsdir.GetINode4Write(file.ToString()), createdList
                                           [0]);
        }
Exemplo n.º 2
0
            /// <summary>Load the snapshots section from fsimage.</summary>
            /// <remarks>
            /// Load the snapshots section from fsimage. Also add snapshottable feature
            /// to snapshottable directories.
            /// </remarks>
            /// <exception cref="System.IO.IOException"/>
            public void LoadSnapshotSection(InputStream @in)
            {
                SnapshotManager sm = fsn.GetSnapshotManager();

                FsImageProto.SnapshotSection section = FsImageProto.SnapshotSection.ParseDelimitedFrom
                                                           (@in);
                int snum = section.GetNumSnapshots();

                sm.SetNumSnapshots(snum);
                sm.SetSnapshotCounter(section.GetSnapshotCounter());
                foreach (long sdirId in section.GetSnapshottableDirList())
                {
                    INodeDirectory dir = fsDir.GetInode(sdirId).AsDirectory();
                    if (!dir.IsSnapshottable())
                    {
                        dir.AddSnapshottableFeature();
                    }
                    else
                    {
                        // dir is root, and admin set root to snapshottable before
                        dir.SetSnapshotQuota(DirectorySnapshottableFeature.SnapshotLimit);
                    }
                    sm.AddSnapshottable(dir);
                }
                LoadSnapshots(@in, snum);
            }
Exemplo n.º 3
0
 internal SnapshotDiffInfo(INodeDirectory snapshotRoot, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                           start, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot end)
 {
     Preconditions.CheckArgument(snapshotRoot.IsSnapshottable());
     this.snapshotRoot = snapshotRoot;
     this.from         = start;
     this.to           = end;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Find the source root directory where the snapshot will be taken
        /// for a given path.
        /// </summary>
        /// <returns>Snapshottable directory.</returns>
        /// <exception cref="System.IO.IOException">
        /// Throw IOException when the given path does not lead to an
        /// existing snapshottable directory.
        /// </exception>
        public virtual INodeDirectory GetSnapshottableRoot(INodesInPath iip)
        {
            string         path = iip.GetPath();
            INodeDirectory dir  = INodeDirectory.ValueOf(iip.GetLastINode(), path);

            if (!dir.IsSnapshottable())
            {
                throw new SnapshotException("Directory is not a snapshottable directory: " + path
                                            );
            }
            return(dir);
        }
Exemplo n.º 5
0
        /// <summary>Set the given directory as a snapshottable directory.</summary>
        /// <remarks>
        /// Set the given directory as a snapshottable directory.
        /// If the path is already a snapshottable directory, update the quota.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        public virtual void SetSnapshottable(string path, bool checkNestedSnapshottable)
        {
            INodesInPath   iip = fsdir.GetINodesInPath4Write(path);
            INodeDirectory d   = INodeDirectory.ValueOf(iip.GetLastINode(), path);

            if (checkNestedSnapshottable)
            {
                CheckNestedSnapshottable(d, path);
            }
            if (d.IsSnapshottable())
            {
                //The directory is already a snapshottable directory.
                d.SetSnapshotQuota(DirectorySnapshottableFeature.SnapshotLimit);
            }
            else
            {
                d.AddSnapshottableFeature();
            }
            AddSnapshottable(d);
        }
Exemplo n.º 6
0
        /// <summary>Check the correctness of snapshot list within snapshottable dir</summary>
        private void CheckSnapshotList(INodeDirectory srcRoot, string[] sortedNames, string
                                       [] names)
        {
            NUnit.Framework.Assert.IsTrue(srcRoot.IsSnapshottable());
            ReadOnlyList <Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot> listByName
                = srcRoot.GetDirectorySnapshottableFeature().GetSnapshotList();

            NUnit.Framework.Assert.AreEqual(sortedNames.Length, listByName.Size());
            for (int i = 0; i < listByName.Size(); i++)
            {
                NUnit.Framework.Assert.AreEqual(sortedNames[i], listByName.Get(i).GetRoot().GetLocalName
                                                    ());
            }
            IList <DirectoryWithSnapshotFeature.DirectoryDiff> listByTime = srcRoot.GetDiffs()
                                                                            .AsList();

            NUnit.Framework.Assert.AreEqual(names.Length, listByTime.Count);
            for (int i_1 = 0; i_1 < listByTime.Count; i_1++)
            {
                Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = srcRoot.GetDirectorySnapshottableFeature
                                                                                 ().GetSnapshotById(listByTime[i_1].GetSnapshotId());
                NUnit.Framework.Assert.AreEqual(names[i_1], s.GetRoot().GetLocalName());
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Add the given snapshottable directory to
 /// <see cref="snapshottables"/>
 /// .
 /// </summary>
 public virtual void AddSnapshottable(INodeDirectory dir)
 {
     Preconditions.CheckArgument(dir.IsSnapshottable());
     snapshottables[dir.GetId()] = dir;
 }