-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
Fully Compatible
-
ALL
-
v8.2, v8.0, v7.0, v6.0
-
-
200
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
0
ISSUE DESCRIPTION AND IMPACT
On sharded clusters in the presence of moveChunk operations, specific aggregation queries including a renaming stage on the shard key as well as a subsequent disjunction ($or) expression on said renamed shard key, may produce duplicate or boundedly stale results.
Example:
The collection has a document where the field ‘a’ is used as the shard key. Running a query that renames 'a' to 'b' and includes it in a disjunction, while chunk migrations are in progress, the query may return duplicate or stale results. In the provided example we explicitly force ‘split’ and ‘moveChunk’ operations which under normal operation, the server performs automatically.
Assuming that we have two shards "shard001", "shard002"
const docs = [ {_id: 0, shardKey: 6, data: NumberInt(0)}, {_id: 1, shardKey: 0, data: NumberInt(0)}, ]; db.coll.insert(docs); coll.createIndex({ shardKey: 1 }); sh.shardCollection("coll", { shardKey: 1 }); sh.splitAt("coll", { shardKey: 3 }) sh.moveChunk("coll", { shardKey: 6 }, "shard001") const query = [ {$project: {renamedShardKey: "$shardKey"}}, {$match: {$or: [{renamedShardKey: 6, data: {$ne: 1}}]}}, ]; coll.aggregate(query) // Result: [ { "_id" : 0, "renamedShardKey" : 6 }, { "_id" : 0, "renamedShardKey" : 6 } ] // (duplicate result)
REMEDIATION AND WORKAROUNDS
Users are recommended to upgrade to the fixed versions. Alternatively, ensure that no orphans exist, by enforcing ‘_waitForDelete: true’ for moveChunks operations.
—-----------------------------------------------------
Original description
In the repro attached, we insert two documents into a collection and then shard the collection. Then we move a chunk so that each shard owns a document, but one shard has an orphaned document.
After running the query in the repro, we see a document appear twice, because the query does not have a shard filter stage so the orphaned document is included in the results.
- is related to
-
SERVER-110219 Denylist agg_orphan_filtering_renamed_shardkey.js from multiversion testing
-
- Closed
-
- related to
-
SERVER-94315 Shard filtering bug with collation
-
- Closed
-