Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MongoDB practice (11) Sharding fragmentation (part I)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This is a large amount of data horizontally extended database cluster system data sub-table stored in each node of sharding.

Users can easily build a distributed MongoDB cluster through simple configuration.

The data chunking of MongoDB is called chunk. Each chunk is a continuous data recorder in Collection.

If the maximum size is 200MB, a new data block is generated.

To build a MongoDB Sharding Cluster, you need three roles

1 、 Shard Server

That is, each Shard that stores the actual data can be a mongod instance or a set of mongod instances.

The composition of the Replica Set. In order to implement the auto-failoverMongoDB within each Shard, it is officially recommended that each Shard

For a group of Replica Set.

2 、 Config Server

In order to store a particular collection in multiple shard, you need to specify a shard key for that collection

For example, {age: 1} shard key can determine which chunk the record belongs to. Config Servers is used to store

Configuration information of all shard nodes, shard key range of each chunk, distribution of chunk in each shard,

Sharding configuration information for all DB and collection in the cluster.

3 、 Route Process

This is a front-end routing client that accesses from this and then asks Config Servers which Shard to query or

Save the record, then connect to the corresponding Shard for operation, and finally return the result to the client. The client only needs to set the original

Queries or update requests sent to mongod are sent to Routing Process intact, regardless of the records being operated

Which Shard is stored on?

Let's build a simple Sharding Cluster on the same physical machine

The architecture diagram is as follows

Create a data directory and log directory

Start Shard Server instance 1 and instance 2

Start Config Server

Start Route Process

The chunkSize item in the mongos startup parameters is used to specify the size of the chunk. The unit is the default size of the MB.

For 200MB, we specify chunkSize as 1MB in order to test the Sharding effect.

Configure Sharding

Next we use MongoDB Shell to log in to mongos and add a Shard node

Verify that Sharding is working properly

We have sliced up the test.users table and let's insert some data to see the results.

Let's take a look at the physical files on disk.

The above results show that the test.users set has been fragmented, but we are routed through mongos and feel

It is less than which shard's chunk where the data is stored, which is one of the advantages of MongoDB user experience, that is,

It is transparent to users.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report