在緊急容錯移轉之後,且 ClusterSet 的各部分之間存在交易集不同的風險時,您必須將叢集從寫入流量或所有流量中隔離。
如果發生網路分割,則可能會出現腦裂情況,其中實例會失去同步,且無法正確通訊以定義同步狀態。當 DBA 決定強制選舉複本叢集成為主要叢集,進而建立多個主要節點時,可能會發生腦裂,導致腦裂情況。
在這種情況下,DBA 可以選擇將原始主要叢集從以下情況中隔離:
寫入。
所有流量。
提供三種隔離操作:
-
<Cluster>.fenceWrites()
:停止將寫入流量傳送至 ClusterSet 的主要叢集。複本叢集不接受寫入,因此此操作對它們沒有影響。可以在 INVALIDATED 複本叢集上使用。此外,如果針對已停用
super_read_only
的複本叢集執行,則會啟用它。 -
<Cluster>.unfenceWrites()
:恢復寫入流量。此操作可以在先前使用<Cluster>.fenceWrites()
操作從寫入流量中隔離的叢集上執行。無法在複本叢集上使用
。cluster
.unfenceWrites() -
<Cluster>.fenceAllTraffic()
:將叢集和該叢集中的所有讀取複本與所有流量隔離。如果您使用<Cluster>.fenceAllTraffic()
將叢集與所有流量隔離,則必須使用dba.rebootClusterFromCompleteOutage()
MySQL Shell 命令重新啟動叢集。如需
dba.rebootClusterFromCompleteOutage()
的詳細資訊,請參閱第 7.8.3 節,〈從重大中斷重新啟動叢集〉。
在複本叢集上發出 .fenceWrites()
會傳回錯誤
ERROR: Unable to fence Cluster from write traffic:
operation not permitted on REPLICA Clusters
Cluster.fenceWrites: The Cluster '<Cluster>' is a REPLICA Cluster
of the ClusterSet '<ClusterSet>' (MYSQLSH 51616)
即使您主要是在屬於叢集集合的叢集上使用隔離,也可以使用 <Cluster>.fenceAllTraffic()
隔離獨立叢集。
-
若要將主要叢集從寫入流量中隔離,請使用 Cluster.fenceWrites 命令,如下所示:
<Cluster>.fenceWrites()
執行命令後
會停用叢集上的自動
super_read_only
管理。在叢集中的所有實例上啟用
super_read_only
。會阻止所有應用程式在叢集上執行寫入。
cluster.fenceWrites() The Cluster 'primary' will be fenced from write traffic * Disabling automatic super_read_only management on the Cluster... * Enabling super_read_only on '127.0.0.1:3311'... * Enabling super_read_only on '127.0.0.1:3312'... * Enabling super_read_only on '127.0.0.1:3313'... NOTE: Applications will now be blocked from performing writes on Cluster 'primary'. Use <Cluster>.unfenceWrites() to resume writes if you are certain a split-brain is not in effect. Cluster successfully fenced from write traffic
-
若要檢查是否已將主要叢集從寫入流量中隔離,請使用
<Cluster>.status
命令,如下所示:<Cluster>.clusterset.status()
輸出如下:
clusterset.status() { "clusters": { "primary": { "clusterErrors": [ "WARNING: Cluster is fenced from Write traffic. Use cluster.unfenceWrites() to unfence the Cluster." ], "clusterRole": "PRIMARY", "globalStatus": "OK_FENCED_WRITES", "primary": null, "status": "FENCED_WRITES", "statusText": "Cluster is fenced from Write Traffic." }, "replica": { "clusterRole": "REPLICA", "clusterSetReplicationStatus": "OK", "globalStatus": "OK" } }, "domainName": "primary", "globalPrimaryInstance": null, "primaryCluster": "primary", "status": "UNAVAILABLE", "statusText": "Primary Cluster is fenced from write traffic."
-
若要解除叢集的隔離並恢復寫入流量至主要叢集,請使用 Cluster.fenceWrites 命令,如下所示:
<Cluster>.unfenceWrites()
會啟用主要叢集上的自動
super_read_only
管理,以及主要叢集實例上的super_read_only
狀態。cluster.unfenceWrites() The Cluster 'primary' will be unfenced from write traffic * Enabling automatic super_read_only management on the Cluster... * Disabling super_read_only on the primary '127.0.0.1:3311'... Cluster successfully unfenced from write traffic
-
若要將叢集與所有流量隔離,請使用 Cluster.fenceAllTraffic 命令,如下所示:
<Cluster>.fenceAllTraffic()
在啟用叢集中所有實例上的
offline_mode
之前,會先在叢集實例的主要實例上啟用super_read_only
狀態。cluster.fenceAllTraffic() The Cluster 'primary' will be fenced from all traffic * Enabling super_read_only on the primary '127.0.0.1:3311'... * Enabling offline_mode on the primary '127.0.0.1:3311'... * Enabling offline_mode on '127.0.0.1:3312'... * Stopping Group Replication on '127.0.0.1:3312'... * Enabling offline_mode on '127.0.0.1:3313'... * Stopping Group Replication on '127.0.0.1:3313'... * Stopping Group Replication on the primary '127.0.0.1:3311'... Cluster successfully fenced from all traffic
-
若要將叢集從所有流量中解除隔離,請使用
dba.rebootClusterFromCompleteOutage()
MySQL Shell 命令。還原叢集後,當系統詢問您是否要將實例重新加入叢集時,請選取 Y,以將實例重新加入叢集。cluster = dba.rebootClusterFromCompleteOutage() Restoring the cluster 'primary' from complete outage... The instance '127.0.0.1:3312' was part of the cluster configuration. Would you like to rejoin it to the cluster? [y/N]: Y The instance '127.0.0.1:3313' was part of the cluster configuration. Would you like to rejoin it to the cluster? [y/N]: Y * Waiting for seed instance to become ONLINE... 127.0.0.1:3311 was restored. Rejoining '127.0.0.1:3312' to the cluster. Rejoining instance '127.0.0.1:3312' to cluster 'primary'... The instance '127.0.0.1:3312' was successfully rejoined to the cluster. Rejoining '127.0.0.1:3313' to the cluster. Rejoining instance '127.0.0.1:3313' to cluster 'primary'... The instance '127.0.0.1:3313' was successfully rejoined to the cluster. The cluster was successfully rebooted. <Cluster:primary>