- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.7k
 
HHH-18377 Support for uuid v6 and v7 generated ids #8719
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
Conversation
5b0017a    to
    066a676      
    Compare
  
    | 
           How will it handle if a separate server generates the same id into the same database? Will it recreate a new ID automatically and try again?  | 
    
          
 No.  | 
    
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 left a few comments about odd references to UUID#randomUUID().  Let's clean those up.
Additionally, you write great detail about what each value generator does.  But you do it on #generateUuid.  I'd prefer to see those on the class Javadoc, because...
Another thing we should do here is to add values for these into UuidGenerator.Style.  Its probably best to have these link to the class Javadoc for the corresponding value-generator.
        
          
                hibernate-core/src/main/java/org/hibernate/id/uuid/UuidV6ValueGenerator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/id/uuid/UuidV6ValueGenerator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/id/uuid/UuidV7ValueGenerator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                hibernate-core/src/main/java/org/hibernate/id/uuid/UuidV7ValueGenerator.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      5134d12    to
    e44c59b      
    Compare
  
    | 
           A few naming related points here... 
 I'll need to pull this locally to squash the commits before I apply. I can apply the name changes at that time if you prefer. Thanks again for the work on this!  | 
    
          
 Changed both things. 
 I've squashed everything into two commits, one for implementation, other for test case. Hope that this is OK? 
 You're welcome. Happy if I can help. Not that I was too busy lately.  | 
    
| 
           In general, we like the test/impl split for the PR as it shows (1) what is addressed and (2) how it was addressed. When we apply them, though, we generally (not always) squash to one as it makes it easier to cherry-pick to other branches. This we won't be backporting, so its less important. Long story short, 2 commits is fine here.  | 
    
        
          
                hibernate-core/src/main/java/org/hibernate/id/uuid/UuidVersion7Strategy.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      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.
A few minor suggestions/requests. Let me know what you think. FWIW I left "suggested changes" in those places to make it easy to apply if you agree.
| * <li>14 bits - the clock sequence, resets to 0 when timestamp changes. </li> | ||
| * <li>48 bits - pseudorandom data to provide uniqueness.</li> | ||
| * </ul> | ||
| * | 
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.
| * | |
| * | |
| * @apiNote Version 6 is field-compatible with Version 1, with the time bits reordered for improved DB locality. | |
| * | 
| */ | ||
| @Override | ||
| public int getGeneratedVersion() { | ||
| // UUIDv6 is a field-compatible version of UUIDv1, reordered for improved DB locality | 
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.
| // UUIDv6 is a field-compatible version of UUIDv1, reordered for improved DB locality | 
| * @param session session | ||
| * | ||
| * @return UUID version 6 | ||
| * @see UuidValueGenerator#generateUuid(SharedSessionContractImplementor) | 
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.
| * @param session session | |
| * | |
| * @return UUID version 6 | |
| * @see UuidValueGenerator#generateUuid(SharedSessionContractImplementor) | |
| * Generates a Version 6 compliant {@linkplain UUID} value. | |
| * | |
| * @return A Version 6 compliant {@linkplain UUID}. | |
| * | |
| * @see UuidValueGenerator#generateUuid | 
| * <li>14 bits - counter to guarantee additional monotonicity, resets to 0 when timestamp changes. </li> | ||
| * <li>48 bits - pseudorandom data to provide uniqueness.</li> | ||
| * </ul> | ||
| * | 
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.
| * | |
| * | |
| * @apiNote A Version 7 UUID features a time-ordered value field derived from the widely | |
| * implemented and well known Unix Epoch timestamp source, the number of milliseconds | |
| * since midnight 1 Jan 1970 UTC, leap seconds excluded. | |
| * | 
| /* | ||
| * UUIDv7 features a time-ordered value field derived from the widely implemented and well- | ||
| * known Unix Epoch timestamp source, the number of milliseconds since midnight 1 Jan 1970 UTC, | ||
| * leap seconds excluded. | ||
| */ | 
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.
| /* | |
| * UUIDv7 features a time-ordered value field derived from the widely implemented and well- | |
| * known Unix Epoch timestamp source, the number of milliseconds since midnight 1 Jan 1970 UTC, | |
| * leap seconds excluded. | |
| */ | 
| * @param session session | ||
| * | ||
| * @return UUID version 7 | ||
| * @see UuidValueGenerator#generateUuid(SharedSessionContractImplementor) | 
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.
| * @param session session | |
| * | |
| * @return UUID version 7 | |
| * @see UuidValueGenerator#generateUuid(SharedSessionContractImplementor) | |
| * Generates a Version 7 {@linkplain UUID}. | |
| * | |
| * @return A Version version 7 {@linkplain UUID}. | |
| * @see UuidValueGenerator#generateUuid(SharedSessionContractImplementor) | 
| 
           Also, clearly we need to address the failures :) Execution failed for task ':hibernate-core:compileTestJava'.
> Compilation failed; see the compiler error output for details. | 
    
          
 One will expect that IDE should know to make basic refactoring things like renaming classes :-)  | 
    
| 
           Applied manually. Thanks!  | 
    
| 
           I'm getting test errors quite consistently. I didn't have a single success of the v6 test so far: Running with jdk-17.0.12+7 on Windows 11 if it matters. I don't know how the implementation works, but it seems broken.  | 
    
| 
           It seems that there is pretty stupid bug :-( I'll check and fix that.  | 
    
| 
           I just ran into another (unrelated but possibly similar) error, which is related to the fact that on Windows, the time source has a precision of 7 digits after the decimal separator.  | 
    
| 
           I've located that problem and will fix it ASAP  | 
    
Jira issue HHH-18377
Implementation of UUID Versioin 6 and UUID Version 7
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.