[SERVER-6491] Prevent dropping shard key index when alternative index doesn't exist Created: 17/Jul/12  Updated: 22/May/23  Resolved: 20/Apr/22

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Sharding
Affects Version/s: 2.0.6, 2.1.2, 2.4.10
Fix Version/s: 6.0.0-rc2, 6.1.0-rc0, 5.0.19

Type: Improvement Priority: Major - P3
Reporter: Spencer Brody (Inactive) Assignee: Randolph Tan
Resolution: Done Votes: 2
Labels: Sharding-EMEA
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Documented
is documented by DOCS-15260 [SERVER] Investigate changes in SERVE... Closed
Duplicate
is duplicated by SERVER-10309 Mongo should not allow removal of sha... Closed
is duplicated by SERVER-21688 Do not allow index for shard key to b... Closed
Problem/Incident
causes SERVER-66264 shardsvrDropIndex should use timeseri... Closed
Related
related to SERVER-64542 shardCollection no-op oplog can be wr... Closed
related to SERVER-67988 dropIndexes is not correctly serializ... Closed
related to SERVER-64950 Use a named ErrorCode when asserting ... Closed
related to SERVER-69492 check_orphans_are_deleted_helpers.js ... Closed
related to SERVER-67299 Prevent dropping shard key index when... Closed
is related to SERVER-76973 Customers still able to drop shard ke... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v6.0, v5.0
Sprint: Sharding 2022-02-21, Sharding 2022-03-07, Sharding NYC 2022-03-21, Sharding NYC 2022-04-04, Sharding NYC 2022-04-18, Sharding 2022-05-02
Participants:
Case:
Linked BF Score: 135

 Description   

This leaves you without an index on the shard key, which can have big performance implications, especially on migrations.



 Comments   
Comment by Githook User [ 22/May/23 ]

Author:

{'name': 'Randolph Tan', 'email': 'randolph@10gen.com', 'username': 'renctan'}

Message: SERVER-6491 Prevent dropping shard key index when alternative index doesn't exist

(cherry picked from commit 8ac94fc68d134eaef7fb3815d25e98ef99f034a3)
Branch: v5.0
https://github.com/mongodb/mongo/commit/8c31e79e63d4d946ae6d150bc61e33d06858f498

Comment by Githook User [ 25/Apr/22 ]

Author:

{'name': 'Randolph Tan', 'email': 'randolph@10gen.com', 'username': 'renctan'}

Message: SERVER-6491 Make dropIndexes take the distlock so it can never run in parallel with shardCollection

(cherry picked from commit 77ffcb1d041dd63b9a8b213183c3b075cb5fca57)
Branch: v6.0
https://github.com/mongodb/mongo/commit/1256b11b0f148f8f5095ba816e18b39f814b4e3d

Comment by Githook User [ 20/Apr/22 ]

Author:

{'name': 'Randolph Tan', 'email': 'randolph@10gen.com', 'username': 'renctan'}

Message: SERVER-6491 Make dropIndexes take the distlock so it can never run in parallel with shardCollection
Branch: master
https://github.com/mongodb/mongo/commit/77ffcb1d041dd63b9a8b213183c3b075cb5fca57

Comment by Githook User [ 16/Mar/22 ]

Author:

{'name': 'Randolph Tan', 'email': 'randolph@10gen.com', 'username': 'renctan'}

Message: SERVER-6491 Prevent dropping shard key index when alternative index doesn't exist
Branch: master
https://github.com/mongodb/mongo/commit/8ac94fc68d134eaef7fb3815d25e98ef99f034a3

Comment by Garaudy Etienne [ 31/Jul/20 ]

Going to create a cloud ticket, asking them to prevent this by graying out the "drop shard key index" in Atlas when there's no alternative index.  

Comment by Asya Kamsky [ 24/Jun/20 ]

Note that there is legitimate times when shard key index can be dropped, that's when there is another index that has the shard key field(s) as its prefix.

Comment by Gianfranco Palumbo [ 05/Feb/15 ]

Tested in 2.4.10:

> sh.status()
--- Sharding Status ---
  sharding version: {
    "_id": 1,
    "version": 3,
    "minCompatibleVersion": 3,
    "currentVersion": 4,
    "clusterId": ObjectId("54d0b6e1297b131595fdabac")
  }
  shards:
    {  "_id": "shard01",  "host": "shard01/gianfranco.local:27018,gianfranco.local:27019,gianfranco.local:27020" }
    {  "_id": "shard02",  "host": "shard02/gianfranco.local:27021,gianfranco.local:27022,gianfranco.local:27023" }
  databases:
    {  "_id": "admin",  "partitioned": false,  "primary": "config" }
    {  "_id": "test",  "partitioned": true,  "primary": "shard01" }
    test.mgendata
      shard key: { "s1": 1 }
      chunks:
        shard01: 18
        shard02: 18
			too many chunks to print, use verbose if you want to force print
 
 
> db.mgendata.getIndexes()
[
  {
    "v": 1,
    "name": "_id_",
    "key": {
      "_id": 1
    },
    "ns": "test.mgendata"
  },
  {
    "v": 1,
    "name": "s1_1_n1_1",
    "key": {
      "s1": 1,
      "n1": 1
    },
    "ns": "test.mgendata"
  }
]
 
> db.mgendata.dropIndex('s1_1_n1_1')
{
  "raw": {
    "shard01/gianfranco.local:27018,gianfranco.local:27019,gianfranco.local:27020": {
      "nIndexesWas": 2,
      "ok": 1
    },
    "shard02/gianfranco.local:27021,gianfranco.local:27022,gianfranco.local:27023": {
      "nIndexesWas": 2,
      "ok": 1
    }
  },
  "ok": 1
}
 
> db.mgendata.getIndexes()
[
  {
    "v": 1,
    "name": "_id_",
    "key": {
      "_id": 1
    },
    "ns": "test.mgendata"
  }
]

Generated at Thu Feb 08 03:11:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.