Search in sources :

Example 11 with NNHAStatusHeartbeat

use of org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat in project hadoop by apache.

the class TestDatanodeProtocolRetryPolicy method testDatanodeRegistrationRetry.

/**
   * Verify the following scenario.
   * 1. The initial DatanodeProtocol.registerDatanode succeeds.
   * 2. DN starts heartbeat process.
   * 3. In the first heartbeat, NN asks DN to reregister.
   * 4. DN calls DatanodeProtocol.registerDatanode.
   * 5. DatanodeProtocol.registerDatanode throws EOFException.
   * 6. DN retries.
   * 7. DatanodeProtocol.registerDatanode succeeds.
   */
@Test(timeout = 60000)
public void testDatanodeRegistrationRetry() throws Exception {
    final DatanodeProtocolClientSideTranslatorPB namenode = mock(DatanodeProtocolClientSideTranslatorPB.class);
    Mockito.doAnswer(new Answer<DatanodeRegistration>() {

        int i = 0;

        @Override
        public DatanodeRegistration answer(InvocationOnMock invocation) throws Throwable {
            i++;
            if (i > 1 && i < 5) {
                LOG.info("mockito exception " + i);
                throw new EOFException("TestDatanodeProtocolRetryPolicy");
            } else {
                DatanodeRegistration dr = (DatanodeRegistration) invocation.getArguments()[0];
                datanodeRegistration = new DatanodeRegistration(dr.getDatanodeUuid(), dr);
                LOG.info("mockito succeeded " + datanodeRegistration);
                return datanodeRegistration;
            }
        }
    }).when(namenode).registerDatanode(Mockito.any(DatanodeRegistration.class));
    when(namenode.versionRequest()).thenReturn(new NamespaceInfo(1, CLUSTER_ID, POOL_ID, 1L));
    Mockito.doAnswer(new Answer<HeartbeatResponse>() {

        int i = 0;

        @Override
        public HeartbeatResponse answer(InvocationOnMock invocation) throws Throwable {
            i++;
            HeartbeatResponse heartbeatResponse;
            if (i == 1) {
                LOG.info("mockito heartbeatResponse registration " + i);
                heartbeatResponse = new HeartbeatResponse(new DatanodeCommand[] { RegisterCommand.REGISTER }, new NNHAStatusHeartbeat(HAServiceState.ACTIVE, 1), null, ThreadLocalRandom.current().nextLong() | 1L);
            } else {
                LOG.info("mockito heartbeatResponse " + i);
                heartbeatResponse = new HeartbeatResponse(new DatanodeCommand[0], new NNHAStatusHeartbeat(HAServiceState.ACTIVE, 1), null, ThreadLocalRandom.current().nextLong() | 1L);
            }
            return heartbeatResponse;
        }
    }).when(namenode).sendHeartbeat(Mockito.any(DatanodeRegistration.class), Mockito.any(StorageReport[].class), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt(), Mockito.any(VolumeFailureSummary.class), Mockito.anyBoolean(), Mockito.any(SlowPeerReports.class));
    dn = new DataNode(conf, locations, null, null) {

        @Override
        DatanodeProtocolClientSideTranslatorPB connectToNN(InetSocketAddress nnAddr) throws IOException {
            Assert.assertEquals(NN_ADDR, nnAddr);
            return namenode;
        }
    };
    // Trigger a heartbeat so that it acknowledges the NN as active.
    dn.getAllBpOs().get(0).triggerHeartbeatForTests();
    waitForBlockReport(namenode);
}
Also used : HeartbeatResponse(org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) VolumeFailureSummary(org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary) DatanodeProtocolClientSideTranslatorPB(org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB) DatanodeRegistration(org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration) NNHAStatusHeartbeat(org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EOFException(java.io.EOFException) SlowPeerReports(org.apache.hadoop.hdfs.server.protocol.SlowPeerReports) NamespaceInfo(org.apache.hadoop.hdfs.server.protocol.NamespaceInfo) Test(org.junit.Test)

Example 12 with NNHAStatusHeartbeat

use of org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat in project hadoop by apache.

the class TestFsDatasetCache method setHeartbeatResponse.

private static void setHeartbeatResponse(DatanodeCommand[] cmds) throws IOException {
    NNHAStatusHeartbeat ha = new NNHAStatusHeartbeat(HAServiceState.ACTIVE, fsImage.getLastAppliedOrWrittenTxId());
    HeartbeatResponse response = new HeartbeatResponse(cmds, ha, null, ThreadLocalRandom.current().nextLong() | 1L);
    doReturn(response).when(spyNN).sendHeartbeat((DatanodeRegistration) any(), (StorageReport[]) any(), anyLong(), anyLong(), anyInt(), anyInt(), anyInt(), (VolumeFailureSummary) any(), anyBoolean(), any(SlowPeerReports.class));
}
Also used : HeartbeatResponse(org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse) NNHAStatusHeartbeat(org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat) StorageReport(org.apache.hadoop.hdfs.server.protocol.StorageReport) SlowPeerReports(org.apache.hadoop.hdfs.server.protocol.SlowPeerReports)

Aggregations

NNHAStatusHeartbeat (org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat)12 DatanodeRegistration (org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration)7 Test (org.junit.Test)7 HeartbeatResponse (org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse)5 SlowPeerReports (org.apache.hadoop.hdfs.server.protocol.SlowPeerReports)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 IOException (java.io.IOException)4 DatanodeProtocolClientSideTranslatorPB (org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB)4 NamespaceInfo (org.apache.hadoop.hdfs.server.protocol.NamespaceInfo)4 VolumeFailureSummary (org.apache.hadoop.hdfs.server.protocol.VolumeFailureSummary)4 InetSocketAddress (java.net.InetSocketAddress)3 DatanodeCommand (org.apache.hadoop.hdfs.server.protocol.DatanodeCommand)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 EOFException (java.io.EOFException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 DatanodeStorage (org.apache.hadoop.hdfs.server.protocol.DatanodeStorage)1 RegisterCommand (org.apache.hadoop.hdfs.server.protocol.RegisterCommand)1 StorageReport (org.apache.hadoop.hdfs.server.protocol.StorageReport)1