Search in sources :

Example 11 with DelayAnswer

use of org.apache.hadoop.test.GenericTestUtils.DelayAnswer in project hadoop by apache.

the class TestStandbyCheckpoints method testReadsAllowedDuringCheckpoint.

@Test(timeout = 300000)
public void testReadsAllowedDuringCheckpoint() throws Exception {
    // Set it up so that we know when the SBN checkpoint starts and ends.
    FSImage spyImage1 = NameNodeAdapter.spyOnFsImage(nns[1]);
    DelayAnswer answerer = new DelayAnswer(LOG);
    Mockito.doAnswer(answerer).when(spyImage1).saveNamespace(Mockito.any(FSNamesystem.class), Mockito.any(NameNodeFile.class), Mockito.any(Canceler.class));
    // Perform some edits and wait for a checkpoint to start on the SBN.
    doEdits(0, 1000);
    nns[0].getRpcServer().rollEditLog();
    answerer.waitForCall();
    assertTrue("SBN is not performing checkpoint but it should be.", answerer.getFireCount() == 1 && answerer.getResultCount() == 0);
    // Make sure that the lock has actually been taken by the checkpointing
    // thread.
    ThreadUtil.sleepAtLeastIgnoreInterrupts(1000);
    // Perform an RPC that needs to take the write lock.
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                nns[1].getRpcServer().restoreFailedStorage("false");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };
    t.start();
    // Make sure that our thread is waiting for the lock.
    ThreadUtil.sleepAtLeastIgnoreInterrupts(1000);
    assertFalse(nns[1].getNamesystem().getFsLockForTests().hasQueuedThreads());
    assertFalse(nns[1].getNamesystem().getFsLockForTests().isWriteLocked());
    assertTrue(nns[1].getNamesystem().getCpLockForTests().hasQueuedThreads());
    // Get /jmx of the standby NN web UI, which will cause the FSNS read lock to
    // be taken.
    String pageContents = DFSTestUtil.urlGet(new URL("http://" + nns[1].getHttpAddress().getHostName() + ":" + nns[1].getHttpAddress().getPort() + "/jmx"));
    assertTrue(pageContents.contains("NumLiveDataNodes"));
    // Make sure that the checkpoint is still going on, implying that the client
    // RPC to the SBN happened during the checkpoint.
    assertTrue("SBN should have still been checkpointing.", answerer.getFireCount() == 1 && answerer.getResultCount() == 0);
    answerer.proceed();
    answerer.waitForResult();
    assertTrue("SBN should have finished checkpointing.", answerer.getFireCount() == 1 && answerer.getResultCount() == 1);
    t.join();
}
Also used : Canceler(org.apache.hadoop.hdfs.util.Canceler) NameNodeFile(org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile) DelayAnswer(org.apache.hadoop.test.GenericTestUtils.DelayAnswer) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Aggregations

DelayAnswer (org.apache.hadoop.test.GenericTestUtils.DelayAnswer)11 Test (org.junit.Test)10 Configuration (org.apache.hadoop.conf.Configuration)6 DatanodeProtocolClientSideTranslatorPB (org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB)5 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)4 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)4 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)4 DataNode (org.apache.hadoop.hdfs.server.datanode.DataNode)4 Path (org.apache.hadoop.fs.Path)3 NameNode (org.apache.hadoop.hdfs.server.namenode.NameNode)3 Canceler (org.apache.hadoop.hdfs.util.Canceler)3 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)2 DatanodeID (org.apache.hadoop.hdfs.protocol.DatanodeID)2 ExtendedBlock (org.apache.hadoop.hdfs.protocol.ExtendedBlock)2 DatanodeDescriptor (org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor)2