How does MongoDB do both, and copy at the same time?

For scaling / fault tolerance, mongodb uses a "replica set" where there is a primary and one or more secondary servers. Primary is used for recording. Secondary are used for reading. This is pretty much the primary slave pattern used in SQL programming. If the primary decreases, the secondary in the secondary cluster takes its place. Thus, the issue of horizontal scaling and fault tolerance will be taken care of. However, this is not a solution that makes you stunned. A true fragment contains only a fraction of all the data, so if the secondary in the replica set is a fragment, how can it qualify as primary when it does not have all the data needed to service requests?

Shouldn't we have a replica set for each of the fragments?

This is obviously a beginner, so a link that visually or otherwise illustrates how to do this will be useful.

+6
source share
3 answers

Your assumption is true, each fragment contains a separate set of replicas. When a write request arrives, MongoS finds the correct fragment for it based on the fragment key, and the data is written to Primary from the replica set contained in that fragment. This leads to scaling of the record, since the (selected) fragment key must distribute the records across all your fragments.

+3
source

A shard is the sum of primary and secondary (a set of replicas), so yes, you will need to set a replica in each shard.

Part of all data is stored in primary form and shared with secondary to maintain consistency. If the primary output is disabled, the secondary is selected as the new primary and has the same data as its predecessor in order to start work immediately. This means that data with private data is still present and not lost.

+1
source

Typically, you plan to separate fragments to separate replica sets. See http://docs.mongodb.org/manual/core/sharded-clusters/ for an overview of MongoDB shards.

0
source

All Articles