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

planner: use TxnCtx.InfoSchema to prevent schema inconsistency #49947

Merged
merged 3 commits into from
Jan 2, 2024

Conversation

hawkingrei
Copy link
Member

@hawkingrei hawkingrei commented Dec 31, 2023

What problem does this PR solve?

Issue Number: ref #41622

close #49751

Problem Summary:

What changed and how does it work?

The result of sctx.GetInfoSchema().(infoschema.InfoSchema) is not stable if the caller side is not in a transaction && snapshot_ts is not set, it just get the latest InfoSchema:

tidb/pkg/session/session.go

Lines 4052 to 4074 in c20874e

func (s *session) GetInfoSchema() sessionctx.InfoschemaMetaVersion {
vars := s.GetSessionVars()
var is infoschema.InfoSchema
if snap, ok := vars.SnapshotInfoschema.(infoschema.InfoSchema); ok {
logutil.BgLogger().Info("use snapshot schema", zap.Uint64("conn", vars.ConnectionID), zap.Int64("schemaVersion", snap.SchemaMetaVersion()))
is = snap
} else {
vars.TxnCtxMu.Lock()
if vars.TxnCtx != nil {
if tmp, ok := vars.TxnCtx.InfoSchema.(infoschema.InfoSchema); ok {
is = tmp
}
}
vars.TxnCtxMu.Unlock()
}
if is == nil {
is = domain.GetDomain(s).InfoSchema()
}
// Override the infoschema if the session has temporary table.
return temptable.AttachLocalTemporaryTableInfoSchema(s, is)
}

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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.

planner: use TxnCtx.InfoSchema to prevent schema inconsistency

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. do-not-merge/needs-tests-checked needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-tests-checked labels Dec 31, 2023
Copy link

codecov bot commented Dec 31, 2023

Codecov Report

Merging #49947 (d162acb) into master (d6aeaf0) will decrease coverage by 3.2670%.
Report is 3 commits behind head on master.
The diff coverage is 33.3333%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49947        +/-   ##
================================================
- Coverage   72.0575%   68.7906%   -3.2670%     
================================================
  Files          1437       1439         +2     
  Lines        345628     407669     +62041     
================================================
+ Hits         249051     280438     +31387     
- Misses        76506     108394     +31888     
+ Partials      20071      18837      -1234     
Flag Coverage Δ
integration 43.8999% <33.3333%> (?)
unit 72.0374% <ø> (-0.0201%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 56.3129% <ø> (ø)
parser ∅ <ø> (∅)
br 43.9542% <ø> (-7.4449%) ⬇️

@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 31, 2023
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 2, 2024
Copy link

ti-chi-bot bot commented Jan 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qw4990, tiancaiamao

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:

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 Jan 2, 2024
Copy link

ti-chi-bot bot commented Jan 2, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-01-02 02:12:18.270794267 +0000 UTC m=+2136629.308021189: ☑️ agreed by tiancaiamao.
  • 2024-01-02 02:15:07.605770562 +0000 UTC m=+2136798.642997489: ☑️ agreed by qw4990.

@hawkingrei
Copy link
Member Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 2, 2024
u
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
@hawkingrei
Copy link
Member Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 2, 2024
@hawkingrei hawkingrei added needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. labels Jan 2, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.1: #49963.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 2, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #49964.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 2, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #49965.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 2, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #49966.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-5.4: #49967.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 2, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
rleungx pushed a commit to rleungx/tidb that referenced this pull request Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v7.1 serverless: sysbench update hit runtime error: index out of range [4] with length 4
4 participants