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

Tablet Manager: Make WaitForPosition() accept either file:pos or GTID-based positions. #6374

Merged

Conversation

PrismaPhonic
Copy link
Contributor

@PrismaPhonic PrismaPhonic commented Jun 24, 2020

This PR modifies WaitMasterPos which is ultimately called by WaitForPosition() such that WaitMasterPos() will respect the flavor of the GTIDSet in the supplied Position if that flavor is filePos. Previously, no matter what flavor the Position was, we always deferred to the flavor inherent to the connection grabbed from the Mysqld connection pool. This PR provides an essential update that allows WaitForPosition() to accept either file-based positions, or GTID based positions.

Related Issue: #6206

@PrismaPhonic PrismaPhonic marked this pull request as ready for review June 24, 2020 23:16
@PrismaPhonic PrismaPhonic requested a review from sougou as a code owner June 24, 2020 23:16
@PrismaPhonic PrismaPhonic changed the title TabletManager: Make WaitForPosition() accept either file:pos or GTID-based positions. Tablet Manager: Make WaitForPosition() accept either file:pos or GTID-based positions. Jun 24, 2020
conn, err = mysql.Connect(ctx, params)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need to conn.Recycle()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For mysql.Connect there is no Recycle(). Recycle is a method available to a connection coming from a connection pool. In this case, we are making a direct connection to override the flavor.

Copy link
Member

Choose a reason for hiding this comment

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

It sounds like this code is going away anyway, but for future reference, we would need to defer conn.Close() in this case.

…nnection.

Signed-off-by: Peter Farr <Peter@PrismaPhonic.com>
@PrismaPhonic PrismaPhonic force-pushed the wait-for-position-accept-file-based branch from 5a42866 to 7d81833 Compare July 8, 2020 00:49
@PrismaPhonic
Copy link
Contributor Author

Refactored per @enisoc's suggestions. PTAL when you have the chance, thanks!

Comment on lines +170 to +175
if err != nil {
return Position{}, err
}
return Position{
GTIDSet: gtidSet,
}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Merely a coding style comment, feel free to ignore. What I usually do is:

Suggested change
if err != nil {
return Position{}, err
}
return Position{
GTIDSet: gtidSet,
}, nil
return Position{
GTIDSet: gtidSet,
}, err

it's the caller's responsibility to check if err != nil and if so, to ignore the GTIDSet value.

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 followed the pattern established in the rest of the codebase but you bring up a good point. I'm somewhat split on this. I agree with you that it's the caller's responsibility to check if err != nil but I'm also used to writing in languages where if a result is errorful, it's not even possible to access the successful result.

In this case though if err is not nil, then gtidSet would be nil anyway, so I think your version would actually return the same result with less code - and I like that. I suppose it's a question of how others feel regarding established patterns that already exist in the Vitess codebase, and if we should follow those patterns or break them when it's sensible? @enisoc @deepthi @systay @sougou?

Copy link
Member

Choose a reason for hiding this comment

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

I prefer the less compact version because it is easier to read.

Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

LGTM

@deepthi deepthi merged commit dd9d8cf into vitessio:master Jul 8, 2020
@deepthi deepthi deleted the wait-for-position-accept-file-based branch July 8, 2020 20:39
@deepthi deepthi added this to the v7.0 milestone Jul 27, 2020
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.

4 participants