Example #1
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);
            }
Example #2
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);
        }
Example #3
0
        /// <summary>Load snapshots and snapshotQuota for a Snapshottable directory.</summary>
        /// <param name="snapshottableParent">The snapshottable directory for loading.</param>
        /// <param name="numSnapshots">The number of snapshots that the directory has.</param>
        /// <param name="loader">The loader</param>
        /// <exception cref="System.IO.IOException"/>
        public static void LoadSnapshotList(INodeDirectory snapshottableParent, int numSnapshots
                                            , DataInput @in, FSImageFormat.Loader loader)
        {
            DirectorySnapshottableFeature sf = snapshottableParent.GetDirectorySnapshottableFeature
                                                   ();

            Preconditions.CheckArgument(sf != null);
            for (int i = 0; i < numSnapshots; i++)
            {
                // read snapshots
                Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = loader.GetSnapshot(@in
                                                                                                );
                s.GetRoot().SetParent(snapshottableParent);
                sf.AddSnapshot(s);
            }
            int snapshotQuota = @in.ReadInt();

            snapshottableParent.SetSnapshotQuota(snapshotQuota);
        }
Example #4
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);
        }