Пример #1
0
        // Generate a block report, optionally corrupting the generation
        // stamp and/or length of one block.
        private static StorageBlockReport[] GetBlockReports(DataNode dn, string bpid, bool
                                                            corruptOneBlockGs, bool corruptOneBlockLen)
        {
            IDictionary <DatanodeStorage, BlockListAsLongs> perVolumeBlockLists = dn.GetFSDataset
                                                                                      ().GetBlockReports(bpid);

            // Send block report
            StorageBlockReport[] reports = new StorageBlockReport[perVolumeBlockLists.Count];
            bool corruptedGs             = false;
            bool corruptedLen            = false;
            int  reportIndex             = 0;

            foreach (KeyValuePair <DatanodeStorage, BlockListAsLongs> kvPair in perVolumeBlockLists)
            {
                DatanodeStorage  dnStorage = kvPair.Key;
                BlockListAsLongs blockList = kvPair.Value;
                // Walk the list of blocks until we find one each to corrupt the
                // generation stamp and length, if so requested.
                BlockListAsLongs.Builder builder = BlockListAsLongs.Builder();
                foreach (BlockListAsLongs.BlockReportReplica block in blockList)
                {
                    if (corruptOneBlockGs && !corruptedGs)
                    {
                        long gsOld = block.GetGenerationStamp();
                        long gsNew;
                        do
                        {
                            gsNew = rand.Next();
                        }while (gsNew == gsOld);
                        block.SetGenerationStamp(gsNew);
                        Log.Info("Corrupted the GS for block ID " + block);
                        corruptedGs = true;
                    }
                    else
                    {
                        if (corruptOneBlockLen && !corruptedLen)
                        {
                            long lenOld = block.GetNumBytes();
                            long lenNew;
                            do
                            {
                                lenNew = rand.Next((int)lenOld - 1);
                            }while (lenNew == lenOld);
                            block.SetNumBytes(lenNew);
                            Log.Info("Corrupted the length for block ID " + block);
                            corruptedLen = true;
                        }
                    }
                    builder.Add(new BlockListAsLongs.BlockReportReplica(block));
                }
                reports[reportIndex++] = new StorageBlockReport(dnStorage, builder.Build());
            }
            return(reports);
        }
Пример #2
0
        public virtual void TestSafeModeIBRBeforeFirstFullBR()
        {
            // pretend to be in safemode
            Org.Mockito.Mockito.DoReturn(true).When(fsn).IsInStartupSafeMode();
            DatanodeDescriptor  node = nodes[0];
            DatanodeStorageInfo ds   = node.GetStorageInfos()[0];

            node.isAlive = true;
            DatanodeRegistration nodeReg = new DatanodeRegistration(node, null, null, string.Empty
                                                                    );

            // register new node
            bm.GetDatanodeManager().RegisterDatanode(nodeReg);
            bm.GetDatanodeManager().AddDatanode(node);
            NUnit.Framework.Assert.AreEqual(node, bm.GetDatanodeManager().GetDatanode(node));
            NUnit.Framework.Assert.AreEqual(0, ds.GetBlockReportCount());
            // Build a incremental report
            IList <ReceivedDeletedBlockInfo> rdbiList = new AList <ReceivedDeletedBlockInfo>();

            // Build a full report
            BlockListAsLongs.Builder builder = BlockListAsLongs.Builder();
            // blk_42 is finalized.
            long receivedBlockId = 42;
            // arbitrary
            BlockInfoContiguous receivedBlock = AddBlockToBM(receivedBlockId);

            rdbiList.AddItem(new ReceivedDeletedBlockInfo(new Block(receivedBlock), ReceivedDeletedBlockInfo.BlockStatus
                                                          .ReceivedBlock, null));
            builder.Add(new FinalizedReplica(receivedBlock, null, null));
            // blk_43 is under construction.
            long receivingBlockId = 43;
            BlockInfoContiguous receivingBlock = AddUcBlockToBM(receivingBlockId);

            rdbiList.AddItem(new ReceivedDeletedBlockInfo(new Block(receivingBlock), ReceivedDeletedBlockInfo.BlockStatus
                                                          .ReceivingBlock, null));
            builder.Add(new ReplicaBeingWritten(receivingBlock, null, null, null));
            // blk_44 has 2 records in IBR. It's finalized. So full BR has 1 record.
            long receivingReceivedBlockId = 44;
            BlockInfoContiguous receivingReceivedBlock = AddBlockToBM(receivingReceivedBlockId
                                                                      );

            rdbiList.AddItem(new ReceivedDeletedBlockInfo(new Block(receivingReceivedBlock),
                                                          ReceivedDeletedBlockInfo.BlockStatus.ReceivingBlock, null));
            rdbiList.AddItem(new ReceivedDeletedBlockInfo(new Block(receivingReceivedBlock),
                                                          ReceivedDeletedBlockInfo.BlockStatus.ReceivedBlock, null));
            builder.Add(new FinalizedReplica(receivingReceivedBlock, null, null));
            // blk_45 is not in full BR, because it's deleted.
            long ReceivedDeletedBlockId = 45;

            rdbiList.AddItem(new ReceivedDeletedBlockInfo(new Block(ReceivedDeletedBlockId),
                                                          ReceivedDeletedBlockInfo.BlockStatus.ReceivedBlock, null));
            rdbiList.AddItem(new ReceivedDeletedBlockInfo(new Block(ReceivedDeletedBlockId),
                                                          ReceivedDeletedBlockInfo.BlockStatus.DeletedBlock, null));
            // blk_46 exists in DN for a long time, so it's in full BR, but not in IBR.
            long existedBlockId = 46;
            BlockInfoContiguous existedBlock = AddBlockToBM(existedBlockId);

            builder.Add(new FinalizedReplica(existedBlock, null, null));
            // process IBR and full BR
            StorageReceivedDeletedBlocks srdb = new StorageReceivedDeletedBlocks(new DatanodeStorage
                                                                                     (ds.GetStorageID()), Sharpen.Collections.ToArray(rdbiList, new ReceivedDeletedBlockInfo
                                                                                                                                      [rdbiList.Count]));

            bm.ProcessIncrementalBlockReport(node, srdb);
            // Make sure it's the first full report
            NUnit.Framework.Assert.AreEqual(0, ds.GetBlockReportCount());
            bm.ProcessReport(node, new DatanodeStorage(ds.GetStorageID()), builder.Build(), null
                             , false);
            NUnit.Framework.Assert.AreEqual(1, ds.GetBlockReportCount());
            // verify the storage info is correct
            NUnit.Framework.Assert.IsTrue(bm.GetStoredBlock(new Block(receivedBlockId)).FindStorageInfo
                                              (ds) >= 0);
            NUnit.Framework.Assert.IsTrue(((BlockInfoContiguousUnderConstruction)bm.GetStoredBlock
                                               (new Block(receivingBlockId))).GetNumExpectedLocations() > 0);
            NUnit.Framework.Assert.IsTrue(bm.GetStoredBlock(new Block(receivingReceivedBlockId
                                                                      )).FindStorageInfo(ds) >= 0);
            NUnit.Framework.Assert.IsNull(bm.GetStoredBlock(new Block(ReceivedDeletedBlockId)
                                                            ));
            NUnit.Framework.Assert.IsTrue(bm.GetStoredBlock(new Block(existedBlock)).FindStorageInfo
                                              (ds) >= 0);
        }