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

proxy: refine sqlserver.SQLServer #27

Merged
merged 3 commits into from
Aug 8, 2022
Merged

proxy: refine sqlserver.SQLServer #27

merged 3 commits into from
Aug 8, 2022

Conversation

xhebox
Copy link
Collaborator

@xhebox xhebox commented Aug 4, 2022

What problem does this PR solve?

Issue Number: ref #15

Problem Summary: As title

What is changed and how it works:

  1. rename to proxy.SQLServer
  2. pass logger to SQLServer and ClientConnection
  3. handle cleanup of connection smoothly
  4. replace siddontong/go-mysql to one from go-mysql-org
  5. use more errors.Collect

Check List

Tests

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

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
  • Has weirctl change
  • Other user behavior changes

Release note

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

None

@xhebox xhebox requested a review from djshow832 August 4, 2022 09:18
1. rename to proxy.SQLServer
2. pass logger to SQLServer and ClientConnection
3. handle cleanup of connection smoothly
4. replace siddontong/go-mysql to one from go-mysql-org

Signed-off-by: xhe <xw897002528@gmail.com>
This was referenced Aug 4, 2022
pkg/proxy/proxy.go Outdated Show resolved Hide resolved
pkg/proxy/proxy.go Outdated Show resolved Hide resolved
default:
conn, err := s.listener.Accept()
if err != nil {
if errors.Is(err, net.ErrClosed) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use if opErr, ok := err.(*net.OpError) as TiDB does?

Copy link
Collaborator Author

@xhebox xhebox Aug 4, 2022

Choose a reason for hiding this comment

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

I prefer the new style. Also, if errors are wrapped, type cast would not work. ButIs() always works without thinking much.

Copy link
Collaborator Author

@xhebox xhebox Aug 5, 2022

Choose a reason for hiding this comment

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

Another thing is that there are many *net.OpError. But I think we should only return nil on ErrClosed. That is also the description of the original implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if errors are wrapped, type cast would not work.

I think we should keep the code the same with TiDB when you can not thoroughly test it, because TiDB has been running for a long time.

That is also the description of the original implementation.

Which description? The one of TiDB or golang?

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 mean weir. The logging message is on closed connection and return nil.

Copy link
Collaborator Author

@xhebox xhebox Aug 5, 2022

Choose a reason for hiding this comment

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

I think we should keep the code the same with TiDB when you can not thoroughly test it, because TiDB has been running for a long time.

I think it is fine. Mysql protocol did not define anything about the behavior of accept. And returnn nil if clients disconnects on its own is normal among other apps. But we should report errors if it is not ErrClosed(BTW, ErrClosed is also the only one exposed error in net package).

pkg/proxy/proxy.go Outdated Show resolved Hide resolved
xhebox added 2 commits August 5, 2022 10:56
Signed-off-by: xhe <xw897002528@gmail.com>
Signed-off-by: xhe <xw897002528@gmail.com>
@djshow832 djshow832 merged commit 1c4b17f into pingcap:main Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants