/** * <p>Getter for the field <code>batchExecutor</code>.</p> * * @return a {@link com.google.cloud.bigtable.hbase.BatchExecutor} object. */ protected synchronized BatchExecutor getBatchExecutor() { if (batchExecutor == null) { batchExecutor = new BatchExecutor(bigtableConnection.getSession(), hbaseAdapter); } return batchExecutor; }
private <T> List<CompletableFuture<?>> asyncRequests(List<? extends Row> actions) { return map(getBatchExecutor().issueAsyncRowRequests(actions, new Object[actions.size()], null), FutureUtils::toCompletableFuture); }
/** * Implementation of {@link org.apache.hadoop.hbase.client.Table#existsAll(List)}. * * @param gets a {@link java.util.List} object. * @return an array of {@link java.lang.Boolean} objects. * @throws java.io.IOException if any. */ public boolean[] exists(List<Get> gets) throws IOException { // get(gets) will throw if there are any errors: Result[] getResults = batch(gets); boolean[] exists = new boolean[getResults.length]; for (int index = 0; index < getResults.length; index++) { exists[index] = !getResults[index].isEmpty(); } return exists; } }
/** * <p>batch.</p> * * @param actions a {@link java.util.List} object. * @param results an array of {@link java.lang.Object} objects. * @throws java.io.IOException if any. * @throws java.lang.InterruptedException if any. */ public void batch(List<? extends Row> actions, @Nullable Object[] results) throws IOException, InterruptedException { if (results == null) { results = new Object[actions.size()]; } batchCallback(actions, results, null); }
public <R> List<ListenableFuture<?>> issueAsyncRowRequests(List<? extends Row> actions, Object[] results, Batch.Callback<R> callback) { BulkOperation bulkOperation = new BulkOperation(session, requestAdapter.getBigtableTableName()); try { List<ListenableFuture<?>> resultFutures = new ArrayList<>(actions.size()); for (int i = 0; i < actions.size(); i++) { resultFutures .add(issueAsyncRowRequest(bulkOperation, actions.get(i), callback, results, i)); } return resultFutures; } finally { bulkOperation.flush(); } }
/** {@inheritDoc} */ @Override public boolean[] existsAll(List<Get> gets) throws IOException { LOG.trace("existsAll(Get)"); try (Scope scope = TRACER.spanBuilder("BigtableTable.existsAll").startScopedSpan()) { addBatchSizeAnnotation(gets); List<Get> existGets = new ArrayList<>(gets.size()); for(Get get : gets ){ existGets.add(GetAdapter.setCheckExistenceOnly(get)); } return getBatchExecutor().exists(existGets); } }
/** * Issue a single RPC recording the result into {@code results[index]} and if not-null, invoking * the supplied callback. * @param bulkOperation An object that encapsulates a set of Mutations and Reads that happen via a * bulk API. * @param row The action to perform * @param callback The callback to invoke when the RPC completes and we have results * @param results An array of results, into which we should store the result of the operation * @param index The into into the array of results where we should store our result * @param <R> The action type * @param <T> The type of the callback. * @return A ListenableFuture that will have the result when the RPC completes. */ private <R extends Row, T> ListenableFuture<Result> issueAsyncRowRequest( BulkOperation bulkOperation, Row row, Batch.Callback<T> callback, Object[] results, int index) { LOG.trace("issueRowRequest(BulkOperation, Row, Batch.Callback, Object[], index"); SettableFuture<Result> resultFuture = SettableFuture.create(); RpcResultFutureCallback<T> futureCallback = new RpcResultFutureCallback<T>(row, callback, index, results, resultFuture); results[index] = null; Futures.addCallback(issueAsyncRequest(bulkOperation, row), futureCallback, MoreExecutors.directExecutor()); return resultFuture; }
/** * <p>batch.</p> * * @param actions a {@link java.util.List} object. * @param results an array of {@link java.lang.Object} objects. * @throws java.io.IOException if any. * @throws java.lang.InterruptedException if any. */ public void batch(List<? extends Row> actions, @Nullable Object[] results) throws IOException, InterruptedException { if (results == null) { results = new Object[actions.size()]; } batchCallback(actions, results, null); }
public <R> List<ListenableFuture<?>> issueAsyncRowRequests(List<? extends Row> actions, Object[] results, Batch.Callback<R> callback) { BulkOperation bulkOperation = new BulkOperation(session, requestAdapter.getBigtableTableName()); try { List<ListenableFuture<?>> resultFutures = new ArrayList<>(actions.size()); for (int i = 0; i < actions.size(); i++) { resultFutures .add(issueAsyncRowRequest(bulkOperation, actions.get(i), callback, results, i)); } return resultFutures; } finally { bulkOperation.flush(); } }
/** {@inheritDoc} */ @Override public boolean[] existsAll(List<Get> gets) throws IOException { LOG.trace("existsAll(Get)"); try (Scope scope = TRACER.spanBuilder("BigtableTable.existsAll").startScopedSpan()) { addBatchSizeAnnotation(gets); List<Get> existGets = new ArrayList<>(gets.size()); for(Get get : gets ){ existGets.add(GetAdapter.setCheckExistenceOnly(get)); } return getBatchExecutor().exists(existGets); } }
/** * Issue a single RPC recording the result into {@code results[index]} and if not-null, invoking * the supplied callback. * @param bulkOperation An object that encapsulates a set of Mutations and Reads that happen via a * bulk API. * @param row The action to perform * @param callback The callback to invoke when the RPC completes and we have results * @param results An array of results, into which we should store the result of the operation * @param index The into into the array of results where we should store our result * @param <R> The action type * @param <T> The type of the callback. * @return A ListenableFuture that will have the result when the RPC completes. */ private <R extends Row, T> ListenableFuture<Result> issueAsyncRowRequest( BulkOperation bulkOperation, Row row, Batch.Callback<T> callback, Object[] results, int index) { LOG.trace("issueRowRequest(BulkOperation, Row, Batch.Callback, Object[], index"); SettableFuture<Result> resultFuture = SettableFuture.create(); RpcResultFutureCallback<T> futureCallback = new RpcResultFutureCallback<T>(row, callback, index, results, resultFuture); results[index] = null; Futures.addCallback(issueAsyncRequest(bulkOperation, row), futureCallback, MoreExecutors.directExecutor()); return resultFuture; }
protected synchronized BatchExecutor getBatchExecutor() { if (batchExecutor == null) { batchExecutor = new BatchExecutor(asyncConnection.getSession(), hbaseAdapter); } return batchExecutor; }
private <T> List<CompletableFuture<?>> asyncRequests(List<? extends Row> actions) { return map(getBatchExecutor().issueAsyncRowRequests(actions, new Object[actions.size()], null), FutureUtils::toCompletableFuture); }
/** * Implementation of {@link org.apache.hadoop.hbase.client.Table#existsAll(List)}. * * @param gets a {@link java.util.List} object. * @return an array of {@link java.lang.Boolean} objects. * @throws java.io.IOException if any. */ public boolean[] exists(List<Get> gets) throws IOException { // get(gets) will throw if there are any errors: Result[] getResults = batch(gets); boolean[] exists = new boolean[getResults.length]; for (int index = 0; index < getResults.length; index++) { exists[index] = !getResults[index].isEmpty(); } return exists; } }
/** * <p>batch.</p> * * @param actions a {@link java.util.List} object. * @return an array of {@link org.apache.hadoop.hbase.client.Result} objects. * @throws java.io.IOException if any. */ public Result[] batch(List<? extends Row> actions) throws IOException { try { Object[] resultsOrErrors = new Object[actions.size()]; batchCallback(actions, resultsOrErrors, null); // At this point we are guaranteed that the array only contains results, // if it had any errors, batch would've thrown an exception Result[] results = new Result[resultsOrErrors.length]; System.arraycopy(resultsOrErrors, 0, results, 0, results.length); return results; } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Encountered exception in batch(List<>).", e); throw new IOException("Batch error", e); } }
/** * <p>Getter for the field <code>batchExecutor</code>.</p> * * @return a {@link com.google.cloud.bigtable.hbase.BatchExecutor} object. */ protected synchronized BatchExecutor getBatchExecutor() { if (batchExecutor == null) { batchExecutor = new BatchExecutor(bigtableConnection.getSession(), hbaseAdapter); } return batchExecutor; }
"Result array must have same dimensions as actions list."); Timer.Context timerContext = batchTimer.time(); List<ListenableFuture<?>> resultFutures = issueAsyncRowRequests(actions, results, callback); try {
/** {@inheritDoc} */ @Override public void put(List<Put> puts) throws IOException { LOG.trace("put(List<Put>)"); if (puts == null || puts.isEmpty()) { return; } else if (puts.size() == 1) { try { put(puts.get(0)); } catch (IOException e) { throw createRetriesExhaustedWithDetailsException(e, puts.get(0)); } } else { getBatchExecutor().batch(puts); } }
/** * <p>batch.</p> * * @param actions a {@link java.util.List} object. * @return an array of {@link org.apache.hadoop.hbase.client.Result} objects. * @throws java.io.IOException if any. */ public Result[] batch(List<? extends Row> actions) throws IOException { try { Object[] resultsOrErrors = new Object[actions.size()]; batchCallback(actions, resultsOrErrors, null); // At this point we are guaranteed that the array only contains results, // if it had any errors, batch would've thrown an exception Result[] results = new Result[resultsOrErrors.length]; System.arraycopy(resultsOrErrors, 0, results, 0, results.length); return results; } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Encountered exception in batch(List<>).", e); throw new IOException("Batch error", e); } }
protected synchronized BatchExecutor getBatchExecutor() { if (batchExecutor == null) { batchExecutor = new BatchExecutor(asyncConnection.getSession(), hbaseAdapter); } return batchExecutor; }