From 4baf2b386c46c89690b88d113d990427afbb3152 Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:05:28 +0530 Subject: [PATCH] Cherry-pick 8ba7607230f7de31ff142c4aa16cad8ce80da00b with conflicts --- go/vt/vtgate/vcursor_impl.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go index e9b1d3d7712..0748d63b9d5 100644 --- a/go/vt/vtgate/vcursor_impl.go +++ b/go/vt/vtgate/vcursor_impl.go @@ -22,6 +22,7 @@ import ( "io" "sort" "strings" + "sync" "sync/atomic" "time" @@ -133,6 +134,8 @@ type ( resultsObserver resultsObserver + // this protects the interOpStats and shardsStats fields from concurrent writes + mu sync.Mutex // this is a map of the number of rows that every primitive has returned // if this field is nil, it means that we are not logging operator traffic interOpStats map[engine.Primitive]engine.RowsReceived @@ -536,6 +539,7 @@ func (vc *vcursorImpl) ExecutePrimitive(ctx context.Context, primitive engine.Pr return nil, vterrors.New(vtrpcpb.Code_UNAVAILABLE, "upstream shards are not available") } +<<<<<<< HEAD:go/vt/vtgate/vcursor_impl.go func (vc *vcursorImpl) logOpTraffic(primitive engine.Primitive, res *sqltypes.Result) { if vc.interOpStats != nil { rows := vc.interOpStats[primitive] @@ -545,13 +549,38 @@ func (vc *vcursorImpl) logOpTraffic(primitive engine.Primitive, res *sqltypes.Re rows = append(rows, len(res.Rows)) } vc.interOpStats[primitive] = rows +======= +func (vc *VCursorImpl) logOpTraffic(primitive engine.Primitive, res *sqltypes.Result) { + if vc.interOpStats == nil { + return +>>>>>>> 8ba7607230 (vexplain to protect the log fields from concurrent writes (#17460)):go/vt/vtgate/executorcontext/vcursor_impl.go } + + vc.mu.Lock() + defer vc.mu.Unlock() + + rows := vc.interOpStats[primitive] + if res == nil { + rows = append(rows, 0) + } else { + rows = append(rows, len(res.Rows)) + } + vc.interOpStats[primitive] = rows } +<<<<<<< HEAD:go/vt/vtgate/vcursor_impl.go func (vc *vcursorImpl) logShardsQueried(primitive engine.Primitive, shardsNb int) { if vc.shardsStats != nil { vc.shardsStats[primitive] += engine.ShardsQueried(shardsNb) +======= +func (vc *VCursorImpl) logShardsQueried(primitive engine.Primitive, shardsNb int) { + if vc.shardsStats == nil { + return +>>>>>>> 8ba7607230 (vexplain to protect the log fields from concurrent writes (#17460)):go/vt/vtgate/executorcontext/vcursor_impl.go } + vc.mu.Lock() + defer vc.mu.Unlock() + vc.shardsStats[primitive] += engine.ShardsQueried(shardsNb) } func (vc *vcursorImpl) ExecutePrimitiveStandalone(ctx context.Context, primitive engine.Primitive, bindVars map[string]*querypb.BindVariable, wantfields bool) (*sqltypes.Result, error) {