Skip to content

Commit

Permalink
Throttled transactions return MySQL error code 1041 ER_OUT_OF_RESOURC…
Browse files Browse the repository at this point in the history
…ES (vitessio#12949)

This error code seems better suited to represent the fact that transactions are
being throttled by the server due to some form of resource contention than the
current code 1203 ER_TOO_MANY_USER_CONNECTIONS.

Signed-off-by: Eduardo J. Ortega U <5791035+ejortegau@users.noreply.github.com>
  • Loading branch information
ejortegau authored and timvaillancourt committed May 27, 2024
1 parent 03dc05b commit 974961a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion go/mysql/sql_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"

"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
Expand Down Expand Up @@ -135,7 +136,11 @@ func mapToSQLErrorFromErrorCode(err error, msg string) *SQLError {
ss = SSAccessDeniedError
case vtrpcpb.Code_RESOURCE_EXHAUSTED:
num = demuxResourceExhaustedErrors(err.Error())
ss = SSClientError
// 1041 ER_OUT_OF_RESOURCES has SQLSTATE HYOOO as per https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html#error_er_out_of_resources,
// so don't override it here in that case.
if num != EROutOfResources {
ss = SSClientError
}
case vtrpcpb.Code_UNIMPLEMENTED:
num = ERNotSupportedYet
ss = SSClientError
Expand Down Expand Up @@ -223,6 +228,8 @@ func demuxResourceExhaustedErrors(msg string) int {
switch {
case isGRPCOverflowRE.Match([]byte(msg)):
return ERNetPacketTooLarge
case strings.Contains(msg, "Transaction throttled"):
return EROutOfResources
default:
return ERTooManyUserConnections
}
Expand Down
8 changes: 7 additions & 1 deletion go/mysql/sql_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDumuxResourceExhaustedErrors(t *testing.T) {
func TestDemuxResourceExhaustedErrors(t *testing.T) {
type testCase struct {
msg string
want int
Expand All @@ -42,6 +42,7 @@ func TestDumuxResourceExhaustedErrors(t *testing.T) {
// This should be explicitly handled by returning ERNetPacketTooLarge from the execturo directly
// and therefore shouldn't need to be teased out of another error.
{"in-memory row count exceeded allowed limit of 13", ERTooManyUserConnections},
{"rpc error: code = ResourceExhausted desc = Transaction throttled", EROutOfResources},
}

for _, c := range cases {
Expand Down Expand Up @@ -151,6 +152,11 @@ func TestNewSQLErrorFromError(t *testing.T) {
num: ERNoDb,
ss: SSNoDB,
},
{
err: vterrors.Errorf(vtrpc.Code_RESOURCE_EXHAUSTED, "vttablet: rpc error: code = ResourceExhausted desc = Transaction throttled"),
num: EROutOfResources,
ss: SSUnknownSQLState,
},
}

for _, tc := range tCases {
Expand Down

0 comments on commit 974961a

Please sign in to comment.