Exemple #1
0
            /// <summary>Load FileDiff list for a file with snapshot feature</summary>
            /// <exception cref="System.IO.IOException"/>
            private void LoadFileDiffList(InputStream @in, INodeFile file, int size)
            {
                FileDiffList diffs = new FileDiffList();

                FSImageFormatProtobuf.LoaderContext state = parent.GetLoaderContext();
                for (int i = 0; i < size; i++)
                {
                    FsImageProto.SnapshotDiffSection.FileDiff pbf = FsImageProto.SnapshotDiffSection.FileDiff
                                                                    .ParseDelimitedFrom(@in);
                    INodeFileAttributes copy = null;
                    if (pbf.HasSnapshotCopy())
                    {
                        FsImageProto.INodeSection.INodeFile fileInPb = pbf.GetSnapshotCopy();
                        PermissionStatus permission = FSImageFormatPBINode.Loader.LoadPermission(fileInPb
                                                                                                 .GetPermission(), state.GetStringTable());
                        AclFeature acl = null;
                        if (fileInPb.HasAcl())
                        {
                            int[] entries = AclEntryStatusFormat.ToInt(FSImageFormatPBINode.Loader.LoadAclEntries
                                                                           (fileInPb.GetAcl(), state.GetStringTable()));
                            acl = new AclFeature(entries);
                        }
                        XAttrFeature xAttrs = null;
                        if (fileInPb.HasXAttrs())
                        {
                            xAttrs = new XAttrFeature(FSImageFormatPBINode.Loader.LoadXAttrs(fileInPb.GetXAttrs
                                                                                                 (), state.GetStringTable()));
                        }
                        copy = new INodeFileAttributes.SnapshotCopy(pbf.GetName().ToByteArray(), permission
                                                                    , acl, fileInPb.GetModificationTime(), fileInPb.GetAccessTime(), (short)fileInPb
                                                                    .GetReplication(), fileInPb.GetPreferredBlockSize(), unchecked ((byte)fileInPb.GetStoragePolicyID
                                                                                                                                        ()), xAttrs);
                    }
                    FileDiff diff = new FileDiff(pbf.GetSnapshotId(), copy, null, pbf.GetFileSize());
                    IList <HdfsProtos.BlockProto> bpl    = pbf.GetBlocksList();
                    BlockInfoContiguous[]         blocks = new BlockInfoContiguous[bpl.Count];
                    for (int j = 0; j < e; ++j)
                    {
                        Block blk = PBHelper.Convert(bpl[j]);
                        BlockInfoContiguous storedBlock = fsn.GetBlockManager().GetStoredBlock(blk);
                        if (storedBlock == null)
                        {
                            storedBlock = fsn.GetBlockManager().AddBlockCollection(new BlockInfoContiguous(blk
                                                                                                           , copy.GetFileReplication()), file);
                        }
                        blocks[j] = storedBlock;
                    }
                    if (blocks.Length > 0)
                    {
                        diff.SetBlocks(blocks);
                    }
                    diffs.AddFirst(diff);
                }
                file.AddSnapshotFeature(diffs);
            }
        /// <exception cref="System.IO.IOException"/>
        private void DumpSnapshotDiffSection(InputStream @in)
        {
            @out.Write("<SnapshotDiffSection>");
            while (true)
            {
                FsImageProto.SnapshotDiffSection.DiffEntry e = FsImageProto.SnapshotDiffSection.DiffEntry
                                                               .ParseDelimitedFrom(@in);
                if (e == null)
                {
                    break;
                }
                @out.Write("<diff>");
                O("inodeid", e.GetInodeId());
                switch (e.GetType())
                {
                case FsImageProto.SnapshotDiffSection.DiffEntry.Type.Filediff:
                {
                    for (int i = 0; i < e.GetNumOfDiff(); ++i)
                    {
                        @out.Write("<filediff>");
                        FsImageProto.SnapshotDiffSection.FileDiff f = FsImageProto.SnapshotDiffSection.FileDiff
                                                                      .ParseDelimitedFrom(@in);
                        O("snapshotId", f.GetSnapshotId()).O("size", f.GetFileSize()).O("name", f.GetName
                                                                                            ().ToStringUtf8());
                        @out.Write("</filediff>\n");
                    }
                    break;
                }

                case FsImageProto.SnapshotDiffSection.DiffEntry.Type.Directorydiff:
                {
                    for (int i = 0; i < e.GetNumOfDiff(); ++i)
                    {
                        @out.Write("<dirdiff>");
                        FsImageProto.SnapshotDiffSection.DirectoryDiff d = FsImageProto.SnapshotDiffSection.DirectoryDiff
                                                                           .ParseDelimitedFrom(@in);
                        O("snapshotId", d.GetSnapshotId()).O("isSnapshotroot", d.GetIsSnapshotRoot()).O("childrenSize"
                                                                                                        , d.GetChildrenSize()).O("name", d.GetName().ToStringUtf8());
                        for (int j = 0; j < d.GetCreatedListSize(); ++j)
                        {
                            FsImageProto.SnapshotDiffSection.CreatedListEntry ce = FsImageProto.SnapshotDiffSection.CreatedListEntry
                                                                                   .ParseDelimitedFrom(@in);
                            @out.Write("<created>");
                            O("name", ce.GetName().ToStringUtf8());
                            @out.Write("</created>\n");
                        }
                        foreach (long did in d.GetDeletedINodeList())
                        {
                            @out.Write("<deleted>");
                            O("inode", did);
                            @out.Write("</deleted>\n");
                        }
                        foreach (int dRefid in d.GetDeletedINodeRefList())
                        {
                            @out.Write("<deleted>");
                            O("inodereference-index", dRefid);
                            @out.Write("</deleted>\n");
                        }
                        @out.Write("</dirdiff>\n");
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
                @out.Write("</diff>");
            }
            @out.Write("</SnapshotDiffSection>\n");
        }