Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove inaccessible Mongo shard

I have a MongoDB sharded setup with 3 shards: shard0000, shard0001 and shard0002. The machine that runs shard0002 is down now, which causes all my queries to fail. I'd like to temporarily remove shard0002 from my setup and keep working with the first two shards. That should be doable assuming I only use unsharded collections that reside in the first two shards, right?

What I tried first is: db.runCommand({removeshard: 'IP:PORT'}) which obviously doesn't help, because it just puts the shard in draining mode, which will never end (since it's down). Then I tried connected to my config server and did db.shards.remove({_id: 'shard0002'}) on the config DB then restart mongos so it reloads the config. Now whenever I try to do anything I get "can't find shard for: shard0002".

Is there any way to just let Mongo know that I don't care about that shard for now, then re-enable it later when it becomes available.

like image 913
ibz Avatar asked Oct 05 '10 05:10

ibz


People also ask

Does MongoDB shard automatically?

Hashed Sharding involves computing a hash of the shard key field's value. Each chunk is then assigned a range based on the hashed shard key values. MongoDB automatically computes the hashes when resolving queries using hashed indexes.

What is shard key in MongoDB?

The shard key is either a single indexed field or multiple fields covered by a compound index that determines the distribution of the collection's documents among the cluster's shards.


2 Answers

I had a different problem, and I manually removed the shard with:

use config
db.shards.remove({"_id":"shard0002"});
like image 155
mcr Avatar answered Dec 19 '22 00:12

mcr


Manually modify the the shard entry in the config db, then removeshard

like image 26
sdot257 Avatar answered Dec 19 '22 02:12

sdot257