-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate connection API to use the new auto-generated admin clients. #2879
Changes from all commits
edc5bbf
49a85df
4cd497b
4a6aa8e
b2aa09d
8d6d71e
77e6e7d
e8b7fad
8aa84e1
57fd405
1253563
d4f6a60
3efaf7c
f41b39f
7e3287f
7edd24d
451d2c1
5ca5d6d
5272aa3
14f6080
f1ec78c
acb847a
2da9e18
a36ed1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
import com.google.cloud.spanner.Statement; | ||
import com.google.cloud.spanner.TimestampBound; | ||
import com.google.cloud.spanner.TimestampBound.Mode; | ||
import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient; | ||
import com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement; | ||
import com.google.cloud.spanner.connection.AbstractStatementParser.StatementType; | ||
import com.google.cloud.spanner.connection.StatementExecutor.StatementTimeout; | ||
|
@@ -186,6 +187,7 @@ static UnitOfWorkType of(TransactionMode transactionMode) { | |
|
||
private final Spanner spanner; | ||
private final DdlClient ddlClient; | ||
private final DatabaseAdminClient databaseAdminClient; | ||
private final DatabaseClient dbClient; | ||
private final BatchClient batchClient; | ||
private boolean autocommit; | ||
|
@@ -273,7 +275,8 @@ static UnitOfWorkType of(TransactionMode transactionMode) { | |
this.autoPartitionMode = options.isAutoPartitionMode(); | ||
this.maxPartitions = options.getMaxPartitions(); | ||
this.maxPartitionedParallelism = options.getMaxPartitionedParallelism(); | ||
this.ddlClient = createDdlClient(); | ||
this.databaseAdminClient = spanner.createDatabaseAdminClient(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will create a separate admin client for each connection that is created, including underlying gRPC channels. That means that an application that uses a JDBC connection that opens 100 connections, all of a sudden uses 4 channels (for the normal Spanner instance) + 100 (or 400? I don't remember exactly what channel settings we are using for the generated admin clients) channels for the 100 DatabaseAdmin clients. It also means that creating a new Currently, creating a |
||
this.ddlClient = createDdlClient(databaseAdminClient); | ||
setDefaultTransactionOptions(); | ||
} | ||
|
||
|
@@ -283,6 +286,7 @@ static UnitOfWorkType of(TransactionMode transactionMode) { | |
ConnectionOptions options, | ||
SpannerPool spannerPool, | ||
DdlClient ddlClient, | ||
DatabaseAdminClient databaseAdminClient, | ||
DatabaseClient dbClient, | ||
BatchClient batchClient) { | ||
this.leakedException = | ||
|
@@ -291,6 +295,7 @@ static UnitOfWorkType of(TransactionMode transactionMode) { | |
new StatementExecutor(options.isUseVirtualThreads(), Collections.emptyList()); | ||
this.spannerPool = Preconditions.checkNotNull(spannerPool); | ||
this.options = Preconditions.checkNotNull(options); | ||
this.databaseAdminClient = Preconditions.checkNotNull(databaseAdminClient); | ||
this.spanner = spannerPool.getSpanner(options, this); | ||
this.ddlClient = Preconditions.checkNotNull(ddlClient); | ||
this.dbClient = Preconditions.checkNotNull(dbClient); | ||
|
@@ -306,9 +311,10 @@ Spanner getSpanner() { | |
return this.spanner; | ||
} | ||
|
||
private DdlClient createDdlClient() { | ||
private DdlClient createDdlClient(DatabaseAdminClient databaseAdminClient) { | ||
return DdlClient.newBuilder() | ||
.setDatabaseAdminClient(spanner.getDatabaseAdminClient()) | ||
.setDatabaseAdminClient(databaseAdminClient) | ||
.setProjectId(options.getProjectId()) | ||
.setInstanceId(options.getInstanceId()) | ||
.setDatabaseName(options.getDatabaseName()) | ||
.build(); | ||
|
@@ -362,6 +368,13 @@ public ApiFuture<Void> closeAsync() { | |
statementExecutor.shutdown(); | ||
leakedException = null; | ||
spannerPool.removeConnection(options, this); | ||
try { | ||
if (!databaseAdminClient.isTerminated() || !databaseAdminClient.isShutdown()) { | ||
databaseAdminClient.close(); | ||
} | ||
} catch (RuntimeException ex) { | ||
throw SpannerExceptionFactory.newSpannerException(ex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure that we want to propagate this exception? Or should we just ignore it? Are there any potential things that the user might have done wrong that could cause an exception here? If yes, then it is probably best to propagate it. If this is more of a 'better-safe-than-sorry' and/or 'this sometimes randomly causes an exception, no idea why'-kind of situation, then I would suggest that we ignore the exception. But see also above: I don't think we should create a separate |
||
} | ||
return ApiFutures.transform( | ||
ApiFutures.allAsList(futures), ignored -> null, MoreExecutors.directExecutor()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this? I think it will be confusing for customers when to use which of these two methods (
getDialect()
andgetDatabaseDialect()
). Could we instead instruct users to useDialect.toProto()
instead when they need the proto version?