Search in sources :

Example 1 with LeaseExpiredException

use of org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException in project hadoop by apache.

the class TestFileAppend4 method testRecoverFinalizedBlock.

/**
   * Test case that stops a writer after finalizing a block but
   * before calling completeFile, and then tries to recover
   * the lease from another thread.
   */
@Test(timeout = 60000)
public void testRecoverFinalizedBlock() throws Throwable {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(5).build();
    try {
        cluster.waitActive();
        NamenodeProtocols preSpyNN = cluster.getNameNodeRpc();
        NamenodeProtocols spyNN = spy(preSpyNN);
        // Delay completeFile
        GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG);
        doAnswer(delayer).when(spyNN).complete(anyString(), anyString(), (ExtendedBlock) anyObject(), anyLong());
        DFSClient client = new DFSClient(null, spyNN, conf, null);
        file1 = new Path("/testRecoverFinalized");
        final OutputStream stm = client.create("/testRecoverFinalized", true);
        // write 1/2 block
        AppendTestUtil.write(stm, 0, 4096);
        final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
        Thread t = new Thread() {

            @Override
            public void run() {
                try {
                    stm.close();
                } catch (Throwable t) {
                    err.set(t);
                }
            }
        };
        t.start();
        LOG.info("Waiting for close to get to latch...");
        delayer.waitForCall();
        // At this point, the block is finalized on the DNs, but the file
        // has not been completed in the NN.
        // Lose the leases
        LOG.info("Killing lease checker");
        client.getLeaseRenewer().interruptAndJoin();
        FileSystem fs1 = cluster.getFileSystem();
        FileSystem fs2 = AppendTestUtil.createHdfsWithDifferentUsername(fs1.getConf());
        LOG.info("Recovering file");
        recoverFile(fs2);
        LOG.info("Telling close to proceed.");
        delayer.proceed();
        LOG.info("Waiting for close to finish.");
        t.join();
        LOG.info("Close finished.");
        // We expect that close will get a "File is not open" error.
        Throwable thrownByClose = err.get();
        assertNotNull(thrownByClose);
        assertTrue(thrownByClose instanceof LeaseExpiredException);
        GenericTestUtils.assertExceptionContains("File is not open for writing", thrownByClose);
    } finally {
        cluster.shutdown();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) NamenodeProtocols(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) GenericTestUtils(org.apache.hadoop.test.GenericTestUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) LeaseExpiredException(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.Test)

Example 2 with LeaseExpiredException

use of org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException in project hbase by apache.

the class TestWALSplit method testMovedWALDuringRecovery.

// Test for HBASE-3412
@Test(timeout = 300000)
public void testMovedWALDuringRecovery() throws Exception {
    // This partial mock will throw LEE for every file simulating
    // files that were moved
    FileSystem spiedFs = Mockito.spy(fs);
    // The "File does not exist" part is very important,
    // that's how it comes out of HDFS
    Mockito.doThrow(new LeaseExpiredException("Injected: File does not exist")).when(spiedFs).append(Mockito.<Path>any());
    retryOverHdfsProblem(spiedFs);
}
Also used : LeaseExpiredException(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.Test)

Example 3 with LeaseExpiredException

use of org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException in project hbase by apache.

the class FSHDFSUtils method recoverLease.

/**
   * Try to recover the lease.
   * @param dfs
   * @param nbAttempt
   * @param p
   * @param startWaiting
   * @return True if dfs#recoverLease came by true.
   * @throws FileNotFoundException
   */
boolean recoverLease(final DistributedFileSystem dfs, final int nbAttempt, final Path p, final long startWaiting) throws FileNotFoundException {
    boolean recovered = false;
    try {
        recovered = dfs.recoverLease(p);
        LOG.info((recovered ? "Recovered lease, " : "Failed to recover lease, ") + getLogMessageDetail(nbAttempt, p, startWaiting));
    } catch (IOException e) {
        if (e instanceof LeaseExpiredException && e.getMessage().contains("File does not exist")) {
            // This exception comes out instead of FNFE, fix it
            throw new FileNotFoundException("The given WAL wasn't found at " + p);
        } else if (e instanceof FileNotFoundException) {
            throw (FileNotFoundException) e;
        }
        LOG.warn(getLogMessageDetail(nbAttempt, p, startWaiting), e);
    }
    return recovered;
}
Also used : LeaseExpiredException(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 4 with LeaseExpiredException

use of org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException in project hadoop by apache.

the class TestClientProtocolForPipelineRecovery method testGetNewStamp.

@Test
public void testGetNewStamp() throws IOException {
    int numDataNodes = 1;
    Configuration conf = new HdfsConfiguration();
    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDataNodes).build();
    try {
        cluster.waitActive();
        FileSystem fileSys = cluster.getFileSystem();
        NamenodeProtocols namenode = cluster.getNameNodeRpc();
        /* Test writing to finalized replicas */
        Path file = new Path("dataprotocol.dat");
        DFSTestUtil.createFile(fileSys, file, 1L, (short) numDataNodes, 0L);
        // get the first blockid for the file
        ExtendedBlock firstBlock = DFSTestUtil.getFirstBlock(fileSys, file);
        // test getNewStampAndToken on a finalized block
        try {
            namenode.updateBlockForPipeline(firstBlock, "");
            Assert.fail("Can not get a new GS from a finalized block");
        } catch (IOException e) {
            Assert.assertTrue(e.getMessage().contains("not " + BlockUCState.UNDER_CONSTRUCTION));
        }
        // test getNewStampAndToken on a non-existent block
        try {
            long newBlockId = firstBlock.getBlockId() + 1;
            ExtendedBlock newBlock = new ExtendedBlock(firstBlock.getBlockPoolId(), newBlockId, 0, firstBlock.getGenerationStamp());
            namenode.updateBlockForPipeline(newBlock, "");
            Assert.fail("Cannot get a new GS from a non-existent block");
        } catch (IOException e) {
            Assert.assertTrue(e.getMessage().contains("does not exist"));
        }
        /* Test RBW replicas */
        // change first block to a RBW
        DFSOutputStream out = null;
        try {
            out = (DFSOutputStream) (fileSys.append(file).getWrappedStream());
            out.write(1);
            out.hflush();
            FSDataInputStream in = null;
            try {
                in = fileSys.open(file);
                firstBlock = DFSTestUtil.getAllBlocks(in).get(0).getBlock();
            } finally {
                IOUtils.closeStream(in);
            }
            // test non-lease holder
            DFSClient dfs = ((DistributedFileSystem) fileSys).dfs;
            try {
                namenode.updateBlockForPipeline(firstBlock, "test" + dfs.clientName);
                Assert.fail("Cannot get a new GS for a non lease holder");
            } catch (LeaseExpiredException e) {
                Assert.assertTrue(e.getMessage().startsWith("Lease mismatch"));
            }
            // test null lease holder
            try {
                namenode.updateBlockForPipeline(firstBlock, null);
                Assert.fail("Cannot get a new GS for a null lease holder");
            } catch (LeaseExpiredException e) {
                Assert.assertTrue(e.getMessage().startsWith("Lease mismatch"));
            }
            // test getNewStampAndToken on a rbw block
            namenode.updateBlockForPipeline(firstBlock, dfs.clientName);
        } finally {
            IOUtils.closeStream(out);
        }
    } finally {
        cluster.shutdown();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) NamenodeProtocols(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols) Configuration(org.apache.hadoop.conf.Configuration) ExtendedBlock(org.apache.hadoop.hdfs.protocol.ExtendedBlock) IOException(java.io.IOException) LeaseExpiredException(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) Test(org.junit.Test)

Example 5 with LeaseExpiredException

use of org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException in project hadoop by apache.

the class TestFileAppend4 method testCompleteOtherLeaseHoldersFile.

/**
   * Test case that stops a writer after finalizing a block but
   * before calling completeFile, recovers a file from another writer,
   * starts writing from that writer, and then has the old lease holder
   * call completeFile
   */
@Test(timeout = 60000)
public void testCompleteOtherLeaseHoldersFile() throws Throwable {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(5).build();
    try {
        cluster.waitActive();
        NamenodeProtocols preSpyNN = cluster.getNameNodeRpc();
        NamenodeProtocols spyNN = spy(preSpyNN);
        // Delay completeFile
        GenericTestUtils.DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG);
        doAnswer(delayer).when(spyNN).complete(anyString(), anyString(), (ExtendedBlock) anyObject(), anyLong());
        DFSClient client = new DFSClient(null, spyNN, conf, null);
        file1 = new Path("/testCompleteOtherLease");
        final OutputStream stm = client.create("/testCompleteOtherLease", true);
        // write 1/2 block
        AppendTestUtil.write(stm, 0, 4096);
        final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
        Thread t = new Thread() {

            @Override
            public void run() {
                try {
                    stm.close();
                } catch (Throwable t) {
                    err.set(t);
                }
            }
        };
        t.start();
        LOG.info("Waiting for close to get to latch...");
        delayer.waitForCall();
        // At this point, the block is finalized on the DNs, but the file
        // has not been completed in the NN.
        // Lose the leases
        LOG.info("Killing lease checker");
        client.getLeaseRenewer().interruptAndJoin();
        FileSystem fs1 = cluster.getFileSystem();
        FileSystem fs2 = AppendTestUtil.createHdfsWithDifferentUsername(fs1.getConf());
        LOG.info("Recovering file");
        recoverFile(fs2);
        LOG.info("Opening file for append from new fs");
        FSDataOutputStream appenderStream = fs2.append(file1);
        LOG.info("Writing some data from new appender");
        AppendTestUtil.write(appenderStream, 0, 4096);
        LOG.info("Telling old close to proceed.");
        delayer.proceed();
        LOG.info("Waiting for close to finish.");
        t.join();
        LOG.info("Close finished.");
        // We expect that close will get a "Lease mismatch"
        // error.
        Throwable thrownByClose = err.get();
        assertNotNull(thrownByClose);
        assertTrue(thrownByClose instanceof LeaseExpiredException);
        GenericTestUtils.assertExceptionContains("not the lease owner", thrownByClose);
        // The appender should be able to close properly
        appenderStream.close();
    } finally {
        cluster.shutdown();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) NamenodeProtocols(org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) GenericTestUtils(org.apache.hadoop.test.GenericTestUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) LeaseExpiredException(org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Test(org.junit.Test)

Aggregations

LeaseExpiredException (org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException)6 FileSystem (org.apache.hadoop.fs.FileSystem)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 Path (org.apache.hadoop.fs.Path)3 NamenodeProtocols (org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols)3 FileNotFoundException (java.io.FileNotFoundException)2 InterruptedIOException (java.io.InterruptedIOException)2 OutputStream (java.io.OutputStream)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 GenericTestUtils (org.apache.hadoop.test.GenericTestUtils)2 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 ExtendedBlock (org.apache.hadoop.hdfs.protocol.ExtendedBlock)1