Jack
Jack

Reputation: 5890

MongoDb:Is there better way to copy production environment data to testing environment

Now I have two shards:shard3(16g),shard4(15g) and three machines: the deploy like this: 10.10.10.5:(mongoS,configureserver,shard3 primary,shard4 primary) 10.10.10.6:(mongoS,configureserver,shard3 secondary,shard4 secondary) 10.10.10.7:(mongoS,configureserver,shard3 arbitor,shard4 arbitor)

now I want to make a performance testing(about adding new shards),I know I can't use the production environment to test since that will impact the production performance,So I want to copy all of the data to my testing three machines:20.20.20.5,20.20.20.6 and 20.20.20.7,I read the manual book but can't find a better way,So dear guys could you please give me an advice.

by the way,ask two little questions:First:like my production environment,how do I change the arbitor node to secondary,i.e I want change 10.10.10.7 to secondary shards,because I wanna 10.7 share the read pressure with 10.6. Second:how do I indicate the Mongos read primary node but secondary node,you know the mongoS writes on primary while read on secondary,but I wanna both read and write on primary node for getting the newest data immediately. Thanks inadvance Jack

Upvotes: 2

Views: 1150

Answers (2)

ChadsworthIII
ChadsworthIII

Reputation: 106

As long as you have a primary up and a majority of your replica set, the replica set will be writable. So naturally, as long as the primary is not overloaded and you have not taken down 2 out of 4 of your nodes, you will be able to write to the primary. It just will only replicate to the majority of the nodes that are up.

In general, we try to discourage even numbered replica-sets so I would take the arbiter offline and stick to your 3 replica sets. This is because you really don't win anything from having the arbiter. If 2 nodes fail either way you do not have a majority and the replica set will become read only. If one node goes down you will still be up for writes. The arbiter doesn't help anything in an even number set.

When you tried to perform these queries that went to only one secondary, was the new secondary all caught up datawise? If it was in "Recovery" state, then it's possible that the reads would not have gone to it yet since it had not replicated all of the data. Aside from that, there are ways to specify read preferences.

Documentation on all of the different read preferences and how to use them can be found here: http://docs.mongodb.org/manual/applications/replication/#read-preference

Upvotes: 0

ChadsworthIII
ChadsworthIII

Reputation: 106

You should look at the following documentation: http://www.mongodb.org/display/DOCS/Import+Export+Tools. You can likely use mongoexport and mongoimport for what you want to do. Or you can also use mongodump & mongorestore. This will allow you to backup and restore your data onto the testing environment.

First question: You Can't "convert" an arbiter into a secondary. The only real way to do this would be to add a new node to the replica-set, and then take down the arbiter and later remove it from the replica-set. You can add a new mongod to the replica-set using rs.add() on an existing replica set node. You do it in this order to avoid downtime. If you don't mind downtime, then order doesn't particularly matter. Documentation on adding a node to a replica set can be found here: http://www.mongodb.org/display/DOCS/Replica+Sets+-+Basics

Also, if you are doing readScaling and using SlaveOK() it's important you keep in mind that if there is replication lag from the primary to either of the secondaries, there is the potential for you to read stale data. If this is acceptable for your application than its fine, but it's important for you to realize that if you simultaneously query two nodes in a replica-set, you may read in two different values for the same query based on replication lag.

Second Question: If you want to always only read/write from the primary than you should not run with SlaveOK. SlaveOK off is the default, but if you already turned it on just call it again passing in false.

Upvotes: 2

Related Questions