/// <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); } } }
/// <summary> /// If some blocks at the end of the block list no longer belongs to /// any inode, collect them and update the block list. /// </summary> public virtual void CollectBlocksAndClear(BlockStoragePolicySuite bsps, INodeFile file, INode.BlocksMapUpdateInfo info, IList <INode> removedINodes) { // check if everything is deleted. if (IsCurrentFileDeleted() && GetDiffs().AsList().IsEmpty()) { file.DestroyAndCollectBlocks(bsps, info, removedINodes); return; } // find max file size. long max; FileDiff diff = GetDiffs().GetLast(); if (IsCurrentFileDeleted()) { max = diff == null ? 0 : diff.GetFileSize(); } else { max = file.ComputeFileSize(); } // Collect blocks that should be deleted FileDiff last = diffs.GetLast(); BlockInfoContiguous[] snapshotBlocks = last == null ? null : last.GetBlocks(); if (snapshotBlocks == null) { file.CollectBlocksBeyondMax(max, info); } else { file.CollectBlocksBeyondSnapshot(snapshotBlocks, info); } }