-
Notifications
You must be signed in to change notification settings - Fork 399
feat: Spanner non-awaiting DDL #15280
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
Changes from 4 commits
1aa3b4f
c299d51
5752bb3
3c984c9
901a44e
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| using Google.Cloud.Spanner.Admin.Database.V1; | ||
| using Google.Cloud.Spanner.Common.V1; | ||
| using Google.Cloud.Spanner.V1; | ||
| using Google.LongRunning; | ||
| using Google.Protobuf; | ||
| using Google.Protobuf.WellKnownTypes; | ||
| using Grpc.Core; | ||
|
|
@@ -235,10 +236,27 @@ private async Task<SpannerDataReader> ExecuteDmlReaderAsync(CommandBehavior beha | |
| } | ||
|
|
||
| private async Task<int> ExecuteDdlAsync(CancellationToken cancellationToken) | ||
| { | ||
| await ExecuteDdlAsync(pollUntilCompleted: true, cancellationToken).ConfigureAwait(false); | ||
| return 0; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Starts a DDL operation, but does not wait for the long-running operation to finish. | ||
| /// </summary> | ||
| /// <returns>The name of the long-running operation that was created</returns> | ||
| internal async Task<string> StartDdlAsync(CancellationToken cancellationToken) | ||
| { | ||
| var operation = await ExecuteDdlAsync(pollUntilCompleted: false, cancellationToken).ConfigureAwait(false); | ||
| return operation?.Name ?? ""; | ||
|
||
| } | ||
|
|
||
| private async Task<Operation> ExecuteDdlAsync(bool pollUntilCompleted, CancellationToken cancellationToken) | ||
| { | ||
| string commandText = CommandTextBuilder.CommandText; | ||
| var builder = Connection.Builder; | ||
| var connectionOptions = new SpannerClientCreationOptions(builder); | ||
| Operation operation = null; | ||
|
|
||
| // Create the builder separately from actually building, so we can note the channel that it created. | ||
| // (This is fairly unpleasant, but we'll try to improve this in the next version of GAX.) | ||
|
|
@@ -258,11 +276,15 @@ private async Task<int> ExecuteDdlAsync(CancellationToken cancellationToken) | |
| ProtoDescriptors = CommandTextBuilder.ProtobufDescriptors?.ToByteString() ?? ByteString.Empty, | ||
| }; | ||
| var response = await databaseAdminClient.CreateDatabaseAsync(request).ConfigureAwait(false); | ||
| response = await response.PollUntilCompletedAsync().ConfigureAwait(false); | ||
| if (pollUntilCompleted) | ||
|
||
| { | ||
| response = await response.PollUntilCompletedAsync().ConfigureAwait(false); | ||
| } | ||
| if (response.IsFaulted) | ||
olavloite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| throw SpannerException.FromOperationFailedException(response.Exception); | ||
| } | ||
| operation = response.RpcMessage; | ||
| } | ||
| else if (CommandTextBuilder.IsDropDatabaseCommand) | ||
| { | ||
|
|
@@ -295,11 +317,15 @@ private async Task<int> ExecuteDdlAsync(CancellationToken cancellationToken) | |
| }; | ||
|
|
||
| var response = await databaseAdminClient.UpdateDatabaseDdlAsync(request).ConfigureAwait(false); | ||
| response = await response.PollUntilCompletedAsync().ConfigureAwait(false); | ||
| if (pollUntilCompleted) | ||
| { | ||
| response = await response.PollUntilCompletedAsync().ConfigureAwait(false); | ||
| } | ||
| if (response.IsFaulted) | ||
| { | ||
| throw SpannerException.FromOperationFailedException(response.Exception); | ||
| } | ||
| operation = response.RpcMessage; | ||
| } | ||
| } | ||
| catch (RpcException gRpcException) | ||
|
|
@@ -312,7 +338,7 @@ private async Task<int> ExecuteDdlAsync(CancellationToken cancellationToken) | |
| channel?.Shutdown(); | ||
| } | ||
|
|
||
| return 0; | ||
| return operation; | ||
| } | ||
|
|
||
| private async Task<int> ExecuteMutationsAsync(CancellationToken cancellationToken) | ||
|
|
||
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.
Would you mind leaving the existing tests as is and creating a new one for this. The one we have is not great (re: name and what its testing) ,but if we also check that the operation name is returned, then it gets even more confusing. I'm fine if you duplicate this one and tweak it, or just use the create tables and drop database parts of it.
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.
Done