Skip to content
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

ddl: use the correct timezone to encode record for adding index (#46055) #46104

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #46055

What problem does this PR solve?

Issue Number: close #46033

Problem Summary:

Normally, TiDB converts timestamp values to UTC before writing them to the storage, and converts them back when reading. For adding index, we

  1. Read the table records from storage.
  2. Encode the index records.
  3. Write/Ingest the index records to storage.

In step 1, the datum returned by extractDatumByOffsets() is in UTC timezone. It is converted to UTC again in step 2. As a result, index timestamp is converted twice.

Unistore DAG request decoding:

switch dagReq.TimeZoneName {
case "":
sc.TimeZone = time.FixedZone("UTC", int(dagReq.TimeZoneOffset))
case "System":
sc.TimeZone = time.Local
default:
sc.TimeZone, err = time.LoadLocation(dagReq.TimeZoneName)
if err != nil {
return nil, nil, errors.Trace(err)
}
}

TiKV DAG request decoding:
https://github.com/tikv/tikv/blob/14dd8cce96e064a029e58de8cf832c35d44e09a5/components/tidb_query_datatype/src/expr/ctx.rs#L86-L94

For Unistore and TiKV, the time zone name is always considered first, and the time zone offset second.

Thus, the way to buildDAGPB is wrong:

dagReq.TimeZoneName, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location())

We assigned both name and offset to UTC and -0600 respectively. UTC is kept but -0600 is discarded during parsing the DAG request.

What is changed and how it works?

Assign the time zone offset in buildDAGPB, and leave time zone name to be empty.

// Zone computes the time zone in effect at time t, returning the abbreviated
// name of the zone (such as "CET") and its offset in seconds east of UTC.
func (t Time) Zone() (name string, offset int) {
	name, offset, _, _, _ = t.loc.lookup(t.unixSec())
	return
}

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Aug 15, 2023
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 15, 2023
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 15, 2023
@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Aug 15, 2023
@@ -485,7 +485,7 @@ func getRestoreData(tblInfo *model.TableInfo, targetIdx, pkIdx *model.IndexInfo,

func buildDAGPB(sCtx sessionctx.Context, tblInfo *model.TableInfo, colInfos []*model.ColumnInfo) (*tipb.DAGRequest, error) {
dagReq := &tipb.DAGRequest{}
dagReq.TimeZoneName, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location())
_, dagReq.TimeZoneOffset = timeutil.Zone(sCtx.GetSessionVars().Location())
Copy link
Contributor

@zimulala zimulala Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we only need to change 'TimeZoneName' and not 'TimeZoneOffset'?

@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

❗ No coverage uploaded for pull request base (release-6.5@4e6af00). Click here to learn what that means.
The diff coverage is n/a.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-6.5     #46104   +/-   ##
================================================
  Coverage               ?   74.3184%           
================================================
  Files                  ?       1084           
  Lines                  ?     353658           
  Branches               ?          0           
================================================
  Hits                   ?     262833           
  Misses                 ?      74377           
  Partials               ?      16448           

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Aug 15, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 16, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wjhuang2016, zimulala

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [wjhuang2016,zimulala]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 16, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Aug 16, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-08-15 12:15:15.18418585 +0000 UTC m=+633279.733201831: ☑️ agreed by zimulala.
  • 2023-08-16 05:53:32.635092147 +0000 UTC m=+696777.184108119: ☑️ agreed by wjhuang2016.

@hawkingrei
Copy link
Member

/retest

1 similar comment
@tangenta
Copy link
Contributor

/retest

@HuSharp
Copy link
Contributor

HuSharp commented Aug 17, 2023

/retest-required

@ti-chi-bot ti-chi-bot bot merged commit 76953b2 into pingcap:release-6.5 Aug 17, 2023
3 checks passed
@HuSharp HuSharp deleted the cherry-pick-46055-to-release-6.5 branch August 18, 2023 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants