Search in sources :

Example 1 with BigtableSession

use of com.google.cloud.bigtable.grpc.BigtableSession in project YCSB by brianfrankcooper.

the class GoogleBigtableClient method init.

@Override
public void init() throws DBException {
    Properties props = getProperties();
    // Defaults the user can override if needed
    CONFIG.set("google.bigtable.auth.service.account.enable", "true");
    // make it easy on ourselves by copying all CLI properties into the config object.
    final Iterator<Entry<Object, Object>> it = props.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Object, Object> entry = it.next();
        CONFIG.set((String) entry.getKey(), (String) entry.getValue());
    }
    clientSideBuffering = getProperties().getProperty(CLIENT_SIDE_BUFFERING, "false").equals("true") ? true : false;
    System.err.println("Running Google Bigtable with Proto API" + (clientSideBuffering ? " and client side buffering." : "."));
    synchronized (CONFIG) {
        ++threadCount;
        if (session == null) {
            try {
                options = BigtableOptionsFactory.fromConfiguration(CONFIG);
                session = new BigtableSession(options);
                // important to instantiate the first client here, otherwise the
                // other threads may receive an NPE from the options when they try
                // to read the cluster name.
                client = session.getDataClient();
            } catch (IOException e) {
                throw new DBException("Error loading options from config: ", e);
            }
        } else {
            client = session.getDataClient();
        }
        if (clientSideBuffering) {
            heapSizeManager = new HeapSizeManager(Long.parseLong(getProperties().getProperty(ASYNC_MUTATOR_MAX_MEMORY, Long.toString(AsyncExecutor.ASYNC_MUTATOR_MAX_MEMORY_DEFAULT))), Integer.parseInt(getProperties().getProperty(ASYNC_MAX_INFLIGHT_RPCS, Integer.toString(AsyncExecutor.MAX_INFLIGHT_RPCS_DEFAULT))));
            asyncExecutor = new AsyncExecutor(client, heapSizeManager);
        }
    }
    if ((getProperties().getProperty("debug") != null) && (getProperties().getProperty("debug").compareTo("true") == 0)) {
        debug = true;
    }
    final String columnFamily = getProperties().getProperty("columnfamily");
    if (columnFamily == null) {
        System.err.println("Error, must specify a columnfamily for Bigtable table");
        throw new DBException("No columnfamily specified");
    }
    columnFamilyBytes = Bytes.toBytes(columnFamily);
}
Also used : DBException(com.yahoo.ycsb.DBException) Entry(java.util.Map.Entry) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) IOException(java.io.IOException) ByteString(com.google.bigtable.repackaged.com.google.protobuf.ByteString) Properties(java.util.Properties) HeapSizeManager(com.google.cloud.bigtable.grpc.async.HeapSizeManager) AsyncExecutor(com.google.cloud.bigtable.grpc.async.AsyncExecutor)

Example 2 with BigtableSession

use of com.google.cloud.bigtable.grpc.BigtableSession in project beam by apache.

the class BigtableServiceImpl method openForWriting.

@Override
public BigtableWriterImpl openForWriting(String tableId) throws IOException {
    BigtableSession session = new BigtableSession(options);
    BigtableTableName tableName = options.getInstanceName().toTableName(tableId);
    return new BigtableWriterImpl(session, tableName);
}
Also used : BigtableTableName(com.google.cloud.bigtable.grpc.BigtableTableName) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession)

Example 3 with BigtableSession

use of com.google.cloud.bigtable.grpc.BigtableSession in project beam by apache.

the class BigtableServiceImpl method tableExists.

@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);
    }
}
Also used : GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException)

Example 4 with BigtableSession

use of com.google.cloud.bigtable.grpc.BigtableSession in project beam by apache.

the class BigtableWriteIT method setup.

@Before
public void setup() throws Exception {
    PipelineOptionsFactory.register(BigtableTestOptions.class);
    options = TestPipeline.testingPipelineOptions().as(BigtableTestOptions.class);
    bigtableOptions = new Builder().setProjectId(options.getProjectId()).setInstanceId(options.getInstanceId()).setUserAgent("apache-beam-test").build();
    session = new BigtableSession(bigtableOptions.toBuilder().setCredentialOptions(CredentialOptions.credential(options.as(GcpOptions.class).getGcpCredential())).build());
    tableAdminClient = session.getTableAdminClient();
}
Also used : Builder(com.google.cloud.bigtable.config.BigtableOptions.Builder) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) Before(org.junit.Before)

Aggregations

BigtableSession (com.google.cloud.bigtable.grpc.BigtableSession)4 IOException (java.io.IOException)2 GetTableRequest (com.google.bigtable.admin.v2.GetTableRequest)1 ByteString (com.google.bigtable.repackaged.com.google.protobuf.ByteString)1 Builder (com.google.cloud.bigtable.config.BigtableOptions.Builder)1 BigtableTableName (com.google.cloud.bigtable.grpc.BigtableTableName)1 AsyncExecutor (com.google.cloud.bigtable.grpc.async.AsyncExecutor)1 HeapSizeManager (com.google.cloud.bigtable.grpc.async.HeapSizeManager)1 ByteString (com.google.protobuf.ByteString)1 DBException (com.yahoo.ycsb.DBException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 Before (org.junit.Before)1