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

docs: RFC: Enhancement of Internal System Session Management #60120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Mar 17, 2025

What problem does this PR solve?

Issue Number: ref #60115

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 the release-note-none Denotes a PR that doesn't merit a release note. label Mar 17, 2025
Copy link

ti-chi-bot bot commented Mar 17, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from lcwangchao, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 17, 2025
@lcwangchao lcwangchao force-pushed the rfc_session_pool branch 2 times, most recently from 4aa4266 to be483cc Compare March 17, 2025 11:18
@hawkingrei
Copy link
Member

I don't know if the new version of the session pool will still use the implementation from github.com/ngaut/pools. However, I think this implementation is quite problematic and even less practical than the official pool. It's just that historically, there was a time when the Go language did not have sync.Pool , and implementing it ourselves had some advantages.

@hawkingrei
Copy link
Member

According to the convention of sync.Pool, if your object is problematic, you just don't put it back into the Pool. It will naturally be cleaned up after the next GC.

@lcwangchao
Copy link
Collaborator Author

lcwangchao commented Mar 18, 2025

I don't know if the new version of the session pool will still use the implementation from github.com/ngaut/pools. However, I think this implementation is quite problematic and even less practical than the official pool. It's just that historically, there was a time when the Go language did not have sync.Pool , and implementing it ourselves had some advantages.

Thanks for the advise. I'll try to use the sync.Pool in the next pull request.

Copy link

tiprow bot commented Mar 18, 2025

@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 da37c49 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.

}

func (s *Session) ExecuteInternal(ctx context.Context, sql string, args ...any) (sqlexec.RecordSet, error) {
if err := s.internal.checkOwner(s); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of checkOwner, I think we can add a atomic bool closed field to *Session. When *Session is put back to the pool, store true to closed.

In other words, lifecycle management belongs to Session, not session

Copy link
Member

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

Comment on lines +57 to +62
if r := recover(); r != nil {
// Always destroy the session when panic to avoid undetermined state.
se.Destroy()
panic(r)
}
p.put(se)
Copy link
Member

Choose a reason for hiding this comment

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

I think if any error occurs, we should destroy it as well.

}
```

The `mu` protects the internal session from concurrent access, and the field `sctx` is the real session context that holds the session's state.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should discourage users from using the same session across multiple threads, as I’m concerned it could create a lot of issues. In the current session design, our expectation is that it shouldn’t be used this way.

Copy link
Member

Choose a reason for hiding this comment

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

Or am I misunderstanding the purpose of this mutex?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants