Skip to Content
MongoDB权威指南(第3版)
book

MongoDB权威指南(第3版)

by Shannon Bradshaw, Eoin Brazil, Kristina Chodorow
November 2021
Intermediate to advanced
410 pages
12h 1m
Chinese
Posts & Telecom Press
Content preview from MongoDB权威指南(第3版)
207
11
副本集的组成
本章介绍副本集的各个部分是如何组织在一起的,包括:
副本集成员如何复制新数据;
如何让新成员开始工作;
选举是如何进行的;
可能出现的服务器端和网络故障场景。
11.1
 同步
复制是指在多台服务器上保持相同的数据副本。
MongoDB
实现此功能的方式是保存操作
日志(
oplog
,其中包含了主节点执行的每一次写操作。
oplog
是存在于主节点
local
数据
库中的一个固定集合。从节点通过查询此集合以获取需要复制的操作。
每个从节点都维护着自己的
oplog
,用来记录它从主节点复制的每个操作
。这使得每个成
员都可以被用作其他成员的同步源,如图
1
1-1
所示。从节点从同步源中获取操作,将其应
用到自己的数据集上,然后再写入
oplog
。如果应用某个操作失败(只有在基础数据已
损坏或数据与主节点不一致时才会发生这种情况),则从节点会停止从当前数据源复制数
据。
如果一个从节点由于某种原因而停止运行,那么当它重新启动后,就会从
oplog
中的最后
一个操作开始同步。由于这些操作是先应用到数据上然后再写入
oplog
,因此从节点可能
会重复已经应用到其数据上的操作。
MongoDB
在设计时就考虑到了这种情况
:将
oplog
的同一个操作执行多次与只执行一次效果是一样的。
oplog
中的每个操作都是幂等的
。也
就是说,无论对目标数据集应用一次还是多次,
oplog
操作都会产生相同的结果。
208
11
6 7 8 9 10 11 12 13 14
主节点
6 7 8 9 10
从节点 1
查询
{"$gt":10} ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9787115576538