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

Comments

Projects
None yet
7 participants
@dhasenan
Copy link

dhasenan commented May 25, 2015

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Author

dhasenan commented May 27, 2015

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

@Araq Araq added the Stdlib label May 27, 2015

@dom96 dom96 added the Easy label Apr 4, 2016

@dom96

This comment has been minimized.

Copy link
Member

dom96 commented Apr 4, 2016

What's the status of this?

@andreaferretti

This comment has been minimized.

Copy link
Collaborator

andreaferretti commented Aug 1, 2018

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

This comment has been minimized.

Copy link
Collaborator

andreaferretti commented Aug 10, 2018

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

This comment has been minimized.

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.

@dom96 dom96 added the Hacktoberfest label Oct 2, 2018

@narimiran narimiran closed this Jan 10, 2019

@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 in 9ac0cbd Jan 30, 2019

@timotheecour

This comment has been minimized.

Copy link
Contributor

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

fixes #2796 (#10500) [backport]
(cherry picked from commit 9ac0cbd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment