-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spanner): Add DML, DQL, Mutation, Txn Actions and Utility method…
…s for executor framework (#8976) * feat(spanner): add code for executor framework * feat(spanner): lint fix * feat(spanner): check test flakiness * feat(spanner): revert - check test flakiness * feat(spanner): update context * feat(spanner): add start and finish transaction actions * feat(spanner): remove the fixed TODO * feat(spanner): add input stream handling * feat(spanner): code fixes
- Loading branch information
1 parent
1a16cbf
commit ca76671
Showing
12 changed files
with
1,690 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package actions | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"cloud.google.com/go/spanner" | ||
"cloud.google.com/go/spanner/test/cloudexecutor/executor/internal/outputstream" | ||
"cloud.google.com/go/spanner/test/cloudexecutor/executor/internal/utility" | ||
executorpb "cloud.google.com/go/spanner/test/cloudexecutor/proto" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
// DmlActionHandler holds the necessary components required for DML action. | ||
type DmlActionHandler struct { | ||
Action *executorpb.DmlAction | ||
FlowContext *ExecutionFlowContext | ||
OutcomeSender *outputstream.OutcomeSender | ||
} | ||
|
||
// ExecuteAction executes a DML update action request, store the results in the outputstream.OutcomeSender. | ||
func (h *DmlActionHandler) ExecuteAction(ctx context.Context) error { | ||
h.FlowContext.mu.Lock() | ||
defer h.FlowContext.mu.Unlock() | ||
log.Printf("Executing dml update %s\n %v\n", h.FlowContext.transactionSeed, h.Action) | ||
stmt, err := utility.BuildQuery(h.Action.GetUpdate()) | ||
if err != nil { | ||
return h.OutcomeSender.FinishWithError(err) | ||
} | ||
|
||
var iter *spanner.RowIterator | ||
txn, err := h.FlowContext.getTransactionForWrite() | ||
if err != nil { | ||
return h.OutcomeSender.FinishWithError(err) | ||
} | ||
h.OutcomeSender.InitForQuery() | ||
iter = txn.Query(ctx, stmt) | ||
defer iter.Stop() | ||
log.Printf("Parsing DML result %s\n", h.FlowContext.transactionSeed) | ||
err = processResults(iter, 0, h.OutcomeSender, h.FlowContext) | ||
if err != nil { | ||
if status.Code(err) == codes.Aborted { | ||
return h.OutcomeSender.FinishWithTransactionRestarted() | ||
} | ||
return h.OutcomeSender.FinishWithError(err) | ||
} | ||
h.OutcomeSender.AppendDmlRowsModified(iter.RowCount) | ||
return h.OutcomeSender.FinishSuccessfully() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.