[SERVER-71819] Broadcast collMod command to all shards Created: 03/Dec/22  Updated: 29/Oct/23  Resolved: 12/Sep/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.1, 7.2.0-rc0, 7.0.3, 6.0.12

Type: Bug Priority: Major - P3
Reporter: Vishnu Kaushik Assignee: Pol Pinol
Resolution: Fixed Votes: 0
Labels: shardingemea-qw
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
depends on SERVER-78524 async_rpc util getAllResponsesOrFirst... Closed
is depended on by SERVER-62310 collMod command not sent to all shard... Closed
is depended on by SERVER-75653 Add check for validator rules on chec... Backlog
Duplicate
duplicates SERVER-62310 collMod command not sent to all shard... Closed
Problem/Incident
causes SERVER-81033 Ignore the `collMod` response from th... Closed
Related
is related to SERVER-77307 Denylist schema_validator_with_expr_v... Closed
Assigned Teams:
Sharding EMEA
Backwards Compatibility: Minor Change
Operating System: ALL
Backport Requested:
v7.1, v7.0, v6.0
Sprint: Sharding EMEA 2023-05-29, Sharding EMEA 2023-06-12, Sharding EMEA 2023-06-26, Sharding EMEA 2023-07-10, Sharding EMEA 2023-07-24, Sharding EMEA 2023-08-07, Sharding EMEA 2023-09-04, Sharding EMEA 2023-09-18
Participants:
Linked BF Score: 0
Story Points: 3

 Description   

When we run collMod on a collection in a sharded cluster, the CollModCoordinator runs collMod only on shards that own a chunk. This makes it possible to bypass the effects of collMod under certain conditions.

For example, let's take a two shard set up, only one node in each shard and in the config server. Shard shard-rs0 is the primary shard for the collection we use below. Run the following commands on mongos:

// Create and shard collection.
db.apple.insert({a: 1})
sh.shardCollection('test.apple', {_id: 1})
 
// Disable the balancer so we can get the chunks to stay where we want them
sh.disableBalancing('test.apple')
 
// Let's have two chunks, and I'm going to move both to non-primary shard 'shard-rs1'.
sh.splitAt('test.apple', {_id: 0})
sh.moveChunk('test.apple', {_id: 1}, 'shard-rs1')
sh.moveChunk('test.apple', {_id: -1}, 'shard-rs1')
 
// Turn on schema validation - we see that "collMod" only runs on non-primary 'shard-rs1', because it owns all the
// chunks.
db.runCommand({collMod: "apple", validator: {$jsonSchema: {properties: {a: {bsonType: "int"}}}}})
 
// This doesn't reflect the collMod. My guess is this is because mongos talks to the primary shard
// which never ran collMod.
db.getCollectionInfos()
 
// Schema validation complains, as it should (query runs on non-primary shard):
db.apple.insert({_id: 0, a: "hello"})
 
// Move a chunk back to primary shard.
sh.moveChunk('test.apple', {_id: 1}, 'shard-rs0')
 
// Validation complains, because it is routed to 'shard-rs1':
db.apple.insert({_id: -2, a: "hello"})
// Doesn't complain and insert works, because it is routed to 'shard-rs0':
db.apple.insert({_id: 2, a: "hello"})

In the above example the final statement bypassed the schema validation, which shouldn't happen.

I have not investigated how other collMod behaviors (such as to convert indexes to unique) are affected and if other DDL coordinators have the same problem.



 Comments   
Comment by Githook User [ 17/Oct/23 ]

Author:

{'name': 'Pol Pinol Castuera', 'email': 'pol.pinol@mongodb.com', 'username': 'PolPinol'}

Message: SERVER-71819 Broadcast collMod command to all shards

(cherry picked from commit eec54ec63e557e18f0e8361335b9a39887572b4d)

SERVER-81033 Ignore the `collMod` response from the db primary shard if it has no chunks

(cherry picked from commit 76ef13cd2ef0798606f8387a088a1edff1093d9a)
Branch: v7.1
https://github.com/mongodb/mongo/commit/a332192a120fd0f482ad7c5e6be4fe331b3c38e1

Comment by Githook User [ 04/Oct/23 ]

Author:

{'name': 'Pol Pinol Castuera', 'email': 'pol.pinol@mongodb.com', 'username': 'PolPinol'}

Message: SERVER-71819 Broadcast collMod command to all shards

(cherry picked from commit eec54ec63e557e18f0e8361335b9a39887572b4d)

SERVER-81033 Ignore the `collMod` response from the db primary shard if it has no chunks

(cherry picked from commit 76ef13cd2ef0798606f8387a088a1edff1093d9a)
Branch: v6.0
https://github.com/mongodb/mongo/commit/b707967712ee3fd3cae5431f736e91f665b0133a

Comment by Githook User [ 04/Oct/23 ]

Author:

{'name': 'Pol Pinol Castuera', 'email': 'pol.pinol@mongodb.com', 'username': 'PolPinol'}

Message: SERVER-71819 Broadcast collMod command to all shards

(cherry picked from commit eec54ec63e557e18f0e8361335b9a39887572b4d)

SERVER-81033 Ignore the `collMod` response from the db primary shard if it has no chunks

(cherry picked from commit 76ef13cd2ef0798606f8387a088a1edff1093d9a)
Branch: v7.0
https://github.com/mongodb/mongo/commit/6b4286cab30323314e68773755ac47086136d1d5

Comment by Githook User [ 12/Sep/23 ]

Author:

{'name': 'Pol Pinol Castuera', 'email': 'pol.pinol@mongodb.com', 'username': 'PolPinol'}

Message: SERVER-71819 Broadcast collMod command to all shards
Branch: master
https://github.com/mongodb/mongo/commit/eec54ec63e557e18f0e8361335b9a39887572b4d

Comment by Vishnu Kaushik [ 05/Dec/22 ]

I'm not sure if other backports to 5.0 and lower are required. I'll defer that to the sharding team. Thanks!

Comment by Vishnu Kaushik [ 03/Dec/22 ]

CC: tommaso.tocci@mongodb.com

Generated at Thu Feb 08 06:20:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.