Ejemplo n.º 1
0
        /// <summary>Set the given snapshottable directory to non-snapshottable.</summary>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException">if there are snapshots in the directory.
        ///     </exception>
        /// <exception cref="System.IO.IOException"/>
        public virtual void ResetSnapshottable(string path)
        {
            INodesInPath   iip = fsdir.GetINodesInPath4Write(path);
            INodeDirectory d   = INodeDirectory.ValueOf(iip.GetLastINode(), path);
            DirectorySnapshottableFeature sf = d.GetDirectorySnapshottableFeature();

            if (sf == null)
            {
                // the directory is already non-snapshottable
                return;
            }
            if (sf.GetNumSnapshots() > 0)
            {
                throw new SnapshotException("The directory " + path + " has snapshot(s). " + "Please redo the operation after removing all the snapshots."
                                            );
            }
            if (d == fsdir.GetRoot())
            {
                d.SetSnapshotQuota(0);
            }
            else
            {
                d.RemoveSnapshottableFeature();
            }
            RemoveSnapshottable(d);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestSetQuota()
        {
            Path dir = new Path("/TestSnapshot");

            hdfs.Mkdirs(dir);
            // allow snapshot on dir and create snapshot s1
            SnapshotTestHelper.CreateSnapshot(hdfs, dir, "s1");
            Path sub = new Path(dir, "sub");

            hdfs.Mkdirs(sub);
            Path fileInSub = new Path(sub, "file");

            DFSTestUtil.CreateFile(hdfs, fileInSub, Blocksize, Replication, seed);
            INodeDirectory subNode = INodeDirectory.ValueOf(fsdir.GetINode(sub.ToString()), sub
                                                            );

            // subNode should be a INodeDirectory, but not an INodeDirectoryWithSnapshot
            NUnit.Framework.Assert.IsFalse(subNode.IsWithSnapshot());
            hdfs.SetQuota(sub, long.MaxValue - 1, long.MaxValue - 1);
            subNode = INodeDirectory.ValueOf(fsdir.GetINode(sub.ToString()), sub);
            NUnit.Framework.Assert.IsTrue(subNode.IsQuotaSet());
            NUnit.Framework.Assert.IsFalse(subNode.IsWithSnapshot());
        }