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