-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
expression: fix uuid generate duplicate value with multi-node #10590
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10590 +/- ##
================================================
- Coverage 78.3658% 78.3465% -0.0193%
================================================
Files 414 414
Lines 87704 87709 +5
================================================
- Hits 68730 68717 -13
- Misses 13840 13852 +12
- Partials 5134 5140 +6 |
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
after using google uuid, we can not generate the same uuid even in different tidb-servers? |
If multiple tidb instances are deployed on one machine, will they generate the same uuid? |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
In master
select uuid()
will got this result:the question is
000000000000
part, it should node an IEEE 802 node number for RFC 4122 version-1but has be
000000000000
, the root question is https://github.com/myesui/uuid/blob/master/generator.go#L21 init a generator but doesn't call https://github.com/myesui/uuid/blob/master/generator.go#L230 to init node value from https://github.com/myesui/uuid/blob/master/generator.go#L508as result, mutiple node generate uuid maybe duplicate if they be called as same time.
What is changed and how it works?
the easiest way to fix this question is call
NewGenerator
upper case method to init, instead of useuuid.NewV1
, but after some look NewGenerator doesn't handle the question interface can not obtain, after thinking maybe we should change to https://github.com/google/uuid which 's impl is more like RFC's requirement https://github.com/google/uuid/blob/master/node.go#L39ps: mysql's implement https://github.com/mysql/mysql-server/blob/6b10960e9d2e606b2774143da60903d641ac542f/sql/item_strfunc.cc#L3898 also will use random nodeid when interface can not obtain too, https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid, and uuid can be duplicate but it should be very low probability
at last, our ddl use
uuid.NewV4
don't have this problem will keep use old lib.Check List
Tests
after this patch will got
Code changes
Side effects
"Breaking backward compatibility" should not be problem, V1 use timestamp and new version will add real not it should not duplicate to old generated data by old tidb.
Related changes
This change is