public virtual void TestDeadDatanode() { Configuration conf = new HdfsConfiguration(); conf.SetInt(DFSConfigKeys.DfsNamenodeHeartbeatRecheckIntervalKey, 500); conf.SetLong(DFSConfigKeys.DfsHeartbeatIntervalKey, 1L); cluster = new MiniDFSCluster.Builder(conf).Build(); cluster.WaitActive(); string poolId = cluster.GetNamesystem().GetBlockPoolId(); // wait for datanode to be marked live DataNode dn = cluster.GetDataNodes()[0]; DatanodeRegistration reg = DataNodeTestUtils.GetDNRegistrationForBP(cluster.GetDataNodes ()[0], poolId); DFSTestUtil.WaitForDatanodeState(cluster, reg.GetDatanodeUuid(), true, 20000); // Shutdown and wait for datanode to be marked dead dn.Shutdown(); DFSTestUtil.WaitForDatanodeState(cluster, reg.GetDatanodeUuid(), false, 20000); DatanodeProtocol dnp = cluster.GetNameNodeRpc(); ReceivedDeletedBlockInfo[] blocks = new ReceivedDeletedBlockInfo[] { new ReceivedDeletedBlockInfo (new Block(0), ReceivedDeletedBlockInfo.BlockStatus.ReceivedBlock, null) }; StorageReceivedDeletedBlocks[] storageBlocks = new StorageReceivedDeletedBlocks[] { new StorageReceivedDeletedBlocks(reg.GetDatanodeUuid(), blocks) }; // Ensure blockReceived call from dead datanode is rejected with IOException try { dnp.BlockReceivedAndDeleted(reg, poolId, storageBlocks); NUnit.Framework.Assert.Fail("Expected IOException is not thrown"); } catch (IOException) { } // Expected // Ensure blockReport from dead datanode is rejected with IOException StorageBlockReport[] report = new StorageBlockReport[] { new StorageBlockReport(new DatanodeStorage(reg.GetDatanodeUuid()), BlockListAsLongs.Empty) }; try { dnp.BlockReport(reg, poolId, report, new BlockReportContext(1, 0, Runtime.NanoTime ())); NUnit.Framework.Assert.Fail("Expected IOException is not thrown"); } catch (IOException) { } // Expected // Ensure heartbeat from dead datanode is rejected with a command // that asks datanode to register again StorageReport[] rep = new StorageReport[] { new StorageReport(new DatanodeStorage (reg.GetDatanodeUuid()), false, 0, 0, 0, 0) }; DatanodeCommand[] cmd = dnp.SendHeartbeat(reg, rep, 0L, 0L, 0, 0, 0, null).GetCommands (); NUnit.Framework.Assert.AreEqual(1, cmd.Length); NUnit.Framework.Assert.AreEqual(cmd[0].GetAction(), RegisterCommand.Register.GetAction ()); }
public virtual void TestZeroLenReplicas() { if (Log.IsDebugEnabled()) { Log.Debug("Running " + GenericTestUtils.GetMethodName()); } DataNode spyDN = Org.Mockito.Mockito.Spy(dn); Org.Mockito.Mockito.DoReturn(new ReplicaRecoveryInfo(block.GetBlockId(), 0, block .GetGenerationStamp(), HdfsServerConstants.ReplicaState.Finalized)).When(spyDN). InitReplicaRecovery(Matchers.Any <BlockRecoveryCommand.RecoveringBlock>()); Daemon d = spyDN.RecoverBlocks("fake NN", InitRecoveringBlocks()); d.Join(); DatanodeProtocol dnP = dn.GetActiveNamenodeForBP(PoolId); Org.Mockito.Mockito.Verify(dnP).CommitBlockSynchronization(block, RecoveryId, 0, true, true, DatanodeID.EmptyArray, null); }
public virtual void TestNoReplicaUnderRecovery() { if (Log.IsDebugEnabled()) { Log.Debug("Running " + GenericTestUtils.GetMethodName()); } dn.data.CreateRbw(StorageType.Default, block, false); try { dn.SyncBlock(rBlock, InitBlockRecords(dn)); NUnit.Framework.Assert.Fail("Sync should fail"); } catch (IOException e) { e.Message.StartsWith("Cannot recover "); } DatanodeProtocol namenode = dn.GetActiveNamenodeForBP(PoolId); Org.Mockito.Mockito.Verify(namenode, Org.Mockito.Mockito.Never()).CommitBlockSynchronization (Matchers.Any <ExtendedBlock>(), Matchers.AnyLong(), Matchers.AnyLong(), Matchers.AnyBoolean (), Matchers.AnyBoolean(), Matchers.Any <DatanodeID[]>(), Matchers.Any <string[]>( )); }
public virtual void TestNotMatchedReplicaID() { if (Log.IsDebugEnabled()) { Log.Debug("Running " + GenericTestUtils.GetMethodName()); } ReplicaInPipelineInterface replicaInfo = dn.data.CreateRbw(StorageType.Default, block , false).GetReplica(); ReplicaOutputStreams streams = null; try { streams = replicaInfo.CreateStreams(true, DataChecksum.NewDataChecksum(DataChecksum.Type .Crc32, 512)); streams.GetChecksumOut().Write('a'); dn.data.InitReplicaRecovery(new BlockRecoveryCommand.RecoveringBlock(block, null, RecoveryId + 1)); try { dn.SyncBlock(rBlock, InitBlockRecords(dn)); NUnit.Framework.Assert.Fail("Sync should fail"); } catch (IOException e) { e.Message.StartsWith("Cannot recover "); } DatanodeProtocol namenode = dn.GetActiveNamenodeForBP(PoolId); Org.Mockito.Mockito.Verify(namenode, Org.Mockito.Mockito.Never()).CommitBlockSynchronization (Matchers.Any <ExtendedBlock>(), Matchers.AnyLong(), Matchers.AnyLong(), Matchers.AnyBoolean (), Matchers.AnyBoolean(), Matchers.Any <DatanodeID[]>(), Matchers.Any <string[]>( )); } finally { streams.Close(); } }
public DatanodeProtocolServerSideTranslatorPB(DatanodeProtocol impl) { this.impl = impl; }