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

IDs are not necessarily unique #2

Open
wglasshusain opened this issue Oct 14, 2014 · 4 comments
Open

IDs are not necessarily unique #2

wglasshusain opened this issue Oct 14, 2014 · 4 comments

Comments

@wglasshusain
Copy link
Contributor

Hi,

I've got a web service (written in Lusty, using lusty-store-mongo) which creates records in MongoDb.

When i call the web service repeatedly to create records for the same collection and return the id from MongoDb, I see that the object id sometimes repeats.

I wrote a test in Java to rapidly call my web service to repeatedly create records and output the id. Out of every 100 queries, I get 2-10 that have dup ids.

Example (first 10 records created). You can see the 6th id is the same as the first.

13:52:04.138 ID 543d889b636239a227000001
13:52:04.281 ID 543d889b636239a127000001
13:52:04.420 ID 543d889b6362399f27000001
13:52:04.561 ID 543d889b6362399f27000001
13:52:04.701 ID 543d889b6362399f27000001
13:52:04.844 ID 543d889b636239a227000001  - CONFLICTING ID: 543d889b636239a227000001
13:52:04.988 ID 543d889b636239a127000001
13:52:05.127 ID 543d889c636239a127000001
13:52:05.277 ID 543d889c636239a127000001
13:52:05.422 ID 543d889c636239a027000001

The web service itself is simple. It does the following

local allowableFields = {"account",  "project",  "group",  "name",  "roles",  "minUsers", "optionalRoles"}
local record = {}
for _, v in pairs(allowableFields) do
  if inputItem[v] then
    record[v] = inputItem[v]
  end
end

record.created = date(true):fmt('${iso}.000Z')
record.lastModified = date(true):fmt('${iso}.000Z')

store.post(record)

store is a Lusty store object. After this bit of code, it returns record._id.

Looking at the Mongol code, I see that the id includes a timestamp and also a incrementing number. I hypothesize that the number is not correctly incrementing, and that creating a bunch of records in a short time can generate the same id. Does this seem plausible?

It's possible that the issue is also in lusty-store-mongo. I am currently attempting to duplicate this in a test which calls Mongol Resty driver directly, but my Lua skills are a bit rusty and I haven't pulled together the Busted test yet.

@DorianGray
Copy link
Member

I pushed a new version to address this (0.8-2).

The problem was that the resty-mongol driver was getting the process id from the master nginx process instead of the process id from the worker processes.

Try it out!

@DorianGray
Copy link
Member

@wglasshusain Did you get a chance to see if this takes care of your issue?

@wglasshusain
Copy link
Contributor Author

Not yet -- will try it out in the next few days.

Thanks!

WGH

On Mon, Oct 20, 2014 at 3:29 PM, Robert Andrew Ditthardt <
[email protected]> wrote:

@wglasshusain https://github.com/wglasshusain Did you get a chance to
see if this takes care of your issue?


Reply to this email directly or view it on GitHub
#2 (comment)
.

William Glass-Husain /forio | +1 (415) 440 7500 x89 | forio.com
http://www.forio.com/

@wglasshusain
Copy link
Contributor Author

Sadly, my test code still shows this error. I confirmed my vagrant box has only resty-mongol 0.8-2 installed. Rapidly generating 100 records still generates some records with conflicting ids.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants