First, create a MongoDB design drawing for testing:
The figure is clear. Can take my other notes: http://blog.csdn.net/crazyjixiang/article/category/844957 if not clear please leave a message
Replication set is used to avoid data loss on a single node.
The test results are as follows:
Insert 228 million data records on the server. After the insertion is complete, the 162 server is disconnected and then executed in mongos quickly.
> db.users.count()Fri Jul 29 16:05:11 uncaught exception: count failed: { "assertion" : "DBClientBase::findOne: transport error: 10.10.21.162:27017 query: { setShardVersion: \"test.users\", configdb: \"10.7.3.228:27019\", version: Timestamp 5000|1, serverID: ObjectId('4e325735277d2098a18b5cca'), shard: \"set162163228\", shardHost: \"set162163228/10.10.21.162:27018,10.10.21.163:27017\" }", "assertionCode" : 10276, "errmsg" : "db assertion failure", "ok" : 0}
If an exception is thrown, run dB. Users. Count ()
> db.users.count()10000000
It is found that it is normal. 163 is changed to primary.
Then, continue to insert 163 million data, and disconnect the server when the insertion process is interrupted.
The insert operation is normal. After the insertion, we compare the data of the following 164 servers + the data on the 162 servers connected is exactly equal to 2000.
After the two servers are connected again, the data keeps changing and load balancing is ongoing.
NOTE: If an instant power failure occurs in the data center, the data may still be faulty, but this probability is very small.