private static <T> T get(CompletableFuture<T> future) throws IOException { try { return future.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } } }
@Override public LocatedBlock addBlock(ClientProtocol namenode, String src, String clientName, ExtendedBlock previous, DatanodeInfo[] excludeNodes, long fileId, String[] favoredNodes) throws IOException { try { return (LocatedBlock) addBlockMethod.invoke(namenode, src, clientName, previous, excludeNodes, fileId, favoredNodes, null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { Throwables.propagateIfPossible(e.getTargetException(), IOException.class); throw new RuntimeException(e); } } };
@Override public LocatedBlock addBlock(ClientProtocol namenode, String src, String clientName, ExtendedBlock previous, DatanodeInfo[] excludeNodes, long fileId, String[] favoredNodes) throws IOException { try { return (LocatedBlock) addBlockMethod.invoke(namenode, src, clientName, previous, excludeNodes, fileId, favoredNodes); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { Throwables.propagateIfPossible(e.getTargetException(), IOException.class); throw new RuntimeException(e); } } };
private long write(Consumer<CompletableFuture<Long>> action) throws IOException { CompletableFuture<Long> future = new CompletableFuture<>(); action.accept(future); try { return future.get().longValue(); } catch (InterruptedException e) { InterruptedIOException ioe = new InterruptedIOException(); ioe.initCause(e); throw ioe; } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause(), IOException.class); throw new RuntimeException(e.getCause()); } }
/** * A helper class for getting the result of a Future, and convert the error to an * {@link IOException}. */ public static <T> T get(Future<T> future) throws IOException { try { return future.get(); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } } }
/** * Public because of AsyncFSWAL. Should be package-private */ public static AsyncWriter createAsyncWriter(Configuration conf, FileSystem fs, Path path, boolean overwritable, long blocksize, EventLoopGroup eventLoopGroup, Class<? extends Channel> channelClass) throws IOException { // Configuration already does caching for the Class lookup. Class<? extends AsyncWriter> logWriterClass = conf.getClass( "hbase.regionserver.hlog.async.writer.impl", AsyncProtobufLogWriter.class, AsyncWriter.class); try { AsyncWriter writer = logWriterClass.getConstructor(EventLoopGroup.class, Class.class) .newInstance(eventLoopGroup, channelClass); writer.init(fs, path, conf, overwritable, blocksize); return writer; } catch (Exception e) { if (e instanceof CommonFSUtils.StreamLacksCapabilityException) { LOG.error("The RegionServer async write ahead log provider " + "relies on the ability to call " + e.getMessage() + " for proper operation during " + "component failures, but the current FileSystem does not support doing so. Please " + "check the config value of '" + CommonFSUtils.HBASE_WAL_DIR + "' and ensure " + "it points to a FileSystem mount that has suitable capabilities for output streams."); } else { LOG.debug("Error instantiating log writer.", e); } Throwables.propagateIfPossible(e, IOException.class); throw new IOException("cannot get log writer", e); } }
public synchronized List<Result> getAll() throws Exception { while (!finished) { wait(); } if (error != null) { Throwables.propagateIfPossible(error, Exception.class); throw new Exception(error); } return results; }
@Override public synchronized Result next() throws IOException { while (queue.isEmpty()) { if (closed) { return null; } if (error != null) { Throwables.propagateIfPossible(error, IOException.class); throw new IOException(error); } try { wait(); } catch (InterruptedException e) { throw new InterruptedIOException(); } } Result result = queue.poll(); if (!result.isCursor()) { cacheSize -= calcEstimatedSize(result); if (resumer != null && cacheSize <= maxCacheSize / 2) { resumePrefetch(); } } return result; }
public synchronized Result take() throws IOException, InterruptedException { for (;;) { if (!queue.isEmpty()) { return queue.poll(); } if (finished) { if (error != null) { Throwables.propagateIfPossible(error, IOException.class); throw new IOException(error); } else { return null; } } wait(); } }
@Override public void sync(boolean forceSync) throws IOException { try { asyncWriter.sync().get(); } catch (InterruptedException e) { throw new InterruptedIOException(); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause(), IOException.class); throw new IOException(e.getCause()); } } }
@Override public Encryptor createEncryptor(Configuration conf, FileEncryptionInfo feInfo, DFSClient client) throws IOException { try { KeyVersion decryptedKey = (KeyVersion) decryptEncryptedDataEncryptionKeyMethod.invoke(client, feInfo); CryptoCodec cryptoCodec = CryptoCodec.getInstance(conf, feInfo.getCipherSuite()); Encryptor encryptor = cryptoCodec.createEncryptor(); encryptor.init(decryptedKey.getMaterial(), feInfo.getIV()); return encryptor; } catch (InvocationTargetException e) { Throwables.propagateIfPossible(e.getTargetException(), IOException.class); throw new RuntimeException(e.getTargetException()); } catch (GeneralSecurityException e) { throw new IOException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } };
table.coprocessorService(MultiRowMutationService.class, row, row, callable); } catch (Throwable e) { Throwables.propagateIfPossible(e, IOException.class); throw new IOException(e);
@Override public Encryptor createEncryptor(Configuration conf, FileEncryptionInfo feInfo, DFSClient client) throws IOException { try { KeyVersion decryptedKey = (KeyVersion) decryptEncryptedDataEncryptionKeyMethod .invoke(null, feInfo, client.getKeyProvider()); CryptoCodec cryptoCodec = CryptoCodec.getInstance(conf, feInfo.getCipherSuite()); Encryptor encryptor = cryptoCodec.createEncryptor(); encryptor.init(decryptedKey.getMaterial(), feInfo.getIV()); return encryptor; } catch (InvocationTargetException e) { Throwables.propagateIfPossible(e.getTargetException(), IOException.class); throw new RuntimeException(e.getTargetException()); } catch (GeneralSecurityException e) { throw new IOException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } };
} catch (InvocationTargetException e) { Throwable cause = e.getTargetException(); Throwables.propagateIfPossible(cause, IOException.class); throw new RuntimeException(cause);
private void endBlock() throws IOException { Preconditions.checkState(waitingAckQueue.isEmpty(), "should call flush first before calling close"); if (state != State.STREAMING) { throw new IOException("stream already broken"); } state = State.CLOSING; long finalizedLength = ackedBlockLength; PacketHeader header = new PacketHeader(4, finalizedLength, nextPacketSeqno, true, 0, false); buf.release(); buf = null; int headerLen = header.getSerializedSize(); ByteBuf headerBuf = alloc.directBuffer(headerLen); header.putInBuffer(headerBuf.nioBuffer(0, headerLen)); headerBuf.writerIndex(headerLen); CompletableFuture<Long> future = new CompletableFuture<>(); waitingAckQueue.add(new Callback(future, finalizedLength, datanodeList)); datanodeList.forEach(ch -> ch.writeAndFlush(headerBuf.retainedDuplicate())); headerBuf.release(); try { future.get(); } catch (InterruptedException e) { throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } }
private static <T> T get(CompletableFuture<T> future) throws IOException { try { return future.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } } }
@Override public synchronized Result next() throws IOException { while (queue.isEmpty()) { if (closed) { return null; } if (error != null) { Throwables.propagateIfPossible(error, IOException.class); throw new IOException(error); } try { wait(); } catch (InterruptedException e) { throw new InterruptedIOException(); } } Result result = queue.poll(); if (!result.isCursor()) { cacheSize -= calcEstimatedSize(result); if (resumer != null && cacheSize <= maxCacheSize / 2) { resumePrefetch(); } } return result; }
private static <T> T get(CompletableFuture<T> future) throws IOException { try { return future.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { Throwable cause = e.getCause(); Throwables.propagateIfPossible(cause, IOException.class); throw new IOException(cause); } } }
public synchronized List<Result> getAll() throws Exception { while (!finished) { wait(); } if (error != null) { Throwables.propagateIfPossible(error, Exception.class); throw new Exception(error); } return results; }
@Override protected void sync(AsyncWriter writer) throws IOException { try { writer.sync().get(); } catch (InterruptedException e) { throw new InterruptedIOException(); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause()); throw new IOException(e.getCause()); } } }