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);
            }
        /// <summary>
        /// Test
        /// <see cref="Snapshot.IdComparator"/>
        /// .
        /// </summary>
        public virtual void TestIdCmp()
        {
            PermissionStatus perm = PermissionStatus.CreateImmutable("user", "group", FsPermission
                                                                     .CreateImmutable((short)0));
            INodeDirectory snapshottable = new INodeDirectory(0, DFSUtil.String2Bytes("foo"),
                                                              perm, 0L);

            snapshottable.AddSnapshottableFeature();
            Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot[] snapshots = new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                                                   [] { new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(1, "s1", snapshottable
                                                                                                                                                     ), new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(1, "s1", snapshottable
                                                                                                                                                                                                                     ), new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(2, "s2", snapshottable
                                                                                                                                                                                                                                                                                     ), new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot(2, "s2", snapshottable
                                                                                                                                                                                                                                                                                                                                                     ) };
            NUnit.Framework.Assert.AreEqual(0, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                            .IdComparator.Compare(null, null));
            foreach (Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s in snapshots)
            {
                NUnit.Framework.Assert.IsTrue(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                              .IdComparator.Compare(null, s) > 0);
                NUnit.Framework.Assert.IsTrue(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                              .IdComparator.Compare(s, null) < 0);
                foreach (Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot t in snapshots)
                {
                    int expected = string.CompareOrdinal(s.GetRoot().GetLocalName(), t.GetRoot().GetLocalName
                                                             ());
                    int computed = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.IdComparator
                                   .Compare(s, t);
                    NUnit.Framework.Assert.AreEqual(expected > 0, computed > 0);
                    NUnit.Framework.Assert.AreEqual(expected == 0, computed == 0);
                    NUnit.Framework.Assert.AreEqual(expected < 0, computed < 0);
                }
            }
        }
Example #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);
        }