-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Add generation of COMB UUID's #43
Conversation
@aztech-dev This appears to be failing on HHVM only, with this error:
|
Actually, I ran more tests it's not an HHVM only error, Quickfix is to revert to using float based microtime with rounding to ms precision. I'm a bit busy these days with non-OSS work (bills gotta be paid...), but I'll try to clear some time today to investigate a bit more and push a fix. |
Finally got around to fixing the implementation. I'm using a 0.00001 seconds precision, which should be safe for ~89 years (2**48 / (365 * 86400 * 100000)), lest I am wrong in my math. Going down to 0.000001 feels a bit short (8.9 years), though if you feel it's safe to go down that path, I'll amend my commit to do so. |
Sorry. I must have missed this. I'll take a look this week. |
No worries. Thanks for the update :)
|
Speaking of oblivion :p still havent had time to review ? Let me know if anything needs changing |
This looks good to me. I'm sorry for taking so long to review it. I think v3 might be in a good place now. I need to go through a clean up some documentation and make sure we've got good code coverage. Once that's done, I think I'll be able to cut a release. Thanks! |
No worries :) I admit I didnt really push test coverage up, but let me know if you need a hand with that considering your schedule seems tight these days. |
@ghola As I mentionned in another comment, the original intent was to have a third optional parameter in the constructor's signature in case some users wanted to change the precision of the timestamp. I'm open to debate as to whether this is really useful, and if not, it should be a constant, otherwise the missing parameter on the constructor should be added:
|
@aztech-dev Yep, I read that comment. I side with making it a constant. If it's not easy to come up with a scenario in which having it as a parameter would be useful or if noone needed/requested it there is no point in implementing it like that ... YAGNI. |
I'm quite OK with either approach actually :) |
@aztech-dev, I see the use of Trying to wrap my head around this math to understand it… The contents of this
Most of the time,
However, if the hex value of timestamp is already longer than 12 bytes, then no padding will take place and the Now, the timestamp is being generated with the following code:
So, in order to achieve a return value of
So, that puts the high-end boundary date at Does that sound correct? |
Looks right :) |
Pardon me to jump in there, but I'm interested in sequential uuid for time-series. Is there anyway to get the date, time and millisecond out of this generated Uuid ? |
Dismiss my previous message, I was hacking a bit and found the TimestampFirstCombCodec... then everything else suddenly made sense. But on another question: Is it a good idea to keep this under uuid v4 ? As it seems to me that this is not exactly a v4 right ? And shouldn't it be better if it could provide the timestamp part ? Right now, we're face the error of v4 when requiring the time part. |
A COMB UUID is a combined (hence "COMB") random UUID with timestamp. Its format is defined in this article by Jimmy Nilsson. The goal of a COMB UUID is to replace the least significant bytes of the node field with the current timestamp, attempting to to compensate for the reduced clustering in database indexes. It's not an end-all-be-all solution, but it's an option. You're right that it's not exactly a v4 UUID, but it is based on a v4 UUID. And it's definitely not a v1 UUID. You can create one like this: $factory = new UuidFactory();
$generator = new CombGenerator(
$factory->getRandomGenerator(),
$factory->getNumberConverter()
);
$factory->setRandomGenerator($generator);
$combUuid = $factory->uuid4(); Then, I'd recommend using a You might also be interested in PR #118, which introduces a codec to store v1 UUIDs in an optimized way for InnoDB tables in MySQL. I'm waiting to reproduce the benchmarks found in this Percona blog post before merging the PR. |
No description provided.