-
Notifications
You must be signed in to change notification settings - Fork 12
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
Implement UUID version 7 #14
Conversation
And rename the one proposed to [v7_ns].
I merged your patch as 413249e but I don't think we are there yet API wise. Let's use this PR for discussing this. In 3c6abae. I renamed your version to Now I think we still want at least:
Any thoughts ? Also is it a problem for you if |
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.
I'm not a specialist for UUID; just think this looks solid. Thanks for adding v7 to uuidm. Does this need more test cases or it the construction so obvious (how bits are placed) that problems would show up?
I like your decision to provide a call with all the parameters defined in the RFC to provide clients flexibility to make their own libraries to provide their own monotonicity schemes; and a more ergonomic / interoperable that uses nanoseconds. About generators, an important property of v7 is to provide ordered timestamps. The RFC talks about the methods in detail in section 6.2. The generators can ignore these if we think users won't generally need the precision, but then the generators must be made ad-hoc.
I'm unsure about mixing randomness and monotonicity, do you have any opinions on implementing this scheme? Maybe we want another behaviour.
Regarding 2 and 3: I don't have any objections about this, I'm all for making the API as easy to use as possible, so these are all well. Adding an example of them would be clarifying to users as well.
Not a problem at all, thanks for asking. |
So I had a read at the spec. There's quite a few things you can do to generate V7 UUIDs and the right one depends quite a bit on your application needs or the strictness of your monotonicity constraints. Since
For now I think this is good enough, more generators can be added in the future if other good schemes emerge. I added a quick start with various example and notably how to use Thank you all for your input! |
At the risk of making the quick start less self-contained, I think it would be good to either use |
The standard mandates a POSIX timestamp and If you really need monotonicity, you'd be better of trying to combine a POSIX clock, a monotononic clock and stable storage but all that is way beyond In general I think it's better to design your system so that it takes into account that monotonicity (and unicity) may be violated in rare cases and that it should not be a catastrophy for your system… |
Implement a function to construct v7 UUIDs as defined by RFC 9562. These incorporate timestamps so that they sort by order of creation - although in the implementation, a timestamp value has to be supplied.
I've not modifed the version type - a V7 variant could be added, but I'm not sure how much sense that would make.