Can't delete an Shard

I am doing M103: Basic Cluster Administration from MongoDB University.

During the chapter “Setting Up a Sharded Cluster” I successfully configured one Shard. Then in next LAB “Chapter 3: Sharding Lab - Configure a Sharded Cluster” asked to add another shard, which I did it successfully. As their are two shard added in same mongos while run the validate the script it’s return a message.

validate_lab_first_sharded_cluster

Mongos not configured correctly - make sure you have only added one shard to
your cluster.

I tried to remove the old shard, which is also not getting removed, it remain in “draining ongoing” state. I tried to see the mongodb documentation but not able to figure out properly.

I am new in MongoDB, if anyone can help me. Below is the removeshard output

MongoDB Enterprise mongos> db.adminCommand( { removeShard: “m103-example” } )
{
“msg” : “draining ongoing”,
“state” : “ongoing”,
“remaining” : {
“chunks” : NumberLong(0),
“dbs” : NumberLong(3)
},
“note” : “you need to drop or movePrimary these databases”,
“dbsToMove” : [
“m103”,
“newDB”,
“test”
],
“ok” : 1,
“operationTime” : Timestamp(1578886498, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1578886498, 1),
“signature” : {
“hash” : BinData(0,“cKZMZd4580YsaLBTA3lx7xEWHYc=”),
“keyId” : NumberLong(“6781065834904158234”)
}
}
}
MongoDB Enterprise mongos>

Please check this link

Removing a Shard from a sharded cluster

I think it takes time depending on data/network
What is the current status?

1 Like

Hi @Kaushik_76938,

Yes, it takes time as the data would be getting migrated to the remaining shard.

Please let me know if you are still facing any issue.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

How long will draining take? I accidentally created a set with the m103-example name during the lecture and have tried to delete that in the lab as I have configured everything else. But mine’s been draining for 40 mins

MongoDB Enterprise mongos> sh.status()                                                              
--- Sharding Status ---                                                                             
  sharding version: {                                                                               
        "_id" : 1,                                                                                  
        "minCompatibleVersion" : 5,                                                                 
        "currentVersion" : 6,                                                                       
        "clusterId" : ObjectId("5e5bf92acf58d3c64d5ecfde")                                          
  }                                                                                                 
  shards:                                                                                           
        {  "_id" : "m103-example",  "host" : "m103-example/192.168.103.100:27011,m103:27012,m103:270
13",  "state" : 1,  "draining" : true }                                                             
        {  "_id" : "m103-repl",  "host" : "m103-repl/192.168.103.100:27002,192.168.103.100:27003,m10
3:27001",  "state" : 1 }                                                                            
  active mongoses:                                                                                  
        "3.6.17" : 1                                                                                
  autosplit:                                                                                        
        Currently enabled: yes                                                                      
  balancer:                                                                                         
        Currently enabled:  yes                                                                     
        Currently running:  yes                                                                     
        Failed balancer rounds in last 5 attempts:  5                                               
        Last reported error:  Could not find host matching read preference { mode: "primary" } for s
et m103-example                                                                                     
        Time of Reported error:  Sun Mar 01 2020 21:34:22 GMT+0000 (UTC)                            
        Migration Results for the last 24 hours:                                                    
                No recent migrations                                                                
  databases:                                                                                        
        {  "_id" : "applicationData",  "primary" : "m103-repl",  "partitioned" : false }            
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }                         
                config.system.sessions                                                              
                        shard key: { "_id" : 1 }                                                    
                        unique: false                                                               
                        balancing: true                                                             
                        chunks:                                                                     
                                m103-example    1                                                   
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : m103-e
xample Timestamp(1, 0)                                                                              
        {  "_id" : "testDatabase",  "primary" : "m103-repl",  "partitioned" : false }               
                                                                                                    
MongoDB Enterprise mongos>                                                                          

@Jonathon_93506, save yourself some time and:

  1. Shutdown all three nodes of the config server replica set
  2. Delete the data files of all three nodes of the config server replica set
  3. Startup the config server replica set
  4. Connect to the mongos and add the correct shard
3 Likes