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

executor, session: Add Detach() method to detach the record set #54091

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

YangKeao
Copy link
Member

What problem does this PR solve?

Issue Number: close #54090

Problem Summary:

The original recordSet and execStmtResult are too complicated to implement the lazy cursor fetch feature. We do need a much simpler one: without explicit transaction, without metrics/summaries and only supports read-only statements.

What changed and how does it work?

This PR adds a method Detach to create a new record set from existing recordSet or execStmtResult. The new record set can run without depending on the session context.

However, currently the executor still cannot be detached, so this PR specially handled the TableReaderExecutor and left a TODO here.

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.

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 18, 2024
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 64.40678% with 21 lines in your changes missing coverage. Please review.

Project coverage is 57.4713%. Comparing base (f124165) to head (a5b23d4).
Report is 70 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54091         +/-   ##
=================================================
- Coverage   74.5222%   57.4713%   -17.0510%     
=================================================
  Files          1508       1646        +138     
  Lines        358470     621228     +262758     
=================================================
+ Hits         267140     357028      +89888     
- Misses        71953     240476     +168523     
- Partials      19377      23724       +4347     
Flag Coverage Δ
integration 38.5191% <1.6949%> (?)
unit 72.4316% <64.4067%> (-0.9818%) ⬇️

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

Components Coverage Δ
dumpling 52.9656% <ø> (-2.2339%) ⬇️
parser ∅ <ø> (∅)
br 62.1306% <ø> (+18.2291%) ⬆️

@YangKeao YangKeao force-pushed the static-record-set branch 2 times, most recently from 4a820cb to 6a6f561 Compare June 18, 2024 12:09
@YangKeao
Copy link
Member Author

/retest

2 similar comments
@YangKeao
Copy link
Member Author

/retest

@YangKeao
Copy link
Member Author

/retest

@YangKeao
Copy link
Member Author

/retest

@YangKeao YangKeao force-pushed the static-record-set branch 5 times, most recently from 8c62fcf to 2688b85 Compare June 19, 2024 12:34
// FIXME: if the following code meets error, the `detachedRS` will be leaked.
// The error may occur during the begin/commit of the newly created transaction on the given `startTS``.

// FIXME: block the min-start-ts. Now the `min-start-ts` will advance and exceed the `startTS` used by
Copy link
Member Author

Choose a reason for hiding this comment

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

This FIXME will be fixed in #54114

RecordSet

// Detach detaches the record set from the current session context.
Detach() (RecordSet, error)
Copy link
Collaborator

@lcwangchao lcwangchao Jun 20, 2024

Choose a reason for hiding this comment

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

Could we make this function to TryDetach() (RecordSet, bool) because when recordSet cannot be detached, it may be a normal case

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll return TryDetach() (RecordSet, bool, error) to indicate whether the statement is suitable to detach, and whether it detaches successfully. I sounds strange but I didn't come up a better way 🤦.

If the caller receives nil, false, _, it means the original record set can still be used. If the caller receives _, _, err, it means the state of session/recordSet is in a chaos, and usually the connection will be halted.

pkg/executor/adapter.go Outdated Show resolved Hide resolved
pkg/session/session.go Outdated Show resolved Hide resolved
@YangKeao YangKeao force-pushed the static-record-set branch 3 times, most recently from 94c73b6 to 70904b6 Compare June 20, 2024 13:17
@YangKeao
Copy link
Member Author

/retest

@YangKeao YangKeao requested a review from lcwangchao June 24, 2024 05:57
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jun 24, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 24, 2024
Copy link

ti-chi-bot bot commented Jun 24, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lcwangchao, xhebox

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 Jun 24, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-06-24 06:17:16.662552326 +0000 UTC m=+613963.148041159: ☑️ agreed by xhebox.
  • 2024-06-24 06:23:09.586045142 +0000 UTC m=+614316.071533969: ☑️ agreed by lcwangchao.

@ti-chi-bot ti-chi-bot bot merged commit e036274 into pingcap:master Jun 24, 2024
23 checks passed
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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Detach method for RecordSet to detach a record set from the session context
3 participants