Search in sources :

Example 21 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hadoop by apache.

the class BPServiceActor method register.

/**
   * Register one bp with the corresponding NameNode
   * <p>
   * The bpDatanode needs to register with the namenode on startup in order
   * 1) to report which storage it is serving now and 
   * 2) to receive a registrationID
   *  
   * issued by the namenode to recognize registered datanodes.
   * 
   * @param nsInfo current NamespaceInfo
   * @see FSNamesystem#registerDatanode(DatanodeRegistration)
   * @throws IOException
   */
void register(NamespaceInfo nsInfo) throws IOException {
    // The handshake() phase loaded the block pool storage
    // off disk - so update the bpRegistration object from that info
    DatanodeRegistration newBpRegistration = bpos.createRegistration();
    LOG.info(this + " beginning handshake with NN");
    while (shouldRun()) {
        try {
            // Use returned registration from namenode with updated fields
            newBpRegistration = bpNamenode.registerDatanode(newBpRegistration);
            newBpRegistration.setNamespaceInfo(nsInfo);
            bpRegistration = newBpRegistration;
            break;
        } catch (EOFException e) {
            // namenode might have just restarted
            LOG.info("Problem connecting to server: " + nnAddr + " :" + e.getLocalizedMessage());
            sleepAndLogInterrupts(1000, "connecting to server");
        } catch (SocketTimeoutException e) {
            // namenode is busy
            LOG.info("Problem connecting to server: " + nnAddr);
            sleepAndLogInterrupts(1000, "connecting to server");
        }
    }
    LOG.info("Block pool " + this + " successfully registered with NN");
    bpos.registrationSucceeded(this, bpRegistration);
    // random short delay - helps scatter the BR from all DNs
    scheduler.scheduleBlockReport(dnConf.initialBlockReportDelayMs);
}
Also used : DatanodeRegistration(org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException)

Example 22 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hadoop by apache.

the class TestTransferFsImage method testImageUploadTimeout.

/**
   * Test to verify the timeout of Image upload
   */
@Test(timeout = 10000)
public void testImageUploadTimeout() throws Exception {
    Configuration conf = new HdfsConfiguration();
    NNStorage mockStorage = Mockito.mock(NNStorage.class);
    HttpServer2 testServer = HttpServerFunctionalTest.createServer("hdfs");
    try {
        testServer.addServlet("ImageTransfer", ImageServlet.PATH_SPEC, TestImageTransferServlet.class);
        testServer.start();
        URL serverURL = HttpServerFunctionalTest.getServerURL(testServer);
        // set the timeout here, otherwise it will take default.
        TransferFsImage.timeout = 2000;
        File tmpDir = new File(new FileSystemTestHelper().getTestRootDir());
        tmpDir.mkdirs();
        File mockImageFile = File.createTempFile("image", "", tmpDir);
        FileOutputStream imageFile = new FileOutputStream(mockImageFile);
        imageFile.write("data".getBytes());
        imageFile.close();
        Mockito.when(mockStorage.findImageFile(Mockito.any(NameNodeFile.class), Mockito.anyLong())).thenReturn(mockImageFile);
        Mockito.when(mockStorage.toColonSeparatedString()).thenReturn("storage:info:string");
        try {
            TransferFsImage.uploadImageFromStorage(serverURL, conf, mockStorage, NameNodeFile.IMAGE, 1L);
            fail("TransferImage Should fail with timeout");
        } catch (SocketTimeoutException e) {
            assertEquals("Upload should timeout", "Read timed out", e.getMessage());
        }
    } finally {
        testServer.stop();
    }
}
Also used : FileSystemTestHelper(org.apache.hadoop.fs.FileSystemTestHelper) SocketTimeoutException(java.net.SocketTimeoutException) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) FileOutputStream(java.io.FileOutputStream) NameNodeFile(org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) HttpServer2(org.apache.hadoop.http.HttpServer2) File(java.io.File) NameNodeFile(org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile) URL(java.net.URL) HttpServerFunctionalTest(org.apache.hadoop.http.HttpServerFunctionalTest) Test(org.junit.Test)

Example 23 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hadoop by apache.

the class TestTimelineClient method createTimelineClientFakeTimelineClientRetryOp.

private TimelineClientImpl createTimelineClientFakeTimelineClientRetryOp(YarnConfiguration conf) {
    TimelineClientImpl client = new TimelineClientImpl() {

        @Override
        protected TimelineConnector createTimelineConnector() {
            TimelineConnector connector = new TimelineConnector(true, authUgi, doAsUser, token) {

                @Override
                public TimelineClientRetryOp createRetryOpForOperateDelegationToken(final PrivilegedExceptionAction<?> action) throws IOException {
                    TimelineClientRetryOpForOperateDelegationToken op = spy(new TimelineClientRetryOpForOperateDelegationToken(UserGroupInformation.getCurrentUser(), action));
                    doThrow(new SocketTimeoutException("Test socketTimeoutException")).when(op).run();
                    return op;
                }
            };
            addIfService(connector);
            return connector;
        }
    };
    client.init(conf);
    client.start();
    return client;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 24 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hbase by apache.

the class TestClientNoCluster method testTimeoutAndRetries.

/**
   * Remove the @Ignore to try out timeout and retry asettings
   * @throws IOException
   */
@Ignore
@Test
public void testTimeoutAndRetries() throws IOException {
    Configuration localConfig = HBaseConfiguration.create(this.conf);
    // This override mocks up our exists/get call to throw a RegionServerStoppedException.
    localConfig.set("hbase.client.connection.impl", RpcTimeoutConnection.class.getName());
    Connection connection = ConnectionFactory.createConnection(localConfig);
    Table table = connection.getTable(TableName.META_TABLE_NAME);
    Throwable t = null;
    LOG.info("Start");
    try {
        // An exists call turns into a get w/ a flag.
        table.exists(new Get(Bytes.toBytes("abc")));
    } catch (SocketTimeoutException e) {
        // I expect this exception.
        LOG.info("Got expected exception", e);
        t = e;
    } catch (RetriesExhaustedException e) {
        // This is the old, unwanted behavior.  If we get here FAIL!!!
        fail();
    } finally {
        table.close();
    }
    connection.close();
    LOG.info("Stop");
    assertTrue(t != null);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hbase by apache.

the class TestIPCUtil method testWrapException.

@Test
public void testWrapException() throws Exception {
    final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0);
    assertTrue(wrapException(address, new ConnectException()) instanceof ConnectException);
    assertTrue(wrapException(address, new SocketTimeoutException()) instanceof SocketTimeoutException);
    assertTrue(wrapException(address, new ConnectionClosingException("Test AbstractRpcClient#wrapException")) instanceof ConnectionClosingException);
    assertTrue(wrapException(address, new CallTimeoutException("Test AbstractRpcClient#wrapException")).getCause() instanceof CallTimeoutException);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) ConnectionClosingException(org.apache.hadoop.hbase.exceptions.ConnectionClosingException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Aggregations

SocketTimeoutException (java.net.SocketTimeoutException)369 IOException (java.io.IOException)200 Test (org.junit.Test)91 Socket (java.net.Socket)52 SocketException (java.net.SocketException)46 InputStream (java.io.InputStream)43 ServerSocket (java.net.ServerSocket)42 InetSocketAddress (java.net.InetSocketAddress)38 ConnectException (java.net.ConnectException)34 UnknownHostException (java.net.UnknownHostException)31 OutputStream (java.io.OutputStream)27 MalformedURLException (java.net.MalformedURLException)27 URL (java.net.URL)27 DatagramPacket (java.net.DatagramPacket)25 HttpURLConnection (java.net.HttpURLConnection)23 HashMap (java.util.HashMap)21 File (java.io.File)20 ArrayList (java.util.ArrayList)20 InterruptedIOException (java.io.InterruptedIOException)19 BufferedInputStream (java.io.BufferedInputStream)18