From c7ad375bafb7288a05617ad6905fab8b5b13856c Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Wed, 19 Feb 2025 16:17:27 -0600 Subject: [PATCH] Wrap healthcheck error only when in a tx Signed-off-by: Florent Poinsard --- go/vt/discovery/healthcheck.go | 2 +- go/vt/vterrors/code.go | 2 +- go/vt/vtgate/scatter_conn.go | 4 ++++ go/vt/vtgate/tx_conn.go | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/go/vt/discovery/healthcheck.go b/go/vt/discovery/healthcheck.go index 404eb5f86df..2f270bd7518 100644 --- a/go/vt/discovery/healthcheck.go +++ b/go/vt/discovery/healthcheck.go @@ -872,7 +872,7 @@ func (hc *HealthCheckImpl) TabletConnection(ctx context.Context, alias *topodata hc.mu.Unlock() if thc == nil || thc.Conn == nil { // TODO: test that throws this error - return nil, vterrors.VT15001(vtrpc.Code_NOT_FOUND, fmt.Sprintf("tablet: %v is either down or nonexistent", alias)) + return nil, vterrors.Errorf(vtrpc.Code_NOT_FOUND, "tablet: %v is either down or nonexistent", alias) } return thc.Connection(ctx), nil } diff --git a/go/vt/vterrors/code.go b/go/vt/vterrors/code.go index 7085956825d..f0b4e6fbcd6 100644 --- a/go/vt/vterrors/code.go +++ b/go/vt/vterrors/code.go @@ -121,7 +121,7 @@ var ( VT14004 = errorWithoutState("VT14004", vtrpcpb.Code_UNAVAILABLE, "cannot find keyspace for: %s", "The specified keyspace could not be found.") VT14005 = errorWithoutState("VT14005", vtrpcpb.Code_UNAVAILABLE, "cannot lookup sidecar database for keyspace: %s", "Failed to read sidecar database identifier.") - VT15001 = errorWithNoCode("VT15001", "transient error, please retry the transaction: %s", "The opened transaction should be closed by the application and re-tried.") + VT15001 = errorWithNoCode("VT15001", "transient transaction error, please issue a ROLLBACK and retry the transaction: %s", "The opened transaction must be ROLLBACK by the application and re-tried.") VT15002 = errorWithoutState("VT15002", vtrpcpb.Code_FAILED_PRECONDITION, "previous transaction failed fatally: issue a ROLLBACK query in order to acknowledge the failed transaction", "This error appears after a VT15001 error was sent back to the client, future queries on the same session will fail until a ROLLBACK is explicitly sent to VTGate.") // Errors is a list of errors that must match all the variables diff --git a/go/vt/vtgate/scatter_conn.go b/go/vt/vtgate/scatter_conn.go index 85f236a9a18..ca9eece4b61 100644 --- a/go/vt/vtgate/scatter_conn.go +++ b/go/vt/vtgate/scatter_conn.go @@ -332,6 +332,10 @@ func getQueryService(ctx context.Context, rs *srvtopo.ResolvedShard, info *shard return rs.Gateway, nil } qs, err := rs.Gateway.QueryServiceByAlias(ctx, info.alias, rs.Target) + if err != nil && info.transactionID != 0 { + err = vterrors.VT15001(vterrors.Code(err), err.Error()) + } + if err == nil || skipReset { return qs, err } diff --git a/go/vt/vtgate/tx_conn.go b/go/vt/vtgate/tx_conn.go index dbd76b04c7a..4da63c055ad 100644 --- a/go/vt/vtgate/tx_conn.go +++ b/go/vt/vtgate/tx_conn.go @@ -166,7 +166,11 @@ func (txc *TxConn) queryService(ctx context.Context, alias *topodatapb.TabletAli if alias == nil { return txc.tabletGateway, nil } - return txc.tabletGateway.QueryServiceByAlias(ctx, alias, nil) + qs, err := txc.tabletGateway.QueryServiceByAlias(ctx, alias, nil) + if err != nil { + return nil, vterrors.VT15001(vterrors.Code(err), err.Error()) + } + return qs, nil } func (txc *TxConn) commitShard(ctx context.Context, s *vtgatepb.Session_ShardSession, logging *econtext.ExecuteLogger) error {