movePrimary and locking dbs

30 views
Skip to first unread message

dberry

unread,
Jul 18, 2017, 4:49:03 PM7/18/17
to mongodb-user
I have 2 replica sets that have some sharded databases and I am attempting to migrate to a standard 3 box replica set without sharding.

MongoDB 2.6.9
Here is sh.status()

--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "version" : 4,
    "minCompatibleVersion" : 4,
    "currentVersion" : 5,
    "clusterId" : ObjectId("520d987c7a2704256a159b7e")
}
  shards:
    {  "_id" : "data1",  "host" : "data1/1.1.1.1:27017,1.1.1.2:27017,1.1.1.3:27017" }
    {  "_id" : "data2",  "host" : "data2/1.1.1.4:27017,1.1.1.5:27017,1.1.1.6:27017" }
  databases:
    {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
    {  "_id" : "staging",  "partitioned" : true,  "primary" : "data2" }
        staging.content.chunks
            shard key: { "files_id" : 1 }
            chunks:
                data1    1
                data2    1
            { "files_id" : { "$minKey" : 1 } } -->> { "files_id" : ObjectId("XXXXXXXXXXXXXXX") } on : data1 Timestamp(2, 0)
            { "files_id" : ObjectId("XXXXXXXXXXXXXXXXXX") } -->> { "files_id" : { "$maxKey" : 1 } } on : data2 Timestamp(2, 1)
    {  "_id" : "production",  "partitioned" : true,  "primary" : "data2" }
        production.content.chunks
            shard key: { "files_id" : 1 }
            chunks:
                data2    3856
                data1    21109
            too many chunks to print, use verbose if you want to force print
    {  "_id" : "test",  "partitioned" : false,  "primary" : "data2" }
    {  "_id" : "local",  "partitioned" : false,  "primary" : "data1" }
    {  "_id" : "alpha-staging",  "partitioned" : false,  "primary" : "data2" }
    {  "_id" : "beta-staging",  "partitioned" : false,  "primary" : "data2" }
    {  "_id" : "alpha-production",  "partitioned" : false,  "primary" : "data1" }
    {  "_id" : "beta-production",  "partitioned" : false,  "primary" : "data1" }



The first task would be to migrate the data to one partition using movePrimary so for example I would run  db.runCommand( { movePrimary:"beta-production", to:"data2"})

My question is this:  Would I be able to continue to write to the 'bat-production' database while it is being moved?  If not, what other solutions are there for a 'live' migration? 

For the sharded dbs(staging,production) do I run movePrimary and then removeShard "data1"?

-dave






Kevin Adistambha

unread,
Aug 7, 2017, 12:28:03 AM8/7/17
to mongodb-user

Hi Dave

It's been some time since you posted this question. Have you found a method to unshard your deployment?

Would I be able to continue to write to the ‘bat-production’ database while it is being moved?

Unfortunately the short answer is no.

This is described in detail in the Considerations section in the movePrimary page. Specifically this sentence regarding an unsharded collection: “Avoid accessing an un-sharded collection during migration. movePrimary does not prevent reading and writing during its operation, and such actions yield undefined behavior.”

For the sharded dbs(staging,production) do I run movePrimary and then removeShard “data1”?

Yes you can perform a movePrimary then removeShard to remove the data1 shard. However, I believe currently there is no supported method to unshard a collection without downtime. mongodump and mongorestore may be the most straightforward method to migrate from a sharded cluster to a replica set.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages