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

Example Analysis of data loss of replica set in MongoDB

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you the "Example Analysis of Missing Data in Copy Set in MongoDB". The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn the article "Example Analysis of Missing Data in Copy Set in MongoDB".

1. Summary description

The test scenario is: one master, one slave and one verification

test case

step1: Close from copy;

Step 2: Insert that piece of data into the master copy;

Step 3: Close the master copy;

Step 4: Open the auxiliary copy. This copy will be upgraded to the main copy. After this, you will see that the new main copy does not have the data inserted just now.

---When testing, please pay attention to the test steps.

Step 5: After the original node is added to the cluster again, it will become a new secondary replica. Testing inserted data results in a rollback.

2. Specific test procedures

(1) Test server, original test environment

Primary Server: Port Secondary Server: Port Witness Server: PortXXX.124: 27220XXX.XXX.123: 27221XXX.134:27220

(2) Test procedures

Step 1 Insert the following data into the master database (XXX.124: 27220), which takes longer to execute.

for(var i = 0; i

< 100000; i++) { db.order0522.insert({a: i});}; Step 2 在上述命令执行的过程中,关于副主Server上的mongodb服务,服务命名为mongodboplogtest.service systemctl stop mongodboplogtest.service Step 3.查询主副本上数据库insert的数据量,为100000.命令完全插入。

Step 4. Turn off the Mongodb service on the master replica, named mongodboplogtest.service

systemctl stop mongodboplogtest.service

Step 5 Start MongoDB on the secondary node

systemctl start mongodboplogtest.service

Step 6 At this time, the auxiliary node (XXX.123) is upgraded to the primary node, and the data is 30337(100000-30337 records are lost).

At this time, 124 (original node) is "stateStr" : "(not reachable/healthy)"

Step 7: Start the service on the original master node. The cluster status. The description of the original master node is temporarily in "stateStr" : "ROLLBACK".

Step 8 After rollback, the state changes to "stateStr" : "SECONDARY"

Step 9: Query the original node data. At this time, the data amount is 30337(100000-30337 records are also lost).

3. Can the missing data be found?

We found that after restarting the mongodb service of the original node (XXX.124), there is an additional rollback directory under the data directory.

Pre-restart data directory

Data directory after restart

After entering this directory, we see that a bson file with database + collection name + time is generated.

The above is all the content of this article "Sample analysis of missing data in replica sets in MongoDB". Thank you for reading it! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

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