Exemplo n.º 1
0
        public virtual void TestDeletionWithZeroSizeBlock2()
        {
            Path foo    = new Path("/foo");
            Path subDir = new Path(foo, "sub");
            Path bar    = new Path(subDir, "bar");

            DFSTestUtil.CreateFile(hdfs, bar, Blocksize, Replication, 0L);
            hdfs.Append(bar);
            INodeFile barNode = fsdir.GetINode4Write(bar.ToString()).AsFile();

            BlockInfoContiguous[] blks = barNode.GetBlocks();
            NUnit.Framework.Assert.AreEqual(1, blks.Length);
            ExtendedBlock previous = new ExtendedBlock(fsn.GetBlockPoolId(), blks[0]);

            cluster.GetNameNodeRpc().AddBlock(bar.ToString(), hdfs.GetClient().GetClientName(
                                                  ), previous, null, barNode.GetId(), null);
            SnapshotTestHelper.CreateSnapshot(hdfs, foo, "s1");
            barNode = fsdir.GetINode4Write(bar.ToString()).AsFile();
            blks    = barNode.GetBlocks();
            NUnit.Framework.Assert.AreEqual(2, blks.Length);
            NUnit.Framework.Assert.AreEqual(Blocksize, blks[0].GetNumBytes());
            NUnit.Framework.Assert.AreEqual(0, blks[1].GetNumBytes());
            hdfs.Delete(subDir, true);
            Path sbar = SnapshotTestHelper.GetSnapshotPath(foo, "s1", "sub/bar");

            barNode = fsdir.GetINode(sbar.ToString()).AsFile();
            blks    = barNode.GetBlocks();
            NUnit.Framework.Assert.AreEqual(1, blks.Length);
            NUnit.Framework.Assert.AreEqual(Blocksize, blks[0].GetNumBytes());
        }
Exemplo n.º 2
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);
                    }
                }
            }