Example #1
0
        /// <summary>Add a snapshot.</summary>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException"/>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
        public virtual Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot AddSnapshot
            (INodeDirectory snapshotRoot, int id, string name)
        {
            //check snapshot quota
            int n = GetNumSnapshots();

            if (n + 1 > snapshotQuota)
            {
                throw new SnapshotException("Failed to add snapshot: there are already " + n + " snapshot(s) and the snapshot quota is "
                                            + snapshotQuota);
            }
            Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot s = new Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                                             (id, name, snapshotRoot);
            byte[] nameBytes = s.GetRoot().GetLocalNameBytes();
            int    i         = SearchSnapshot(nameBytes);

            if (i >= 0)
            {
                throw new SnapshotException("Failed to add snapshot: there is already a " + "snapshot with the same name \""
                                            + Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.GetSnapshotName(s) +
                                            "\".");
            }
            DirectoryWithSnapshotFeature.DirectoryDiff d = GetDiffs().AddDiff(id, snapshotRoot
                                                                              );
            d.SetSnapshotRoot(s.GetRoot());
            snapshotsByNames.Add(-i - 1, s);
            // set modification time
            long now = Time.Now();

            snapshotRoot.UpdateModificationTime(now, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                .CurrentStateId);
            s.GetRoot().SetModificationTime(now, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                            .CurrentStateId);
            return(s);
        }