/** * 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); } } }
@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); } } } }
try { options = BigtableOptionsFactory.fromConfiguration(CONFIG); session = new BigtableSession(options); client = session.getDataClient(); } catch (IOException e) { throw new DBException("Error loading options from config: ", e); client = session.getDataClient();
@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 BulkOperation( BigtableSession session, BigtableTableName tableName) { this.bulkRead = session.createBulkRead(tableName); this.bulkMutation = session.createBulkMutation(tableName); }
/** * <p>toTableName.</p> * * @param tableId a {@link java.lang.String} object. * @return a {@link com.google.cloud.bigtable.grpc.BigtableTableName} object. */ public BigtableTableName toTableName(String tableId) { return new BigtableTableName(toTableNameStr(tableId)); }
/** * Sets a cluster size to a specific size. * @param clusterId * @param zoneId * @param newSize * @throws InterruptedException if the cluster is in the middle of updating, and an interrupt was * received */ public void setClusterSize(String clusterId, String zoneId, int newSize) throws InterruptedException { setClusterSize(instanceName.toClusterName(clusterId).getClusterName(), newSize); }
/** * <p>Getter for the field <code>adminClientWrapper</code>.</p> * * @return a {@link BigtableTableAdminClientWrapper} object. * @throws java.io.IOException if any. */ public synchronized IBigtableTableAdminClient getTableAdminClientWrapper() throws IOException { if (adminClientWrapper == null) { adminClientWrapper = new BigtableTableAdminClientWrapper(getTableAdminClient(), options); } return adminClientWrapper; }
/** * <p>getBigtableTableAdminClient.</p> * * @return a {@link com.google.cloud.bigtable.grpc.BigtableTableAdminClient} object. * @throws java.io.IOException if any. */ protected BigtableTableAdminClient getBigtableTableAdminClient() throws IOException { return session.getTableAdminClient(); }
/** {@inheritDoc} */ @Override public void dropRowRange(String tableId, String rowKeyPrefix) { adminClient.dropRowRange(buildDropRowRangeRequest(tableId, rowKeyPrefix)); }
rows = client.readRowsAsync(rrr.build()).get(); if (rows == null || rows.isEmpty()) { return Status.NOT_FOUND;
@Override public ListenableFuture<MutateRowResponse> call(BigtableDataClient client, MutateRowRequest request) { return client.mutateRowAsync(request); } };
@Override public ListenableFuture<ReadModifyWriteRowResponse> call(BigtableDataClient client, ReadModifyWriteRowRequest request) { return client.readModifyWriteRowAsync(request); } };
/** {@inheritDoc} */ @Override public void waitForOperation(Operation operation) throws IOException, TimeoutException { waitForOperation(operation, 10, TimeUnit.MINUTES); }
@Override public void run() { // The first invocation of BigtableSessionSharedThreadPools.getInstance() is expensive. // Reference it so that it gets constructed asynchronously. BigtableSessionSharedThreadPools.getInstance(); } });
@Override public ListenableFuture<List<MutateRowsResponse>> call(BigtableDataClient client, MutateRowsRequest request) { return client.mutateRowsAsync(request); } };
@Override public ManagedChannel create() throws IOException { return createNettyChannel(host, options, interceptors); } };
protected BulkOperation( BigtableSession session, BigtableTableName tableName) { this.bulkRead = session.createBulkRead(tableName); this.bulkMutation = session.createBulkMutation(tableName); }
rows = client.readRowsAsync(rrr.build()).get(); if (rows == null || rows.isEmpty()) { return Status.NOT_FOUND;