-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
chore(spanner): handle commit retry protocol extension for mux rw #11472
Open
rahul2393
wants to merge
2
commits into
main
Choose a base branch
from
mux-commit-retry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,6 +504,101 @@ func TestReadWriteTransaction_PrecommitToken(t *testing.T) { | |
} | ||
} | ||
|
||
func TestCommitWithMultiplexedSessionRetry(t *testing.T) { | ||
ctx := context.Background() | ||
server, client, teardown := setupMockedTestServerWithConfig(t, ClientConfig{ | ||
DisableNativeMetrics: true, | ||
SessionPoolConfig: SessionPoolConfig{ | ||
MinOpened: 1, | ||
MaxOpened: 1, | ||
enableMultiplexSession: true, | ||
enableMultiplexedSessionForRW: true, | ||
}, | ||
}) | ||
defer teardown() | ||
|
||
// newCommitResponseWithPrecommitToken creates a simulated response with a PrecommitToken | ||
newCommitResponseWithPrecommitToken := func() *sppb.CommitResponse { | ||
precommitToken := &sppb.MultiplexedSessionPrecommitToken{ | ||
PrecommitToken: []byte("commit-retry-precommit-token"), | ||
} | ||
|
||
// Create a CommitResponse with the PrecommitToken | ||
return &sppb.CommitResponse{ | ||
MultiplexedSessionRetry: &sppb.CommitResponse_PrecommitToken{PrecommitToken: precommitToken}, | ||
} | ||
} | ||
|
||
// Simulate a commit response with a MultiplexedSessionRetry | ||
server.TestSpanner.PutExecutionTime(MethodCommitTransaction, | ||
SimulatedExecutionTime{ | ||
Responses: []interface{}{newCommitResponseWithPrecommitToken()}, | ||
}) | ||
|
||
_, err := client.ReadWriteTransaction(ctx, func(ctx context.Context, tx *ReadWriteTransaction) error { | ||
ms := []*Mutation{ | ||
Insert("t_foo", []string{"col1", "col2"}, []interface{}{int64(1), int64(2)}), | ||
Update("t_foo", []string{"col1", "col2"}, []interface{}{"one", []byte(nil)}), | ||
} | ||
if err := tx.BufferWrite(ms); err != nil { | ||
return err | ||
} | ||
|
||
iter := tx.Query(ctx, NewStatement(SelectSingerIDAlbumIDAlbumTitleFromAlbums)) | ||
defer iter.Stop() | ||
for { | ||
_, err := iter.Next() | ||
if err == iterator.Done { | ||
break | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if _, err := tx.Update(ctx, Statement{SQL: UpdateBarSetFoo}); err != nil { | ||
return err | ||
Comment on lines
+559
to
+560
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. Commit retry only happens in cases of DQL+Mutation. Lets remove DML to avoid confusion |
||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
t.Fatalf("Commit failed: %v", err) | ||
} | ||
|
||
// Verify that the commit was retried | ||
requests := drainRequestsFromServer(server.TestSpanner) | ||
commitCount := 0 | ||
for _, req := range requests { | ||
if commitReq, ok := req.(*sppb.CommitRequest); ok { | ||
if !strings.Contains(commitReq.GetSession(), "multiplexed") { | ||
t.Errorf("Expected session to be multiplexed") | ||
} | ||
commitCount++ | ||
if commitCount == 1 { | ||
// Validate that the first commit had mutations set | ||
if len(commitReq.Mutations) == 0 { | ||
t.Fatalf("Expected first commit to have mutations set") | ||
} | ||
if commitReq.PrecommitToken == nil || !strings.Contains(string(commitReq.PrecommitToken.PrecommitToken), "ResultSetPrecommitToken") { | ||
t.Fatalf("Expected first commit to have precommit token 'ResultSetPrecommitToken', got: %v", commitReq.PrecommitToken) | ||
} | ||
} else if commitCount == 2 { | ||
// Validate that the second commit attempt had mutations un-set | ||
if len(commitReq.Mutations) != 0 { | ||
t.Fatalf("Expected second commit to have no mutations set") | ||
} | ||
// Validate that the second commit had the precommit token set | ||
if commitReq.PrecommitToken == nil || string(commitReq.PrecommitToken.PrecommitToken) != "commit-retry-precommit-token" { | ||
t.Fatalf("Expected second commit to have precommit token 'commit-retry-precommit-token', got: %v", commitReq.PrecommitToken) | ||
} | ||
} | ||
} | ||
} | ||
if commitCount != 2 { | ||
t.Fatalf("Expected 2 commit attempts, got %d", commitCount) | ||
} | ||
} | ||
|
||
func TestMutationOnlyCaseAborted(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: Here can we get the precommit token, pass it to setPrecommitToken method and then below use t.precommittoken?
I understand that the precommittoken reveived in res should be latest but here we will need to rely on sequence number to determine that the precommit token is indeed latest. This will save us in future in cases where the precommit token received in res could be outdated.