Search in sources :

Example 76 with InterruptedIOException

use of java.io.InterruptedIOException in project hbase by apache.

the class FSUtils method setClusterId.

/**
   * Writes a new unique identifier for this cluster to the "hbase.id" file
   * in the HBase root directory
   * @param fs the root directory FileSystem
   * @param rootdir the path to the HBase root directory
   * @param clusterId the unique identifier to store
   * @param wait how long (in milliseconds) to wait between retries
   * @throws IOException if writing to the FileSystem fails and no wait value
   */
public static void setClusterId(FileSystem fs, Path rootdir, ClusterId clusterId, int wait) throws IOException {
    while (true) {
        try {
            Path idFile = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
            Path tempIdFile = new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY + Path.SEPARATOR + HConstants.CLUSTER_ID_FILE_NAME);
            // Write the id file to a temporary location
            FSDataOutputStream s = fs.create(tempIdFile);
            try {
                s.write(clusterId.toByteArray());
                s.close();
                s = null;
                // the rename failed
                if (!fs.rename(tempIdFile, idFile)) {
                    throw new IOException("Unable to move temp version file to " + idFile);
                }
            } finally {
                // Attempt to close the stream if still open on the way out
                try {
                    if (s != null)
                        s.close();
                } catch (IOException ignore) {
                }
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Created cluster ID file at " + idFile.toString() + " with ID: " + clusterId);
            }
            return;
        } catch (IOException ioe) {
            if (wait > 0) {
                LOG.warn("Unable to create cluster ID file in " + rootdir.toString() + ", retrying in " + wait + "msec: " + StringUtils.stringifyException(ioe));
                try {
                    Thread.sleep(wait);
                } catch (InterruptedException e) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
                }
            } else {
                throw ioe;
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) InterruptedIOException(java.io.InterruptedIOException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 77 with InterruptedIOException

use of java.io.InterruptedIOException in project hbase by apache.

the class FSUtils method setVersion.

/**
   * Sets version of file system
   *
   * @param fs filesystem object
   * @param rootdir hbase root directory
   * @param version version to set
   * @param wait time to wait for retry
   * @param retries number of times to retry before throwing an IOException
   * @throws IOException e
   */
public static void setVersion(FileSystem fs, Path rootdir, String version, int wait, int retries) throws IOException {
    Path versionFile = new Path(rootdir, HConstants.VERSION_FILE_NAME);
    Path tempVersionFile = new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY + Path.SEPARATOR + HConstants.VERSION_FILE_NAME);
    while (true) {
        try {
            // Write the version to a temporary file
            FSDataOutputStream s = fs.create(tempVersionFile);
            try {
                s.write(toVersionByteArray(version));
                s.close();
                s = null;
                // if the rename failed. Throw an IOE in that case.
                if (!fs.rename(tempVersionFile, versionFile)) {
                    throw new IOException("Unable to move temp version file to " + versionFile);
                }
            } finally {
                // Attempt to close the stream on the way out if it is still open.
                try {
                    if (s != null)
                        s.close();
                } catch (IOException ignore) {
                }
            }
            LOG.info("Created version file at " + rootdir.toString() + " with version=" + version);
            return;
        } catch (IOException e) {
            if (retries > 0) {
                LOG.debug("Unable to create version file at " + rootdir.toString() + ", retrying", e);
                fs.delete(versionFile, false);
                try {
                    if (wait > 0) {
                        Thread.sleep(wait);
                    }
                } catch (InterruptedException ie) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(ie);
                }
                retries--;
            } else {
                throw e;
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) InterruptedIOException(java.io.InterruptedIOException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 78 with InterruptedIOException

use of java.io.InterruptedIOException in project hbase by apache.

the class TestClientOperationInterrupt method testInterrupt50Percent.

@Test
public void testInterrupt50Percent() throws IOException, InterruptedException {
    final AtomicInteger noEx = new AtomicInteger(0);
    final AtomicInteger badEx = new AtomicInteger(0);
    final AtomicInteger noInt = new AtomicInteger(0);
    final AtomicInteger done = new AtomicInteger(0);
    List<Thread> threads = new ArrayList<>();
    final int nbThread = 100;
    for (int i = 0; i < nbThread; i++) {
        Thread t = new Thread() {

            @Override
            public void run() {
                try {
                    Table ht = util.getConnection().getTable(tableName);
                    Result r = ht.get(new Get(row1));
                    noEx.incrementAndGet();
                } catch (IOException e) {
                    LOG.info("exception", e);
                    if (!(e instanceof InterruptedIOException) || (e instanceof SocketTimeoutException)) {
                        badEx.incrementAndGet();
                    } else {
                        if (Thread.currentThread().isInterrupted()) {
                            noInt.incrementAndGet();
                            LOG.info("The thread should NOT be with the 'interrupt' status.");
                        }
                    }
                } finally {
                    done.incrementAndGet();
                }
            }
        };
        t.setName("TestClientOperationInterrupt #" + i);
        threads.add(t);
        t.start();
    }
    for (int i = 0; i < nbThread / 2; i++) {
        threads.get(i).interrupt();
    }
    boolean stillAlive = true;
    while (stillAlive) {
        stillAlive = false;
        for (Thread t : threads) {
            if (t.isAlive()) {
                stillAlive = true;
            }
        }
        Threads.sleep(10);
    }
    Assert.assertFalse(Thread.currentThread().isInterrupted());
    Assert.assertTrue(" noEx: " + noEx.get() + ", badEx=" + badEx.get() + ", noInt=" + noInt.get(), noEx.get() == nbThread / 2 && badEx.get() == 0);
    // The problem here is that we need the server to free its handlers to handle all operations
    while (done.get() != nbThread) {
        Thread.sleep(1);
    }
    Table ht = util.getConnection().getTable(tableName);
    Result r = ht.get(new Get(row1));
    Assert.assertFalse(r.isEmpty());
}
Also used : InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 79 with InterruptedIOException

use of java.io.InterruptedIOException in project hadoop by apache.

the class RecoveredContainerLaunch method call.

/**
   * Wait on the process specified in pid file and return its exit code
   */
@SuppressWarnings("unchecked")
@Override
public Integer call() {
    int retCode = ExitCode.LOST.getExitCode();
    ContainerId containerId = container.getContainerId();
    String appIdStr = containerId.getApplicationAttemptId().getApplicationId().toString();
    String containerIdStr = containerId.toString();
    dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_LAUNCHED));
    boolean notInterrupted = true;
    try {
        File pidFile = locatePidFile(appIdStr, containerIdStr);
        if (pidFile != null) {
            String pidPathStr = pidFile.getPath();
            pidFilePath = new Path(pidPathStr);
            exec.activateContainer(containerId, pidFilePath);
            retCode = exec.reacquireContainer(new ContainerReacquisitionContext.Builder().setContainer(container).setUser(container.getUser()).setContainerId(containerId).build());
        } else {
            LOG.warn("Unable to locate pid file for container " + containerIdStr);
        }
    } catch (InterruptedException | InterruptedIOException e) {
        LOG.warn("Interrupted while waiting for exit code from " + containerId);
        notInterrupted = false;
    } catch (IOException e) {
        LOG.error("Unable to recover container " + containerIdStr, e);
    } finally {
        if (notInterrupted) {
            this.completed.set(true);
            exec.deactivateContainer(containerId);
            try {
                getContext().getNMStateStore().storeContainerCompleted(containerId, retCode);
            } catch (IOException e) {
                LOG.error("Unable to set exit code for container " + containerId);
            }
        }
    }
    if (retCode != 0) {
        LOG.warn("Recovered container exited with a non-zero exit code " + retCode);
        this.dispatcher.getEventHandler().handle(new ContainerExitEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_FAILURE, retCode, "Container exited with a non-zero exit code " + retCode));
        return retCode;
    }
    LOG.info("Recovered container " + containerId + " succeeded");
    dispatcher.getEventHandler().handle(new ContainerEvent(containerId, ContainerEventType.CONTAINER_EXITED_WITH_SUCCESS));
    return 0;
}
Also used : ContainerEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent) Path(org.apache.hadoop.fs.Path) InterruptedIOException(java.io.InterruptedIOException) ContainerExitEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerExitEvent) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) File(java.io.File)

Example 80 with InterruptedIOException

use of java.io.InterruptedIOException in project hadoop by apache.

the class TestCopy method testInterruptedRename.

@Test
public void testInterruptedRename() throws Exception {
    FSDataOutputStream out = mock(FSDataOutputStream.class);
    whenFsCreate().thenReturn(out);
    when(mockFs.getFileStatus(eq(tmpPath))).thenReturn(fileStat);
    when(mockFs.rename(eq(tmpPath), eq(path))).thenThrow(new InterruptedIOException());
    FSInputStream in = mock(FSInputStream.class);
    when(in.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1);
    tryCopyStream(in, false);
    verify(mockFs).delete(eq(tmpPath), anyBoolean());
    verify(mockFs).rename(eq(tmpPath), eq(path));
    verify(mockFs, never()).delete(eq(path), anyBoolean());
    verify(mockFs, never()).close();
}
Also used : InterruptedIOException(java.io.InterruptedIOException) FSInputStream(org.apache.hadoop.fs.FSInputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Test(org.junit.Test)

Aggregations

InterruptedIOException (java.io.InterruptedIOException)286 IOException (java.io.IOException)195 Test (org.junit.Test)40 Socket (java.net.Socket)28 ArrayList (java.util.ArrayList)27 InputStream (java.io.InputStream)23 ExecutionException (java.util.concurrent.ExecutionException)23 ConnectException (java.net.ConnectException)22 InetSocketAddress (java.net.InetSocketAddress)21 ByteBuffer (java.nio.ByteBuffer)21 Path (org.apache.hadoop.fs.Path)20 NoRouteToHostException (java.net.NoRouteToHostException)19 EOFException (java.io.EOFException)17 OutputStream (java.io.OutputStream)17 SocketTimeoutException (java.net.SocketTimeoutException)17 ServletException (javax.servlet.ServletException)17 CountDownLatch (java.util.concurrent.CountDownLatch)16 SocketException (java.net.SocketException)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)15