From 70f424940e15cac664982aca87c5de56b4bb404e Mon Sep 17 00:00:00 2001 From: Rafer Hazen Date: Sun, 12 May 2024 23:14:43 -0600 Subject: [PATCH] Add error transformer to vtgate executor (#15894) --- go/vt/vtgate/executor.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 0c4f963019e..2679cf5a2fd 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -78,6 +78,8 @@ var ( queriesRoutedByTable = stats.NewCountersWithMultiLabels("QueriesRoutedByTable", "Queries routed from vtgate to vttablet by plan type, keyspace and table", []string{"Plan", "Keyspace", "Table"}) exceedMemoryRowsLogger = logutil.NewThrottledLogger("ExceedMemoryRows", 1*time.Minute) + + errorTransform errorTransformer = nullErrorTransformer{} ) const ( @@ -246,7 +248,10 @@ func (e *Executor) Execute(ctx context.Context, mysqlCtx vtgateservice.MySQLConn logStats.SaveEndTime() e.queryLogger.Send(logStats) + + err = errorTransform.TransformError(err) err = vterrors.TruncateError(err, truncateErrorLen) + return result, err } @@ -385,8 +390,11 @@ func (e *Executor) StreamExecute( logStats.SaveEndTime() e.queryLogger.Send(logStats) - return vterrors.TruncateError(err, truncateErrorLen) + err = errorTransform.TransformError(err) + err = vterrors.TruncateError(err, truncateErrorLen) + + return err } func canReturnRows(stmtType sqlparser.StatementType) bool { @@ -1352,7 +1360,11 @@ func (e *Executor) Prepare(ctx context.Context, method string, safeSession *Safe logStats.SaveEndTime() e.queryLogger.Send(logStats) } - return fld, vterrors.TruncateError(err, truncateErrorLen) + + err = errorTransform.TransformError(err) + err = vterrors.TruncateError(err, truncateErrorLen) + + return fld, err } func (e *Executor) prepare(ctx context.Context, safeSession *SafeSession, sql string, bindVars map[string]*querypb.BindVariable, logStats *logstats.LogStats) ([]*querypb.Field, error) { @@ -1606,3 +1618,14 @@ func (e *Executor) Close() { func (e *Executor) environment() *vtenv.Environment { return e.env } + +type ( + errorTransformer interface { + TransformError(err error) error + } + nullErrorTransformer struct{} +) + +func (nullErrorTransformer) TransformError(err error) error { + return err +}