Example usage for java.io InterruptedIOException InterruptedIOException

List of usage examples for java.io InterruptedIOException InterruptedIOException

Introduction

In this page you can find the example usage for java.io InterruptedIOException InterruptedIOException.

Prototype

public InterruptedIOException() 

Source Link

Document

Constructs an InterruptedIOException with null as its error detail message.

Usage

From source file:org.apache.hadoop.hbase.master.SplitLogManager.java

/**
 * Create znodes /hbase/recovering-regions/[region_ids...]/[failed region server names ...] for
 * all regions of the passed in region servers
 * @param serverName the name of a region server
 * @param userRegions user regiones assigned on the region server
 *//*from  w  ww  . j  a  va 2 s  .  co  m*/
void markRegionsRecoveringInZK(final ServerName serverName, Set<HRegionInfo> userRegions)
        throws KeeperException, InterruptedIOException {
    if (userRegions == null || !this.distributedLogReplay) {
        return;
    }

    try {
        this.recoveringRegionLock.lock();
        // mark that we're creating recovering znodes
        this.lastRecoveringNodeCreationTime = EnvironmentEdgeManager.currentTimeMillis();

        for (HRegionInfo region : userRegions) {
            String regionEncodeName = region.getEncodedName();
            long retries = this.zkretries;

            do {
                String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, regionEncodeName);
                long lastRecordedFlushedSequenceId = -1;
                try {
                    long lastSequenceId = this.master.getServerManager()
                            .getLastFlushedSequenceId(regionEncodeName.getBytes());

                    /*
                     * znode layout: .../region_id[last known flushed sequence id]/failed server[last known
                     * flushed sequence id for the server]
                     */
                    byte[] data = ZKUtil.getData(this.watcher, nodePath);
                    if (data == null) {
                        ZKUtil.createSetData(this.watcher, nodePath,
                                ZKUtil.positionToByteArray(lastSequenceId));
                    } else {
                        lastRecordedFlushedSequenceId = SplitLogManager.parseLastFlushedSequenceIdFrom(data);
                        if (lastRecordedFlushedSequenceId < lastSequenceId) {
                            // update last flushed sequence id in the region level
                            ZKUtil.setData(this.watcher, nodePath, ZKUtil.positionToByteArray(lastSequenceId));
                        }
                    }
                    // go one level deeper with server name
                    nodePath = ZKUtil.joinZNode(nodePath, serverName.getServerName());
                    if (lastSequenceId <= lastRecordedFlushedSequenceId) {
                        // the newly assigned RS failed even before any flush to the region
                        lastSequenceId = lastRecordedFlushedSequenceId;
                    }
                    ZKUtil.createSetData(this.watcher, nodePath,
                            ZKUtil.regionSequenceIdsToByteArray(lastSequenceId, null));
                    LOG.debug("Mark region " + regionEncodeName + " recovering from failed region server "
                            + serverName);

                    // break retry loop
                    break;
                } catch (KeeperException e) {
                    // ignore ZooKeeper exceptions inside retry loop
                    if (retries <= 1) {
                        throw e;
                    }
                    // wait a little bit for retry
                    try {
                        Thread.sleep(20);
                    } catch (InterruptedException e1) {
                        throw new InterruptedIOException();
                    }
                } catch (InterruptedException e) {
                    throw new InterruptedIOException();
                }
            } while ((--retries) > 0 && (!this.stopper.isStopped()));
        }
    } finally {
        this.recoveringRegionLock.unlock();
    }
}

From source file:org.apache.hadoop.hbase.ipc.RpcClientImpl.java

/** Make a call, passing <code>param</code>, to the IPC server running at
 * <code>address</code> which is servicing the <code>protocol</code> protocol,
 * with the <code>ticket</code> credentials, returning the value.
 * Throws exceptions if there are network problems or if the remote code
 * threw an exception.//w  w  w . jav a 2s.  c o m
 * @param ticket Be careful which ticket you pass. A new user will mean a new Connection.
 *          {@link UserProvider#getCurrent()} makes a new instance of User each time so will be a
 *          new Connection each time.
 * @return A pair with the Message response and the Cell data (if any).
 * @throws InterruptedException
 * @throws IOException
 */
@Override
protected Pair<Message, CellScanner> call(PayloadCarryingRpcController pcrc, MethodDescriptor md, Message param,
        Message returnType, User ticket, InetSocketAddress addr) throws IOException, InterruptedException {
    if (pcrc == null) {
        pcrc = new PayloadCarryingRpcController();
    }
    CellScanner cells = pcrc.cellScanner();

    final Call call = new Call(this.callIdCnt.getAndIncrement(), md, param, cells, returnType,
            pcrc.getCallTimeout());

    final Connection connection = getConnection(ticket, call, addr);

    final CallFuture cts;
    if (connection.callSender != null) {
        cts = connection.callSender.sendCall(call, pcrc.getPriority(), Trace.currentSpan());
        pcrc.notifyOnCancel(new RpcCallback<Object>() {
            @Override
            public void run(Object parameter) {
                connection.callSender.remove(cts);
            }
        });
        if (pcrc.isCanceled()) {
            // To finish if the call was cancelled before we set the notification (race condition)
            call.callComplete();
            return new Pair<Message, CellScanner>(call.response, call.cells);
        }
    } else {
        cts = null;
        connection.tracedWriteRequest(call, pcrc.getPriority(), Trace.currentSpan());
    }

    while (!call.done) {
        if (call.checkAndSetTimeout()) {
            if (cts != null)
                connection.callSender.remove(cts);
            break;
        }
        if (connection.shouldCloseConnection.get()) {
            throw new ConnectionClosingException(
                    "Call id=" + call.id + " on server " + addr + " aborted: connection is closing");
        }
        try {
            synchronized (call) {
                if (call.done)
                    break;
                call.wait(Math.min(call.remainingTime(), 1000) + 1);
            }
        } catch (InterruptedException e) {
            call.setException(new InterruptedIOException());
            if (cts != null)
                connection.callSender.remove(cts);
            throw e;
        }
    }

    if (call.error != null) {
        if (call.error instanceof RemoteException) {
            call.error.fillInStackTrace();
            throw call.error;
        }
        // local exception
        throw wrapException(addr, call.error);
    }

    return new Pair<Message, CellScanner>(call.response, call.cells);
}

From source file:org.apache.hadoop.hbase.master.SplitLogManager.java

/**
 * This function is used in distributedLogReplay to fetch last flushed sequence id from ZK
 * @param zkw//from   ww  w  .jav a  2s.c  o m
 * @param serverName
 * @param encodedRegionName
 * @return the last flushed sequence ids recorded in ZK of the region for <code>serverName<code>
 * @throws IOException
 */
public static RegionStoreSequenceIds getRegionFlushedSequenceId(ZooKeeperWatcher zkw, String serverName,
        String encodedRegionName) throws IOException {
    // when SplitLogWorker recovers a region by directly replaying unflushed WAL edits,
    // last flushed sequence Id changes when newly assigned RS flushes writes to the region.
    // If the newly assigned RS fails again(a chained RS failures scenario), the last flushed
    // sequence Id name space (sequence Id only valid for a particular RS instance), changes
    // when different newly assigned RS flushes the region.
    // Therefore, in this mode we need to fetch last sequence Ids from ZK where we keep history of
    // last flushed sequence Id for each failed RS instance.
    RegionStoreSequenceIds result = null;
    String nodePath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, encodedRegionName);
    nodePath = ZKUtil.joinZNode(nodePath, serverName);
    try {
        byte[] data;
        try {
            data = ZKUtil.getData(zkw, nodePath);
        } catch (InterruptedException e) {
            throw new InterruptedIOException();
        }
        if (data != null) {
            result = ZKUtil.parseRegionStoreSequenceIds(data);
        }
    } catch (KeeperException e) {
        throw new IOException("Cannot get lastFlushedSequenceId from ZooKeeper for server=" + serverName
                + "; region=" + encodedRegionName, e);
    } catch (DeserializationException e) {
        LOG.warn("Can't parse last flushed sequence Id from znode:" + nodePath, e);
    }
    return result;
}

From source file:org.apache.hadoop.hbase.client.HTable.java

/**
 * {@inheritDoc}/*from www  .  j  a v a 2 s  . c o m*/
 */
@Override
public Boolean[] exists(final List<Get> gets) throws IOException {
    if (gets.isEmpty())
        return new Boolean[] {};
    if (gets.size() == 1)
        return new Boolean[] { exists(gets.get(0)) };

    for (Get g : gets) {
        g.setCheckExistenceOnly(true);
    }

    Object[] r1;
    try {
        r1 = batch(gets);
    } catch (InterruptedException e) {
        throw (InterruptedIOException) new InterruptedIOException().initCause(e);
    }

    // translate.
    Boolean[] results = new Boolean[r1.length];
    int i = 0;
    for (Object o : r1) {
        // batch ensures if there is a failure we get an exception instead
        results[i++] = ((Result) o).getExists();
    }

    return results;
}

From source file:org.apache.hadoop.hbase.regionserver.HRegion.java

private Map<byte[], List<StoreFile>> doClose(final boolean abort, MonitoredTask status) throws IOException {
    if (isClosed()) {
        LOG.warn("Region " + this + " already closed");
        return null;
    }/*from   w w  w. j  ava 2 s .c o m*/

    if (coprocessorHost != null) {
        status.setStatus("Running coprocessor pre-close hooks");
        this.coprocessorHost.preClose(abort);
    }

    status.setStatus("Disabling compacts and flushes for region");
    synchronized (writestate) {
        // Disable compacting and flushing by background threads for this
        // region.
        writestate.writesEnabled = false;
        LOG.debug("Closing " + this + ": disabling compactions & flushes");
        waitForFlushesAndCompactions();
    }
    // If we were not just flushing, is it worth doing a preflush...one
    // that will clear out of the bulk of the memstore before we put up
    // the close flag?
    if (!abort && worthPreFlushing()) {
        status.setStatus("Pre-flushing region before close");
        LOG.info("Running close preflush of " + this.getRegionNameAsString());
        try {
            internalFlushcache(status);
        } catch (IOException ioe) {
            // Failed to flush the region. Keep going.
            status.setStatus("Failed pre-flush " + this + "; " + ioe.getMessage());
        }
    }

    this.closing.set(true);
    status.setStatus("Disabling writes for close");
    // block waiting for the lock for closing
    lock.writeLock().lock();
    try {
        if (this.isClosed()) {
            status.abort("Already got closed by another process");
            // SplitTransaction handles the null
            return null;
        }
        LOG.debug("Updates disabled for region " + this);
        // Don't flush the cache if we are aborting
        if (!abort) {
            int flushCount = 0;
            while (this.getMemstoreSize().get() > 0) {
                try {
                    if (flushCount++ > 0) {
                        int actualFlushes = flushCount - 1;
                        if (actualFlushes > 5) {
                            // If we tried 5 times and are unable to clear memory, abort
                            // so we do not lose data
                            throw new DroppedSnapshotException("Failed clearing memory after " + actualFlushes
                                    + " attempts on region: " + Bytes.toStringBinary(getRegionName()));
                        }
                        LOG.info("Running extra flush, " + actualFlushes + " (carrying snapshot?) " + this);
                    }
                    internalFlushcache(status);
                } catch (IOException ioe) {
                    status.setStatus("Failed flush " + this + ", putting online again");
                    synchronized (writestate) {
                        writestate.writesEnabled = true;
                    }
                    // Have to throw to upper layers.  I can't abort server from here.
                    throw ioe;
                }
            }
        }

        Map<byte[], List<StoreFile>> result = new TreeMap<byte[], List<StoreFile>>(Bytes.BYTES_COMPARATOR);
        if (!stores.isEmpty()) {
            // initialize the thread pool for closing stores in parallel.
            ThreadPoolExecutor storeCloserThreadPool = getStoreOpenAndCloseThreadPool(
                    "StoreCloserThread-" + this.getRegionNameAsString());
            CompletionService<Pair<byte[], Collection<StoreFile>>> completionService = new ExecutorCompletionService<Pair<byte[], Collection<StoreFile>>>(
                    storeCloserThreadPool);

            // close each store in parallel
            for (final Store store : stores.values()) {
                assert abort || store.getFlushableSize() == 0;
                completionService.submit(new Callable<Pair<byte[], Collection<StoreFile>>>() {
                    @Override
                    public Pair<byte[], Collection<StoreFile>> call() throws IOException {
                        return new Pair<byte[], Collection<StoreFile>>(store.getFamily().getName(),
                                store.close());
                    }
                });
            }
            try {
                for (int i = 0; i < stores.size(); i++) {
                    Future<Pair<byte[], Collection<StoreFile>>> future = completionService.take();
                    Pair<byte[], Collection<StoreFile>> storeFiles = future.get();
                    List<StoreFile> familyFiles = result.get(storeFiles.getFirst());
                    if (familyFiles == null) {
                        familyFiles = new ArrayList<StoreFile>();
                        result.put(storeFiles.getFirst(), familyFiles);
                    }
                    familyFiles.addAll(storeFiles.getSecond());
                }
            } catch (InterruptedException e) {
                throw (InterruptedIOException) new InterruptedIOException().initCause(e);
            } catch (ExecutionException e) {
                throw new IOException(e.getCause());
            } finally {
                storeCloserThreadPool.shutdownNow();
            }
        }
        this.closed.set(true);
        if (memstoreSize.get() != 0)
            LOG.error("Memstore size is " + memstoreSize.get());
        if (coprocessorHost != null) {
            status.setStatus("Running coprocessor post-close hooks");
            this.coprocessorHost.postClose(abort);
        }
        if (this.metricsRegion != null) {
            this.metricsRegion.close();
        }
        if (this.metricsRegionWrapper != null) {
            Closeables.closeQuietly(this.metricsRegionWrapper);
        }
        status.markComplete("Closed");
        LOG.info("Closed " + this);
        return result;
    } finally {
        lock.writeLock().unlock();
    }
}

From source file:org.apache.hadoop.hbase.util.HBaseFsck.java

/**
 * Load the list of disabled tables in ZK into local set.
 * @throws ZooKeeperConnectionException//  w  w w.ja  va2s. c  om
 * @throws IOException
 */
private void loadDisabledTables() throws ZooKeeperConnectionException, IOException {
    HConnectionManager.execute(new HConnectable<Void>(getConf()) {
        @Override
        public Void connect(HConnection connection) throws IOException {
            ZooKeeperWatcher zkw = createZooKeeperWatcher();
            try {
                for (TableName tableName : ZKTableStateClientSideReader.getDisabledOrDisablingTables(zkw)) {
                    disabledTables.add(tableName);
                }
            } catch (KeeperException ke) {
                throw new IOException(ke);
            } catch (InterruptedException e) {
                throw new InterruptedIOException();
            } finally {
                zkw.close();
            }
            return null;
        }
    });
}

From source file:org.apache.hadoop.hbase.ipc.RpcClient.java

/** Make a call, passing <code>param</code>, to the IPC server running at
 * <code>address</code> which is servicing the <code>protocol</code> protocol,
 * with the <code>ticket</code> credentials, returning the value.
 * Throws exceptions if there are network problems or if the remote code
 * threw an exception.//from  w  ww .  j  a  v a 2  s. c  o m
 * @param ticket Be careful which ticket you pass. A new user will mean a new Connection.
 *          {@link UserProvider#getCurrent()} makes a new instance of User each time so will be a
 *          new Connection each time.
 * @return A pair with the Message response and the Cell data (if any).
 * @throws InterruptedException
 * @throws IOException
 */
Pair<Message, CellScanner> call(MethodDescriptor md, Message param, CellScanner cells, Message returnType,
        User ticket, InetSocketAddress addr, int callTimeout, int priority)
        throws IOException, InterruptedException {
    Call call = new Call(md, param, cells, returnType, callTimeout);
    Connection connection = getConnection(ticket, call, addr, this.codec, this.compressor);

    CallFuture cts = null;
    if (connection.callSender != null) {
        cts = connection.callSender.sendCall(call, priority, Trace.currentSpan());
    } else {
        connection.tracedWriteRequest(call, priority, Trace.currentSpan());
    }

    while (!call.done) {
        if (call.checkAndSetTimeout()) {
            if (cts != null)
                connection.callSender.remove(cts);
            break;
        }
        if (connection.shouldCloseConnection.get()) {
            throw new IOException(
                    "Call id=" + call.id + " on server " + addr + " aborted: connection is closing");
        }
        try {
            synchronized (call) {
                call.wait(Math.min(call.remainingTime(), 1000) + 1);
            }
        } catch (InterruptedException e) {
            call.setException(new InterruptedIOException());
            if (cts != null)
                connection.callSender.remove(cts);
            throw e;
        }
    }

    if (call.error != null) {
        if (call.error instanceof RemoteException) {
            call.error.fillInStackTrace();
            throw call.error;
        }
        // local exception
        throw wrapException(addr, call.error);
    }

    return new Pair<Message, CellScanner>(call.response, call.cells);
}

From source file:org.apache.hadoop.hbase.master.HMaster.java

/**
 * @return cluster status/*w  w  w. ja v a 2  s.  c  o m*/
 */
public ClusterStatus getClusterStatus() throws InterruptedIOException {
    // Build Set of backup masters from ZK nodes
    List<String> backupMasterStrings;
    try {
        backupMasterStrings = ZKUtil.listChildrenNoWatch(this.zooKeeper,
                this.zooKeeper.backupMasterAddressesZNode);
    } catch (KeeperException e) {
        LOG.warn(this.zooKeeper.prefix("Unable to list backup servers"), e);
        backupMasterStrings = new ArrayList<String>(0);
    }
    List<ServerName> backupMasters = new ArrayList<ServerName>(backupMasterStrings.size());
    for (String s : backupMasterStrings) {
        try {
            byte[] bytes;
            try {
                bytes = ZKUtil.getData(this.zooKeeper,
                        ZKUtil.joinZNode(this.zooKeeper.backupMasterAddressesZNode, s));
            } catch (InterruptedException e) {
                throw new InterruptedIOException();
            }
            if (bytes != null) {
                ServerName sn;
                try {
                    sn = ServerName.parseFrom(bytes);
                } catch (DeserializationException e) {
                    LOG.warn("Failed parse, skipping registering backup server", e);
                    continue;
                }
                backupMasters.add(sn);
            }
        } catch (KeeperException e) {
            LOG.warn(this.zooKeeper.prefix("Unable to get information about " + "backup servers"), e);
        }
    }
    Collections.sort(backupMasters, new Comparator<ServerName>() {
        @Override
        public int compare(ServerName s1, ServerName s2) {
            return s1.getServerName().compareTo(s2.getServerName());
        }
    });

    String clusterId = fileSystemManager != null ? fileSystemManager.getClusterId().toString() : null;
    Map<String, RegionState> regionsInTransition = assignmentManager != null
            ? assignmentManager.getRegionStates().getRegionsInTransition()
            : null;
    String[] coprocessors = cpHost != null ? getMasterCoprocessors() : null;
    boolean balancerOn = loadBalancerTracker != null ? loadBalancerTracker.isBalancerOn() : false;
    Map<ServerName, ServerLoad> onlineServers = null;
    Set<ServerName> deadServers = null;
    if (serverManager != null) {
        deadServers = serverManager.getDeadServers().copyServerNames();
        onlineServers = serverManager.getOnlineServers();
    }
    return new ClusterStatus(VersionInfo.getVersion(), clusterId, onlineServers, deadServers, serverName,
            backupMasters, regionsInTransition, coprocessors, balancerOn);
}

From source file:org.apache.hadoop.hdfs.server.datanode.FSDataset.java

private void createVolumes(FSVolumeSet volumes, DataStorage storage, Configuration conf, VolumeMap volumeMap,
        Map<Integer, String> namespaceIdDir) throws IOException {
    FSVolume[] myVolumes = volumes.getVolumes();

    ArrayList<VolumeThread> scanners = new ArrayList<VolumeThread>(myVolumes.length);

    for (FSVolume volume : myVolumes) {
        scanners.add(new VolumeThread(volume, conf, namespaceIdDir, volumes.supportAppends));
    }//from   w ww .j  a va  2 s .  c  o m

    for (VolumeThread vt : scanners) {
        vt.start();
    }
    boolean hasError = false;
    for (VolumeThread vt : scanners) {
        try {
            vt.join();
        } catch (InterruptedException e) {
            throw (InterruptedIOException) new InterruptedIOException().initCause(e);
        }
        if (!hasError && vt.hasError) {
            hasError = true;
        }

    }
    if (hasError) {
        throw new IOException("Error creating volumes");
    }
}

From source file:org.apache.hadoop.hbase.util.FSUtils.java

/**
 * This function is to scan the root path of the file system to get either the
 * mapping between the region name and its best locality region server or the
 * degree of locality of each region on each of the servers having at least
 * one block of that region. The output map parameters are both optional.
 *
 * @param conf//from  www .j  a  va  2  s .  c o m
 *          the configuration to use
 * @param desiredTable
 *          the table you wish to scan locality for
 * @param threadPoolSize
 *          the thread pool size to use
 * @param regionToBestLocalityRSMapping
 *          the map into which to put the best locality mapping or null
 * @param regionDegreeLocalityMapping
 *          the map into which to put the locality degree mapping or null,
 *          must be a thread-safe implementation
 * @throws IOException
 *           in case of file system errors or interrupts
 */
private static void getRegionLocalityMappingFromFS(final Configuration conf, final String desiredTable,
        int threadPoolSize, Map<String, String> regionToBestLocalityRSMapping,
        Map<String, Map<String, Float>> regionDegreeLocalityMapping) throws IOException {
    FileSystem fs = FileSystem.get(conf);
    Path rootPath = FSUtils.getRootDir(conf);
    long startTime = EnvironmentEdgeManager.currentTimeMillis();
    Path queryPath;
    // The table files are in ${hbase.rootdir}/data/<namespace>/<table>/*
    if (null == desiredTable) {
        queryPath = new Path(new Path(rootPath, HConstants.BASE_NAMESPACE_DIR).toString() + "/*/*/*/");
    } else {
        queryPath = new Path(FSUtils.getTableDir(rootPath, TableName.valueOf(desiredTable)).toString() + "/*/");
    }

    // reject all paths that are not appropriate
    PathFilter pathFilter = new PathFilter() {
        @Override
        public boolean accept(Path path) {
            // this is the region name; it may get some noise data
            if (null == path) {
                return false;
            }

            // no parent?
            Path parent = path.getParent();
            if (null == parent) {
                return false;
            }

            String regionName = path.getName();
            if (null == regionName) {
                return false;
            }

            if (!regionName.toLowerCase().matches("[0-9a-f]+")) {
                return false;
            }
            return true;
        }
    };

    FileStatus[] statusList = fs.globStatus(queryPath, pathFilter);

    if (null == statusList) {
        return;
    } else {
        LOG.debug("Query Path: " + queryPath + " ; # list of files: " + statusList.length);
    }

    // lower the number of threads in case we have very few expected regions
    threadPoolSize = Math.min(threadPoolSize, statusList.length);

    // run in multiple threads
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 60, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(statusList.length));
    try {
        // ignore all file status items that are not of interest
        for (FileStatus regionStatus : statusList) {
            if (null == regionStatus) {
                continue;
            }

            if (!regionStatus.isDirectory()) {
                continue;
            }

            Path regionPath = regionStatus.getPath();
            if (null == regionPath) {
                continue;
            }

            tpe.execute(new FSRegionScanner(fs, regionPath, regionToBestLocalityRSMapping,
                    regionDegreeLocalityMapping));
        }
    } finally {
        tpe.shutdown();
        int threadWakeFrequency = conf.getInt(HConstants.THREAD_WAKE_FREQUENCY, 60 * 1000);
        try {
            // here we wait until TPE terminates, which is either naturally or by
            // exceptions in the execution of the threads
            while (!tpe.awaitTermination(threadWakeFrequency, TimeUnit.MILLISECONDS)) {
                // printing out rough estimate, so as to not introduce
                // AtomicInteger
                LOG.info("Locality checking is underway: { Scanned Regions : " + tpe.getCompletedTaskCount()
                        + "/" + tpe.getTaskCount() + " }");
            }
        } catch (InterruptedException e) {
            throw (InterruptedIOException) new InterruptedIOException().initCause(e);
        }
    }

    long overhead = EnvironmentEdgeManager.currentTimeMillis() - startTime;
    String overheadMsg = "Scan DFS for locality info takes " + overhead + " ms";

    LOG.info(overheadMsg);
}