定義
rs.reconfig( configuration, { options } )既存のレプリカセットを再構成し、既存のレプリカセット構成を上書きします。メソッドを実行するには、レプリカセットのプライマリに接続する必要があります。
重要
mongosh メソッド
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.データベースコマンドについては、
replSetReconfigコマンドを参照してください。MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
The
rs.reconfig()method has the following syntax:rs.reconfig( <configuration>, { "force" : <boolean>, "maxTimeMS" : <int> } ) Parameterタイプ説明ドキュメント
レプリカセットの構成を指定するドキュメント。
ブール値
任意
使用可能なレプリカセット ノードに新しい構成を強制的に受け入れさせるには、
trueを指定します。デフォルトはfalseです。強制的に再構成すると、 がコミットした書き込みの ロールバック
"majority"など、予期しない動作が発生する可能性があります。integer
任意
Specifies a cumulative time limit in milliseconds for processing the
rs.reconfig()operation. By default,rs.reconfig()waits indefinitely for the replica configuration to propagate to a majority of replica set members.To reconfigure an existing replica set, first retrieve the current configuration with
rs.conf(), modify the configuration document as needed, and then pass the modified document tors.reconfig().forceパラメーターを使用すると、非プライマリ ノードに対し再構成コマンドを発行できます。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
動作
グローバル書込み保証 (write concern)
You must explicitly set the global default write concern before attempting to reconfigure a replica set with a configuration that would change the implicit default write concern. To set the global default write concern, use the setDefaultRWConcern command.
term レプリカ構成フィールド
The term field is set by the primary replica set member. The primary ignores the term field if set explicitly in the rs.reconfig() operation.
再構成により追加または除外できるのは一度に 1 つの投票ノードのみ
rs.reconfig() by default allows adding or removing no more than 1 voting member at a time. For example, a new configuration can make at most one of the following changes to the cluster membership:
新しい投票レプリカセット ノードを追加
既存の投票レプリカセット ノードを排除
既存のレプリカセット ノードの
votesを変更
To add or remove multiple voting members, issue a series of rs.reconfig() operations to add or remove one member at a time.
Issuing a force reconfiguration immediately installs the new configuration even if it adds or removes multiple voting members. Force reconfiguration can cause unexpected behavior, such as the rollback of "majority" committed write operations.
再構成により、過半数のノードをレプリカ構成をインストールするまで待機させる
rs.reconfig() waits until a majority of voting replica set members install the new replica configuration before returning success. A voting member is any replica set member where members[n].votes is 1, including arbiters.
レプリカセット ノードは、ハートビートを介してレプリカ構成を伝達します。ノードは、より高い version および term を持つ構成を学ぶたびに、新しい構成をインストールします。再構成プロセスには、2 つの異なる「待機」フェーズがあります。
- 1) 新しい構成をインストールする前に、現在の構成がコミットされるまで待機します。
The "current" configuration refers to the replica configuration in use by the primary at the time
rs.reconfig()is issued.構成は、次の場合にコミットされます。
投票権のあるレプリカセット ノードの過半数が、現在の構成をインストールした
以前の構成で
"majority"でコミットされたすべての書込みが、現在の構成でも過半数に複製された
通常、現在の構成は、投票権のあるレプリカセット ノードの過半数にすでにインストールされています。ただし、以前の構成でコミットされた書込みの過半数が、現在の構成ですべてコミットされるとは限りません。
Delayedノードまたはlagging behindプライマリであるノードは、このフェーズで費やす時間を増やすことができます。操作がmaxTimeMS制限付きで発行され、待機中に操作が制限を超えた場合、操作はエラーを返し、新しい構成を破棄します。 制限は累積であり、次のフェーズに進んでリセットされません。
- 2) 新しい構成の投票ノードの過半数が新しい構成をインストールするまで待機します。
The "new" configuration refers to the replica configuration specified to
rs.reconfig().プライマリは、新しいレプリカ構成をインストールして使用を開始し、その後に構成を残りのレプリカセットノードに伝達します。この操作は、投票権のあるノードの過半数が新しい構成をインストールすることは待ちますが、新しい構成がコミットされることを待つ必要はありません。
操作がmaxTimeMS制限付きで発行され、待機中に操作が制限を超えた場合、操作はエラーを返しますが、新しい構成の使用と伝達は続行されます。
Issuing a force reconfiguration immediately installs the new configuration regardless of the commitment status of the previous configuration. Force reconfiguration can cause unexpected behavior, such as the rollback of "majority" committed write operations.
現在のレプリカ構成のコミット ステータスを確認するには、レプリカ セットのプライマリで、commitStatus パラメータを指定して replSetGetConfig を発行します。
アクセス制御
アクセス制御を強制する配置でメソッドを実行するには、ユーザーはクラスター リソースに対する replSetConfigure 特権アクションを持っている必要があります。admin データベースで使用可能な clusterManager 組み込みロールは、このコマンドに必要な特権を提供します。
ロック動作
rs.reconfig() obtains a special mutually exclusive lock to prevent more than one rs.reconfig() operation from occurring at the same time.
混合バージョンのレプリカセット
警告
MongoDB のバージョンによって検証ルールが異なる可能性があるため、異なるバージョンの MongoDB のノードを含むレプリカセットの再設定は避けてください。
可用性
The rs.reconfig() shell method can trigger the current primary to step down in some situations. Primary step-down triggers an election to select a new primary:
プライマリが降格すると、進行中のすべての書込みが停止します。 詳細については、「動作 」を参照してください。
デフォルトの replica configuration settings を前提とすると、クラスターが新しいプライマリを選択するまでの時間の中央値は、通常 12 秒を超えないはずです。これには、プライマリを利用不可としてマークし、選挙を呼び出して完了するために必要な時間が含まれます。settings.electionTimeoutMillis レプリケーション構成オプションを変更することで、この期間を調整できます。ネットワーク レイテンシなどの要因により、レプリカセット選挙が完了するまでにかかる時間が長くなる可能性があり、その結果、クラスターがプライマリなしで稼働できる時間にも影響します。これらの要因は、お使いのクラスター アーキテクチャによって異なります。
選挙プロセス中、クラスタは新しいプライマリを選出するまで書込み (write) 操作を受け付けません。
アプリケーション接続ロジックには、自動フェールオーバーとその後の選挙に対する許容範囲が含まれている必要があります。MongoDB ドライバーはプライマリの損失を検出し、自動的に 1 回、特定の書き込み操作を再試行することで、自動フェイルオーバーと選挙の組み込み処理を追加で行います。
互換性のあるドライバでは、デフォルトで再試行可能な書き込みが有効になります
実稼働クラスターへの潜在的な影響をさらに軽減するには、スケジュールされたメンテナンス期間中にのみ再構成してください。
{ force: true }
ノードの優先順位と投票
ノードを除外した後に発信接続を削除する
Using rs.reconfig() to remove a replica set member does not automatically drop open outgoing connections from other replica set members to the removed member.
デフォルトでは、レプリカセット ノードは 5 分間待機してから、除外されたノードへの接続を削除します。シャーディングされたレプリカセットでは、ShardingTaskExecutorPoolHostTimeoutMS サーバー パラメーターを使用してこのタイムアウトを変更できます。
レプリカセットから削除されたノードへのすべての送信接続をすぐに削除するには、レプリカセット上の残りの各ノードでdropConnections管理コマンドを実行します。
db.adminCommand( { "dropConnections" : 1, "hostAndPort" : [ "<hostname>:<port>" ] } )
<hostname> と <port> を除外されたノードのものに置き換えます。
新しい投票レプリカセットノードの自動再構成
MongoDB 5.0 以降では、新しく追加されたセカンダリは投票ノードとしてカウントされず、SECONDARY 状態に達するまで選出されません。
新しい投票ノードがレプリカセットに追加されると、replSetReconfig はノードの構成に newlyAdded フィールドを内部的に追加します。newlyAdded フィールドを持つノードは、現在の投票ノードの数にはカウントされません。最初の同期が完了し、ノードがSECONDARY の状態に達すると、newlyAdded フィールドは自動的に削除されます。
注意
newlyAddedという名前のフィールドを追加しようとする構成は、{ force: true }で実行した場合でもエラーになります。If an existing node has a
newlyAddedfield, usingrs.reconfig()to change the configuration will not remove thenewlyAddedfield. ThenewlyAddedfield will be appended to the user provided configuration.replSetGetConfigは、その出力からすべてのnewlyAddedフィールドを除きます。newlyAddedフィールドを表示する場合は、local.system.replsetコレクションに直接クエリできます。
例
rs0 という名前のレプリカセットは以下のような構成になっています。
{ "_id" : "rs0", "version" : 1, "protocolVersion" : Long(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" : 1, "tags" : { }, "secondaryDelaySecs" : Long(0), "votes" : 1 }, { "_id" : 2, "host" : "mongodb2.example.net:27017", "arbiterOnly" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : Long(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : 2000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("58858acc1f5609ed986b641b") } }
レプリカセット ノードの優先順位の変更
The following sequence of operations updates the members[n].priority of the second member. The operations are issued through a mongosh session that is connected to the primary.
cfg = rs.conf(); cfg.members[1].priority = 2; rs.reconfig(cfg);
2 番目のステートメントは、
members[n].priority値をmembers配列の 2 番目のドキュメントに設定します。追加設定については、「レプリカセットの構成設定」を参照してください。配列内のノード構成ドキュメントにアクセスするために、ステートメントはレプリカセット ノードの
members[n]._idフィールドではなく、配列インデックスを使用します。The last statement calls the
rs.reconfig()method with the modifiedcfgto initialize this new configuration. Upon successful reconfiguration, the replica set configuration will resemble the following:
{ "_id" : "rs0", "version" : 2, "protocolVersion" : Long(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" : false, "buildIndexes" : true, "hidden" : false, "priority" : 1, "tags" : { }, "secondaryDelaySecs" : Long(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true, "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "catchUpTimeoutMillis" : 2000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 }, "replicaSetId" : ObjectId("58858acc1f5609ed986b641b") } }
レプリカセット設定の変更
クラスター レプリカセット settings ドキュメントを変更することもできます。settings ドキュメントには、レプリカセット全体に適用される構成オプションが含まれています。
The following sequence of operations updates the settings.heartbeatTimeoutSecs of the cluster to 15. The operations are issued through a mongosh session that is connected to the primary.
cfg = rs.conf(); cfg.settings.heartbeatTimeoutSecs = 15; rs.reconfig(cfg);