-
Notifications
You must be signed in to change notification settings - Fork 6.2k
executor: keep analyze status remaining time in UTC #67229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ti-chi-bot
merged 5 commits into
pingcap:master
from
0xPoe:fix/show-analyze-status-remaining-timezone
Apr 2, 2026
+47
−10
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25be698
executor: add regression test for analyze status remaining time
0xPoe c35c7a2
executor: keep analyze status remaining time in UTC
0xPoe cc47e0c
docs: add comments
0xPoe 3239183
fix: simplify code
0xPoe 6d1ca89
fix: make lint happy
0xPoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2548,11 +2548,15 @@ func dataForAnalyzeStatusHelper(ctx context.Context, e *memtableRetriever, sctx | |
| jobInfo := chunkRow.GetString(3) | ||
| processedRows := chunkRow.GetInt64(4) | ||
| var startTime, endTime any | ||
| // startTime and endTime use the local timezone for displaying. | ||
| // startTimeUTC is used to calculate the remaining duration of the job. | ||
| var startTimeUTC *time.Time | ||
| if !chunkRow.IsNull(5) { | ||
| t, err := chunkRow.GetTime(5).GoTime(time.UTC) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| startTimeUTC = &t | ||
| startTime = types.NewTime(types.FromGoTime(t.In(sctx.GetSessionVars().TimeZone)), mysql.TypeDatetime, 0) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the original bug comes form. We use the session time, but we applied it as UTC in later usage. |
||
| } | ||
| if !chunkRow.IsNull(6) { | ||
|
|
@@ -2576,11 +2580,10 @@ func dataForAnalyzeStatusHelper(ctx context.Context, e *memtableRetriever, sctx | |
|
|
||
| var remainDurationStr, progressDouble, estimatedRowCntStr any | ||
| if state == statistics.AnalyzeRunning && !strings.HasPrefix(jobInfo, "merge global stats") { | ||
| startTime, ok := startTime.(types.Time) | ||
| if !ok { | ||
| if startTimeUTC == nil { | ||
| return nil, errors.New("invalid start time") | ||
| } | ||
| remainingDuration, progress, estimatedRowCnt, remainDurationErr := getRemainDurationForAnalyzeStatusHelper(ctx, sctx, &startTime, | ||
| remainingDuration, progress, estimatedRowCnt, remainDurationErr := getRemainDurationForAnalyzeStatusHelper(ctx, sctx, startTimeUTC, | ||
| dbName, tableName, partitionName, processedRows) | ||
| if remainDurationErr != nil { | ||
| logutil.BgLogger().Warn("get remaining duration failed", zap.Error(remainDurationErr)) | ||
|
|
@@ -2617,16 +2620,13 @@ func dataForAnalyzeStatusHelper(ctx context.Context, e *memtableRetriever, sctx | |
|
|
||
| func getRemainDurationForAnalyzeStatusHelper( | ||
| ctx context.Context, | ||
| sctx sessionctx.Context, startTime *types.Time, | ||
| sctx sessionctx.Context, startTimeUTC *time.Time, | ||
| dbName, tableName, partitionName string, processedRows int64, | ||
| ) (_ *time.Duration, percentage, totalCnt float64, err error) { | ||
| remainingDuration := time.Duration(0) | ||
| if startTime != nil { | ||
| start, err := startTime.GoTime(time.UTC) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Buggy code! |
||
| if err != nil { | ||
| return nil, percentage, totalCnt, err | ||
| } | ||
| duration := time.Now().UTC().Sub(start) | ||
| if startTimeUTC != nil { | ||
| // time.Time.Sub uses the actual instant. | ||
| duration := time.Since(*startTimeUTC) | ||
| if intest.InTest { | ||
| if val := ctx.Value(AnalyzeProgressTest); val != nil { | ||
| remainingDuration, percentage = calRemainInfoForAnalyzeStatus(ctx, int64(totalCnt), processedRows, duration) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.