/** * <p> * Constructor for AsyncExecutor. * </p> * @param client a {@link com.google.cloud.bigtable.grpc.BigtableDataClient} object for executing * RPCs. */ public AsyncExecutor(BigtableDataClient client) { this(client, new OperationAccountant()); }
/** * <p> * hasInflightRequests. * </p> * @return a boolean. */ public boolean hasInflightRequests() { return operationsAccountant.hasInflightOperations(); }
public synchronized void sendUnsent() { if (currentBatch != null) { try { currentBatch.run(); } finally { operationAccountant.registerOperation(currentBatch.completionFuture); } currentBatch = null; } }
/** * Blocks until all outstanding RPCs and retries have completed * * @throws java.lang.InterruptedException if any. */ public void awaitCompletion() throws InterruptedException { boolean performedWarning = false; while (hasInflightOperations()) { synchronized (signal) { if (hasInflightOperations()) { signal.wait(finishWaitMillis); } } long now = clock.nanoTime(); if (now >= noSuccessCheckDeadlineNanos) { logNoSuccessWarning(now); resetNoSuccessWarningDeadline(); performedWarning = true; } } if (performedWarning) { LOG.info("awaitCompletion() completed"); } }
/** * Send any outstanding {@link MutateRowRequest}s and wait until all requests are complete. */ public void flush() throws InterruptedException { sendUnsent(); operationAccountant.awaitCompletion(); }
@VisibleForTesting OperationAccountant(NanoClock clock, long finishWaitMillis) { this.clock = clock; this.finishWaitMillis = finishWaitMillis; resetNoSuccessWarningDeadline(); }
/** * Waits until all operations managed by the * {@link com.google.cloud.bigtable.grpc.async.OperationAccountant} complete. See * {@link com.google.cloud.bigtable.grpc.async.OperationAccountant#awaitCompletion()} for more * information. * @throws java.io.IOException if something goes wrong. */ public void flush() throws IOException { LOG.trace("Flushing"); try { operationsAccountant.awaitCompletion(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException("Batch operations were interrupted."); } LOG.trace("Done flushing"); }
private boolean onOperationCompletion() { resetNoSuccessWarningDeadline(); if (count.decrementAndGet() == 0) { synchronized (signal) { signal.notifyAll(); } } return true; }
BulkMutation( BigtableTableName tableName, BigtableDataClient client, OperationAccountant operationAccountant, ScheduledExecutorService retryExecutorService, BulkOptions bulkOptions) { this.tableName = tableName.toString(); this.client = client; this.retryExecutorService = retryExecutorService; this.operationAccountant = operationAccountant; this.maxRowKeyCount = bulkOptions.getBulkMaxRowKeyCount(); this.maxRequestSize = bulkOptions.getBulkMaxRequestSize(); this.autoflushMs = bulkOptions.getAutoflushMs(); }
private <RequestT extends MessageLite, ResponseT> ListenableFuture<ResponseT> call( AsyncCall<RequestT, ResponseT> rpc, RequestT request) { // Wait until both the memory and rpc count maximum requirements are achieved before getting a // unique id used to track this request. ListenableFuture<ResponseT> future; try { future = rpc.call(client, request); } catch (Throwable e) { future = Futures.immediateFailedFuture(e); } operationsAccountant.registerOperation(future); return future; }