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 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); } } } }
/** * 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); } } }
@Before public void setup() { MockitoAnnotations.initMocks(this); BigtableOptions options = new BigtableOptions.Builder().setProjectId("project").setInstanceId("instance").build(); when(mockSession.getOptions()).thenReturn(options); when(mockSession.createBulkMutation(eq(TABLE_NAME))).thenReturn(mockBulkMutation); when(mockSession.getDataClient()).thenReturn(mockBigtableDataClient); }
public BigtableAsyncConnection(Configuration conf, AsyncRegistry ignoredRegistry, String ignoredClusterId, User ignoredUser) throws IOException { LOG.debug("Creating BigtableAsyncConnection"); this.conf = conf; BigtableOptions opts; try { opts = BigtableOptionsFactory.fromConfiguration(conf); } catch (IOException ioe) { LOG.error("Error loading BigtableOptions from Configuration.", ioe); throw ioe; } this.closed = false; this.session = new BigtableSession(opts); this.options = this.session.getOptions(); }
@Override public AsyncTableRegionLocator getRegionLocator(TableName tableName) { return new BigtableAsyncTableRegionLocator(tableName, options, this.session.getDataClient()); }
/** * Constructed by BigtableConnection * * @param bigtableConnection a {@link org.apache.hadoop.hbase.client.AbstractBigtableConnection} object. * @param hbaseAdapter a {@link com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter} object. */ public AbstractBigtableTable(AbstractBigtableConnection bigtableConnection, HBaseRequestAdapter hbaseAdapter) { this.bigtableConnection = bigtableConnection; BigtableSession session = bigtableConnection.getSession(); this.options = session.getOptions(); this.client = session.getDataClient(); this.clientWrapper = session.getClientWrapper(); this.hbaseAdapter = hbaseAdapter; this.tableName = hbaseAdapter.getTableName(); this.requestContext = RequestContext.create( InstanceName.of(options.getProjectId(), options.getInstanceId()), options.getAppProfileId()); }
@Override public boolean tableExists(String tableId) throws IOException { try (BigtableSession session = new BigtableSession(options)) { GetTableRequest getTable = GetTableRequest.newBuilder() .setName(options.getInstanceName().toTableNameStr(tableId)) .build(); session.getTableAdminClient().getTable(getTable); return true; } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { return false; } String message = String.format( "Error checking whether table %s (BigtableOptions %s) exists", tableId, options); LOG.error(message, e); throw new IOException(message, e); } }
/** * <p> * Constructor for BigtableBufferedMutator. * </p> * @param adapter Converts HBase objects to Bigtable protos * @param configuration For Additional configuration. TODO: move this to options * @param session a {@link com.google.cloud.bigtable.grpc.BigtableSession} to get * {@link com.google.cloud.bigtable.config.BigtableOptions}, * {@link com.google.cloud.bigtable.grpc.async.AsyncExecutor} and * {@link com.google.cloud.bigtable.grpc.async.BulkMutation} objects from starting the * async operations on the BigtableDataClient. */ public BigtableBufferedMutatorHelper( HBaseRequestAdapter adapter, Configuration configuration, BigtableSession session) { this.adapter = adapter; this.configuration = configuration; this.options = session.getOptions(); this.asyncExecutor = session.createAsyncExecutor(); BigtableTableName tableName = this.adapter.getBigtableTableName(); this.bulkMutation = session.createBulkMutation(tableName); }
/** * <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(); }
@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(); }
protected BulkOperation( BigtableSession session, BigtableTableName tableName) { this.bulkRead = session.createBulkRead(tableName); this.bulkMutation = session.createBulkMutation(tableName); }
/** * <p> * Constructor for AbstractBigtableAdmin. * </p> * @param connection a {@link CommonConnection} object. * @throws IOException */ public AbstractBigtableAdmin(CommonConnection connection) throws IOException { LOG.debug("Creating BigtableAdmin"); configuration = connection.getConfiguration(); options = connection.getOptions(); this.connection = connection; bigtableTableAdminClient = connection.getSession().getTableAdminClient(); disabledTables = connection.getDisabledTables(); bigtableInstanceName = options.getInstanceName(); tableAdapter = new TableAdapter(bigtableInstanceName); tableAdminClientWrapper = connection.getSession().getTableAdminClientWrapper(); String clusterId = configuration.get(BigtableOptionsFactory.BIGTABLE_SNAPSHOT_CLUSTER_ID_KEY, null); if (clusterId != null) { bigtableSnapshotClusterName = bigtableInstanceName.toClusterName(clusterId); } }
@Override public Reader createReader(BigtableSource source) throws IOException { BigtableSession session = new BigtableSession(options); return new BigtableReaderImpl(session, source); }
/** * Constructor for BatchExecutor. * * @param session a {@link com.google.cloud.bigtable.grpc.BigtableSession} object. * @param requestAdapter a {@link com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter} * object. */ public BatchExecutor(BigtableSession session, HBaseRequestAdapter requestAdapter) { this.session = session; this.asyncExecutor = session.createAsyncExecutor(); this.options = session.getOptions(); this.requestAdapter = requestAdapter; }
/** * <p>Constructor for BigtableBufferedMutator.</p> * * @param adapter Converts HBase objects to Bigtable protos * @param configuration For Additional configuration. TODO: move this to options * @param listener Handles exceptions. By default, it just throws the exception. * @param session a {@link com.google.cloud.bigtable.grpc.BigtableSession} to get {@link com.google.cloud.bigtable.config.BigtableOptions}, {@link com.google.cloud.bigtable.grpc.async.AsyncExecutor} * and {@link com.google.cloud.bigtable.grpc.async.BulkMutation} objects from * starting the async operations on the BigtableDataClient. */ public BigtableBufferedMutator( HBaseRequestAdapter adapter, Configuration configuration, BigtableSession session, BufferedMutator.ExceptionListener listener) { helper = new BigtableBufferedMutatorHelper(adapter, configuration, session); this.listener = listener; this.host = session.getOptions().getDataHost().toString(); }
protected BigtableClusterName getClusterName() throws IOException { return connection.getSession().getClusterName(); }
public BigtableAsyncConnection(Configuration conf, AsyncRegistry ignoredRegistry, String ignoredClusterId, User ignoredUser) throws IOException { LOG.debug("Creating BigtableAsyncConnection"); this.conf = conf; BigtableOptions opts; try { opts = BigtableOptionsFactory.fromConfiguration(conf); } catch (IOException ioe) { LOG.error("Error loading BigtableOptions from Configuration.", ioe); throw ioe; } this.closed = false; this.session = new BigtableSession(opts); this.options = this.session.getOptions(); }
@Override public AsyncTableRegionLocator getRegionLocator(TableName tableName) { return new BigtableAsyncTableRegionLocator(tableName, options, this.session.getDataClient()); }
/** * Constructed by BigtableConnection * * @param bigtableConnection a {@link org.apache.hadoop.hbase.client.AbstractBigtableConnection} object. * @param hbaseAdapter a {@link com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter} object. */ public AbstractBigtableTable(AbstractBigtableConnection bigtableConnection, HBaseRequestAdapter hbaseAdapter) { this.bigtableConnection = bigtableConnection; BigtableSession session = bigtableConnection.getSession(); this.options = session.getOptions(); this.client = session.getDataClient(); this.clientWrapper = session.getClientWrapper(); this.hbaseAdapter = hbaseAdapter; this.tableName = hbaseAdapter.getTableName(); this.requestContext = RequestContext.create( InstanceName.of(options.getProjectId(), options.getInstanceId()), options.getAppProfileId()); }