/** * 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); } } }
public TableAdapter2x(BigtableOptions options) { bigtableInstanceName = options.getInstanceName(); }
public TableAdapter2x(BigtableOptions options) { bigtableInstanceName = options.getInstanceName(); }
public BigtableTableAdminClientWrapper(@Nonnull BigtableTableAdminClient adminClient, @Nonnull BigtableOptions options){ Preconditions.checkNotNull(adminClient); Preconditions.checkNotNull(options); this.adminClient = adminClient; this.instanceName = options.getInstanceName(); }
/** * Constructor for the utility. Prefer * {@link BigtableClusterUtilities#forInstance(String, String)} or * {@link BigtableClusterUtilities#forAllInstances(String)} rather than this method. * @param options that specify projectId, instanceId, credentials and retry options. * @throws GeneralSecurityException * @throws IOException */ public BigtableClusterUtilities(final BigtableOptions options) throws IOException, GeneralSecurityException { this.instanceName = Preconditions.checkNotNull( options.getInstanceName(), "ProjectId and instanceId have to be set in the options. Use '-' for all instanceIds."); channel = BigtableSession.createChannelPool(options.getAdminHost(), options); client = new BigtableInstanceGrpcClient(channel); }
@Override public BigtableWriterImpl openForWriting(String tableId) throws IOException { BigtableSession session = new BigtableSession(options); BigtableTableName tableName = options.getInstanceName().toTableName(tableId); return new BigtableWriterImpl(session, tableName); }
@Override public List<HRegionInfo> getAllRegionInfos(TableName tableName) throws IOException { ServerName serverName = ServerName.valueOf(options.getDataHost(), options.getPort(), 0); SampleRowKeysRequest.Builder request = SampleRowKeysRequest.newBuilder(); request.setTableName(options.getInstanceName().toTableNameStr(tableName.getNameAsString())); List<SampleRowKeysResponse> sampleRowKeyResponse = this.session.getDataClient().sampleRowKeys(request.build()); return getSampledRowKeysAdapter(tableName, serverName).adaptResponse(sampleRowKeyResponse) .stream() .map(location -> location.getRegionInfo()) .collect(Collectors.toCollection(CopyOnWriteArrayList::new)); }
@Override public List<HRegionInfo> getAllRegionInfos(TableName tableName) throws IOException { ServerName serverName = ServerName.valueOf(options.getDataHost(), options.getPort(), 0); SampleRowKeysRequest.Builder request = SampleRowKeysRequest.newBuilder(); request.setTableName(options.getInstanceName().toTableNameStr(tableName.getNameAsString())); List<SampleRowKeysResponse> sampleRowKeyResponse = this.session.getDataClient().sampleRowKeys(request.build()); return getSampledRowKeysAdapter(tableName, serverName).adaptResponse(sampleRowKeyResponse) .stream() .map(location -> location.getRegionInfo()) .collect(Collectors.toCollection(CopyOnWriteArrayList::new)); }
@Override public CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName) { return CompletableFuture.supplyAsync(() -> { try { return CreateTableFromSnapshotRequest.newBuilder() .setParent(options.getInstanceName().toString()) .setTableId(tableName.getNameAsString()) .setSourceSnapshot(getClusterName().toSnapshotName(snapshotName)).build(); } catch (IOException e) { throw new CompletionException(e); } }).thenCompose( c -> bigtableTableAdminClient.createTableFromSnapshotAsync(c).thenApply(r -> null)); }
@Override public CompletableFuture<Void> snapshot(String snapshotName, TableName tableName) { return CompletableFuture.supplyAsync(() -> { try { return SnapshotTableRequest.newBuilder() .setCluster(getSnapshotClusterName().toString()) .setSnapshotId(snapshotName) .setName(options.getInstanceName().toTableNameStr(tableName.getNameAsString())).build(); } catch (IOException e) { throw new CompletionException(e); } }).thenCompose( c -> bigtableTableAdminClient.snapshotTableAsync(c).thenApply(r -> null)); }
@Override public CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName) { return CompletableFuture.supplyAsync(() -> { try { return CreateTableFromSnapshotRequest.newBuilder() .setParent(options.getInstanceName().toString()) .setTableId(tableName.getNameAsString()) .setSourceSnapshot(getClusterName().toSnapshotName(snapshotName)).build(); } catch (IOException e) { throw new CompletionException(e); } }).thenCompose( c -> bigtableTableAdminClient.createTableFromSnapshotAsync(c).thenApply(r -> null)); }
@Override public CompletableFuture<Void> snapshot(String snapshotName, TableName tableName) { return CompletableFuture.supplyAsync(() -> { try { return SnapshotTableRequest.newBuilder() .setCluster(getSnapshotClusterName().toString()) .setSnapshotId(snapshotName) .setName(options.getInstanceName().toTableNameStr(tableName.getNameAsString())).build(); } catch (IOException e) { throw new CompletionException(e); } }).thenCompose( c -> bigtableTableAdminClient.snapshotTableAsync(c).thenApply(r -> null)); }
public AbstractBigtableRegionLocator (TableName tableName, BigtableOptions options, BigtableDataClient client) { this.tableName = tableName; this.client = client; this.bigtableTableName = options.getInstanceName().toTableName(tableName.getNameAsString()); ServerName serverName = ServerName.valueOf(options.getDataHost(), options.getPort(), 0); this.adapter = getSampledRowKeysAdapter(tableName, serverName); }
public AbstractBigtableRegionLocator (TableName tableName, BigtableOptions options, BigtableDataClient client) { this.tableName = tableName; this.client = client; this.bigtableTableName = options.getInstanceName().toTableName(tableName.getNameAsString()); ServerName serverName = ServerName.valueOf(options.getDataHost(), options.getPort(), 0); this.adapter = getSampledRowKeysAdapter(tableName, serverName); }
public BigtableAsyncAdmin(CommonConnection asyncConnection) throws IOException { LOG.debug("Creating BigtableAsyncAdmin"); this.options = asyncConnection.getOptions(); this.bigtableTableAdminClient = new BigtableTableAdminClient( asyncConnection.getSession().getTableAdminClient()); this.disabledTables = asyncConnection.getDisabledTables(); this.bigtableInstanceName = options.getInstanceName(); this.tableAdapter2x = new TableAdapter2x(options); this.asyncConnection = asyncConnection; this.configuration = asyncConnection.getConfiguration(); String clusterId = configuration.get(BigtableOptionsFactory.BIGTABLE_SNAPSHOT_CLUSTER_ID_KEY, null); if (clusterId != null) { bigtableSnapshotClusterName = bigtableInstanceName.toClusterName(clusterId); } }
public BigtableAsyncAdmin(CommonConnection asyncConnection) throws IOException { LOG.debug("Creating BigtableAsyncAdmin"); this.options = asyncConnection.getOptions(); this.bigtableTableAdminClient = new BigtableTableAdminClient( asyncConnection.getSession().getTableAdminClient()); this.disabledTables = asyncConnection.getDisabledTables(); this.bigtableInstanceName = options.getInstanceName(); this.tableAdapter2x = new TableAdapter2x(options); this.asyncConnection = asyncConnection; this.configuration = asyncConnection.getConfiguration(); String clusterId = configuration.get(BigtableOptionsFactory.BIGTABLE_SNAPSHOT_CLUSTER_ID_KEY, null); if (clusterId != null) { bigtableSnapshotClusterName = bigtableInstanceName.toClusterName(clusterId); } }
/** * <p>Constructor for HBaseRequestAdapter.</p> * * @param options a {@link BigtableOptions} object. * @param tableName a {@link TableName} object. * @param mutationAdapters a {@link MutationAdapters} object. */ public HBaseRequestAdapter(BigtableOptions options, TableName tableName, MutationAdapters mutationAdapters) { this(tableName, options.getInstanceName().toTableName(tableName.getQualifierAsString()), mutationAdapters, RequestContext.create( InstanceName.of(options.getProjectId(), options.getInstanceId()), options.getAppProfileId() )); }
@After public void tearDown() throws Exception { final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId); deleteTable(tableName); session.close(); }
@Override public List<SampleRowKeysResponse> getSampleRowKeys(BigtableSource source) throws IOException { try (BigtableSession session = new BigtableSession(options)) { SampleRowKeysRequest request = SampleRowKeysRequest.newBuilder() .setTableName(options.getInstanceName().toTableNameStr(source.getTableId().get())) .build(); return session.getDataClient().sampleRowKeys(request); } } }
@Override public boolean start() throws IOException { RowSet.Builder rowSetBuilder = RowSet.newBuilder(); for (ByteKeyRange sourceRange : source.getRanges()) { rowSetBuilder = rowSetBuilder.addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFrom(sourceRange.getStartKey().getValue())) .setEndKeyOpen(ByteString.copyFrom(sourceRange.getEndKey().getValue()))); } RowSet rowSet = rowSetBuilder.build(); String tableNameSr = session.getOptions().getInstanceName().toTableNameStr(source.getTableId().get()); ReadRowsRequest.Builder requestB = ReadRowsRequest.newBuilder().setRows(rowSet).setTableName(tableNameSr); if (source.getRowFilter() != null) { requestB.setFilter(source.getRowFilter()); } results = session.getDataClient().readRows(requestB.build()); return advance(); }