-
Notifications
You must be signed in to change notification settings - Fork 0
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
misc oids #431
Comments
var t = ...
proc genOid*(): Oid =
## Generates a new OID.
t = getTime().toUnix.int32
var i = int32(atomicInc(incr))
... => let t = ...
proc genOid*(): Oid =
## Generates a new OID.
var t = getTime().toUnix.int32
var i = int32(atomicInc(incr))
... |
var
t = getTime().toUnix.int32
seed = initRand(t)
incr: int = seed.rand(0x7fff)
let fuzz = int32(seed.rand(high(int32))) (in https://github.com/nim-lang/Nim/pull/16203/files) |
instead maybe: in |
|
EDIT: see https://github.com/mongodb/mongo/blob/master/src/mongo/bson/oid.cpp which uses:
=> SecureRandom should be ported and defined in std/random |
instead, make sure there's no overflow by using uint throughout (and/or cast as needed) note: can be seen with: when defined case5:
var incr: int = 0x7fff
proc main =
while true:
var i = int32(atomicInc(incr))
main() which quickly overflows notemongodb oid makes no guarantee of increasing ids, so wrap-around behavior (instead of raising overflow error) is fine; see https://stackoverflow.com/questions/31057827/is-mongodb-id-objectid-generated-in-an-ascending-order |
controversial; EDIT: ignore for now since https://github.com/mongodb/mongo/blob/master/src/mongo/bson/oid.cpp also uses a random number not generated from processid/machine id we should use what's recommended in https://www.mongodb.com/blog/post/generating-globally-unique-identifiers-for-use-with-mongodb
in particular, this needs to be implemented:
instead of: note:another doc https://docs.mongodb.com/manual/reference/method/ObjectId/ just mentions links
EDIT:
|
|
|
|
links
The text was updated successfully, but these errors were encountered: