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

Add MysqlGTIDSet.Add() and Minus() methods #667

Merged
merged 2 commits into from
Jan 26, 2022

Conversation

ostinru
Copy link

@ostinru ostinru commented Jan 18, 2022

  • fix off-by-one error

@@ -180,6 +180,8 @@ func (t *mysqlTestSuite) TestMysqlGTIDMinus(c *check.C) {
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-57:60-90", "3E11FA47-71CA-11E1-9E33-C80AA9429562:23", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20-22:24-57:60-90"},
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-57:60-90", "3E11FA47-71CA-11E1-9E33-C80AA9429562:22-70", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20-21:71-90"},
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:28-57", "3E11FA47-71CA-11E1-9E33-C80AA9429562:28-57", ""},
Copy link
Collaborator

Choose a reason for hiding this comment

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

found a failed case

		{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-21", "3E11FA47-71CA-11E1-9E33-C80AA9429562:21", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20"},

please check it

Copy link
Author

Choose a reason for hiding this comment

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

You right.

New version with changes:

  • merge 2 loops into one, so it will be easier to reason about
  • explicit IF conditions to make it clear which cases are handled in each branch

Hope, this time it is correct for all inputs

if j < len(in) {
subtrahend = in[j]
} else {
subtrahend = Interval{math.MaxInt64, math.MaxInt64}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can

append minuend to n
check if i+1 out of range and append s.Intervals[i+1:]... to n

it's OK not to change

Copy link
Author

Choose a reason for hiding this comment

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

There were 2 bugs in 50 lines :(
So, I would prefer not to increase cyclomatic complexity of this code and keep it as it in PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

wait @atercattus 's review as this function is complex

Copy link
Author

Choose a reason for hiding this comment

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

Hi, @atercattus have you had a chance to look into this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I'm going to merge this PR if he does not respond it tomorrow)

@lance6716 lance6716 merged commit 3566d1e into go-mysql-org:master Jan 26, 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