Skip to content
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

oids counter starts at zero; spec says it should be random #2796

Closed
dhasenan opened this issue May 25, 2015 · 7 comments
Closed

oids counter starts at zero; spec says it should be random #2796

dhasenan opened this issue May 25, 2015 · 7 comments

Comments

@dhasenan
Copy link

http://docs.mongodb.org/manual/reference/object-id/ says that the 'counter' field of an object ID should start at a random value. In oids.nim, it starts at 0.

I have a patch for this, and I'm using this issue to get approval from my workplace to commit to Nim.

@flaviut
Copy link
Contributor

flaviut commented May 27, 2015

If your proposed fix uses math.random, it won't be a useful change. It'd essentially expand the clock value to 7 byes, 3 of which would be redundant.

@dhasenan
Copy link
Author

That would only be true if the counter were re-randomized each time the clock changed, and even then not so much.

@dom96
Copy link
Contributor

dom96 commented Apr 4, 2016

What's the status of this?

@andreaferretti
Copy link
Collaborator

The linked documentation reads

The 12-byte ObjectId value consists of:

    a 4-byte value representing the seconds since the Unix epoch,
    a 3-byte machine identifier,
    a 2-byte process id, and
    a 3-byte counter, starting with a random value.

but the implementation in oids.nim is

type
  Oid* = object ## an OID
    time: int32  ##
    fuzz: int32  ##
    count: int32 ##

where fuzz is random but fixed. This does not seem to be too compatible.

Either

  • we update the oids module, or
  • we declare and document that nim oids are unique but not mongo compatible, or
  • we remove oids from the standard library

@andreaferretti
Copy link
Collaborator

I propose that we just remove from the documentation any link with mongodb, since the implementation is not compatible, but unique ids are useful anyway (notice that there is an external library for actual uuids though).

Mongo drivers can implement oids that are actually compatible with the spec

@Araq
Copy link
Member

Araq commented Aug 10, 2018

The module was written for Mongodb though and I ported the C code from it (it looks like Mongo later changed its implementation). No idea why we can't simply fix this and call it a day.

@narimiran narimiran reopened this Jan 16, 2019
narimiran added a commit to narimiran/Nim that referenced this issue Jan 30, 2019
@Araq Araq closed this as completed in 9ac0cbd Jan 30, 2019
@timotheecour
Copy link
Member

timotheecour commented Jan 31, 2019

@Araq

The module was written for Mongodb though and I ported the C code from it (it looks like Mongo later changed its implementation). No idea why we can't simply fix this and call it a day.

that's tracked here: genOid has low entropy (creates lots of 0 bits) · Issue #9741 · nim-lang/Nim

narimiran added a commit that referenced this issue Jan 31, 2019
(cherry picked from commit 9ac0cbd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants