Skip to content

Commit d0a66bb

Browse files
committed
docs-11115 rs.add and initial sync
1 parent dc527e9 commit d0a66bb

8 files changed

+255
-112
lines changed

source/includes/apiargs-method-rs.add-param.yaml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
arg_name: param
22
description: |
3-
The new member to add to the replica set.
3+
4+
The new member to add to the replica set. Specify either as a string
5+
or a configuration document:
46
5-
If a string, specify the hostname and optionally the port number for
6-
the new member. See :ref:`rs-add-hostname` for an example.
7+
- If a document, specify a replica set member configuration document
8+
as found in the :rsconf:`members` array. You must specify the
9+
:rsconf:`~members[n].host` field in the member configuration
10+
document.
711
8-
If a document, specify a replica set member configuration document as
9-
found in the :rsconf:`members` array. You must
10-
specify :rsconf:`members[n]._id` and the
11-
:rsconf:`members[n].host` fields in the member
12-
configuration document. See
13-
:ref:`rs-add-member-configuration-document` for an example.
12+
.. code-block:: javascript
13+
14+
{
15+
_id: <int>,
16+
host: <string>, // required
17+
arbiterOnly: <boolean>,
18+
buildIndexes: <boolean>,
19+
hidden: <boolean>,
20+
priority: <number>,
21+
tags: <document>,
22+
slaveDelay: <int>,
23+
votes: <number>
24+
}
25+
26+
For a description of the configuration field, refer to
27+
:rsconf:`members`.
28+
29+
- If a string, specify the hostname and optionally the port number
30+
for the new member.
1431
15-
See :doc:`/reference/replica-configuration` document for full
16-
documentation of all replica set configuration options
1732
interface: method
1833
name: host
1934
operation: rs.add

source/includes/steps-convert-replica-set-add-new-shard.yaml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
stepnum: 1
21
title:
32
text: Start each member of the replica set with the appropriate options.
43
character: "`"
@@ -25,7 +24,6 @@ post: |
2524
title:
2625
text: Connect a :binary:`~bin.mongo` shell to a replica set member.
2726
character: "`"
28-
stepnum: 2
2927
ref: open-shell
3028
pre: |
3129
Connect a :binary:`~bin.mongo` shell to *one* member of the replica set
@@ -36,7 +34,6 @@ action:
3634
code: |
3735
mongo mongodb3.example.net
3836
---
39-
stepnum: 3
4037
title: "Initiate the replica set."
4138
level: 4
4239
ref: initiate-rs
@@ -54,27 +51,16 @@ action:
5451
code: |
5552
rs.initiate( {
5653
_id : "rs1",
57-
members: [ { _id : 0, host : "mongodb3.example.net:27017" } ]
54+
members: [
55+
{ _id: 0, host: "mongodb3.example.net:27017" },
56+
{ _id: 1, host: "mongodb4.example.net:27017" },
57+
{ _id: 2, host: "mongodb5.example.net:27017" }
58+
]
5859
})
5960
---
60-
stepnum: 4
61-
title:
62-
text: Add the remaining members to the replica set.
63-
character: "`"
64-
ref: add-remaining-members
65-
pre: |
66-
Add the remaining members with the :method:`rs.add()` method.
67-
action:
68-
copyable: true
69-
language: javascript
70-
code: |
71-
rs.add("mongodb4.example.net")
72-
rs.add("mongodb5.example.net")
73-
---
7461
title:
7562
text: "Connect a ``mongo`` shell to the ``mongos``."
7663
character: "`"
77-
stepnum: 5
7864
ref: connect-mongos
7965
action:
8066
copyable: true
@@ -85,7 +71,6 @@ action:
8571
title:
8672
text: Add the shard.
8773
character: "`"
88-
stepnum: 6
8974
ref: add-mongos-shard
9075
pre: |
9176
In a :binary:`~bin.mongo` shell connected to the :binary:`~bin.mongos`, add
@@ -95,4 +80,4 @@ action:
9580
language: javascript
9681
code: |
9782
sh.addShard( "rs1/mongodb3.example.net:27017,mongodb4.example.net:27017,mongodb5.example.net:27017" )
98-
...
83+
...

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
title: Start the replacement config server.
2-
stepnum: 1
32
ref: start-config-server
43
pre: |
54
@@ -15,31 +14,65 @@ action:
1514
mongod --configsvr --replSet <replicaSetName> --bind_ip localhost,<ip address of the mongod host>
1615
---
1716
title: Add the new config server to the replica set.
18-
stepnum: 2
1917
ref: add-to-replica-set
2018
pre: |
2119
Connect a :binary:`~bin.mongo` shell to the primary of the config server
2220
replica set and use :method:`rs.add()` to add the new member.
21+
22+
.. tip::
23+
24+
.. include:: /includes/tip-repl-set-add-members.rst
25+
2326
action:
2427
language: javascript
2528
code: |
26-
rs.add("<hostnameNew>:<portNew>")
29+
rs.add( { host: "<hostnameNew>:<portNew>", priority: 0, votes: 0 } )
30+
2731
post: |
2832
The initial sync process copies all the data from one member of the
2933
config server replica set to the new member without restarting.
3034
3135
:binary:`~bin.mongos` instances automatically recognize the change in the
3236
config server replica set members without restarting.
3337
---
38+
title: Update the newly added config server's votes and priority settings.
39+
ref: reconfig
40+
41+
content: |
42+
43+
a. Ensure that the new member has reached :replstate:`SECONDARY`
44+
state. To check the state of the replica set members, run
45+
:method:`rs.status()`:
46+
47+
.. cssclass:: copyable-code
48+
.. code-block:: javascript
49+
50+
rs.status()
51+
52+
#. Reconfigure the replica set to update the votes and priority of
53+
the new member:
54+
55+
.. code-block:: javascript
56+
57+
var cfg = rs.conf();
58+
59+
cfg.members[n].priority = 1; // Substitute the correct array index for the new member
60+
cfg.members[n].votes = 1; // Substitute the correct array index for the new member
61+
62+
rs.reconfig(cfg)
63+
64+
where ``n`` is the array index of the new member in the
65+
:rsconf:`members` array.
66+
67+
.. include:: /includes/warning-rs-reconfig.rst
68+
---
3469
title: Shut down the member to replace.
35-
stepnum: 3
3670
ref: shut-down-old-member
3771
content: |
3872
If replacing the primary member, step down the primary first before
3973
shutting down.
4074
---
4175
title: Remove the member to replace from the config server replica set.
42-
stepnum: 4
4376
ref: remove-old-member
4477
pre: |
4578
Upon completion of initial sync of the replacement config server,
@@ -56,7 +89,6 @@ post: |
5689
.. end-for-migration-steps
5790
---
5891
title: "If necessary, update ``mongos`` configuration or DNS entry."
59-
stepnum: 5
6092
ref: update-mongos-setting
6193
pre: |
6294
With replica set config servers, the :binary:`~bin.mongos` instances specify
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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
8+
online but no primary can be elected. To avoid such situations,
9+
consider adding the new secondary initially with
10+
: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.

source/reference/method/rs.add.txt

Lines changed: 102 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Definition
1818
Adds a member to a :term:`replica set`. To run the method, you must
1919
connect to the :term:`primary` of the replica set.
2020

21+
2122
.. include:: /includes/apiargs/method-rs.add-param.rst
2223

2324
:method:`rs.add()` provides a wrapper around some of the
@@ -40,56 +41,134 @@ which will disconnect the shell (such as adding a new member with
4041
a higher priority than the current primary). In such cases, the :binary:`~bin.mongo`
4142
shell may display an error even if the operation succeeds.
4243

44+
.. tip::
45+
46+
.. include:: /includes/tip-repl-set-add-members.rst
47+
4348
Example
4449
-------
4550

46-
.. _rs-add-hostname:
51+
.. _rs-add-member-new-replica-set:
4752

48-
Pass a Hostname String to ``rs.add()``
49-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
Add a Secondary to a New Replica Set
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5055

51-
The following operation adds a :binary:`~bin.mongod` instance, running on
52-
the host ``mongodb3.example.net`` and accessible on the default port
53-
``27017``:
56+
To add a new secondary member with default vote and priority settings
57+
to a new replica set, you can call the :method:`rs.add()` method with:
5458

55-
.. code-block:: javascript
59+
- Member Configuration Document
5660

57-
rs.add('mongodb3.example.net:27017')
61+
.. cssclass:: copyable-code
5862

59-
If ``mongodb3.example.net`` is an arbiter, use the following form:
63+
.. code-block:: javascript
6064

61-
.. code-block:: javascript
65+
rs.add( { host: "mongodbd4.example.net:27017" } )
6266

63-
rs.add('mongodb3.example.net:27017', true)
67+
- Host name
6468

65-
.. include:: /includes/extracts/arbiters-and-pvs-with-reference.rst
69+
.. cssclass:: copyable-code
70+
71+
.. code-block:: javascript
72+
73+
rs.add( "mongodbd4.example.net:27017" )
6674

6775
.. _rs-add-member-configuration-document:
6876

69-
Pass a Member Configuration Document to ``rs.add()``
70-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77+
Add a Secondary to an Existing Replica Set
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
80+
.. tip::
81+
82+
.. include:: /includes/tip-repl-set-add-members.rst
83+
84+
To add a new secondary member with default vote and priority settings
85+
to an existing replica set:
86+
87+
#. Add the member initially as a :ref:`non-voting
88+
<replica-set-non-voting-members>`, :doc:`priority 0
89+
</core/replica-set-priority-0-member>` member:
90+
91+
.. cssclass:: copyable-code
92+
93+
.. code-block:: javascript
94+
95+
rs.add( { host: "mongodbd4.example.net:27017", priority: 0, votes: 0 } )
96+
97+
#. Ensure that the new member has reached :replstate:`SECONDARY` state.
98+
To check the state of the replica set members, run
99+
:method:`rs.status()`:
100+
101+
.. cssclass:: copyable-code
102+
.. code-block:: javascript
103+
104+
rs.status()
105+
106+
#. Reconfigure the replica set to update the votes and priority of the
107+
new member:
108+
109+
.. code-block:: javascript
71110

72-
.. versionchanged:: 3.0.0
73-
Previous versions required an ``_id`` field in the document you
74-
passed to :method:`rs.add()`. After 3.0.0 you can omit the
75-
``_id`` field in this document.
76-
:rsconf:`members[n]._id` describes the requirements for specifying ``_id``.
111+
var cfg = rs.conf();
112+
113+
cfg.members[n].priority = 1; // Substitute the correct array index for the new member
114+
cfg.members[n].votes = 1; // Substitute the correct array index for the new member
115+
116+
rs.reconfig(cfg)
117+
118+
where ``n`` is the array index of the new member in the
119+
:rsconf:`members` array.
120+
121+
.. include:: /includes/warning-rs-reconfig.rst
122+
123+
.. _rs-add-priority-0:
124+
125+
Add a Priority 0 Member to a Replica Set
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77127

78128
The following operation adds a :binary:`~bin.mongod` instance, running on
79129
the host ``mongodb4.example.net`` and accessible on the default port
80130
``27017``, as a :doc:`priority 0 </core/replica-set-priority-0-member>`
81131
secondary member:
82132

133+
.. cssclass:: copyable-code
134+
83135
.. code-block:: javascript
84136

85137
rs.add( { host: "mongodbd4.example.net:27017", priority: 0 } )
86138

87-
You must specify the
88-
:rsconf:`members[n].host` field in the member
139+
You must specify the :rsconf:`members[n].host` field in the member
89140
configuration document.
90141

91-
See the :doc:`/reference/replica-configuration` for the available
92-
replica set member configuration settings.
142+
See the :rsconf:`members` for the available replica set member
143+
configuration settings.
144+
145+
.. _rs-add-hostname:
146+
147+
Add an Arbiter to a Replica Set
148+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149+
150+
The following operation adds a :binary:`~bin.mongod` instance, running on
151+
the host ``mongodb3.example.net`` and accessible on the default port
152+
``27017`` as an arbiter:
153+
154+
- Member Configuration Document
155+
156+
.. cssclass:: copyable-code
157+
158+
.. code-block:: javascript
159+
160+
rs.add( { host: "mongodb3.example.net:27017", arbiterOnly: true } )
161+
162+
- Host name
163+
164+
.. cssclass:: copyable-code
165+
166+
.. code-block:: javascript
167+
168+
rs.add("mongodb3.example.net:27017"'", true)
169+
170+
.. include:: /includes/extracts/arbiters-and-pvs-with-reference.rst
171+
93172

94173
See also:
95174

0 commit comments

Comments
 (0)