public virtual void TestTriggerBlockIdCollision()
        {
            Configuration conf = new HdfsConfiguration();

            conf.SetInt(DFSConfigKeys.DfsReplicationKey, 1);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();

            try
            {
                cluster.WaitActive();
                FileSystem   fs         = cluster.GetFileSystem();
                FSNamesystem fsn        = cluster.GetNamesystem();
                int          blockCount = 10;
                // Create a file with a few blocks to rev up the global block ID
                // counter.
                Path path1 = new Path("testBlockIdCollisionDetection_file1.dat");
                DFSTestUtil.CreateFile(fs, path1, IoSize, BlockSize * blockCount, BlockSize, Replication
                                       , Seed);
                IList <LocatedBlock> blocks1 = DFSTestUtil.GetAllBlocks(fs, path1);
                // Rewind the block ID counter in the name system object. This will result
                // in block ID collisions when we try to allocate new blocks.
                SequentialBlockIdGenerator blockIdGenerator = fsn.GetBlockIdManager().GetBlockIdGenerator
                                                                  ();
                blockIdGenerator.SetCurrentValue(blockIdGenerator.GetCurrentValue() - 5);
                // Trigger collisions by creating a new file.
                Path path2 = new Path("testBlockIdCollisionDetection_file2.dat");
                DFSTestUtil.CreateFile(fs, path2, IoSize, BlockSize * blockCount, BlockSize, Replication
                                       , Seed);
                IList <LocatedBlock> blocks2 = DFSTestUtil.GetAllBlocks(fs, path2);
                Assert.AssertThat(blocks2.Count, CoreMatchers.Is(blockCount));
                // Make sure that file2 block IDs start immediately after file1
                Assert.AssertThat(blocks2[0].GetBlock().GetBlockId(), CoreMatchers.Is(blocks1[9].
                                                                                      GetBlock().GetBlockId() + 1));
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Beispiel #2
0
 public BlockIdManager(BlockManager blockManager)
 {
     this.generationStampV1Limit = GenerationStamp.GrandfatherGenerationStamp;
     this.blockIdGenerator       = new SequentialBlockIdGenerator(blockManager);
 }