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

mysql: Add ConnectionReady callback to Handler interface #9496

Merged
merged 1 commit into from
Jan 18, 2022

Conversation

mattrobenolt
Copy link
Contributor

This is is useful to determine the intermediate state after
NewConnection and before ConnectionClosed, basically for a handler to
know if authentication, etc, were successful. NewConnection is way too
soon in the process to determine if the connection got fully
established.

Signed-off-by: Matt Robenolt matt@ydekproductions.com

Checklist

  • Should this PR be backported?
  • Tests were added or are not required
  • Documentation was added or is not required

This is is useful to determine the intermediate state after
NewConnection and before ConnectionClosed, basically for a handler to
know if authentication, etc, were successful. NewConnection is way too
soon in the process to determine if the connection got fully
established.

Signed-off-by: Matt Robenolt <matt@ydekproductions.com>
Comment on lines +477 to +479
// Tell our handler that we're finished handshake and are ready to
// process commands.
l.handler.ConnectionReady(c)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to where we think it's best to determine Ready. It seemed to me to put it right before the for{} loop that started reading commands. But wasn't sure if yall had an opinion on putting it before the SlowConnectionWarnThreshold check, since in theory this callback can add extra connection time. I at least felt it was important to put after the last OK packet sent.

@@ -820,6 +820,10 @@ func (t testRun) NewConnection(c *Conn) {
panic("implement me")
}

func (t testRun) ConnectionReady(c *Conn) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just filling in all of the other internal implementations of the Handler interface.

When doing this, I was thinking it might be nice to introduce a stub UnimplementedHandler struct that all implementation can embed that provides default no-op handlers. Similar to how gRPC gives you the stub to satisfy the interface. That way an implementation isn't require to implement every callback if they're not needed.

I'd be happy to follow up with an UnimplementedHandler struct if you also think this is valuable. It'd help wiht the boilerplate in the tests and all that get touched in this PR.

@frouioui frouioui added release notes Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: TabletManager labels Jan 13, 2022
Copy link
Member

@frouioui frouioui left a comment

Choose a reason for hiding this comment

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

I might be missing something, but I have a hard time understanding what l.handler.ConnectionReady is doing. All the implementations of ConnectionReady are empty methods, is that on purpose?

@mattrobenolt
Copy link
Contributor Author

@frouioui correct, within vitess core, there's no use for it. It's a no-op hook so other implementations of mysql.Handler can use it. In our case, we need it for PlanetScale.

Copy link
Collaborator

@systay systay left a comment

Choose a reason for hiding this comment

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

Sorry you had to wait so long for this to get reviewed

@systay systay merged commit 8e29df5 into vitessio:main Jan 18, 2022
@mattrobenolt mattrobenolt deleted the connection-ready-callback branch January 18, 2022 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: TabletManager Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants