Skip to content

Commit

Permalink
[release-18.0] VReplication workflows: retry "wrong tablet type" erro…
Browse files Browse the repository at this point in the history
…rs (#16645) (#16651)

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Rohit Nayak <rohit@planetscale.com>
  • Loading branch information
vitess-bot[bot] and rohit-nayak-ps authored Aug 27, 2024
1 parent cb39bd9 commit e8c5e5b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
11 changes: 11 additions & 0 deletions go/vt/vttablet/tabletmanager/vreplication/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"fmt"
"strconv"

vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/vterrors"

"vitess.io/vitess/go/constants/sidecar"
"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/sqltypes"
Expand Down Expand Up @@ -123,6 +126,14 @@ func isUnrecoverableError(err error) bool {
if err == nil {
return false
}
switch vterrors.Code(err) {
case vtrpcpb.Code_FAILED_PRECONDITION:
if vterrors.RxWrongTablet.MatchString(err.Error()) {
// If the chosen tablet type picked changes, say due to PRS/ERS, we should retry.
return false
}
return true
}
sqlErr, isSQLErr := sqlerror.NewSQLErrorFromError(err).(*sqlerror.SQLError)
if !isSQLErr {
return false
Expand Down
86 changes: 86 additions & 0 deletions go/vt/vttablet/tabletmanager/vreplication/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright 2024 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 vreplication

import (
"errors"
"testing"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/vt/vterrors"

vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
)

// TestIsUnrecoverableError tests the different error cases for isUnrecoverableError().
func TestIsUnrecoverableError(t *testing.T) {
if runNoBlobTest {
t.Skip()
}

type testCase struct {
name string
err error
expected bool
}

testCases := []testCase{
{
name: "Nil error",
err: nil,
expected: false,
},
{
name: "vterrors.Code_FAILED_PRECONDITION",
err: vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "test error"),
expected: true,
},
{
name: "vterrors.Code_FAILED_PRECONDITION, WrongTablet",
err: vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "%s: %v, want: %v or %v", vterrors.WrongTablet, "PRIMARY", "REPLICA", nil),
expected: false,
},
{
name: "Non-SQL error",
err: errors.New("non-SQL error"),
expected: false,
},
{
name: "SQL error with ERUnknownError",
err: sqlerror.NewSQLError(sqlerror.ERUnknownError, "test SQL error", "test"),
expected: false,
},
{
name: "SQL error with ERAccessDeniedError",
err: sqlerror.NewSQLError(sqlerror.ERAccessDeniedError, "access denied", "test"),
expected: true,
},
{
name: "SQL error with ERDataOutOfRange",
err: sqlerror.NewSQLError(sqlerror.ERDataOutOfRange, "data out of range", "test"),
expected: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := isUnrecoverableError(tc.err)
require.Equal(t, tc.expected, result)
})
}
}

0 comments on commit e8c5e5b

Please sign in to comment.