Exemplo n.º 1
0
 /// <summary>
 /// Check if the given INode (or one of its descendants) is snapshottable and
 /// already has snapshots.
 /// </summary>
 /// <param name="target">The given INode</param>
 /// <param name="snapshottableDirs">
 /// The list of directories that are snapshottable
 /// but do not have snapshots yet
 /// </param>
 /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.SnapshotException"/>
 internal static void CheckSnapshot(INode target, IList <INodeDirectory> snapshottableDirs
                                    )
 {
     if (target.IsDirectory())
     {
         INodeDirectory targetDir         = target.AsDirectory();
         DirectorySnapshottableFeature sf = targetDir.GetDirectorySnapshottableFeature();
         if (sf != null)
         {
             if (sf.GetNumSnapshots() > 0)
             {
                 string fullPath = targetDir.GetFullPathName();
                 throw new SnapshotException("The directory " + fullPath + " cannot be deleted since "
                                             + fullPath + " is snapshottable and already has snapshots");
             }
             else
             {
                 if (snapshottableDirs != null)
                 {
                     snapshottableDirs.AddItem(targetDir);
                 }
             }
         }
         foreach (INode child in targetDir.GetChildrenList(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                                           .CurrentStateId))
         {
             CheckSnapshot(child, snapshottableDirs);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>Get a listing of all the snapshots of a snapshottable directory</summary>
        /// <exception cref="System.IO.IOException"/>
        private static DirectoryListing GetSnapshotsListing(FSDirectory fsd, string src,
                                                            byte[] startAfter)
        {
            Preconditions.CheckState(fsd.HasReadLock());
            Preconditions.CheckArgument(src.EndsWith(HdfsConstants.SeparatorDotSnapshotDir),
                                        "%s does not end with %s", src, HdfsConstants.SeparatorDotSnapshotDir);
            string dirPath = FSDirectory.NormalizePath(Sharpen.Runtime.Substring(src, 0, src.
                                                                                 Length - HdfsConstants.DotSnapshotDir.Length));
            INode          node              = fsd.GetINode(dirPath);
            INodeDirectory dirNode           = INodeDirectory.ValueOf(node, dirPath);
            DirectorySnapshottableFeature sf = dirNode.GetDirectorySnapshottableFeature();

            if (sf == null)
            {
                throw new SnapshotException("Directory is not a snapshottable directory: " + dirPath
                                            );
            }
            ReadOnlyList <Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot> snapshots =
                sf.GetSnapshotList();
            int skipSize = ReadOnlyList.Util.BinarySearch(snapshots, startAfter);

            skipSize = skipSize < 0 ? -skipSize - 1 : skipSize + 1;
            int numOfListing = Math.Min(snapshots.Size() - skipSize, fsd.GetLsLimit());

            HdfsFileStatus[] listing = new HdfsFileStatus[numOfListing];
            for (int i = 0; i < numOfListing; i++)
            {
                Snapshot.Root sRoot = snapshots.Get(i + skipSize).GetRoot();
                listing[i] = CreateFileStatus(fsd, src, sRoot.GetLocalNameBytes(), sRoot, BlockStoragePolicySuite
                                              .IdUnspecified, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId
                                              , false, INodesInPath.FromINode(sRoot));
            }
            return(new DirectoryListing(listing, snapshots.Size() - skipSize - numOfListing));
        }
Exemplo n.º 3
0
        public override void DumpTreeRecursively(PrintWriter @out, StringBuilder prefix,
                                                 int snapshot)
        {
            base.DumpTreeRecursively(@out, prefix, snapshot);
            @out.Write(", childrenSize=" + GetChildrenList(snapshot).Size());
            DirectoryWithQuotaFeature q = GetDirectoryWithQuotaFeature();

            if (q != null)
            {
                @out.Write(", " + q);
            }
            if (this is Snapshot.Root)
            {
                @out.Write(", snapshotId=" + snapshot);
            }
            @out.WriteLine();
            if (prefix.Length >= 2)
            {
                prefix.Length = prefix.Length - 2;
                prefix.Append("  ");
            }
            DumpTreeRecursively(@out, prefix, new _IEnumerable_874(this, snapshot));
            DirectorySnapshottableFeature s = GetDirectorySnapshottableFeature();

            if (s != null)
            {
                s.DumpTreeRecursively(this, @out, prefix, snapshot);
            }
        }
Exemplo n.º 4
0
        /// <summary>remove DirectorySnapshottableFeature</summary>
        public virtual void RemoveSnapshottableFeature()
        {
            DirectorySnapshottableFeature s = GetDirectorySnapshottableFeature();

            Preconditions.CheckState(s != null, "The dir does not have snapshottable feature: this=%s"
                                     , this);
            this.RemoveFeature(s);
            if (s.GetDiffs().AsList().Count > 0)
            {
                // add a DirectoryWithSnapshotFeature back
                DirectoryWithSnapshotFeature sf = new DirectoryWithSnapshotFeature(s.GetDiffs());
                AddFeature(sf);
            }
        }
Exemplo n.º 5
0
        /// <summary>add DirectorySnapshottableFeature</summary>
        public virtual void AddSnapshottableFeature()
        {
            Preconditions.CheckState(!IsSnapshottable(), "this is already snapshottable, this=%s"
                                     , this);
            DirectoryWithSnapshotFeature  s             = this.GetDirectoryWithSnapshotFeature();
            DirectorySnapshottableFeature snapshottable = new DirectorySnapshottableFeature(s
                                                                                            );

            if (s != null)
            {
                this.RemoveFeature(s);
            }
            this.AddFeature(snapshottable);
        }