Skip to content

Commit

Permalink
Wrap healthcheck error only when in a tx
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Feb 19, 2025
1 parent 293720a commit c7ad375
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vterrors/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtgate/scatter_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion go/vt/vtgate/tx_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c7ad375

Please sign in to comment.