Ejemplo n.º 1
0
        /// <summary>
        /// Load the
        /// <see cref="Org.Apache.Hadoop.Hdfs.Tools.Snapshot.SnapshotDiff"/>
        /// list for the INodeDirectoryWithSnapshot
        /// directory.
        /// </summary>
        /// <param name="dir">The snapshottable directory for loading.</param>
        /// <param name="in">
        /// The
        /// <see cref="System.IO.DataInput"/>
        /// instance to read.
        /// </param>
        /// <param name="loader">The loader</param>
        /// <exception cref="System.IO.IOException"/>
        public static void LoadDirectoryDiffList(INodeDirectory dir, DataInput @in, FSImageFormat.Loader
                                                 loader)
        {
            int size = @in.ReadInt();

            if (dir.IsWithSnapshot())
            {
                DirectoryWithSnapshotFeature.DirectoryDiffList diffs = dir.GetDiffs();
                for (int i = 0; i < size; i++)
                {
                    diffs.AddFirst(LoadDirectoryDiff(dir, @in, loader));
                }
            }
        }
        /// <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());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find the latest snapshot that 1) covers the given inode (which means the
        /// snapshot was either taken on the inode or taken on an ancestor of the
        /// inode), and 2) was taken before the given snapshot (if the given snapshot
        /// is not null).
        /// </summary>
        /// <param name="inode">the given inode that the returned snapshot needs to cover</param>
        /// <param name="anchor">the returned snapshot should be taken before this given id.</param>
        /// <returns>
        /// id of the latest snapshot that covers the given inode and was taken
        /// before the the given snapshot (if it is not null).
        /// </returns>
        public static int FindLatestSnapshot(INode inode, int anchor)
        {
            int latest = NoSnapshotId;

            for (; inode != null; inode = inode.GetParent())
            {
                if (inode.IsDirectory())
                {
                    INodeDirectory dir = inode.AsDirectory();
                    if (dir.IsWithSnapshot())
                    {
                        latest = dir.GetDiffs().UpdatePrior(anchor, latest);
                    }
                }
            }
            return(latest);
        }
Ejemplo n.º 4
0
 /// <summary>Load DirectoryDiff list for a directory with snapshot feature</summary>
 /// <exception cref="System.IO.IOException"/>
 private void LoadDirectoryDiffList(InputStream @in, INodeDirectory dir, int size,
                                    IList <INodeReference> refList)
 {
     if (!dir.IsWithSnapshot())
     {
         dir.AddSnapshotFeature(null);
     }
     DirectoryWithSnapshotFeature.DirectoryDiffList diffs = dir.GetDiffs();
     FSImageFormatProtobuf.LoaderContext            state = parent.GetLoaderContext();
     for (int i = 0; i < size; i++)
     {
         // load a directory diff
         FsImageProto.SnapshotDiffSection.DirectoryDiff diffInPb = FsImageProto.SnapshotDiffSection.DirectoryDiff
                                                                   .ParseDelimitedFrom(@in);
         int snapshotId = diffInPb.GetSnapshotId();
         Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot snapshot = snapshotMap[snapshotId
                                                                             ];
         int  childrenSize             = diffInPb.GetChildrenSize();
         bool useRoot                  = diffInPb.GetIsSnapshotRoot();
         INodeDirectoryAttributes copy = null;
         if (useRoot)
         {
             copy = snapshot.GetRoot();
         }
         else
         {
             if (diffInPb.HasSnapshotCopy())
             {
                 FsImageProto.INodeSection.INodeDirectory dirCopyInPb = diffInPb.GetSnapshotCopy();
                 byte[]           name       = diffInPb.GetName().ToByteArray();
                 PermissionStatus permission = FSImageFormatPBINode.Loader.LoadPermission(dirCopyInPb
                                                                                          .GetPermission(), state.GetStringTable());
                 AclFeature acl = null;
                 if (dirCopyInPb.HasAcl())
                 {
                     int[] entries = AclEntryStatusFormat.ToInt(FSImageFormatPBINode.Loader.LoadAclEntries
                                                                    (dirCopyInPb.GetAcl(), state.GetStringTable()));
                     acl = new AclFeature(entries);
                 }
                 XAttrFeature xAttrs = null;
                 if (dirCopyInPb.HasXAttrs())
                 {
                     xAttrs = new XAttrFeature(FSImageFormatPBINode.Loader.LoadXAttrs(dirCopyInPb.GetXAttrs
                                                                                          (), state.GetStringTable()));
                 }
                 long modTime = dirCopyInPb.GetModificationTime();
                 bool noQuota = dirCopyInPb.GetNsQuota() == -1 && dirCopyInPb.GetDsQuota() == -1 &&
                                (!dirCopyInPb.HasTypeQuotas());
                 if (noQuota)
                 {
                     copy = new INodeDirectoryAttributes.SnapshotCopy(name, permission, acl, modTime,
                                                                      xAttrs);
                 }
                 else
                 {
                     EnumCounters <StorageType> typeQuotas = null;
                     if (dirCopyInPb.HasTypeQuotas())
                     {
                         ImmutableList <QuotaByStorageTypeEntry> qes = FSImageFormatPBINode.Loader.LoadQuotaByStorageTypeEntries
                                                                           (dirCopyInPb.GetTypeQuotas());
                         typeQuotas = new EnumCounters <StorageType>(typeof(StorageType), HdfsConstants.QuotaReset
                                                                     );
                         foreach (QuotaByStorageTypeEntry qe in qes)
                         {
                             if (qe.GetQuota() >= 0 && qe.GetStorageType() != null && qe.GetStorageType().SupportTypeQuota
                                     ())
                             {
                                 typeQuotas.Set(qe.GetStorageType(), qe.GetQuota());
                             }
                         }
                     }
                     copy = new INodeDirectoryAttributes.CopyWithQuota(name, permission, acl, modTime,
                                                                       dirCopyInPb.GetNsQuota(), dirCopyInPb.GetDsQuota(), typeQuotas, xAttrs);
                 }
             }
         }
         // load created list
         IList <INode> clist = LoadCreatedList(@in, dir, diffInPb.GetCreatedListSize());
         // load deleted list
         IList <INode> dlist = LoadDeletedList(refList, @in, dir, diffInPb.GetDeletedINodeList
                                                   (), diffInPb.GetDeletedINodeRefList());
         // create the directory diff
         DirectoryWithSnapshotFeature.DirectoryDiff diff = new DirectoryWithSnapshotFeature.DirectoryDiff
                                                               (snapshotId, copy, null, childrenSize, clist, dlist, useRoot);
         diffs.AddFirst(diff);
     }
 }