Search in sources :

Example 21 with InterruptedIOException

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

the class RemoteAdmin method createTable.

/**
   * Creates a new table.
   * @param desc table descriptor for table
   * @throws IOException if a remote or network exception occurs
   */
public void createTable(HTableDescriptor desc) throws IOException {
    TableSchemaModel model = new TableSchemaModel(desc);
    StringBuilder path = new StringBuilder();
    path.append('/');
    if (accessToken != null) {
        path.append(accessToken);
        path.append('/');
    }
    path.append(desc.getTableName());
    path.append('/');
    path.append("schema");
    int code = 0;
    for (int i = 0; i < maxRetries; i++) {
        Response response = client.put(path.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
        code = response.getCode();
        switch(code) {
            case 201:
                return;
            case 509:
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
                }
                break;
            default:
                throw new IOException("create request to " + path.toString() + " returned " + code);
        }
    }
    throw new IOException("create request to " + path.toString() + " timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) TableSchemaModel(org.apache.hadoop.hbase.rest.model.TableSchemaModel) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 22 with InterruptedIOException

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

the class RemoteHTable method put.

@Override
public void put(Put put) throws IOException {
    CellSetModel model = buildModelFromPut(put);
    StringBuilder sb = new StringBuilder();
    sb.append('/');
    sb.append(Bytes.toString(name));
    sb.append('/');
    sb.append(toURLEncodedBytes(put.getRow()));
    for (int i = 0; i < maxRetries; i++) {
        Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
        int code = response.getCode();
        switch(code) {
            case 200:
                return;
            case 509:
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
                }
                break;
            default:
                throw new IOException("put request failed with " + code);
        }
    }
    throw new IOException("put request timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 23 with InterruptedIOException

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

the class RemoteHTable method delete.

@Override
public void delete(Delete delete) throws IOException {
    String spec = buildRowSpec(delete.getRow(), delete.getFamilyCellMap(), delete.getTimeStamp(), delete.getTimeStamp(), 1);
    for (int i = 0; i < maxRetries; i++) {
        Response response = client.delete(spec);
        int code = response.getCode();
        switch(code) {
            case 200:
                return;
            case 509:
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
                }
                break;
            default:
                throw new IOException("delete request failed with " + code);
        }
    }
    throw new IOException("delete request timed out");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 24 with InterruptedIOException

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

the class ZKProcedureCoordinator method sendGlobalBarrierReached.

@Override
public void sendGlobalBarrierReached(Procedure proc, List<String> nodeNames) throws IOException {
    String procName = proc.getName();
    String reachedNode = zkProc.getReachedBarrierNode(procName);
    LOG.debug("Creating reached barrier zk node:" + reachedNode);
    try {
        // create the reached znode and watch for the reached znodes
        ZKUtil.createWithParents(zkProc.getWatcher(), reachedNode);
        // loop through all the children of the acquire phase and watch for them
        for (String node : nodeNames) {
            String znode = ZKUtil.joinZNode(reachedNode, node);
            if (ZKUtil.watchAndCheckExists(zkProc.getWatcher(), znode)) {
                byte[] dataFromMember = ZKUtil.getData(zkProc.getWatcher(), znode);
                // ProtobufUtil.isPBMagicPrefix will check null
                if (dataFromMember != null && dataFromMember.length > 0) {
                    if (!ProtobufUtil.isPBMagicPrefix(dataFromMember)) {
                        String msg = "Failed to get data from finished node or data is illegally formatted: " + znode;
                        LOG.error(msg);
                        throw new IOException(msg);
                    } else {
                        dataFromMember = Arrays.copyOfRange(dataFromMember, ProtobufUtil.lengthOfPBMagic(), dataFromMember.length);
                        coordinator.memberFinishedBarrier(procName, node, dataFromMember);
                    }
                } else {
                    coordinator.memberFinishedBarrier(procName, node, dataFromMember);
                }
            }
        }
    } catch (KeeperException e) {
        String msg = "Failed while creating reached node:" + reachedNode;
        LOG.error(msg, e);
        throw new IOException(msg, e);
    } catch (InterruptedException e) {
        String msg = "Interrupted while creating reached node:" + reachedNode;
        LOG.error(msg, e);
        throw new InterruptedIOException(msg);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 25 with InterruptedIOException

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

the class ProcedureSyncWait method waitFor.

public static <T> T waitFor(MasterProcedureEnv env, long waitTime, long waitingTimeForEvents, String purpose, Predicate<T> predicate) throws IOException {
    final long done = EnvironmentEdgeManager.currentTime() + waitTime;
    do {
        T result = predicate.evaluate();
        if (result != null && !result.equals(Boolean.FALSE)) {
            return result;
        }
        try {
            Thread.sleep(waitingTimeForEvents);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while sleeping, waiting on " + purpose);
            throw (InterruptedIOException) new InterruptedIOException().initCause(e);
        }
        LOG.debug("Waiting on " + purpose);
    } while (EnvironmentEdgeManager.currentTime() < done && env.isRunning());
    throw new TimeoutIOException("Timed out while waiting on " + purpose);
}
Also used : InterruptedIOException(java.io.InterruptedIOException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException)

Aggregations

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