File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 11# pylint: disable=missing-docstring,redefined-outer-name
2+ import threading
3+ import time
24from datetime import datetime
35
46import pytest
@@ -68,3 +70,28 @@ def test_create_collection_with_collation_with_shard_key_index_prefix(
6870 )
6971
7072 t .compare_all_sharded ()
73+
74+ @pytest .mark .parametrize ("phase" , [Runner .Phase .APPLY , Runner .Phase .CLONE ])
75+ def test_shard_key_update_duplicate_key_error (t : Testing , phase : Runner .Phase ):
76+ """
77+ Test to reproduce pcsm duplicate key error when handling shard key updates
78+ """
79+ db_name = "test_db"
80+ collection_name = "test_collection"
81+ coll = t .source [db_name ][collection_name ]
82+ t .source .admin .command ("shardCollection" , f"{ db_name } .{ collection_name } " , key = {"key_id" : 1 })
83+ coll .insert_one ({"key_id" : 0 , "name" : "item_0" , "value" : "value_0" })
84+ def perform_shard_key_updates ():
85+ num_updates = 20
86+ for i in range (1 , num_updates + 1 ):
87+ key_id = 100 + i
88+ new_key_id = 5000 + i
89+ coll .insert_one ({"key_id" : key_id , "name" : f"test_doc_{ i } " , "value" : f"value_{ key_id } " })
90+ coll .update_one ({"key_id" : key_id }, {"$set" : {"key_id" : new_key_id , "shard_key_updated" : True }})
91+ time .sleep (0.05 )
92+ update_thread = threading .Thread (target = perform_shard_key_updates )
93+ update_thread .start ()
94+ with t .run (phase ):
95+ update_thread .join ()
96+ time .sleep (5 )
97+ t .compare_all_sharded ()
You can’t perform that action at this time.
0 commit comments