Skip to content

Commit

Permalink
debug: add more logs
Browse files Browse the repository at this point in the history
Signed-off-by: Rustin170506 <29879298+Rustin170506@users.noreply.github.com>
  • Loading branch information
Rustin170506 committed Sep 18, 2024
1 parent 7d31f7b commit e46cfd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions pkg/statistics/handle/autoanalyze/priorityqueue/queue2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
statstypes "github.com/pingcap/tidb/pkg/statistics/handle/types"
statsutil "github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pkg/errors"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -141,7 +140,7 @@ func (pq *AnalysisPriorityQueueV2) init() error {
// We apply a penalty to larger tables, which can potentially result in a negative weight.
// To prevent this, we filter out any negative weights. Under normal circumstances, table sizes should not be negative.
if weight <= 0 {
statslogutil.SingletonStatsSamplerLogger().Warn(
statslogutil.StatsLogger().Warn(
"Table gets a negative weight",
zap.Float64("weight", weight),
zap.Stringer("job", job),
Expand All @@ -151,7 +150,7 @@ func (pq *AnalysisPriorityQueueV2) init() error {
// Push the job onto the queue.
err := pq.inner.Add(job)
if err != nil {
logutil.BgLogger().Error("failed to add job to priority queue", zap.Error(err))
statslogutil.StatsLogger().Error("failed to add job to priority queue", zap.Error(err))
}
}
// No partitions, analyze the whole table.
Expand Down Expand Up @@ -219,8 +218,10 @@ func (pq *AnalysisPriorityQueueV2) run() {
case <-pq.ctx.Done():
return
case <-dmlFetchInterval.C:
statslogutil.StatsLogger().Info("fetching dml update")
pq.fetchDMLUpdate()
case <-timeRefreshInterval.C:
statslogutil.StatsLogger().Info("refreshing time")
pq.refreshTime()
}
}
Expand All @@ -237,9 +238,11 @@ func (pq *AnalysisPriorityQueueV2) fetchDMLUpdate() {
values := pq.statsHandle.Values()
lastFetchTimestamp := pq.lastDMLUpdateFetchTimestamp.Load()
var newMaxVersion uint64
statslogutil.StatsLogger().Info("fetching dml update", zap.Uint64("last_fetch_timestamp", lastFetchTimestamp))

for _, value := range values {
if value.Version > lastFetchTimestamp {
statslogutil.StatsLogger().Info("updating table stats", zap.Uint64("version", value.Version))
// Handle the table stats
pq.handleTableStats(value)
}
Expand All @@ -248,11 +251,12 @@ func (pq *AnalysisPriorityQueueV2) fetchDMLUpdate() {

// Only update if we've seen a newer version
if newMaxVersion > lastFetchTimestamp {
statslogutil.StatsLogger().Info("updating last fetch timestamp", zap.Uint64("new_max_version", newMaxVersion))
pq.lastDMLUpdateFetchTimestamp.Store(newMaxVersion)
}
return nil
}); err != nil {
logutil.BgLogger().Error("failed to fetch dml update", zap.Error(err))
statslogutil.StatsLogger().Error("failed to fetch dml update", zap.Error(err))
}
}

Expand Down Expand Up @@ -349,8 +353,8 @@ func (pq *AnalysisPriorityQueueV2) handleTableStats(stats *statistics.Table) {

job.SetWeight(pq.calculator.CalculateWeight(job))
return pq.inner.Add(job)
}); err != nil {
logutil.BgLogger().Error("failed to create table analysis job", zap.Error(err))
}, statsutil.FlagWrapTxn); err != nil {
statslogutil.StatsLogger().Error("failed to create table analysis job", zap.Error(err))
}
}

Expand All @@ -377,12 +381,12 @@ func (pq *AnalysisPriorityQueueV2) refreshTime() {
job.SetIndicators(indicators)
job.SetWeight(pq.calculator.CalculateWeight(job))
if err := pq.inner.Add(job); err != nil {
logutil.BgLogger().Error("failed to add job to priority queue", zap.Error(err))
statslogutil.StatsLogger().Error("failed to add job to priority queue", zap.Error(err))
}
}
return nil
}); err != nil {
logutil.BgLogger().Error("failed to refresh time", zap.Error(err))
}, statsutil.FlagWrapTxn); err != nil {
statslogutil.StatsLogger().Error("failed to refresh time", zap.Error(err))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/statistics/handle/autoanalyze/refresher/refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

// useAnalysisPriorityQueueV2 is a constant that controls whether to use the new priority queue implementation.
const useAnalysisPriorityQueueV2 = false
const useAnalysisPriorityQueueV2 = true

// Refresher provides methods to refresh stats info.
// NOTE: Refresher is not thread-safe.
Expand Down

0 comments on commit e46cfd2

Please sign in to comment.