Skip to content

md5 hash the hostname in the native extension#39

Merged
durran merged 1 commit into
mongodb:masterfrom
hudon:hash-hostname
Jul 30, 2015
Merged

md5 hash the hostname in the native extension#39
durran merged 1 commit into
mongodb:masterfrom
hudon:hash-hostname

Conversation

@hudon

@hudon hudon commented Jul 30, 2015

Copy link
Copy Markdown
Contributor

The native extension implementation for next_object_id doesn't match Ruby's. The latter hashes the hostname while the former does not. This patch fixes the native extension to also MD5 hash the hostname.

@amacneil

Copy link
Copy Markdown

For context (and seo for others running into this issue) this bug has been causing a large number of duplicate ID errors for us:

The operation: #<Moped::Protocol::Command @length=81 @request_id=351 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="db.$cmd" @skip=0 @limit=-1 @selector={:getlasterror=>1, :w=>1} @fields=nil> failed with error 11000: "E11000 duplicate key error index: db.collection.$_id_ dup key: { : ObjectId('55ba4acc69702d000100016a') }" See https://github.com/mongodb/mongo/blob/master/docs/errors.md for details about this error.

Investigating further, the hostname portion of the ObjectId from all servers was set to ip-:

> BSON::ObjectId.from_string('55ba4acc69702d000100016a').to_bson[4..6]
=> "ip-"

This happened to be the prefix of all our machines' hostnames, which meant that if any two machines generated an ID in the same second with the same counter, we got an ObjectId clash.

durran added a commit that referenced this pull request Jul 30, 2015
md5 hash the hostname in the native extension
@durran durran merged commit 02c835f into mongodb:master Jul 30, 2015
@durran

durran commented Jul 30, 2015

Copy link
Copy Markdown
Contributor

Thanks. I'll get a release out quickly.

@durran

durran commented Jul 30, 2015

Copy link
Copy Markdown
Contributor

3.2.1 is out with this fix - thanks again.

@hudon hudon deleted the hash-hostname branch July 30, 2015 18:14
@hudon hudon restored the hash-hostname branch July 30, 2015 18:14
@hudon hudon deleted the hash-hostname branch December 5, 2015 06:01
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

Successfully merging this pull request may close these issues.

3 participants