[SERVER-60543] Change streams can output events in a different order for multi shard transactions Created: 07/Oct/21 Updated: 06/Dec/22 Resolved: 08/Oct/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Randolph Tan | Assignee: | [DO NOT USE] Backlog - Sharding NYC |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Sharding NYC
|
| Operating System: | ALL |
| Participants: |
| Description |
|
Changestreams orders events from txn by the clusterTime of the commitTransaction. But the order of when commit transaction occurs in shard is orthogonal to the order of when individual ops where issued. For example, in the case of changing the shard key of a document. This will involve deleting document on shardA and inserting the document with the new shard key on shardB under a single transaction. It is possible that commit can happen on shardB first, resulting in the change streams showing the insert first instead of the delete. |
| Comments |
| Comment by Randolph Tan [ 08/Oct/21 ] |
|
It turns out that the document key for change streams give you _id + shard key. So even if the insert came before the delete, they will have different document key (since shard key was changed). That means that consumer of change stream can use this information so it won't accidentally delete the document with the new shard key. |