[SERVER-7379] Immutable shardkey becomes mutable Created: 17/Oct/12  Updated: 11/Jul/16  Resolved: 11/Oct/13

Status: Closed
Project: Core Server
Component/s: Sharding, Write Ops
Affects Version/s: 2.2.0
Fix Version/s: 2.5.3

Type: Bug Priority: Critical - P2
Reporter: Kay Agahd Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux 64 bit


Issue Links:
Depends
depends on SERVER-10161 Use new update framework to prevent c... Closed
Duplicate
is duplicated by SERVER-8320 Inserting with a compound shard key r... Closed
is duplicated by SERVER-8830 Able to modify component of shard key Closed
is duplicated by SERVER-8831 Able to unset embedded parts of the s... Closed
is duplicated by SERVER-10161 Use new update framework to prevent c... Closed
Gantt Dependency
Related
related to SERVER-3940 Passing a complete document to update... Closed
is related to SERVER-5710 Update may result in doc without shar... Closed
is related to SERVER-6835 Sharding edge case upserts documents ... Closed
is related to SERVER-9074 Upsert fails with "cannot modify shar... Closed
is related to SERVER-16978 sharding/SERVER-7379.js fails with a ... Closed
Operating System: Linux
Participants:

 Description   

I'm using the following shard key

{"categoryId":1, "store":1, "_id":1}

For testing purposes I only have one document in the collection:

mongos> db.offerChange.find()
{ "_id" : 123, "categoryId" : 9881, "store" : "NEW" }

When I want to update a field, I get correctly an alert "Can't modify shard key's value":

mongos> db.offerChange.update({"_id":123}, {$set:{"store":"NEWEST"}}, true, false)
Can't modify shard key's value. field: store: "NEWEST" collection: offerChange.offerChange

However, I can modify the shard key by executing this:

mongos> db.offerChange.update({"_id":123}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
mongos> db.offerChange.find()
{ "_id" : 123, "categoryId" : 9881, "store" : "NEWEST" }
mongos> 

Also, I could call save to change the shard key again (back):

mongos> db.offerChange.save({"categoryId":9881, "store":"NEW","_id":123})
mongos> db.offerChange.find()
{ "_id" : 123, "categoryId" : 9881, "store" : "NEW" }
mongos> 

Now, when I try to add a second shard key field to the query, I get the same but differently expressed correct alert:

mongos> db.offerChange.update({"_id":123,"store":"NEW"}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
cannot modify shard key for collection offerChange.offerChange, found new value for store

However, when I replace the second by the third shard key field in the query, the update works again:

mongos> db.offerChange.update({"_id":123,"categoryId":9881}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
mongos> db.offerChange.find()
{ "_id" : 123, "categoryId" : 9881, "store" : "NEWEST" }

I asked already in the mongoDB forum but nobody answered so far.
https://groups.google.com/group/mongodb-user/browse_thread/thread/300e0ff4676cb30b?hl=de&noredirect=true&pli=1

As I think that's rather a bug than a feature, I opened this bug report.



 Comments   
Comment by Githook User [ 26/Feb/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-7379 re-enable tests in shard_key_immutable.js
Branch: master
https://github.com/mongodb/mongo/commit/f4c7d400c8f938374474a37cde54e36168e60b26

Comment by Scott Hernandez (Inactive) [ 18/Oct/13 ]

Commit: https://github.com/mongodb/mongo/commit/bfead9163f1cd1ca06d7c358a93fedbe48e9f512

Comment by auto [ 10/Oct/13 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@10gen.com'}

Message: SERVER-7379 Loosen some overtight aliasing checks in debug builds of mutable
Branch: master
https://github.com/mongodb/mongo/commit/1ecabbf312ca97c1c64e0faa315ee3c860ad2b26

Comment by auto [ 10/Oct/13 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@10gen.com'}

Message: SERVER-7379 Fix up nits in shard_key_immutability.js test
Branch: master
https://github.com/mongodb/mongo/commit/dc2c5c5b81e96d19b466d21cba3da03549a1994b

Comment by auto [ 02/Jul/13 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-7379 Immutable shardkey becomes mutable

Added test cases (commented out currently failing ones).
Branch: master
https://github.com/mongodb/mongo/commit/718012dbfc5393d0f74ba5d8c947d85dd1676ece

Comment by Scott Hernandez (Inactive) [ 21/Feb/13 ]

The new $setOnInsert now becomes a logical $set if the result is an insert.

Comment by Randolph Tan [ 21/Dec/12 ]

Passes through a different code path compared to SERVER-5710. Naive checking would break things like:

// shard key: { x: 1, y: 1 }
db.user.update({ x: 1 }, { x: 1, y: 2 }, true);

This is because mongos doesn't know whether doc that matches

{ x: 1 }

exists or not. In other words, if this is actually an upsert, then this should be allowed, but if not, then not allowed. But mongos can't tell whether this will end up as a normal update or upsert.

Comment by Randolph Tan [ 17/Oct/12 ]

Fully reproducible, with slightly different (worse) outcome in the latest version (git 823da97015a5bc950708ff5c565583cc0c6ea25b):

1. update fails silently (even gle gives you nothing) on this case:

mongos> db.offerChange.update({"_id":123}, {$set:{"store":"NEWEST"}}, true, false)
Can't modify shard key's value. field: store: "NEWEST" collection: offerChange.offerChange

2. There is now no warning for this case and the shard key values will be modified!

mongos> db.offerChange.update({"_id":123,"store":"NEW"}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
cannot modify shard key for collection offerChange.offerChange, found new value for store

Generated at Thu Feb 08 03:14:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.