Ejemplo n.º 1
0
        public virtual void TestSafeModeIBR()
        {
            DatanodeDescriptor  node = Org.Mockito.Mockito.Spy(nodes[0]);
            DatanodeStorageInfo ds   = node.GetStorageInfos()[0];

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

            // pretend to be in safemode
            Org.Mockito.Mockito.DoReturn(true).When(fsn).IsInStartupSafeMode();
            // register new node
            bm.GetDatanodeManager().RegisterDatanode(nodeReg);
            bm.GetDatanodeManager().AddDatanode(node);
            // swap in spy
            NUnit.Framework.Assert.AreEqual(node, bm.GetDatanodeManager().GetDatanode(node));
            NUnit.Framework.Assert.AreEqual(0, ds.GetBlockReportCount());
            // send block report, should be processed
            Org.Mockito.Mockito.Reset(node);
            bm.ProcessReport(node, new DatanodeStorage(ds.GetStorageID()), BlockListAsLongs.Empty
                             , null, false);
            NUnit.Framework.Assert.AreEqual(1, ds.GetBlockReportCount());
            // send block report again, should NOT be processed
            Org.Mockito.Mockito.Reset(node);
            bm.ProcessReport(node, new DatanodeStorage(ds.GetStorageID()), BlockListAsLongs.Empty
                             , null, false);
            NUnit.Framework.Assert.AreEqual(1, ds.GetBlockReportCount());
            // re-register as if node restarted, should update existing node
            bm.GetDatanodeManager().RemoveDatanode(node);
            Org.Mockito.Mockito.Reset(node);
            bm.GetDatanodeManager().RegisterDatanode(nodeReg);
            Org.Mockito.Mockito.Verify(node).UpdateRegInfo(nodeReg);
            // send block report, should be processed after restart
            Org.Mockito.Mockito.Reset(node);
            bm.ProcessReport(node, new DatanodeStorage(ds.GetStorageID()), BlockListAsLongs.Empty
                             , null, false);
            // Reinitialize as registration with empty storage list pruned
            // node.storageMap.
            ds = node.GetStorageInfos()[0];
            NUnit.Framework.Assert.AreEqual(1, ds.GetBlockReportCount());
        }
Ejemplo n.º 2
0
        public virtual void TestSafeModeIBRAfterIncremental()
        {
            DatanodeDescriptor  node = Org.Mockito.Mockito.Spy(nodes[0]);
            DatanodeStorageInfo ds   = node.GetStorageInfos()[0];

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

            // pretend to be in safemode
            Org.Mockito.Mockito.DoReturn(true).When(fsn).IsInStartupSafeMode();
            // register new node
            bm.GetDatanodeManager().RegisterDatanode(nodeReg);
            bm.GetDatanodeManager().AddDatanode(node);
            // swap in spy
            NUnit.Framework.Assert.AreEqual(node, bm.GetDatanodeManager().GetDatanode(node));
            NUnit.Framework.Assert.AreEqual(0, ds.GetBlockReportCount());
            // send block report while pretending to already have blocks
            Org.Mockito.Mockito.Reset(node);
            Org.Mockito.Mockito.DoReturn(1).When(node).NumBlocks();
            bm.ProcessReport(node, new DatanodeStorage(ds.GetStorageID()), BlockListAsLongs.Empty
                             , null, false);
            NUnit.Framework.Assert.AreEqual(1, ds.GetBlockReportCount());
        }
Ejemplo n.º 3
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);
        }