Skip to content

Commit 9d18a45

Browse files
committed
DOCS-13526: set initial sync source via initialSyncSourceReadPreference
1 parent 093a307 commit 9d18a45

File tree

3 files changed

+280
-16
lines changed

3 files changed

+280
-16
lines changed

source/core/replica-set-sync.txt

Lines changed: 207 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ Initial Sync
2525
------------
2626

2727
Initial sync copies all the data from one member of the replica set to
28-
another member.
28+
another member. See :ref:`replica-set-initial-sync-source-selection` for
29+
more information on initial sync source selection criteria.
30+
31+
Starting in MongoDB 4.4, you can specify the preferred initial sync
32+
source using the :parameter:`initialSyncSourceReadPreference` parameter.
33+
This parameter can only be specified when starting the
34+
:binary:`~bin.mongod`.
2935

3036
Process
3137
~~~~~~~
@@ -87,6 +93,107 @@ synchronization process from the beginning.
8793
The secondary attempts to restart the initial sync up to ``10`` times
8894
before returning a fatal error.
8995

96+
.. _replica-set-initial-sync-source-selection:
97+
98+
Initial Sync Source Selection
99+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100+
101+
Initial sync source selection depends on the value of the
102+
:binary:`~bin.mongod` startup parameter
103+
:parameter:`initialSyncSourceReadPreference` (*new in 4.4*):
104+
105+
- For :parameter:`initialSyncSourceReadPreference` set to
106+
:readmode:`primary` (default if :rsconf:`chaining
107+
<settings.chainingAllowed>` is disabled), select the :term:`primary`
108+
as the sync source. If the primary is unavailable or unreachable, log
109+
an error and periodically check for primary availability.
110+
111+
- For :parameter:`initialSyncSourceReadPreference` set to
112+
:readmode:`primaryPreferred` (default for voting replica set
113+
members), attempt to select the :term:`primary` as the sync source. If
114+
the primary is unavailable or unreachable, perform sync source
115+
selection from the remaining replica set members.
116+
117+
- For all other supported read modes, perform sync source selection
118+
from the replica set members.
119+
120+
Members performing initial sync source selection make two passes through
121+
the list of all replica set members:
122+
123+
.. tabs::
124+
125+
.. tab:: Sync Source Selection (First Pass)
126+
:tabid: firstpass
127+
128+
The member applies the following criteria to each replica
129+
set member when making the first pass for selecting a
130+
initial sync source:
131+
132+
- The sync source *must* be in the :replstate:`PRIMARY` or
133+
:replstate:`SECONDARY` replication state.
134+
135+
- The sync source *must* be online and reachable.
136+
137+
- If :parameter:`initialSyncSourceReadPreference` is
138+
:readmode:`secondary` or :readmode:`secondaryPreferred`,
139+
the sync source *must* be a :term:`secondary`.
140+
141+
- The sync source *must* be :rsconf:`visible <members[n].hidden>`.
142+
143+
- The sync source *must* be within ``30`` seconds of the newest
144+
oplog entry on the primary.
145+
146+
- If the member :rsconf:`builds indexes
147+
<members[n].buildIndexes>`, the sync source *must*
148+
build indexes.
149+
150+
- If the member :rsconf:`votes <members[n].votes>` in
151+
replica set elections, the sync source *must* also vote.
152+
153+
- If the member is *not* a :rsconf:`delayed member
154+
<members[n].slaveDelay>`, the sync source *must not* be delayed.
155+
156+
- If the member *is* a :rsconf:`delayed member
157+
<members[n].slaveDelay>`, the sync source must have a shorter
158+
configured delay.
159+
160+
- The sync source *must* be faster (i.e. lower latency) than
161+
the current best sync source.
162+
163+
If no candidate sync sources remain after the first pass,
164+
the member performs a second pass with relaxed criteria.
165+
See :guilabel:`Sync Source Selection (Second Pass)`.
166+
167+
.. tab:: Sync Source Selection (Second Pass)
168+
:tabid: second pass
169+
170+
The member applies the following criteria to each replica
171+
set member when making the second pass for selecting a
172+
initial sync source:
173+
174+
- The sync source *must* be in the
175+
:replstate:`PRIMARY` or :replstate:`SECONDARY` replication
176+
state.
177+
178+
- The sync source *must* be online and reachable.
179+
180+
- If :parameter:`initialSyncSourceReadPreference` is
181+
:readmode:`secondary`, the sync source *must* be a
182+
:term:`secondary`.
183+
184+
- If the member :rsconf:`builds indexes
185+
<members[n].buildIndexes>`, the sync source must
186+
build indexes.
187+
188+
- The sync source *must* be faster (i.e. lower latency) than
189+
the current best sync source.
190+
191+
If the member cannot select an initial sync source after two passes, it
192+
logs an error and waits ``1`` second before restarting the selection
193+
process. The secondary :binary:`~bin.mongod` can restart the initial
194+
sync source selection process up to ``10`` times before exiting with an
195+
error.
196+
90197
.. _replica-set-replication:
91198

92199
Replication
@@ -99,21 +206,8 @@ process. [#slow-oplogs]_
99206

100207
Secondaries may automatically change their *sync from* source as needed
101208
based on changes in the ping time and state of other members'
102-
replication.
103-
104-
.. versionchanged:: 3.2
105-
106-
.. include:: /includes/fact-voting-node-sync-incompatibility.rst
107-
108-
Secondaries avoid syncing from
109-
:ref:`delayed members <replica-set-delayed-members>` and :ref:`hidden
110-
members <replica-set-hidden-members>`.
111-
112-
If a secondary member has :rsconf:`members[n].buildIndexes` set to ``true``,
113-
it can only sync from other members where :rsconf:`~members[n].buildIndexes`
114-
is ``true``. Members where :rsconf:`~members[n].buildIndexes` is ``false`` can
115-
sync from any other member, barring other sync restrictions.
116-
:rsconf:`~members[n].buildIndexes` is ``true`` by default.
209+
replication. See :ref:`replica-set-replication-sync-source-selection`
210+
for more information on sync source selection criteria.
117211

118212
.. [#slow-oplogs]
119213

@@ -151,3 +245,100 @@ Flow Control
151245
.. include:: /includes/extracts/4.2-changes-flow-control-general-desc.rst
152246

153247
For more information, see :ref:`flow-control`.
248+
249+
.. _replica-set-replication-sync-source-selection:
250+
251+
Replication Sync Source Selection
252+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253+
254+
Replication sync source selection depends on the replica set
255+
:rsconf:`chaining <settings.chainingAllowed>` setting:
256+
257+
- With chaining enabled (default), perform sync source selection from
258+
the replica set members.
259+
260+
- With chaining disabled, select the :term:`primary` as the sync
261+
source. If the primary is unavailable or unreachable, log an
262+
error and periodically check for primary availability.
263+
264+
Members performing replication sync source selection make two passes
265+
through the list of all replica set members:
266+
267+
.. tabs::
268+
269+
.. tab:: Sync Source Selection (First Pass)
270+
:tabid: firstpass
271+
272+
The member applies the following criteria to each replica
273+
set member when making the first pass for selecting a
274+
replication sync source:
275+
276+
- The sync source *must* be in the :replstate:`PRIMARY` or
277+
:replstate:`SECONDARY` replication state.
278+
279+
- The sync source *must* be online and reachable.
280+
281+
- The sync source *must* have newer oplog entries than the member
282+
(i.e. the sync source is *ahead* of the member).
283+
284+
- The sync source *must* be :rsconf:`visible <members[n].hidden>`.
285+
286+
- The sync source *must* be within ``30`` seconds of the newest
287+
oplog entry on the primary.
288+
289+
- If the member :rsconf:`builds indexes
290+
<members[n].buildIndexes>`, the sync source *must*
291+
build indexes.
292+
293+
- If the member :rsconf:`votes <members[n].votes>` in
294+
replica set elections, the sync source *must* also vote.
295+
296+
- If the member is *not* a :rsconf:`delayed member
297+
<members[n].slaveDelay>`, the sync source *must not* be delayed.
298+
299+
- If the member *is* a :rsconf:`delayed member
300+
<members[n].slaveDelay>`, the sync source must have a shorter
301+
configured delay.
302+
303+
- The sync source *must* be faster (i.e. lower latency) than
304+
the current best sync source.
305+
306+
If no candidate sync sources remain after the first pass,
307+
the member performs a second pass with relaxed criteria.
308+
See the :guilabel:`Sync Source Selection (Second Pass)`.
309+
310+
.. tab:: Sync Source Selection (Second Pass)
311+
:tabid: second pass
312+
313+
The member applies the following criteria to each replica
314+
set member when making the second pass for selecting a
315+
replication sync source:
316+
317+
- The sync source *must* be in the
318+
:replstate:`PRIMARY` or :replstate:`SECONDARY` replication
319+
state.
320+
321+
- The sync source *must* be online and reachable.
322+
323+
- If the member :rsconf:`builds indexes
324+
<members[n].buildIndexes>`, the sync source must
325+
build indexes.
326+
327+
- The sync source *must* be faster (i.e. lower latency) than
328+
the current best sync source.
329+
330+
If the member cannot select a sync source after two passes, it logs an
331+
error and waits ``1`` second before restarting the selection process.
332+
333+
.. note::
334+
335+
Starting in MongoDB 4.4, the startup parameter
336+
:parameter:`initialSyncSourceReadPreference` takes precedence over
337+
the replica set's :rsconf:`settings.chainingAllowed` setting when
338+
selecting an initial sync source. After a replica set member
339+
successfully performs initial sync, it defers to the value of
340+
:rsconf:`~settings.chainingAllowed` when selecting a replication sync
341+
source.
342+
343+
See :ref:`replica-set-initial-sync-source-selection` for more
344+
information on initial sync source selection.

source/reference/parameters.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,51 @@ Replication Parameters
19731973
attempts to resume the process if interrupted by a transient
19741974
network error. The default value is equivalent to 24 hours.
19751975

1976+
.. parameter:: initialSyncSourceReadPreference
1977+
1978+
.. versionadded:: 4.4
1979+
1980+
*Type*: String
1981+
1982+
|mongod-only|
1983+
1984+
The preferred source for performing :ref:`initial sync
1985+
<replica-set-initial-sync>`. Specify one of the following read
1986+
preference modes:
1987+
1988+
- :readmode:`primary`
1989+
- :readmode:`primaryPreferred` (Default for voting replica set members)
1990+
- :readmode:`secondary`
1991+
- :readmode:`secondaryPreferred`
1992+
- :readmode:`nearest` (Default for newly added *or* non-voting replica set members)
1993+
1994+
If the replica set has disabled :rsconf:`chaining
1995+
<settings.chainingAllowed>`, the default
1996+
:parameter:`initialSyncSourceReadPreference` read preference mode
1997+
is :readmode:`primary`.
1998+
1999+
You cannot specify a tag set or ``maxStalenessSeconds`` to
2000+
:parameter:`initialSyncSourceReadPreference`.
2001+
2002+
If the :binary:`~bin.mongod` cannot find a sync source based on the
2003+
specified read preference, it logs an error and restarts the initial
2004+
sync process. The :binary:`~bin.mongod` exits with an error if it
2005+
cannot complete the initial sync process after ``10`` attempts. For
2006+
more information on sync source selection, see
2007+
:ref:`replica-set-initial-sync-source-selection`.
2008+
2009+
:parameter:`initialSyncSourceReadPreference` takes precedence over
2010+
the replica set's :rsconf:`settings.chainingAllowed` setting when
2011+
selecting an initial sync source. After a replica set member
2012+
successfully completes initial sync, it defers to the value of
2013+
:rsconf:`~settings.chainingAllowed` when selecting a replication sync
2014+
source.
2015+
2016+
You can only set this parameter on startup, using either the
2017+
:setting:`setParameter`
2018+
configuration file setting or the
2019+
:option:`--setParameter <mongod --setParameter>` command line option.
2020+
19762021
.. parameter:: oplogInitialFindMaxSeconds
19772022

19782023
.. versionadded:: 3.6

source/release-notes/4.4.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,34 @@ Safe Replica Set Reconfiguration
246246
.. |moreinfo| replace:: For more information, see the
247247
:ref:`replSetGetConfig <replSetGetConfig-commitmentStatus>` command.
248248

249+
Preferred Initial Sync Source
250+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251+
252+
Starting in MongoDB 4.4, you can specify the preferred initial sync
253+
source using the :parameter:`initialSyncSourceReadPreference` parameter.
254+
You can only set this parameter on :binary:`~bin.mongod` startup, using
255+
either the :setting:`setParameter` configuration file setting or the
256+
:option:`--setParameter <mongod --setParameter>` command line option.
257+
258+
:parameter:`initialSyncSourceReadPreference` supports following read
259+
preference modes:
260+
261+
- :readmode:`primary`
262+
- :readmode:`primaryPreferred` (Default for voting replica set members)
263+
- :readmode:`secondary`
264+
- :readmode:`secondaryPreferred`
265+
- :readmode:`nearest` (Default for newly added *or* non-voting replica set members)
266+
267+
If the replica set has disabled :rsconf:`chaining
268+
<settings.chainingAllowed>`, the default
269+
:parameter:`initialSyncSourceReadPreference` read preference mode
270+
is :readmode:`primary`.
271+
272+
You cannot specify a tag set or ``maxStalenessSeconds`` to
273+
:parameter:`initialSyncSourceReadPreference`.
274+
275+
.. seealso:: :ref:`replica-set-initial-sync-source-selection`
276+
249277
Sharded Clusters
250278
----------------
251279

0 commit comments

Comments
 (0)