-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathrs.reconfigForPSASet.txt
319 lines (262 loc) · 8.99 KB
/
rs.reconfigForPSASet.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
======================
rs.reconfigForPSASet()
======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: rs.reconfigForPSASet( memberIndex, config, { options } )
.. versionadded:: 5.0
Safely perform some reconfiguration changes on a
primary-secondary-arbiter (PSA) replica set or on a replica set that
is changing to a PSA architecture. You should only use this method in
one of the following cases:
- You want to reconfigure a secondary in an existing three-member
replica set with a PSA architecture to become a voting,
data-bearing node with a non-zero :rsconf:`priority
<members[n].priority>`.
- You want to add a new voting, data-bearing node with a non-zero
priority to an existing two-member replica set that contains one
voting, data-bearing node and one arbiter.
.. warning::
If the secondary you are adding is lagged and the resulting
replica set is a PSA configuration, the first configuration change
will change the number of nodes that need to commit a change with
:writeconcern:`"majority"`. In this case, your commit point will
lag until the secondary has caught up.
For details about the behavior of this method, see
:ref:`reconfigForPSASet-behavior`.
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-onprem-only.rst
Syntax
------
The :method:`rs.reconfigForPSASet()` method has the following syntax:
.. code-block:: bash
rs.reconfigForPSASet(
memberIndex: <num>,
config: <configuration>,
{
"force" : <boolean>,
"maxTimeMS" : <int>
}
)
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Parameter
- Type
- Description
* - ``memberIndex``
- integer
- The index of the secondary that is being added or modified.
* - ``config``
- document
- A :ref:`document <replica-set-configuration-settings>` that
specifies the new configuration of a replica set.
* - ``force``
- boolean
- *Optional*
:red:`WARNING:` Running the :method:`rs.reconfigForPSASet()`
method with ``force: true`` is not recommended and can lead to
committed writes being rolled back.
Specify ``true`` to force the available replica set members to
accept the new configuration. Defaults to ``false``.
Force reconfiguration can result in unexpected or undesired
behavior, including :ref:`rollback <replica-set-rollbacks>` of
:writeconcern:`"majority"` committed writes.
* - ``maxTimeMS``
- integer
- *Optional*
Specifies a cumulative time limit in milliseconds
for processing each reconfiguration during the
:method:`rs.reconfigForPSASet()` operation. By default,
:method:`rs.reconfigForPSASet()` waits indefinitely for the
replica configurations to propagate to a majority of replica
set members.
.. _reconfigForPSASet-behavior:
Behavior
--------
The :method:`rs.reconfigForPSASet()` method reconfigures your replica
set in two steps:
1. The method reconfigures your replica set to add or modify a secondary
with ``{ votes: 1, priority: 0 }``.
2. Once the added or modified secondary has caught up with all committed
writes, the method reconfigures the secondary to have the
:rsconf:`priority <members[n].priority>` specified in the
:method:`rs.reconfigForPSASet()` command
(``{ votes: 1, priority: <num> }``).
The two-step approach avoids the possibility of rolling back committed
writes in the case of a failover to the new secondary before the new
secondary has all committed writes from the previous configuration.
.. _reconfigForPSASet-usage:
Example
-------
A replica set named ``rs0`` has the following configuration:
.. code-block:: javascript
{
"_id" : "rs0",
"version" : 1,
"term": 1,
"members" : [
{
"_id" : 0,
"host" : "mongodb0.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
},
{
"_id" : 2,
"host" : "mongodb1.example.net:27017",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
}
],
"protocolVersion" : Long("1"),
"writeConcernMajorityJournalDefault": true,
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 2000,
"getLastErrorModes" : {},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("60e6f83923193faa336889d2")
}
}
The following sequence of operations add a new secondary to the replica
set. The operations are issued in the :binary:`~bin.mongosh` shell while
connected to the primary.
.. code-block:: javascript
cfg = rs.conf();
cfg["members"] = [
{
"_id" : 0,
"host" : "mongodb0.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
},
{
"_id" : 1,
"host" : "mongodb1.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 2,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
},
{
"_id" : 2,
"host" : "mongodb2.example.net:27017",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
}
]
rs.reconfigForPSASet(1, cfg);
#. The first statement uses the :method:`rs.conf()` method to retrieve
a document containing the current :ref:`configuration
<replSetGetConfig-output>` for the replica set and stores the
document in the local variable ``cfg``.
#. The second statement adds the new secondary to the ``members`` array.
In this configuration the new secondary is added at ``memberIndex``
``1``. The ``memberIndex`` is the same as the array index. For
additional settings, see :ref:`replica set configuration settings
<replSetGetConfig-output>`.
#. The last statement calls the :method:`rs.reconfigForPSASet()` method
with the ``memberIndex`` ``1`` and the modified ``cfg``. The
``memberIndex`` is the array position of the new member in the
``members`` array. Upon successful reconfiguration, the replica set
configuration resembles the following:
.. code-block:: javascript
{
"_id" : "rs0",
"version" : 1,
"term": 1,
"members" : [
{
"_id" : 0,
"host" : "mongodb0.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
},
{
"_id" : 1,
"host" : "mongodb1.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 2,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
},
{
"_id" : 2,
"host" : "mongodb2.example.net:27017",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {},
"secondaryDelaySecs" : Long("0"),
"votes" : 1
}
],
"protocolVersion" : Long("1"),
"writeConcernMajorityJournalDefault": true,
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 2000,
"getLastErrorModes" : {},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("60e6f83923193faa336889d2")
}
}
.. seealso::
- :method:`rs.conf()`
- :method:`rs.reconfig()`
- :ref:`replSetGetConfig-output`
- :doc:`/administration/replica-set-member-configuration`
- :doc:`/administration/replica-set-maintenance`