[SERVER-71676] Updating a document shard key value can fail if the document has a $ prefixed field Created: 29/Nov/22  Updated: 01/Feb/24

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jack Mulrow Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: sharding-nyc-subteam3
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query Optimization
Operating System: ALL
Steps To Reproduce:

Run this test in the shell and the final "assert.commandWorked" will fail:

(function() {
"use strict";
 
const st = new ShardingTest({shards: 2, config: 1});
const dbName = "testDb";
 
const collName = "testColl";
const ns = dbName + "." + collName;
const db = st.getDB(dbName);
 
// Set up a sharded collection with two shards and a chunk on each.
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {skey: 1}}));
assert.commandWorked(st.s.adminCommand({split: ns, middle: {skey: 0}}));
assert.commandWorked(
    st.s.adminCommand({moveChunk: ns, find: {skey: MinKey}, to: st.shard0.shardName}));
assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {skey: 1}, to: st.shard1.shardName}));
 
// Inserting with a dollar prefixed field works.
assert.commandWorked(db.runCommand({
    insert: collName,
    documents: [{skey: -1, dollarPrefixedField: {"$date": "2012-02-29T00:00:00Z"}}]
}));
 
// But an update that uses a transaction to move the document across shards fails with: "unknown
// operator: $date"
assert.commandWorked(db.runCommand({
    update: collName,
    updates: [{q: {skey: -1}, u: {"$set": {skey: 1}}, upsert: false}],
    txnNumber: NumberLong(1),
    lsid: {id: UUID()},
}));
 
st.stop();
})(); 

Sprint: Sharding NYC 2023-02-06, Sharding NYC 2023-02-20, Sharding NYC 2023-03-06, Sharding NYC 2023-03-20, Sharding NYC 2023-04-03, Sharding NYC 2023-04-17, Sharding NYC 2023-05-01, Sharding NYC 2023-05-15, Sharding NYC 2023-05-29, Sharding NYC 2023-06-12, Sharding NYC 2023-06-26, Sharding NYC 2023-07-10, Sharding NYC 2023-07-24
Participants:
Case:
Story Points: 3

 Description   

If an update to a document's shard key value changes the shard that owns the document, the update transparently spawns a transaction to delete the document and insert it on its new owning shard with the update modifications. This transaction will use the current value of the document as the query for the transactional delete, and this will fail if the document contains a "$" prefixed field that isn't a valid query operator, e.g. $date. Confusingly for users this will not fail if the update does not require spawning a transaction.


Generated at Thu Feb 08 06:19:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.