Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Apr 18, 2024
1 parent 5f1c7b8 commit 4920264
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/statistics/handle/syncload/stats_syncload.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
statstypes "github.com/pingcap/tidb/pkg/statistics/handle/types"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/logutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -224,20 +225,21 @@ func (s *statsSyncLoad) HandleOneTask(sctx sessionctx.Context, lastTask *statsty
task = lastTask
}
resultChan := s.StatsLoad.Singleflight.DoChan(task.Item.Key(), func() (any, error) {
return s.handleOneItemTask(sctx, task)
result, err := s.handleOneItemTask(sctx, task)
intest.Assert(result != nil)
return result, err
})
timeout := time.Until(task.ToTimeout)
select {
case result := <-resultChan:
slr := result.Val.(*stmtctx.StatsLoadResult)
if result.Err == nil {
// result.Val is nil means the task doesn't update. so we don't need to send the result to the channel.
slr := result.Val.(*stmtctx.StatsLoadResult)
task.ResultCh <- *slr
return nil, nil
}
if !updateNeededItemTaskRetryCountAndCheck(task) {
// result.Val is nil means the task doesn't update. so we don't need to send the result to the channel.
slr := result.Val.(*stmtctx.StatsLoadResult)
slr.Error = result.Err
task.ResultCh <- *slr
return nil, nil
Expand Down Expand Up @@ -302,10 +304,8 @@ func (s *statsSyncLoad) handleOneItemTask(sctx sessionctx.Context, task *statsty
Histogram: *statistics.NewHistogram(item.ID, 0, 0, 0, &wrapper.colInfo.FieldType, 0, 0),
IsHandle: tbl.IsPkIsHandle && mysql.HasPriKeyFlag(wrapper.colInfo.GetFlag()),
}
if s.updateCachedItem(item, wrapper.col, wrapper.idx, task.Item.FullLoad) {
return result, nil
}
return nil, nil
s.updateCachedItem(item, wrapper.col, wrapper.idx, task.Item.FullLoad)
return result, nil
}
}
t := time.Now()
Expand All @@ -325,10 +325,10 @@ func (s *statsSyncLoad) handleOneItemTask(sctx sessionctx.Context, task *statsty
}
}
metrics.ReadStatsHistogram.Observe(float64(time.Since(t).Milliseconds()))
if needUpdate && s.updateCachedItem(item, wrapper.col, wrapper.idx, task.Item.FullLoad) {
return result, nil
if needUpdate {
s.updateCachedItem(item, wrapper.col, wrapper.idx, task.Item.FullLoad)
}
return nil, nil
return result, nil
}

// readStatsForOneItem reads hist for one column/index, TODO load data via kv-get asynchronously
Expand Down

0 comments on commit 4920264

Please sign in to comment.