[SERVER-42856] Transactions with write can be sent to the wrong shard Created: 16/Aug/19  Updated: 29/Oct/23  Resolved: 21/Aug/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 4.2.0
Fix Version/s: 4.2.1, 4.3.1

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Randolph Tan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File geo.js    
Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.2
Sprint: Sharding 2019-08-26
Participants:
Linked BF Score: 21

 Description   

Setup:
Collection with hashed shard keys is at version v2, updated at t10

Steps:

  1. Stale mongos starts a transaction with write get SSV, aborts.
  2. Another migration happens, now in version v3, updated at t20.
  3. TxnRouter set with snapshot time to t10 here.
  4. Routing info gets resfreshed to v3 because it was invalidated last time.
  5. Write path gets the routing info based on t10 here
  6. Mongos targets write, correct chunk is selected here.
  7. However, when getting the shard owner of the shard, it will get the shard at t10 because of this
  8. Write request will get sent to the wrong shards, but with correct shard versions since collection routing info is up to date.
  9. We check inside the opObserver if the chunk has moved. However, since we just used the actual document key (and not the hashed value) to find the chunk, it will end up getting the wrong chunk. This will then allow it to pass the "throwIfMoved" check.


 Comments   
Comment by Githook User [ 22/Aug/19 ]

Author:

{'name': 'Randolph Tan', 'email': 'randolph@mongodb.com'}

Message: SERVER-42856 Make the check for chunk moved in the op observer take hashed shard keys into account

(cherry picked from commit 08f836390d61726235e583f46012f43995695c85)
Branch: v4.2
https://github.com/mongodb/mongo/commit/9e5412046b63d1cb8c57a78d0bfffe762ec9ebb1

Comment by Githook User [ 21/Aug/19 ]

Author:

{'email': 'randolph@mongodb.com', 'name': 'Randolph Tan'}

Message: SERVER-42856 Make the check for chunk moved in the op observer take hashed shard keys into account
Branch: master
https://github.com/mongodb/mongo/commit/08f836390d61726235e583f46012f43995695c85

Comment by Randolph Tan [ 16/Aug/19 ]

Attached geo.js (based from geo_center_sphere2.js where this issue was hit in tests).

Generated at Thu Feb 08 05:01:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.