Skip to content

Commit

Permalink
Merge pull request #8456 from tinyspeck/am_remove_legacy_error_codes
Browse files Browse the repository at this point in the history
Remove vtrpc.LegacyErrorCode
  • Loading branch information
ajm188 authored Aug 19, 2021
2 parents e2ef3f0 + e2a37bc commit 1f5a7ed
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 586 deletions.
5 changes: 2 additions & 3 deletions go/sqltypes/proto3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ func TestQueryReponses(t *testing.T) {
},
}, {
Error: &vtrpcpb.RPCError{
LegacyCode: vtrpcpb.LegacyErrorCode_DEADLINE_EXCEEDED_LEGACY,
Message: "deadline exceeded",
Code: vtrpcpb.Code_DEADLINE_EXCEEDED,
Message: "deadline exceeded",
Code: vtrpcpb.Code_DEADLINE_EXCEEDED,
},
Result: nil,
},
Expand Down
252 changes: 43 additions & 209 deletions go/vt/proto/vtrpc/vtrpc.pb.go

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions go/vt/proto/vtrpc/vtrpc_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 0 additions & 70 deletions go/vt/vterrors/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,76 +30,6 @@ import (
// Use these methods to return an error through gRPC and still
// retain its code.

// CodeToLegacyErrorCode maps a vtrpcpb.Code to a vtrpcpb.LegacyErrorCode.
func CodeToLegacyErrorCode(code vtrpcpb.Code) vtrpcpb.LegacyErrorCode {
switch code {
case vtrpcpb.Code_OK:
return vtrpcpb.LegacyErrorCode_SUCCESS_LEGACY
case vtrpcpb.Code_CANCELED:
return vtrpcpb.LegacyErrorCode_CANCELLED_LEGACY
case vtrpcpb.Code_UNKNOWN:
return vtrpcpb.LegacyErrorCode_UNKNOWN_ERROR_LEGACY
case vtrpcpb.Code_INVALID_ARGUMENT:
return vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY
case vtrpcpb.Code_DEADLINE_EXCEEDED:
return vtrpcpb.LegacyErrorCode_DEADLINE_EXCEEDED_LEGACY
case vtrpcpb.Code_ALREADY_EXISTS:
return vtrpcpb.LegacyErrorCode_INTEGRITY_ERROR_LEGACY
case vtrpcpb.Code_PERMISSION_DENIED:
return vtrpcpb.LegacyErrorCode_PERMISSION_DENIED_LEGACY
case vtrpcpb.Code_RESOURCE_EXHAUSTED:
return vtrpcpb.LegacyErrorCode_RESOURCE_EXHAUSTED_LEGACY
case vtrpcpb.Code_FAILED_PRECONDITION:
return vtrpcpb.LegacyErrorCode_QUERY_NOT_SERVED_LEGACY
case vtrpcpb.Code_ABORTED:
return vtrpcpb.LegacyErrorCode_NOT_IN_TX_LEGACY
case vtrpcpb.Code_INTERNAL:
return vtrpcpb.LegacyErrorCode_INTERNAL_ERROR_LEGACY
case vtrpcpb.Code_UNAVAILABLE:
// Legacy code assumes Unavailable errors are sent as Internal.
return vtrpcpb.LegacyErrorCode_INTERNAL_ERROR_LEGACY
case vtrpcpb.Code_UNAUTHENTICATED:
return vtrpcpb.LegacyErrorCode_UNAUTHENTICATED_LEGACY
default:
return vtrpcpb.LegacyErrorCode_UNKNOWN_ERROR_LEGACY
}
}

// LegacyErrorCodeToCode maps a vtrpcpb.LegacyErrorCode to a gRPC vtrpcpb.Code.
func LegacyErrorCodeToCode(code vtrpcpb.LegacyErrorCode) vtrpcpb.Code {
switch code {
case vtrpcpb.LegacyErrorCode_SUCCESS_LEGACY:
return vtrpcpb.Code_OK
case vtrpcpb.LegacyErrorCode_CANCELLED_LEGACY:
return vtrpcpb.Code_CANCELED
case vtrpcpb.LegacyErrorCode_UNKNOWN_ERROR_LEGACY:
return vtrpcpb.Code_UNKNOWN
case vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY:
return vtrpcpb.Code_INVALID_ARGUMENT
case vtrpcpb.LegacyErrorCode_DEADLINE_EXCEEDED_LEGACY:
return vtrpcpb.Code_DEADLINE_EXCEEDED
case vtrpcpb.LegacyErrorCode_INTEGRITY_ERROR_LEGACY:
return vtrpcpb.Code_ALREADY_EXISTS
case vtrpcpb.LegacyErrorCode_PERMISSION_DENIED_LEGACY:
return vtrpcpb.Code_PERMISSION_DENIED
case vtrpcpb.LegacyErrorCode_RESOURCE_EXHAUSTED_LEGACY:
return vtrpcpb.Code_RESOURCE_EXHAUSTED
case vtrpcpb.LegacyErrorCode_QUERY_NOT_SERVED_LEGACY:
return vtrpcpb.Code_FAILED_PRECONDITION
case vtrpcpb.LegacyErrorCode_NOT_IN_TX_LEGACY:
return vtrpcpb.Code_ABORTED
case vtrpcpb.LegacyErrorCode_INTERNAL_ERROR_LEGACY:
// Legacy code sends internal error instead of Unavailable.
return vtrpcpb.Code_UNAVAILABLE
case vtrpcpb.LegacyErrorCode_TRANSIENT_ERROR_LEGACY:
return vtrpcpb.Code_UNAVAILABLE
case vtrpcpb.LegacyErrorCode_UNAUTHENTICATED_LEGACY:
return vtrpcpb.Code_UNAUTHENTICATED
default:
return vtrpcpb.Code_UNKNOWN
}
}

// truncateError shortens errors because gRPC has a size restriction on them.
func truncateError(err error) string {
// For more details see: https://github.com/grpc/grpc-go/issues/443
Expand Down
12 changes: 3 additions & 9 deletions go/vt/vterrors/proto3.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@ func FromVTRPC(rpcErr *vtrpcpb.RPCError) error {
if rpcErr == nil {
return nil
}
code := rpcErr.Code
if code == vtrpcpb.Code_OK {
code = LegacyErrorCodeToCode(rpcErr.LegacyCode)
}
return New(code, rpcErr.Message)
return New(rpcErr.Code, rpcErr.Message)
}

// ToVTRPC converts from vtError to a vtrpcpb.RPCError.
func ToVTRPC(err error) *vtrpcpb.RPCError {
if err == nil {
return nil
}
code := Code(err)
return &vtrpcpb.RPCError{
LegacyCode: CodeToLegacyErrorCode(code),
Code: code,
Message: err.Error(),
Code: Code(err),
Message: err.Error(),
}
}
14 changes: 6 additions & 8 deletions go/vt/vterrors/proto3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ func TestFromVtRPCError(t *testing.T) {
want: nil,
}, {
in: &vtrpcpb.RPCError{
LegacyCode: vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
Message: "bad input",
},
want: New(vtrpcpb.Code_INVALID_ARGUMENT, "bad input"),
}, {
in: &vtrpcpb.RPCError{
LegacyCode: vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
},
want: New(vtrpcpb.Code_INVALID_ARGUMENT, "bad input"),
}, {
Expand Down Expand Up @@ -69,9 +68,8 @@ func TestVtRPCErrorFromVtError(t *testing.T) {
}, {
in: New(vtrpcpb.Code_INVALID_ARGUMENT, "bad input"),
want: &vtrpcpb.RPCError{
LegacyCode: vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
},
}}
for _, tcase := range testcases {
Expand Down
6 changes: 1 addition & 5 deletions go/vt/vttablet/tabletconn/grpc_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,5 @@ func ErrorFromVTRPC(err *vtrpcpb.RPCError) error {
if err == nil {
return nil
}
code := err.Code
if code == vtrpcpb.Code_OK {
code = vterrors.LegacyErrorCodeToCode(err.LegacyCode)
}
return vterrors.Errorf(code, "vttablet: %s", err.Message)
return vterrors.Errorf(err.Code, "vttablet: %s", err.Message)
}
9 changes: 4 additions & 5 deletions go/vt/vttablet/tabletconn/grpc_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ func TestTabletErrorFromRPCError(t *testing.T) {
want vtrpcpb.Code
}{{
in: &vtrpcpb.RPCError{
LegacyCode: vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
Message: "bad input",
},
want: vtrpcpb.Code_INVALID_ARGUMENT,
}, {
in: &vtrpcpb.RPCError{
LegacyCode: vtrpcpb.LegacyErrorCode_BAD_INPUT_LEGACY,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
Message: "bad input",
Code: vtrpcpb.Code_INVALID_ARGUMENT,
},
want: vtrpcpb.Code_INVALID_ARGUMENT,
}, {
Expand Down
20 changes: 0 additions & 20 deletions java/client/src/main/java/io/vitess/client/Proto.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,6 @@ public static void checkError(RPCError error) throws SQLException {
throw new SQLNonTransientException("Vitess RPC error: " + error.toString(), sqlState,
errno);
}

switch (error.getLegacyCode()) {
case SUCCESS_LEGACY:
break;
case BAD_INPUT_LEGACY:
throw new SQLSyntaxErrorException(error.toString(), sqlState, errno);
case DEADLINE_EXCEEDED_LEGACY:
throw new SQLTimeoutException(error.toString(), sqlState, errno);
case INTEGRITY_ERROR_LEGACY:
throw new SQLIntegrityConstraintViolationException(error.toString(), sqlState, errno);
case TRANSIENT_ERROR_LEGACY:
throw new SQLTransientException(error.toString(), sqlState, errno);
case UNAUTHENTICATED_LEGACY:
throw new SQLInvalidAuthorizationSpecException(error.toString(), sqlState, errno);
case NOT_IN_TX_LEGACY:
throw new SQLRecoverableException(error.toString(), sqlState, errno);
default:
throw new SQLNonTransientException("Vitess RPC error: " + error.toString(), sqlState,
errno);
}
}
}

Expand Down
82 changes: 1 addition & 81 deletions proto/vtrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -171,92 +171,12 @@ enum Code {
DATA_LOSS = 15;
}

// LegacyErrorCode is the enum values for Errors. This type is deprecated.
// Use Code instead. Background: In the initial design, we thought
// that we may end up with a different list of canonical error codes
// than the ones defined by grpc. In hindsight, we realize that
// the grpc error codes are fairly generic and mostly sufficient.
// In order to avoid confusion, this type will be deprecated in
// favor of the new Code that matches exactly what grpc defines.
// Some names below have a _LEGACY suffix. This is to prevent
// name collisions with Code.
enum LegacyErrorCode {
// SUCCESS_LEGACY is returned from a successful call.
SUCCESS_LEGACY = 0;

// CANCELLED_LEGACY means that the context was cancelled (and noticed in the app layer,
// as opposed to the RPC layer).
CANCELLED_LEGACY = 1;

// UNKNOWN_ERROR_LEGACY includes:
// 1. MySQL error codes that we don't explicitly handle.
// 2. MySQL response that wasn't as expected. For example, we might expect a MySQL
// timestamp to be returned in a particular way, but it wasn't.
// 3. Anything else that doesn't fall into a different bucket.
UNKNOWN_ERROR_LEGACY = 2;

// BAD_INPUT_LEGACY is returned when an end-user either sends SQL that couldn't be parsed correctly,
// or tries a query that isn't supported by Vitess.
BAD_INPUT_LEGACY = 3;

// DEADLINE_EXCEEDED_LEGACY is returned when an action is taking longer than a given timeout.
DEADLINE_EXCEEDED_LEGACY = 4;

// INTEGRITY_ERROR_LEGACY is returned on integrity error from MySQL, usually due to
// duplicate primary keys.
INTEGRITY_ERROR_LEGACY = 5;

// PERMISSION_DENIED_LEGACY errors are returned when a user requests access to something
// that they don't have permissions for.
PERMISSION_DENIED_LEGACY = 6;

// RESOURCE_EXHAUSTED_LEGACY is returned when a query exceeds its quota in some dimension
// and can't be completed due to that. Queries that return RESOURCE_EXHAUSTED
// should not be retried, as it could be detrimental to the server's health.
// Examples of errors that will cause the RESOURCE_EXHAUSTED code:
// 1. TxPoolFull: this is retried server-side, and is only returned as an error
// if the server-side retries failed.
// 2. Query is killed due to it taking too long.
RESOURCE_EXHAUSTED_LEGACY = 7;

// QUERY_NOT_SERVED_LEGACY means that a query could not be served right now.
// Client can interpret it as: "the tablet that you sent this query to cannot
// serve the query right now, try a different tablet or try again later."
// This could be due to various reasons: QueryService is not serving, should
// not be serving, wrong shard, wrong tablet type, table is part of the denylist, etc.
// Clients that receive this error should usually retry the query, but after taking
// the appropriate steps to make sure that the query will get sent to the correct
// tablet.
QUERY_NOT_SERVED_LEGACY = 8;

// NOT_IN_TX_LEGACY means that we're not currently in a transaction, but we should be.
NOT_IN_TX_LEGACY = 9;

// INTERNAL_ERROR_LEGACY means some invariants expected by underlying
// system has been broken. If you see one of these errors,
// something is very broken.
INTERNAL_ERROR_LEGACY = 10;

// TRANSIENT_ERROR_LEGACY is used for when there is some error that we expect we can
// recover from automatically - often due to a resource limit temporarily being
// reached. Retrying this error, with an exponential backoff, should succeed.
// Clients should be able to successfully retry the query on the same backends.
// Examples of things that can trigger this error:
// 1. Query has been throttled
// 2. VtGate could have request backlog
TRANSIENT_ERROR_LEGACY = 11;

// UNAUTHENTICATED_LEGACY errors are returned when a user requests access to something,
// and we're unable to verify the user's authentication.
UNAUTHENTICATED_LEGACY = 12;
}

// RPCError is an application-level error structure returned by
// VtTablet (and passed along by VtGate if appropriate).
// We use this so the clients don't have to parse the error messages,
// but instead can depend on the value of the code.
message RPCError {
LegacyErrorCode legacy_code = 1;
reserved 1; reserved "legacy_code";
string message = 2;
Code code = 3;
}
Loading

0 comments on commit 1f5a7ed

Please sign in to comment.