@Override public void cleanup() throws DBException { if (bulkMutation != null) { try { bulkMutation.flush(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new DBException(e); } catch(RuntimeException e){ throw new DBException(e); } } synchronized (CONFIG) { --threadCount; if (threadCount <= 0) { try { session.close(); } catch (IOException e) { throw new DBException(e); } } } }
@Override public Status delete(String table, String key) { if (debug) { System.out.println("Doing delete for key: " + key); } setTable(table); final MutateRowRequest.Builder rowMutation = MutateRowRequest.newBuilder() .setRowKey(ByteString.copyFromUtf8(key)) .setTableNameBytes(ByteStringer.wrap(lastTableBytes)); rowMutation.addMutationsBuilder().setDeleteFromRow( DeleteFromRow.getDefaultInstance()); try { if (clientSideBuffering) { bulkMutation.add(rowMutation.build()); } else { client.mutateRow(rowMutation.build()); } return Status.OK; } catch (RuntimeException e) { System.err.println("Failed to delete key: " + key + " " + e.getMessage()); return Status.ERROR; } }
protected void flush() { // If there is a bulk mutation in progress, then send it. bulkMutation.sendUnsent(); bulkRead.flush(); } }
/** * Send any outstanding {@link MutateRowRequest}s and wait until all requests are complete. */ public void flush() throws InterruptedException { sendUnsent(); operationAccountant.awaitCompletion(); }
/** * Initial execution of the RPC. */ public ListenableFuture<ResultT> getAsyncResult() { Preconditions.checkState(operationTimerContext == null); operationTimerContext = rpc.getRpcMetrics().timeOperation(); run(); return completionFuture; }
/** * <p>hasInflightRequests.</p> * * @return a boolean. */ public boolean hasInflightRequests() { return this.asyncExecutor.hasInflightRequests() || (bulkMutation != null && !bulkMutation.isFlushed()); } }
public void sendUnsent() { if (bulkMutation != null) { bulkMutation.sendUnsent(); } }
@Override public void onMessage(MutateRowsResponse message) { try { requestManager.onMessage(message); } catch (Exception e) { setException(e); } }
protected boolean isRequestRetryable() { return rpc.isRetryable(getRetryRequest()); }
synchronized void setCallAndStart(BigtableAsyncRpc<RequestT, ResponseT> rpc, CallOptions callOptions, RequestT request, ClientCall.Listener<ResponseT> listener, Metadata metadata) { // There's a subtle race condition in RetryingStreamOperation which requires a separate // newCall/start split. The call variable needs to be set before onMessage() happens; that // usually will occur, but some unit tests broke with a merged newCall and start. this.call = rpc.newCall(callOptions); rpc.start(request, listener, metadata, call); }
/** {@inheritDoc} */ @Override protected boolean onOK(Metadata trailers) { if (value == null) { // No value received so mark the future as an error completionFuture.setException(NO_VALUE_SET_EXCEPTION); } return true; } }
/** * <p> * hasInflightRequests. * </p> * @return a boolean. */ public boolean hasInflightRequests() { return operationsAccountant.hasInflightOperations(); }
/** * Cancels the RPC. */ public void cancel() { cancel("User requested cancelation."); }
@Override /** * Cancels a request on an error. * * @see com.google.cloud.bigtable.grpc.scanner.RowMerger#onError(Throwable) */ public void onError(Throwable t) { cancel("Cancelled by client with StreamObserver.onError()", t); }
/** * <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()); }
bulkMutation.add(rowMutation.build()); } else { client.mutateRow(rowMutation.build());
/** * Little helper to set the table byte array. If it's different than the last * table we reset the byte array. Otherwise we just use the existing array. * @param table The table we're operating against */ private void setTable(final String table) { if (!lastTable.equals(table)) { lastTable = table; BigtableTableName tableName = options .getInstanceName() .toTableName(table); lastTableBytes = tableName .toString() .getBytes(); synchronized(this) { if (bulkMutation != null) { try { bulkMutation.flush(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } bulkMutation = session.createBulkMutation(tableName); } } }
protected void flush() { // If there is a bulk mutation in progress, then send it. bulkMutation.sendUnsent(); bulkRead.flush(); } }
/** * <p>hasInflightRequests.</p> * * @return a boolean. */ public boolean hasInflightRequests() { return this.asyncExecutor.hasInflightRequests() || (bulkMutation != null && !bulkMutation.isFlushed()); } }
public void sendUnsent() { if (bulkMutation != null) { bulkMutation.sendUnsent(); } }