In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is from Zhang Youdong's article, article link: http://www.mongoing.com/archives/2369
It explains my problem, so forward the record.
2015-12-09 blog, Zhang Youdong's blog zydcom
The Secondary in the Mongodb replication set synchronizes the data from the Primary to keep the data consistent on all nodes in the replica set. Data synchronization mainly involves two processes:
Initial syncreplication (oplog sync)
First synchronize all the data through init sync, and then continuously replay the oplog synchronous incremental data on the Primary through replication.
Initial sync
After Secondary starts, initial sync will be performed first if one of the following conditions is met
Oplog is empty on Secondary, for example, the _ initialSyncFlag flag is set in the newly added empty node local.replset.minvalid collection. The synchronization thread sets the flag when the initial sync starts, and clears it when the initial sync ends, so if the initial sync process fails and the node restarts and finds that the flag is set, it knows that the initial sync should be redone. BackgroundSync::_initialSyncRequestedFlag is set. When the resync command is sent to the node, the flag is set and re-initial sync is forced at this point. Initial sync synchronization process minValid collection setting _ initialSyncFlag get the latest oplog timestamp T0 of the synchronization source get the latest oplog timestamp T1 of the synchronization source from all the collection data of the synchronization source T1 synchronize all oplog of the synchronization source get the latest oplog timestamp T2 synchronization t1~t2 all oplog read index information from the synchronization source, and establish an index to get the latest oplog timestamp T3 synchronization t2~t3 all oplogminValid collections clear _ initialSyncFlag,initial sync end replication (sync oplog)
After the initial sync ends, the Secondary establishes the tailable cursor of the local.oplog.rs on the Primary, constantly fetches the newly written oplog from the Primary, and applies it to itself.
Tailable cursor will obtain a batch of oplog,Secondary to replay oplog with multi-thread at a time to improve efficiency. By grouping oplog into multiple threads according to the namespace to which it belongs, to ensure that all operations on the same namespace are replay by one thread, to ensure that the operation timing of Unified namespace is consistent with that on primary (if the engine supports document locks, you only need to ensure that the operation sequence of the same document is the same as that of primary).
Synchronous scene analysis
1. Replica set initialization
After initializing and selecting the Primary, there is no valid data on the Secondary, and the oplog is empty. Initial sync will be performed first, and then the new oplog will be applied continuously.
two。 New members join
Because there is no valid data on the new members, oplog is empty. Initial sync will be carried out first, and then the new oplog will be applied continuously.
3. Join the nodes with data
The joining of nodes with data is as follows:
The node is disconnected from other nodes in the replica set, restored after a period of time, the node is removed from the replica set (in REMOVED), and it is rejoined by the replSetReconfig command. Since members of the same replica set must have the same replSetName configuration, there should be no other scenarios unless misconfigured
At this point, if the latest oplog timestamp of the node is smaller than the oldest oplog timestamp of all nodes, the node will not find the synchronization source and will always be in RECOVERING and cannot be served; on the contrary, if the synchronization source can be found, it will directly enter the replication phase and constantly apply new oplog.
The node in RECOVERING because Oplog is too old cannot recover automatically and needs manual intervention (so it is very important to set a reasonable oplog size). The easiest way is to send the resync command to let the node re-initial sync.
A brief introduction to the author of Replica Set Data SynchronizationResync a Member of a Replica SetCreate tailable cursor
Zhang Youdong, who works in Aliyun Feitian Technology Department, mainly focuses on distributed storage, Nosql and other technical fields, and participates in the development of TFS (Taobao distributed File system), AliCloudDB for Redis and other projects. welcome to communicate.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.