LuciferYang opened a new issue, #7694:
URL: https://github.com/apache/kyuubi/issues/7694
### Describe the bug
`UuidUtils.generateUUIDv7` lays out a UUID per RFC 9562: 48 bits of Unix
epoch milliseconds, a 4-bit version (`0b0111`), 12 bits of rand_a, then in the
least significant half a 2-bit variant (`0b10`) and 62 bits of rand_b.
`UuidUtilsTest` asserts `uuid.version()` and `uuid.variant()`, and nothing
else about the returned value. Production writes both of those from literals:
```java
long msb = (epochMs << 16); // place timestamp in the top 48 bits
msb |= 0x7000L; // version 7 (UUID bits 48..51)
msb |= randMSB; // low 12 bits of MSB
long lsb = 0x8000000000000000L; // RFC 4122 variant '10'
lsb |= randLSB;
```
So neither assertion depends on `epochMs`, and neither depends on the 74
bits of randomness. Nothing reads the top 48 bits back out, and nothing
compares two generated values.
Three independent mutations of `generateUUIDv7` leave the suite fully green.
Setting `long msb = 0L` so the timestamp is never written. Shifting it out of
position with `epochMs << 20`. And deleting
`SECURE_RANDOM.nextBytes(randomBytes)`, after which
`generateUUIDv7(0xFEDCBA987654L)` returns
`fedcba98-7654-7000-8000-000000000000` on every call, so any two UUIDs made in
the same millisecond are identical.
The version assertion catches a misplaced timestamp only by accident. With
`epochMs << 12` the low nibble of the millisecond value lands in the version
nibble, so whether the suite goes red depends on the current time; across
repeated runs it went both ways.
Time ordering and uniqueness are the two properties #7277 wanted from v7,
and they are exactly the two nothing pins. `generateUUIDv7` has no caller in
the repository yet, so this is worth closing before session IDs and staging
directory names start depending on the layout.
### Affects Version(s)
master (1.13.0-SNAPSHOT), 1.12, 1.11. `UuidUtils` and its test landed
together in #7277, and `branch-1.12` and `branch-1.11` carry the same two
assertions. `branch-1.10` has neither the class nor the test.
### Are you willing to submit PR?
Yes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]