/** * Do a get with a timeout against the passed in <code>future</code>. */ private static <T> T get(final Future<T> future, final long timeout, final TimeUnit units) throws IOException { try { // TODO: how long should we wait? Spin forever? return future.get(timeout, units); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupt while waiting on " + future); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw new IOException(e.getCause()); } } }
@Override public byte[] get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (hasResult) { return result; } try { result = waitForProcedureToComplete(procExec, proc, unit.toMillis(timeout)); hasResult = true; return result; } catch (TimeoutIOException e) { throw new TimeoutException(e.getMessage()); } catch (Exception e) { throw new ExecutionException(e); } } }
synchronized long get(long timeoutNs) throws InterruptedException, ExecutionException, TimeoutIOException { final long done = System.nanoTime() + timeoutNs; while (!isDone()) { wait(1000); if (System.nanoTime() >= done) { throw new TimeoutIOException( "Failed to get sync result after " + TimeUnit.NANOSECONDS.toMillis(timeoutNs) + " ms for txid=" + this.txid + ", WAL system stuck?"); } } if (this.throwable != null) { throw new ExecutionException(this.throwable); } return this.doneTxid; }
private <T> CompletableFuture<T> withTimeout(CompletableFuture<T> future, long timeoutNs, Supplier<String> timeoutMsg) { if (future.isDone() || timeoutNs <= 0) { return future; } Timeout timeoutTask = retryTimer.newTimeout(t -> { if (future.isDone()) { return; } future.completeExceptionally(new TimeoutIOException(timeoutMsg.get())); }, timeoutNs, TimeUnit.NANOSECONDS); return future.whenComplete((loc, error) -> { if (error != null && error.getClass() != TimeoutIOException.class) { // cancel timeout task if we are not completed by it. timeoutTask.cancel(); } }); }
public static <T> T waitFor(MasterProcedureEnv env, long waitTime, long waitingTimeForEvents, String purpose, Predicate<T> predicate) throws IOException { long done = EnvironmentEdgeManager.currentTime() + waitTime; if (done <= 0) { // long overflow, usually this means we pass Long.MAX_VALUE as waitTime done = Long.MAX_VALUE; } boolean logged = false; 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); } if (LOG.isTraceEnabled()) { LOG.trace("waitFor " + purpose); } else { if (!logged) LOG.debug("waitFor " + purpose); } logged = true; } while (EnvironmentEdgeManager.currentTime() < done && env.isRunning()); throw new TimeoutIOException("Timed out while waiting on " + purpose); }
/** * Called by the ProcedureExecutor when the timeout set by setTimeout() is expired. * <p/> * Another usage for this method is to implement retrying. A procedure can set the state to * {@code WAITING_TIMEOUT} by calling {@code setState} method, and throw a * {@link ProcedureSuspendedException} to halt the execution of the procedure, and do not forget a * call {@link #setTimeout(int)} method to set the timeout. And you should also override this * method to wake up the procedure, and also return false to tell the ProcedureExecutor that the * timeout event has been handled. * @return true to let the framework handle the timeout as abort, false in case the procedure * handled the timeout itself. */ protected synchronized boolean setTimeoutFailure(TEnvironment env) { if (state == ProcedureState.WAITING_TIMEOUT) { long timeDiff = EnvironmentEdgeManager.currentTime() - lastUpdate; setFailure("ProcedureExecutor", new TimeoutIOException("Operation timed out after " + StringUtils.humanTimeDiff(timeDiff))); return true; } return false; }
+ getRegionInfo().getEncodedName(); if (reachDeadlineFirst) { throw new TimeoutIOException(message); } else {
/** * Do a get with a timeout against the passed in <code>future</code>. */ private static <T> T get(final Future<T> future, final long timeout, final TimeUnit units) throws IOException { try { // TODO: how long should we wait? Spin forever? return future.get(timeout, units); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupt while waiting on " + future); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw new IOException(e.getCause()); } } }
private CompletableFuture<HRegionLocation> withTimeout(CompletableFuture<HRegionLocation> future, long timeoutNs, Supplier<String> timeoutMsg) { if (future.isDone() || timeoutNs <= 0) { return future; } Timeout timeoutTask = retryTimer.newTimeout(t -> { if (future.isDone()) { return; } future.completeExceptionally(new TimeoutIOException(timeoutMsg.get())); }, timeoutNs, TimeUnit.NANOSECONDS); return future.whenComplete((loc, error) -> { if (error != null && error.getClass() != TimeoutIOException.class) { // cancel timeout task if we are not completed by it. timeoutTask.cancel(); } }); }
traceScope.getSpan().addTimelineAnnotation("Failed to get row lock"); throw new TimeoutIOException("Timed out waiting for lock for row: " + rowKey);
/** * Do a get with a timeout against the passed in <code>future</code>. */ private static <T> T get(final Future<T> future, final long timeout, final TimeUnit units) throws IOException { try { // TODO: how long should we wait? Spin forever? return future.get(timeout, units); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupt while waiting on " + future); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw new IOException(e.getCause()); } } }
private CompletableFuture<HRegionLocation> withTimeout(CompletableFuture<HRegionLocation> future, long timeoutNs, Supplier<String> timeoutMsg) { if (future.isDone() || timeoutNs <= 0) { return future; } Timeout timeoutTask = retryTimer.newTimeout(t -> { if (future.isDone()) { return; } future.completeExceptionally(new TimeoutIOException(timeoutMsg.get())); }, timeoutNs, TimeUnit.NANOSECONDS); return future.whenComplete((loc, error) -> { if (error != null && error.getClass() != TimeoutIOException.class) { // cancel timeout task if we are not completed by it. timeoutTask.cancel(); } }); }
/** * Disable table and wait on completion. May timeout eventually. Use * {@link #disableTableAsync(byte[])} and {@link #isTableDisabled(String)} * instead. * The table has to be in enabled state for it to be disabled. * @param tableName * @throws IOException * There could be couple types of IOException * TableNotFoundException means the table doesn't exist. * TableNotEnabledException means the table isn't in enabled state. */ @Override public void disableTable(final TableName tableName) throws IOException { Future<Void> future = disableTableAsyncV2(tableName); try { future.get(syncWaitTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted when waiting for table to be disabled"); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw new IOException(e.getCause()); } } }
/** * Deletes a table. * Synchronous operation. * * @param tableName name of table to delete * @throws IOException if a remote or network exception occurs */ @Override public void deleteTable(final TableName tableName) throws IOException { Future<Void> future = deleteTableAsyncV2(tableName); try { future.get(syncWaitTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted when waiting for table to be deleted"); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw new IOException(e.getCause()); } } }
/** * Abort a procedure * @param procId ID of the procedure to abort * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? * @return true if aborted, false if procedure already completed or does not exist * @throws IOException */ @Override public boolean abortProcedure( final long procId, final boolean mayInterruptIfRunning) throws IOException { Future<Boolean> future = abortProcedureAsync(procId, mayInterruptIfRunning); try { return future.get(syncWaitTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new InterruptedIOException("Interrupted when waiting for procedure to be cancelled"); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException)e.getCause(); } else { throw new IOException(e.getCause()); } } }
throw new InterruptedIOException("Interrupted when waiting for table to be disabled"); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) {
@InterfaceAudience.Private protected enum Version { UNVERSIONED(0), // Initial number we put on WALKey when we introduced versioning. INITIAL(-1), // Version -2 introduced a dictionary compression facility. Only this // dictionary-based compression is available in version -2. COMPRESSED(-2); public final int code; static final Version[] byCode; static { byCode = Version.values(); for (int i = 0; i < byCode.length; i++) { if (byCode[i].code != -1 * i) { throw new AssertionError("Values in this enum should be descending by one"); } } } Version(int code) { this.code = code; } public boolean atLeast(Version other) { return code <= other.code; } public static Version fromCode(int code) { return byCode[code * -1]; } }
" for table to be enabled; meta scan was done"); } catch (TimeoutException e) { throw new TimeoutIOException(e); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) {
/** * Called by the ProcedureExecutor when the timeout set by setTimeout() is expired. * @return true to let the framework handle the timeout as abort, * false in case the procedure handled the timeout itself. */ protected synchronized boolean setTimeoutFailure(final TEnvironment env) { if (state == ProcedureState.WAITING_TIMEOUT) { long timeDiff = EnvironmentEdgeManager.currentTime() - lastUpdate; setFailure("ProcedureExecutor", new TimeoutIOException( "Operation timed out after " + StringUtils.humanTimeDiff(timeDiff))); return true; } return false; }
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); }