-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Sharding NYC
-
Fully Compatible
-
ALL
-
-
Sharding NYC 2023-05-01
Recently we've seen a few problems where query parsing in sharded contexts can fail because we are failing to plumb through the let parameters and runtimeConstants: see SERVER-75356 and SERVER-71636. This is a similar bug, but it happens for a delete command only when only the following conditions hold:
- featureFlagUpdateOneWithoutShardKey is enabled
- The collection is sharded
- The delete command does not specify the shard key
- The delete command's predicate refers to a let variable
In this case, we use a code path which is guarded behind featureFlagUpdateOneWithoutShardKey. We call extractShardKeyFromBasicQuery(), passing through the predicate but not the let parameters or runtime constants. This function then attempts to parse the predicate without providing the let parameters or runtime constants on the ExpressionContext, causing parsing to fail with an error like the following:
2023-04-12T21:42:50.853Z assert: command failed: { "ok" : 0, "errmsg" : "Use of undefined variable: target_species", "code" : 17276, "codeName" : "Location17276", "$clusterTime" : { "clusterTime" : Timestamp(1681335770, 82), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } }, "operationTime" : Timestamp(1681335770, 82) } with original command request: { "delete" : "test_coll", "let" : { "target_species" : "Song Thrush (Turdus philomelos)" }, "deletes" : [ { "q" : { "$and" : [ { "_id" : 4 }, { "$expr" : { "$eq" : [ "$Species", "$$target_species" ] } } ] }, "limit" : 1 } ], "lsid" : { "id" : UUID("00eb8ffa-8e7b-45a6-980c-a43e5ec06874") }, "$clusterTime" : { "clusterTime" : Timestamp(1681335770, 82), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } } on connection: connection to localhost:20003
I've provided complete repro instructions in the "Steps to Reproduce" section. This bug does not exist in the release configuration of the server, so it seems like we should fix it as part of the "updateOne without shard key" project which I believe covers delete as well.
The solution should be similar to that from SERVER-75356. Namely, we should thread the let parameters and runtime constants through to the ExpressionContext used to parse the query.
- is related to
-
SERVER-71636 Explain executionStats does not work for $lookup on sharded collection
- Closed
-
SERVER-75356 explain command for a find with $expr and let parameters fails if the collection is sharded
- Closed
-
SERVER-81057 Writes without shard key doesn't work with constants defined in 'let'
- Closed