Skip to content

Commit d2eee1c

Browse files
npentrelandf-mongodb
authored andcommitted
DOCSP-7679 Change Initial Sync Semantics
1 parent 5964709 commit d2eee1c

14 files changed

+115
-132
lines changed

source/core/replica-set-elections.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ member votes in an election.
150150
- .. include:: /includes/fact-rs-non-voting-priority-restriction.rst
151151

152152
- .. include:: /includes/fact-rs-nonzero-priority-vote-restriction.rst
153-
153+
154154
- Only voting members in the following states are eligible to vote:
155155

156156
- :replstate:`PRIMARY`
157157

158158
- :replstate:`SECONDARY`
159159

160-
- :replstate:`STARTUP2`
160+
- :replstate:`STARTUP2` (unless the member was newly added to the
161+
replica set)
161162

162163
- :replstate:`RECOVERING`
163164

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ref: initial-sync-semantics
2+
content: |
3+
Starting in MongoDB 5.0, a newly added secondary does not count as a
4+
voting member and cannot be elected until it has reached the
5+
:replstate:`SECONDARY` state.
6+
7+
When a new voting node is added to a replica set,
8+
:dbcommand:`replSetReconfig` will internally add a ``newlyAdded``
9+
field to the node's configuration. Nodes with the ``newlyAdded`` field
10+
do not count towards the current number of voting nodes. When initial
11+
sync completes and the node reaches :replstate:`SECONDARY` state, the
12+
``newlyAdded`` field is automatically removed.
13+
14+
.. note::
15+
16+
- Configurations that attempt to add a field named ``newlyAdded``
17+
will error even if run with ``{ force: true }``.
18+
19+
- If an existing node has a ``newlyAdded`` field, using
20+
:method:`rs.reconfig()` to change the configuration will not
21+
remove the ``newlyAdded`` field. The ``newlyAdded`` field will be
22+
appended to the user provided configuration.
23+
24+
- :dbcommand:`replSetGetConfig` will remove any ``newlyAdded`` fields
25+
from its output. If you would like to see any ``newlyAdded``
26+
fields, you can query the :data:`local.system.replset` collection
27+
directly.

source/includes/replica-states.rst

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
* - 1
1919
- :replstate:`PRIMARY`
20-
20+
2121
- The member in state :doc:`primary </core/replica-set-primary>`
2222
is the only member that can accept write operations. Eligible to
2323
vote.
@@ -38,8 +38,14 @@
3838

3939
* - 5
4040
- :replstate:`STARTUP2`
41-
- The member has joined the set and is running an initial sync. Eligible to
42-
vote.
41+
- The member has joined the set and is running an initial sync.
42+
Eligible to vote.
43+
44+
.. note::
45+
46+
Starting in MongoDB 5.0, if the member was newly added to the
47+
replica set, it is not eligible to vote and cannot be elected
48+
during the initial sync process.
4349

4450
* - 6
4551
- :replstate:`UNKNOWN`

source/includes/steps-replace-disabled-config-server.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ ref: add-to-replica-set
1818
pre: |
1919
Connect a :binary:`~bin.mongo` shell to the primary of the config server
2020
replica set and use :method:`rs.add()` to add the new member.
21-
22-
.. tip::
21+
22+
.. warning::
2323
2424
.. include:: /includes/tip-repl-set-add-members.rst
2525
+9-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
When a newly added secondary has its :rsconf:`~members[n].votes` and
2-
:rsconf:`~members[n].priority` settings greater than zero, during
3-
its initial sync, the secondary still counts as a voting member even
4-
though it cannot serve reads nor become primary because its data is
5-
not yet consistent.
6-
7-
This can lead to a case where a majority of the voting members are
1+
Before MongoDB 5.0, a newly added secondary still counts as a voting
2+
member even though it can neither serve reads nor become primary until
3+
its data is consistent. If you are running a MongoDB version earlier
4+
than 5.0 and add a secondary with its :rsconf:`~members[n].votes`
5+
and :rsconf:`~members[n].priority` settings greater than zero, this can
6+
lead to a case where a majority of the voting members are
87
online but no primary can be elected. To avoid such situations,
98
consider adding the new secondary initially with
109
:rsconf:`priority :0 <members[n].priority>` and :rsconf:`votes :0
11-
<members[n].votes>`. Then, once the member has transitioned into
12-
:replstate:`SECONDARY` state, use :method:`rs.reconfig()` to update its
13-
priority and votes.
10+
<members[n].votes>`. Then, run :method:`rs.status()` to ensure the
11+
member has transitioned into :replstate:`SECONDARY` state. Finally, use
12+
:method:`rs.reconfig()` to update its priority and votes.

source/reference/command/replSetReconfig.txt

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ Reconfiguration Waits Until a Majority of Members Install the Replica Configurat
9999

100100
.. include:: /includes/extracts/replSetReconfig-majority.rst
101101

102+
Automatic Reconfiguration for New Voting Replica Set Members
103+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104+
105+
.. include:: /includes/extracts/initial-sync-semantics.rst
106+
102107
Access Control
103108
~~~~~~~~~~~~~~
104109

source/reference/method/rs.add.txt

+8-38
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ which will disconnect the shell (such as adding a new member with
9797
a higher priority than the current primary). In such cases, the :binary:`~bin.mongo`
9898
shell may display an error even if the operation succeeds.
9999

100-
.. tip::
100+
.. warning::
101101

102102
.. include:: /includes/tip-repl-set-add-members.rst
103103

@@ -133,48 +133,18 @@ to a new replica set, you can call the :method:`rs.add()` method with:
133133
Add a Secondary to an Existing Replica Set
134134
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135135

136-
.. tip::
137-
138-
.. include:: /includes/tip-repl-set-add-members.rst
139-
140-
To add a new secondary member with default vote and priority settings
136+
Add a new secondary member with default vote and priority settings
141137
to an existing replica set:
142138

143-
#. Add the member initially as a :ref:`non-voting
144-
<replica-set-non-voting-members>`, :doc:`priority 0
145-
</core/replica-set-priority-0-member>` member:
146-
147-
.. cssclass:: copyable-code
148-
149-
.. code-block:: javascript
150-
151-
rs.add( { host: "mongodbd4.example.net:27017", priority: 0, votes: 0 } )
152-
153-
#. Ensure that the new member has reached :replstate:`SECONDARY` state.
154-
To check the state of the replica set members, run
155-
:method:`rs.status()`:
156-
157-
.. cssclass:: copyable-code
158-
.. code-block:: javascript
159-
160-
rs.status()
161-
162-
#. Reconfigure the replica set to update the votes and priority of the
163-
new member:
164-
165-
.. code-block:: javascript
166-
167-
var cfg = rs.conf();
139+
.. cssclass:: copyable-code
168140

169-
cfg.members[n].priority = 1; // Substitute the correct array index for the new member
170-
cfg.members[n].votes = 1; // Substitute the correct array index for the new member
141+
.. code-block:: javascript
171142

172-
rs.reconfig(cfg)
143+
rs.add( { host: "mongodbd4.example.net:27017" } )
173144

174-
where ``n`` is the array index of the new member in the
175-
:rsconf:`members` array.
145+
.. warning::
176146

177-
.. include:: /includes/warning-rs-reconfig.rst
147+
.. include:: /includes/tip-repl-set-add-members.rst
178148

179149
.. _rs-add-priority-0:
180150

@@ -212,7 +182,7 @@ the host ``mongodb3.example.net`` and accessible on the default port
212182
.. cssclass:: copyable-code
213183

214184
.. code-block:: javascript
215-
185+
216186
rs.add( { host: "mongodb3.example.net:27017", arbiterOnly: true } )
217187

218188
- Host name

source/reference/method/rs.reconfig.txt

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ modify this timeout using the
226226
Replace ``<hostname>`` and ``<port>`` with those of the removed
227227
member.
228228

229+
Automatic Reconfiguration for New Voting Replica Set Members
230+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231+
232+
.. include:: /includes/extracts/initial-sync-semantics.rst
229233

230234
.. _replica-set-reconfiguration-usage:
231235

source/reference/replica-configuration.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,13 @@ Replica Set Configuration Fields
419419
If you need more than 7 members in one replica set, set
420420
:rsconf:`members[n].votes` to ``0`` for the
421421
additional non-voting members.
422-
422+
423423
.. include:: /includes/fact-rs-non-voting-priority-restriction.rst
424424

425+
Starting in MongoDB 5.0, a newly added secondary does not count as
426+
a voting member and cannot be elected until it has reached
427+
:replstate:`SECONDARY` state.
428+
425429
Non-voting members cannot acknowledge write operations
426430
issued with a :writeconcern:`"majority"` write concern.
427431

source/reference/replica-states.txt

+14-6
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,21 @@ Other States
5252

5353
.. replstate:: STARTUP2
5454

55-
Each data-bearing member of a replica set enters the :replstate:`STARTUP2` state as
56-
soon as :binary:`~bin.mongod` finishes loading that member's
57-
configuration, at which time it becomes an active member of the replica set and is eligible to vote.
55+
Each data-bearing member of a replica set enters the
56+
:replstate:`STARTUP2` state as soon as :binary:`~bin.mongod` finishes
57+
loading that member's configuration, at which time it becomes an
58+
active member of the replica set and is eligible to vote.
59+
5860
The member then decides whether or not to undertake an initial sync.
59-
If a member begins an initial sync, the member remains in :replstate:`STARTUP2` until all
60-
data is copied and all indexes are built. Afterwards, the member transitions to
61-
:replstate:`RECOVERING`.
61+
If a member begins an initial sync, the member remains in
62+
:replstate:`STARTUP2` until all data is copied and all indexes are
63+
built. Afterwards, the member transitions to :replstate:`RECOVERING`.
64+
65+
.. note::
66+
67+
Starting in MongoDB 5.0, if the member was newly added to the
68+
replica set, it is not eligible to vote and cannot be elected
69+
during the initial sync process.
6270

6371
.. replstate:: RECOVERING
6472

source/release-notes/5.0-compatibility.txt

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ operations to the oplog when running as a
8080
:term:`standalone instance <standalone>` should only be done with
8181
guidance from MongoDB Support.
8282

83+
Automatic Reconfiguration for New Voting Replica Set Members
84+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85+
86+
.. include:: /includes/extracts/initial-sync-semantics.rst
87+
8388
Projection Compatibility Changes
8489
--------------------------------
8590

source/tutorial/expand-replica-set.txt

+3-31
Original file line numberDiff line numberDiff line change
@@ -154,43 +154,15 @@ Add a Member to an Existing Replica Set
154154
not know which member is the primary, log into any member of the
155155
replica set and issue the :method:`db.isMaster()` command.
156156

157-
#. Use :method:`rs.add()` to add the new member to the replica set.
157+
#. Use :method:`rs.add()` to add the new member to the replica set.
158158
Pass the :rsconf:`member configuration document <members>` to the
159159
method. For example, to add a member at host
160160
``mongodb3.example.net``, issue the following command:
161161

162162
.. code-block:: javascript
163163

164-
rs.add( { host: "mongodb3.example.net:27017", priority: 0, votes: 0 } )
164+
rs.add( { host: "mongodb3.example.net:27017" } )
165165

166-
.. tip::
166+
.. warning::
167167

168168
.. include:: /includes/tip-repl-set-add-members.rst
169-
170-
#. Ensure that the new member has reached :replstate:`SECONDARY` state.
171-
To check the state of the replica set members, run
172-
:method:`rs.status()`:
173-
174-
.. cssclass:: copyable-code
175-
.. code-block:: javascript
176-
177-
rs.status()
178-
179-
#. Once the newly added member has transitioned into
180-
:replstate:`SECONDARY` state, use :method:`rs.reconfig()` to update
181-
the newly added member's :rsconf:`~members[n].priority` and
182-
:rsconf:`~members[n].votes` if needed.
183-
184-
For example, if :method:`rs.conf()` returns the configuration
185-
document for ``mongodb3.example.net:27017`` as the fifth element in
186-
the :rsconf:`members` array, to update its priority and votes to
187-
``1``, use the following sequence of operations:
188-
189-
.. code-block:: javascript
190-
191-
var cfg = rs.conf();
192-
cfg.members[4].priority = 1
193-
cfg.members[4].votes = 1
194-
rs.reconfig(cfg)
195-
196-
.. include:: /includes/warning-rs-reconfig.rst

source/tutorial/resync-replica-set-member.txt

+12-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ MongoDB provides two options for performing an initial sync:
4646
Procedures
4747
----------
4848

49+
.. note::
50+
51+
To prevent changing the write quorum, never rotate more than one
52+
replica set member at a time.
53+
4954
.. _replica-set-auto-resync-stale-member:
5055

5156
Automatically Sync a Member
@@ -89,7 +94,8 @@ perform an initial sync by restarting the instance without the contents of the
8994
:setting:`~storage.dbPath` directory.
9095

9196
4. :doc:`Start the mongod process </tutorial/manage-mongodb-processes>`,
92-
specifying :ref:`cli-mongod-replica-set` as appropriate.
97+
specifying :ref:`cli-mongod-replica-set` with a new
98+
:rsconf:`members[n]._id`.
9399

94100
At this point, the :binary:`~bin.mongod` performs an initial sync. The length of
95101
the initial sync process depends on the size of the database and the network
@@ -127,5 +133,8 @@ Sync the Member
127133
```````````````
128134

129135
After you have copied the data files from the "seed" source, start the
130-
:binary:`~bin.mongod` instance and allow it to apply all operations from
131-
the oplog until it reflects the current state of the replica set.
136+
:binary:`~bin.mongod` instance with a new :rsconf:`members[n]._id` and
137+
allow it to apply all operations from the oplog until it reflects the
138+
current state of the replica set. To see the current status of the
139+
replica set, use :method:`rs.printSecondaryReplicationInfo()` or
140+
:method:`rs.status()`.

0 commit comments

Comments
 (0)