-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Wrap fatal TX errors in a new vterrors
code
#17669
Open
frouioui
wants to merge
26
commits into
vitessio:main
Choose a base branch
from
planetscale:improved-errors-during-prs
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
26 commits
Select commit
Hold shift + click to select a range
1b5760d
Wrap errors happening during PRS in VT15001
frouioui 1d4855b
rollback when markSavepoint fails
frouioui a41541a
add comment
frouioui 2af7e91
wip - add multi shards test case
frouioui 6513c15
use vt15001 in more places and rollback as soon as we detect this error
frouioui dd3b498
revert / comment changes in tests
frouioui b66a4ef
fix panic
frouioui f11d7f9
wip
frouioui 5ea8a96
Revert unwanted configuration change
frouioui ebe6aab
Fix TestReplicaTransactions assertion
frouioui 1ecc210
Wrap tx errors in VT15001
frouioui b64827b
Fix E2E test and rename VT15001
frouioui b3fd5ca
Improve E2E tests for errors in tx
frouioui 7135534
Wait for main action to complete before setting tablet to SERVING
frouioui 512cc5c
Lower flakiness by using longer tx timeouts
frouioui db8249e
Merge remote-tracking branch 'origin/main' into improved-errors-durin…
frouioui 83dba75
Check for multi-db commit failed warning
frouioui 2829981
Remove unnecessary check
frouioui 293720a
Block queries after VT15001 until ROLLBACK is received
frouioui c7ad375
Wrap healthcheck error only when in a tx
frouioui 812df8f
review suggestions: better proto name and code comments
frouioui 89060c8
review suggestions: more unit tests
frouioui a43a4d4
revert unwanted change to shard_buffer.go
frouioui f5ee299
wrap grpc errors in wrappedService
frouioui 83dc5aa
fix TestReplicaTransactions
frouioui 5baee4d
fix condition check to wrap error
frouioui 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
156 changes: 156 additions & 0 deletions
156
go/test/endtoend/reparent/newfeaturetest/reparent_in_tx_test.go
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,156 @@ | ||
/* | ||
Copyright 2025 The Vitess Authors. | ||
|
||
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 newfeaturetest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
"vitess.io/vitess/go/test/endtoend/reparent/utils" | ||
"vitess.io/vitess/go/vt/vtctl/reparentutil/policy" | ||
) | ||
|
||
var primary int | ||
|
||
// This test ensures that we get a VT15001 error when doing COMMIT while having primary being turned off. | ||
// The test then ensures that, if there was no partial commit, all the inserts were rolled back correctly. | ||
func testCommitError(t *testing.T, conn *mysql.Conn, clusterInstance *cluster.LocalProcessCluster, tablets []*cluster.Vttablet) { | ||
tabletStopped := make(chan bool) | ||
commitDone := make(chan bool) | ||
idx := 1 | ||
createTxAndInsertRows(conn, t, &idx) | ||
|
||
go func() { | ||
<-tabletStopped | ||
_, err := conn.ExecuteFetch("commit", 0, false) | ||
require.ErrorContains(t, err, "VT15001") | ||
commitDone <- true | ||
}() | ||
|
||
reparent(t, clusterInstance, tablets, tabletStopped, commitDone) | ||
|
||
_, err := conn.ExecuteFetch("delete from vt_insert_test", 0, false) | ||
require.NoError(t, err) | ||
} | ||
|
||
func testExecuteError(t *testing.T, conn *mysql.Conn, clusterInstance *cluster.LocalProcessCluster, tablets []*cluster.Vttablet) { | ||
tabletStopped := make(chan bool) | ||
executeDone := make(chan bool) | ||
idx := 1 | ||
createTxAndInsertRows(conn, t, &idx) | ||
|
||
go func() { | ||
idx += 5 | ||
<-tabletStopped | ||
_, err := conn.ExecuteFetch(utils.GetInsertMultipleValuesQuery(idx, idx+1, idx+2, idx+3), 0, false) | ||
require.ErrorContains(t, err, "VT15001") | ||
|
||
// Subsequent queries after a VT15001 should start returning a VT15002 error until we issue a ROLLBACK | ||
_, err = conn.ExecuteFetch("select * from vt_insert_test", 1, false) | ||
require.ErrorContains(t, err, "VT15002") | ||
|
||
_, err = conn.ExecuteFetch("rollback", 0, false) | ||
require.NoError(t, err) | ||
executeDone <- true | ||
}() | ||
|
||
reparent(t, clusterInstance, tablets, tabletStopped, executeDone) | ||
|
||
// if the unhealthy shard is the first one where we commited, let's assert that the table is empty on all the shards | ||
r, err := conn.ExecuteFetch("select * from vt_insert_test", 1, false) | ||
require.NoError(t, err) | ||
require.Len(t, r.Rows, 0) | ||
} | ||
|
||
func createTxAndInsertRows(conn *mysql.Conn, t *testing.T, idx *int) { | ||
_, err := conn.ExecuteFetch("begin", 0, false) | ||
require.NoError(t, err) | ||
|
||
for i := 0; i < 25; i++ { | ||
*idx += 5 | ||
_, err = conn.ExecuteFetch(utils.GetInsertMultipleValuesQuery(*idx, *idx+1, *idx+2, *idx+3), 0, false) | ||
require.NoError(t, err) | ||
time.Sleep(10 * time.Millisecond) | ||
} | ||
} | ||
|
||
func reparent(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tablets []*cluster.Vttablet, tabletStopped, actionDone chan bool) { | ||
// Reparent to the other replica | ||
utils.ShardName = "40-80" | ||
defer func() { | ||
utils.ShardName = "0" | ||
}() | ||
|
||
prsTo := primary - 1 | ||
if primary == 0 { | ||
prsTo = primary + 1 | ||
} | ||
output, err := utils.Prs(t, clusterInstance, tablets[prsTo]) | ||
require.NoError(t, err, "error in PlannedReparentShard output - %s", output) | ||
|
||
// We now restart the vttablet that became a replica. | ||
utils.StopTablet(t, tablets[primary], false) | ||
tabletStopped <- true | ||
primary = prsTo | ||
|
||
// Wait for the action triggering the VT15001 to be done before moving on | ||
<-actionDone | ||
|
||
tablets[0].VttabletProcess.ServingStatus = "SERVING" | ||
err = tablets[0].VttabletProcess.Setup() | ||
require.NoError(t, err) | ||
|
||
} | ||
|
||
func TestErrorsInTransaction(t *testing.T) { | ||
clusterInstance := utils.SetupShardedReparentCluster(t, policy.DurabilitySemiSync, []string{ | ||
"--queryserver-config-transaction-timeout", "5m", | ||
"--queryserver-config-query-timeout", "5m", | ||
}) | ||
|
||
defer utils.TeardownCluster(clusterInstance) | ||
|
||
keyspace := clusterInstance.Keyspaces[0] | ||
vtParams := clusterInstance.GetVTParams(keyspace.Name) | ||
tablets := clusterInstance.Keyspaces[0].Shards[1].Vttablets | ||
|
||
primary = 0 | ||
|
||
// Start by reparenting all the shards to the first tablet. | ||
// Confirm that the replication is setup correctly in the beginning. | ||
// tablets[0] is the primary tablet in the beginning. | ||
utils.ConfirmReplication(t, tablets[primary], []*cluster.Vttablet{tablets[1], tablets[2]}) | ||
|
||
conn, err := mysql.Connect(context.Background(), &vtParams) | ||
require.NoError(t, err) | ||
|
||
_, err = conn.ExecuteFetch("delete from vt_insert_test", 0, false) | ||
require.NoError(t, err) | ||
|
||
t.Run("commit while reparenting", func(t *testing.T) { | ||
testCommitError(t, conn, clusterInstance, tablets) | ||
}) | ||
|
||
t.Run("execute DML while reparenting", func(t *testing.T) { | ||
testExecuteError(t, conn, clusterInstance, tablets) | ||
}) | ||
} |
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
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.
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.
I think we should validate by selecting from the table that no data exists.
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.
Issue with selecting is that the commit can be a partial commit, leading to rows on the healthy shards.