-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
This method allows to create a new OID using a specific epoch time. Mango users really need this feature because their application's logic relies on it in some cases.
That was a hard one...
My team lead, @behackett, raised a concern that constructing OIDs from a timestamp can violate the uniqueness properties of OIDs. It's still useful for queries, but dangerous for inserts. See how pymongo implemented it and the caveats they included. They also zero the non-timestamp fields, which is particularly useful for queries. I think the documentation caveat is useful no matter what. Then there are three broad options (I think) for what to do with the non-timestamp fields (last 8 bytes):
I'm inclined to match what pymongo does. If users want their own special OIDs, they can always generate their own 12-byte strings and pass them as the What do you think? |
Ho right! I will update the documentation. While I agree pymongo does "the right thing", I know some (badly designed) applications which require unique OIDs for the same date. And while the 3 bytes counter has been enough so far, it would be better to use the whole 64 bits like you said. Does it have to be a random number? How about i concatenate 2 special counters randomly initialized? But I also like the possibility of generating "clean" OID with only the date. Maybe I could modify the from_epoch method to accept an optional argument which would tell the function to use zeros. |
I think two counters is really no better than one. For compatibility, how about this as a possible API:
This leaves the default behavior compatible with current practice, gives an option for users to improve the uniqueness property by providing their own random value to pack into the 64-bits of the host+pid+counter fields, and abuses the int-packing to give an easy way to have zeroed host+pid+counter fields for queries. |
I think your API looks good. I'm going to implement it as soon as possible. Note that |
|
This method now supports 3 modes: standard, zeroed and randomized.
I'm sorry -- I think you misunderstood what I meant. I didn't mean that I meant that the second argument should literally be an integer, and that we should pack whatever they give us. If we want to be really nice, we could pack Math::BigInt as well. See The reasons I have for this behavior:
If this feels more daunting to do that you have time for currently, I'm willing to take it forward from here, as I do have strong feelings about the API and I do want this to happen to support Mango::BSON. :-) |
@oliwer, ping. Is this something you want to do or should I take it from here? |
I've amended the method the way I described, more or less, and expanded the documentation a bit. I hope you find this is sufficient for what Mango needs. |
This method allows to create a new OID using a specific epoch time.
Mango users really need this feature because their application's
logic relies on it in some cases.