Exemplo n.º 1
0
            /// <exception cref="System.IO.IOException"/>
            private void SerializeFileDiffList(INodeFile file, OutputStream @out)
            {
                FileWithSnapshotFeature sf = file.GetFileWithSnapshotFeature();

                if (sf != null)
                {
                    IList <FileDiff> diffList = sf.GetDiffs().AsList();
                    FsImageProto.SnapshotDiffSection.DiffEntry entry = ((FsImageProto.SnapshotDiffSection.DiffEntry
                                                                         )FsImageProto.SnapshotDiffSection.DiffEntry.NewBuilder().SetInodeId(file.GetId()
                                                                                                                                             ).SetType(FsImageProto.SnapshotDiffSection.DiffEntry.Type.Filediff).SetNumOfDiff
                                                                            (diffList.Count).Build());
                    entry.WriteDelimitedTo(@out);
                    for (int i = diffList.Count - 1; i >= 0; i--)
                    {
                        FileDiff diff = diffList[i];
                        FsImageProto.SnapshotDiffSection.FileDiff.Builder fb = FsImageProto.SnapshotDiffSection.FileDiff
                                                                               .NewBuilder().SetSnapshotId(diff.GetSnapshotId()).SetFileSize(diff.GetFileSize()
                                                                                                                                             );
                        if (diff.GetBlocks() != null)
                        {
                            foreach (Block block in diff.GetBlocks())
                            {
                                fb.AddBlocks(PBHelper.Convert(block));
                            }
                        }
                        INodeFileAttributes copy = diff.snapshotINode;
                        if (copy != null)
                        {
                            fb.SetName(ByteString.CopyFrom(copy.GetLocalNameBytes())).SetSnapshotCopy(FSImageFormatPBINode.Saver.BuildINodeFile
                                                                                                          (copy, parent.GetSaverContext()));
                        }
                        ((FsImageProto.SnapshotDiffSection.FileDiff)fb.Build()).WriteDelimitedTo(@out);
                    }
                }
            }
Exemplo n.º 2
0
        internal override QuotaCounts CombinePosteriorAndCollectBlocks(BlockStoragePolicySuite
                                                                       bsps, INodeFile currentINode, Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.FileDiff
                                                                       posterior, INode.BlocksMapUpdateInfo collectedBlocks, IList <INode> removedINodes
                                                                       )
        {
            FileWithSnapshotFeature sf = currentINode.GetFileWithSnapshotFeature();

            System.Diagnostics.Debug.Assert(sf != null, "FileWithSnapshotFeature is null");
            return(sf.UpdateQuotaAndCollectBlocks(bsps, currentINode, posterior, collectedBlocks
                                                  , removedINodes));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Copy blocks from the removed snapshot into the previous snapshot
        /// up to the file length of the latter.
        /// </summary>
        /// <remarks>
        /// Copy blocks from the removed snapshot into the previous snapshot
        /// up to the file length of the latter.
        /// Collect unused blocks of the removed snapshot.
        /// </remarks>
        internal virtual void CombineAndCollectSnapshotBlocks(BlockStoragePolicySuite bsps
                                                              , INodeFile file, FileDiff removed, INode.BlocksMapUpdateInfo collectedBlocks, IList
                                                              <INode> removedINodes)
        {
            BlockInfoContiguous[] removedBlocks = removed.GetBlocks();
            if (removedBlocks == null)
            {
                FileWithSnapshotFeature sf = file.GetFileWithSnapshotFeature();
                System.Diagnostics.Debug.Assert(sf != null, "FileWithSnapshotFeature is null");
                if (sf.IsCurrentFileDeleted())
                {
                    sf.CollectBlocksAndClear(bsps, file, collectedBlocks, removedINodes);
                }
                return;
            }
            int      p           = GetPrior(removed.GetSnapshotId(), true);
            FileDiff earlierDiff = p == Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot
                                   .NoSnapshotId ? null : GetDiffById(p);

            // Copy blocks to the previous snapshot if not set already
            if (earlierDiff != null)
            {
                earlierDiff.SetBlocks(removedBlocks);
            }
            BlockInfoContiguous[] earlierBlocks = (earlierDiff == null ? new BlockInfoContiguous
                                                   [] {  } : earlierDiff.GetBlocks());
            // Find later snapshot (or file itself) with blocks
            BlockInfoContiguous[] laterBlocks = FindLaterSnapshotBlocks(removed.GetSnapshotId
                                                                            ());
            laterBlocks = (laterBlocks == null) ? file.GetBlocks() : laterBlocks;
            // Skip blocks, which belong to either the earlier or the later lists
            int i = 0;

            for (; i < removedBlocks.Length; i++)
            {
                if (i < earlierBlocks.Length && removedBlocks[i] == earlierBlocks[i])
                {
                    continue;
                }
                if (i < laterBlocks.Length && removedBlocks[i] == laterBlocks[i])
                {
                    continue;
                }
                break;
            }
            // Check if last block is part of truncate recovery
            BlockInfoContiguous lastBlock = file.GetLastBlock();
            Block dontRemoveBlock         = null;

            if (lastBlock != null && lastBlock.GetBlockUCState().Equals(HdfsServerConstants.BlockUCState
                                                                        .UnderRecovery))
            {
                dontRemoveBlock = ((BlockInfoContiguousUnderConstruction)lastBlock).GetTruncateBlock
                                      ();
            }
            // Collect the remaining blocks of the file, ignoring truncate block
            for (; i < removedBlocks.Length; i++)
            {
                if (dontRemoveBlock == null || !removedBlocks[i].Equals(dontRemoveBlock))
                {
                    collectedBlocks.AddDeleteBlock(removedBlocks[i]);
                }
            }
        }