-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Wrap fatal TX errors in a new vterrors code
#17669
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
Merged
frouioui
merged 41 commits into
vitessio:main
from
planetscale:improved-errors-during-prs
Mar 18, 2025
Merged
Changes from all commits
Commits
Show all changes
41 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 f10eb16
allow SHOW to stop blocking queries after a VT15001
frouioui 949b97f
apply review suggestions
frouioui a34c4fc
Merge remote-tracking branch 'origin/main' into improved-errors-durin…
frouioui 2f0bae1
Move all the wrapping to vtgate + more tests
frouioui 5aac23c
add more tests
frouioui 518b18c
fix test expectations
frouioui 0eea900
Merge remote-tracking branch 'origin/main' into improved-errors-durin…
frouioui abf6a6d
Merge remote-tracking branch 'origin/main' into improved-errors-durin…
frouioui 381351e
Merge remote-tracking branch 'origin/main' into improved-errors-durin…
frouioui 904da55
Move VT15002 to VT09032
frouioui c3f790e
Fix namings and comments
frouioui fa29793
Change functions to be reusable
frouioui c454768
Merge remote-tracking branch 'origin/main' into improved-errors-durin…
frouioui 01530c9
apply review suggestions
frouioui f741e62
modify release notes
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
This file contains hidden or 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 hidden or 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
224 changes: 224 additions & 0 deletions
224
go/test/endtoend/reparent/newfeaturetest/reparent_with_open_tx_test.go
This file contains hidden or 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,224 @@ | ||
| /* | ||
| 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/vt/vterrors" | ||
|
|
||
| "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 when doing a commit while the primary is down. | ||
| 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) | ||
| } | ||
|
|
||
| // This test ensures that we are getting a VT15001 when executing a query on an open transaction | ||
| // while the primary is down. Subsequent queries should fail with a VT09032 until a ROLLBACK | ||
| // or SHOW WARNINGS is issued. | ||
| 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 VT09032 error until we issue a ROLLBACK | ||
| _, err = conn.ExecuteFetch("select * from vt_insert_test", 1, false) | ||
| require.ErrorContains(t, err, "VT09032") | ||
|
|
||
| _, 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 testExecuteErrorWhileTabletIsNotServing(t *testing.T, conn *mysql.Conn, clusterInstance *cluster.LocalProcessCluster, tablets []*cluster.Vttablet) { | ||
| tabletNotServing := make(chan bool) | ||
| executeDone := make(chan bool) | ||
| idx := 1 | ||
| createTxAndInsertRows(conn, t, &idx) | ||
|
|
||
| go func() { | ||
| idx += 5 | ||
| <-tabletNotServing | ||
| _, err := conn.ExecuteFetch(utils.GetInsertMultipleValuesQuery(idx, idx+1, idx+2, idx+3), 0, false) | ||
| require.ErrorContains(t, err, "VT15001") | ||
| require.ErrorContains(t, err, vterrors.WrongTablet) | ||
|
|
||
| // Subsequent queries after a VT15001 should start returning a VT09032 error until we issue a ROLLBACK | ||
| _, err = conn.ExecuteFetch("select * from vt_insert_test", 1, false) | ||
| require.ErrorContains(t, err, "VT09032") | ||
|
|
||
| _, err = conn.ExecuteFetch("rollback", 0, false) | ||
| require.NoError(t, err) | ||
| executeDone <- true | ||
| }() | ||
|
|
||
| makeTabletNotServing(t, clusterInstance, tablets, tabletNotServing, 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 | ||
|
|
||
| // Wait for the action triggering the VT15001 to be done before moving on | ||
| <-actionDone | ||
|
|
||
| tablets[primary].VttabletProcess.ServingStatus = "SERVING" | ||
| err = tablets[primary].VttabletProcess.Setup() | ||
| require.NoError(t, err) | ||
| primary = prsTo | ||
| } | ||
|
|
||
| func makeTabletNotServing(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tablets []*cluster.Vttablet, stateChanged, 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) | ||
| tablets[primary].VttabletProcess.ServingStatus = "NOT_SERVING" | ||
| err = tablets[primary].VttabletProcess.Setup() | ||
| require.NoError(t, err) | ||
| stateChanged <- true | ||
|
|
||
| // Wait for the action triggering the VT15001 to be done before moving on | ||
| <-actionDone | ||
|
|
||
| utils.StopTablet(t, tablets[primary], false) | ||
| tablets[primary].VttabletProcess.ServingStatus = "SERVING" | ||
| err = tablets[primary].VttabletProcess.Setup() | ||
| require.NoError(t, err) | ||
| primary = prsTo | ||
| } | ||
|
|
||
| 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 tablet is NOT_SERVING", func(t *testing.T) { | ||
| testExecuteErrorWhileTabletIsNotServing(t, conn, clusterInstance, tablets) | ||
| }) | ||
|
|
||
| t.Run("execute DML while reparenting", func(t *testing.T) { | ||
| testExecuteError(t, conn, clusterInstance, tablets) | ||
| }) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.