f4b6a3 / uuid-creator

UUID Creator is a Java library for generating Universally Unique Identifiers.
MIT License
410 stars 44 forks source link

TimeOrdered UUID creator generate out-of-order values #69

Closed tri-bao closed 2 years ago

tri-bao commented 2 years ago

I am using version 4.6.1 (latest for the time of writing) and making the following test

    public static void main(String[] args) {
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            UUID smaller = UuidCreator.getTimeOrderedWithMac();
            UUID bigger = UuidCreator.getTimeOrderedWithMac();
            Validate.isTrue(smaller.compareTo(bigger) < 0,
                    "\n%s\n%s", smaller, bigger);
        }
    }

When running that, I quickly get the assertion error. For example the 2 following IDs

1ecf7ad4-11c9-6d7f-9db5-02429e17b126
1ecf7ad4-11c7-6670-9db6-02429e17b126

Is it possible with that generator?

fabiolimace commented 2 years ago

Very interesting!

Fortunately, the clock sequence has been incremented from 00000000-0000-0000-9db5-000000000000 to 00000000-0000-0000-9db6-000000000000 to avoid duplicates.

On my PC it happened after 80 million in loop, simulating a huge batch.

I'll try to fix it after work.

fabiolimace commented 2 years ago

@tri-bao

I found a solution to the problem.

I've also included a new unit test based on your example.

The fix will be available soon in v5.0.0.

tri-bao commented 2 years ago

thanks a lot @fabiolimace Looking forward to v5.0.0

fabiolimace commented 2 years ago

Released v5.0.0.

Thanks for your report!