-
Notifications
You must be signed in to change notification settings - Fork 192
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
V1 Generator Should not Always Increment Sequence Counter #106
Comments
Hi, if you want to create a PR, I can help review it! (I have no authority in the uuid project, just offering my assistance) |
Hi @posborne, do you still have any time to implement this change? If not, I can take a crack at it. |
I will try to work on this today. |
Any recommendations for how to handle storing the "last updated" time in the context? Stable rust only exports If we want the default maybe there's some way we could use Atomics, but there are apparently even platforms where usize == u16. That means we would need a way to store 96 bits of timestamp across up to 6 AtomicUsize values... Just using |
I have a WIP in the linked PR #136, using the Mutex approach for keeping track of the previous time. Surprisingly to me, this only increases the runtime of v1 generation to about 2x the previous time. But it has another drawback too: the default context now requires std whereas the old one would work without it (mutexes are only available with std). Is this really okay? Should we add another context implementation identical to the old one, so we have something for people who want to generate v1 uuids without std? I'm also wondering what the drawbacks to the old context. The RFC does say that we should update it when the timestamp might have stayed the same or gone backwards, but it doesn't forbid or even seem to say we SHOULDN'T increment it when the timestamp moves forward. Of course, the trait is definitely a good idea, I'm just wondering what problems we're going to solve with the new implementation. Does anyone know if there was any rationale for this discussed elsewhere (during the libs blitz perhaps)? |
I put up a more conservative PR at #137. It only adds the trait, and doesn't change the way sequences are generated. It's all backwards compatible. |
Just a note that we don’t merge that PR until 0.6 is released |
137: Add a new trait, `UuidV1ClockSequence` which defines the interface for generating clock sequences. r=Dylan-DPC a=radix * new_v1 now takes any implementor of UuidV1ClockSequence, instead of just UuidV1Context. * UuidV1Context implements UuidV1ClockSequence, but ignores the `seconds` and `nanoseconds` arguments. This takes a more conservative approach. No changes to the way UuidV1Context generates sequences, but now other people can implement their own clock-sequence generators. The nice thing is that *I think* this is entirely backwards compatible (which means that this didn't need to block 1.0). This is meant to address #106. It does not implement all the suggestions that it had, but it allows users to, and also allows us to add more implementations with different clock-sequence strategies in a backwards-compatible way.
I know this has already been closed but I think offering a trait to "solve" this problem is the wrong approach. The default use of ClockSequence here is just plain wrong and should be corrected to follow spec. |
@PrismaPhonic thanks. We are always open to discussing issues and decisions. Moving this to a new issue for better traction. |
The V1 generation code (
new_v1
) rightly state the following in the documentation:Items 1 and 2 can be reasonably guaranteed in a system but the 3rd item is nearly impossible to guarantee in practice as the value needs to be monotonically increasing across the entire life of the system (not just a given boot).
Both the RFC for UUID (RFC4122) and the DCE documentation provide similar guidelines on when the sequence should be modified.
I propose the following change (which I can create a PR for):
UuidV1Context
a trait so that the implementation can be plugged as needed. This is important if one wanted to, for instance, ensure that changes to the time/sequence were persisted.UuidV1Context
responsible for storing the most recent time value (in resolution of 100nsecs).Per RFC4122:
The text was updated successfully, but these errors were encountered: