5

I have a 200gb data base on a sharded four node cluster and and I would like to drop the databse and delet all the files associated to it from the node. I am connecting to my mongos and call dropDatabase on it. The system comes back with ok but if call show dbs, it will show the database again and shows that it is still occupying the 200gb. What I am doing wrong?

1
  • In my case I should disconnect database clients in order to drop it. Commented Jun 2, 2018 at 20:25

2 Answers 2

13

I think you are running into this issue:

https://jira.mongodb.org/browse/SERVER-4804

In most cases it seems like the database is in fact removed but the mongos still reports it as being there. You can verify it is gone by either trying to use the DB and getting an error or by logging into the shards directly and checking.

The bug refers to issues with dropping databases while a migration is happening. You can workaround the cause of the issue by doing something like this (sub in your own dbname):

mongos> use config
switched to db config

// 1. stop the balancer
mongos> db.settings.update({_id: "balancer"}, {$set: {stopped: true}}, true)

// 2. wait for in-progress migrations to finish, this may take a few seconds
mongos> while (db.locks.findOne({_id: "balancer", state: {$ne: 0}}) != null) { sleep(1000); }

// 3. now you can safely drop the database
mongos> use <dbname>
switched to db <dbname>
mongos> db.dropDatabase()
{ "dropped" : "<dbname>", "ok" : 1 }

You may want to run the flushRouterConfig on the mongoses to refresh the config info:

mongos> use config
switched to db config
mongos> var mongoses = db.mongos.find()
mongos> while (mongoses.hasNext()) { new Mongo(mongoses.next()._id).getDB("admin").runCommand({flushRouterConfig: 1}) }
{ "flushed" : true, "ok" : 1 }

Of course, the real fix will only come along when the fix is committed - looks like it is targeted for 2.1

If you are in a broken state, you can try this, but it is tricky:

To "reset" the sharding metadata to recover from this issue, please try to do the following

First, stop the balancer (as above) and wait for migrations to finish (also as above) Next, ensure there is no activity from the app servers on the database in question

Now, ensure that there are no collection entries in config.collections for namespaces beginning with "TestCollection." If so, remove those entries through a mongos:

mongos> use config
mongos> db.collections.find({_id: /^TestCollection\./})
// if any records found, delete them
mongos> db.collections.remove({_id: /^TestCollection\./})

Next up, ensure there is no database entry in config.databases for "TestCollection", and if so, remove it through mongos:

mongos> use config
switched to db config
mongos> db.databases.find({_id: "TestCollection"})
// if any records found, delete them
mongos> db.databases.remove({_id: "TestCollection"})

Now, ensure there are no entries in config.chunks for any namespaces in the database (like the default test namespace). If there are any, remove through mongos:

mongos> use config
switched to db config
mongos> db.chunks.find({ns: /^test\./})
// if any records found, delete them
mongos> db.chunks.remove({ns: /^test\./})

Then, flushRouterConfig on all mongoses:

mongos> use config
switched to db config
mongos> var mongoses = db.mongos.find()
mongos> while (mongoses.hasNext()) { new Mongo(mongoses.next()._id).getDB("admin").runCommand({flushRouterConfig: 1}) }
{ "flushed" : true, "ok" : 1 }
...

Finally, manually connect to each shard primary, and drop the database on the shards (not all shards may have the database, but it's best to be thorough and issue the dropDatabase() call on all

Regarding in-progress migrations, you can use this snippet:

// 2. wait for in-progress migrations to finish, this may take a few seconds
mongos> while (db.locks.findOne({_id: "balancer", state: {$ne: 0}}) != null) { sleep(1000); }

When done, don't forget to reenable the balancer:

mongos> use config
switched to db config

mongos> db.settings.update({_id: "balancer"}, {$set: {stopped: false}}, true)
Sign up to request clarification or add additional context in comments.

7 Comments

Still I can not delet the db. Load balancer is not going.
I think that means that the sharding meta data from this collection might need to be manually corrected, likely because you ran into the bug already - the procedure I outlined is a workaround against the bug but doesn't fix the issue if you've already run into it. In order to fix the sharding metadata, you have to stop the balancer as above, then stop all traffic, then manually alter the config databsase (nto for the faint of heart). Finally, once you have done that you do a flush router config.
If manually fixing the config DB is something you want to try, post the collection name and I'll see what I can do about coming up with a list of instructions.
Sure, the collection name is "TestCollection".
This happened to me again now and do not how to fix it.
|
4

I had this exact same problem, and discovered that issuing the db.dropDatabase as a regular user failed silently but doing the same as sudo worked, in case that helps anyone.

1 Comment

I voted this up but then found out it didn't work sorry. My issue was another process still writing records meant it kept reappearing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.