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

lighting: replace lightning inner contexts with manged ones #56038

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

lcwangchao
Copy link
Collaborator

What problem does this PR solve?

Issue Number: ref #53388

What changed and how does it work?

This RP replaces some internal contexts for lighting/import into to make sure to contexts are simple and easier to maintain, including:

  • litExprContext which wraps StaticExprContext to provide expression context.
  • litTableMutateContext provides table mutate context

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.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 12, 2024
Copy link

tiprow bot commented Sep 12, 2024

Hi @lcwangchao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@@ -62,8 +62,6 @@ func NewTableKVEncoder(
if err != nil {
return nil, err
}
// we need a non-nil TxnCtx to avoid panic when evaluating set clause
baseKVEncoder.SessionCtx.SetTxnCtxNotNil()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not needed any more because we have removed SessionVars in the new session.

compareWithLegacySession(tblCtx, sysVars)

// test for `RowEncodingConfig.IsRowLevelChecksumEnabled` which should be loaded from global variable.
require.False(t, variable.EnableRowLevelChecksum.Load())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IsRowLevelChecksumEnabled is a little special. It's value is affected by the global var variable.EnableRowLevelChecksum , see:

vars.EnableRowLevelChecksum = true

variable.EnableRowLevelChecksum may vary for different TiDB nodes if the variable is in reloading. So it can affect IMPORT INTO statement which can be executed across nodes. But I don't think it's a big deal and to be compatible, we keep the same behavior here.

@@ -312,6 +311,7 @@ func (*sessEvalContext) GetOptionalPropProvider(exprctx.OptionalEvalPropKey) (ex
return nil, false
}

// Deprecated: `session` will be removed soon.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have decided to remove the old session from the next PR. In this PR, it is used in some tests to check the old and new session's behavior are the same

if options.SysVars != nil {
// This sessVars is only used to do validations.
sessVars := variable.NewSessionVars(nil)
// To keep compatible with the old versions, we should to skip errors caused by illegal system variables.
Copy link
Collaborator Author

@lcwangchao lcwangchao Sep 12, 2024

Choose a reason for hiding this comment

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

To keep compatible, filter the valid system variables before constructing the session.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 76.38191% with 47 lines in your changes missing coverage. Please review.

Project coverage is 56.3953%. Comparing base (b3914c5) to head (b4b2445).
Report is 10 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #56038         +/-   ##
=================================================
- Coverage   72.9443%   56.3953%   -16.5491%     
=================================================
  Files          1609       1762        +153     
  Lines        447171     640408     +193237     
=================================================
+ Hits         326186     361160      +34974     
- Misses       100907     254496     +153589     
- Partials      20078      24752       +4674     
Flag Coverage Δ
integration 38.7834% <67.8392%> (?)
unit 72.3576% <81.9672%> (+0.3001%) ⬆️

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

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 52.8854% <ø> (+7.0867%) ⬆️

Comment on lines +217 to +231
func (*litTableMutateContext) GetCachedTableSupport() (tbctx.CachedTableSupport, bool) {
// lightning import does not support cached table.
return nil, false
}

func (*litTableMutateContext) GetTemporaryTableSupport() (tbctx.TemporaryTableSupport, bool) {
// lightning import does not support temporary table.
return nil, false
}

func (*litTableMutateContext) GetExchangePartitionDMLSupport() (tbctx.ExchangePartitionDMLSupport, bool) {
// lightning import is not in a DML query, we do not need to support it.
return nil, false
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PTAL @lance6716 @D3Hunter . some features not supported in lighthing/import into

@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Sep 12, 2024

@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@lcwangchao
Copy link
Collaborator Author

/hold

Should waiting for #56059 merged first

@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 Sep 13, 2024
pkg/lightning/backend/kv/context.go Show resolved Hide resolved
pkg/lightning/backend/kv/context.go Outdated Show resolved Hide resolved
pkg/lightning/backend/kv/context.go Show resolved Hide resolved
pkg/lightning/backend/kv/context.go Show resolved Hide resolved
return &ctx.reservedRowIDAlloc, true
}

// GetBinlogSupport implements the `table.MutateContext` interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

this method will be soon removed by #55955

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, if #55955 merged first, I'll remove this implementation. Otherwise, #55955 should remove this ...

}

// UpdatePhysicalTableDelta implements the `table.StatisticsSupport` interface.
func (ctx *litTableMutateContext) UpdatePhysicalTableDelta(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think lightning don't need implement whole logic. It only need column size by GetColumnSize. Or if we can maintain column size elsewhere this function can be a no-op.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've simplified the implementation, please take a look again.

pkg/lightning/backend/kv/session.go Show resolved Hide resolved
@lcwangchao
Copy link
Collaborator Author

/retest

Copy link

tiprow bot commented Sep 13, 2024

@lcwangchao: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@lcwangchao
Copy link
Collaborator 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 Sep 14, 2024
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

rest lgtm

pkg/lightning/backend/kv/context.go Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the lgtm label Sep 17, 2024
Copy link

ti-chi-bot bot commented Sep 17, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, YangKeao

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

Copy link

ti-chi-bot bot commented Sep 17, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-14 07:26:43.525309586 +0000 UTC m=+686873.265733525: ☑️ agreed by YangKeao.
  • 2024-09-17 04:16:40.0856727 +0000 UTC m=+934669.826096638: ☑️ agreed by D3Hunter.

Copy link

tiprow bot commented Sep 17, 2024

@lcwangchao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow b4b2445 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@lance6716
Copy link
Contributor

/retest

Copy link

tiprow bot commented Sep 17, 2024

@lance6716: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot merged commit 12e5b31 into pingcap:master Sep 17, 2024
23 of 24 checks passed
@lcwangchao lcwangchao deleted the replace_lit_ctx branch September 18, 2024 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants