@Teardown public void teardown() throws Exception { spannerAccessor.close(); }
@ProcessElement public void processElement(ProcessContext c) throws Exception { BatchReadOnlyTransaction tx = spannerAccessor.getBatchClient().batchReadOnlyTransaction(config.getTimestampBound()); c.output(Transaction.create(tx.getBatchTransactionId())); } }
DatabaseClient getDatabaseClient(SpannerConfig spannerConfig) { if (databaseClient == null) { this.spannerAccessor = spannerConfig.connectToSpanner(); return this.spannerAccessor.getDatabaseClient(); } else { return this.databaseClient; } }
@ProcessElement public void processElement(ProcessContext c) { Ddl ddl = c.element(); DatabaseAdminClient databaseAdminClient = spannerAccessor.getDatabaseAdminClient(); List<String> createIndexStatements = ddl.createIndexStatements(); if (!createIndexStatements.isEmpty()) { // This just kicks off the index creation, it does not wait for it to complete. Operation<Void, UpdateDatabaseDdlMetadata> op = databaseAdminClient.updateDatabaseDdl( spannerConfig.getInstanceId().get(), spannerConfig.getDatabaseId().get(), createIndexStatements, null); if (waitForIndexes.get()) { op.waitFor(); } } } }));
public SpannerAccessor connectToSpanner() { SpannerOptions.Builder builder = SpannerOptions.newBuilder(); if (getProjectId() != null) { builder.setProjectId(getProjectId().get()); } if (getServiceFactory() != null) { builder.setServiceFactory(this.getServiceFactory()); } if (getHost() != null) { builder.setHost(getHost().get()); } String userAgentString = USER_AGENT_PREFIX + "/" + ReleaseInfo.getReleaseInfo().getVersion(); builder.setHeaderProvider(FixedHeaderProvider.create("user-agent", userAgentString)); SpannerOptions options = builder.build(); Spanner spanner = options.getService(); DatabaseClient databaseClient = spanner.getDatabaseClient( DatabaseId.of(options.getProjectId(), getInstanceId().get(), getDatabaseId().get())); BatchClient batchClient = spanner.getBatchClient( DatabaseId.of(options.getProjectId(), getInstanceId().get(), getDatabaseId().get())); DatabaseAdminClient databaseAdminClient = spanner.getDatabaseAdminClient(); return new SpannerAccessor(spanner, databaseClient, databaseAdminClient, batchClient); } }
@ProcessElement public void processElement(ProcessContext c) { Transaction transaction = c.sideInput(tx); BatchTransactionId transactionId = transaction.transactionId(); BatchClient batchClient = spannerAccessor.getBatchClient(); BatchReadOnlyTransaction context = batchClient.batchReadOnlyTransaction(transactionId); InformationSchemaScanner scanner = new InformationSchemaScanner(context); Ddl ddl = scanner.scan(); c.output(ddl); } }
mutationGroupBatchesCounter.inc(); Iterable<Mutation> batch = Iterables.concat(mutations); spannerAccessor.getDatabaseClient().writeAtLeastOnce(batch); mutationGroupWriteSuccessCounter.inc(Iterables.size(mutations)); return; for (MutationGroup mg : mutations) { try { spannerAccessor.getDatabaseClient().writeAtLeastOnce(mg); mutationGroupWriteSuccessCounter.inc(); } catch (SpannerException e) {
spannerAccessor.getDatabaseAdminClient();
void closeSpannerAccessor() { if (spannerAccessor != null) { this.spannerAccessor.close(); } }
@ProcessElement public void processElement(ProcessContext c) throws Exception { Transaction tx = c.sideInput(txView); BatchReadOnlyTransaction context = spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId()); for (Partition p : execute(c.element(), context)) { c.output(p); } }
@ProcessElement public void processElement(ProcessContext c) throws Exception { SpannerSchema.Builder builder = SpannerSchema.builder(); DatabaseClient databaseClient = spannerAccessor.getDatabaseClient(); try (ReadOnlyTransaction tx = databaseClient.readOnlyTransaction()) { ResultSet resultSet = readTableInfo(tx); while (resultSet.next()) { String tableName = resultSet.getString(0); String columnName = resultSet.getString(1); String type = resultSet.getString(2); long cellsMutated = resultSet.getLong(3); builder.addColumn(tableName, columnName, type, cellsMutated); } resultSet = readPrimaryKeyInfo(tx); while (resultSet.next()) { String tableName = resultSet.getString(0); String columnName = resultSet.getString(1); String ordering = resultSet.getString(2); builder.addKeyPart(tableName, columnName, "DESC".equalsIgnoreCase(ordering)); } } c.output(builder.build()); }
@Teardown public void teardown() throws Exception { spannerAccessor.close(); }
@ProcessElement public void processElement(ProcessContext c) throws Exception { Transaction tx = c.sideInput(txView); ReadOperation op = c.element(); BatchReadOnlyTransaction context = spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId()); try (ResultSet resultSet = execute(op, context)) { while (resultSet.next()) { c.output(resultSet.getCurrentRowAsStruct()); } } }
@Teardown public void teardown() throws Exception { spannerAccessor.close(); }
@ProcessElement public void processElement(ProcessContext c) throws Exception { Transaction tx = c.sideInput(txView); BatchReadOnlyTransaction batchTx = spannerAccessor.getBatchClient().batchReadOnlyTransaction(tx.transactionId()); Partition p = c.element(); try (ResultSet resultSet = batchTx.execute(p)) { while (resultSet.next()) { Struct s = resultSet.getCurrentRowAsStruct(); c.output(s); } } } }
@Teardown public void teardown() throws Exception { spannerAccessor.close(); }
@Teardown public void teardown() throws Exception { spannerAccessor.close(); }
@Teardown public void teardown() throws Exception { spannerAccessor.close(); }
@Teardown public void teardown() { spannerAccessor.close(); }
@Teardown public void teardown() throws Exception { spannerAccessor.close(); }