MySQL Shell 9.0  /  ...  /  在 InnoDB ClusterSet 中隔離叢集

8.9.1 在 InnoDB ClusterSet 中隔離叢集

緊急容錯移轉之後,如果 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()

在複寫叢集上發出 .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)

即使您主要在屬於 clusterset 的叢集上使用隔離,也可以使用 <Cluster>.fenceAllTraffic() 隔離獨立叢集。

  1. 若要將主要叢集從寫入流量隔離,請使用 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
  2. 若要檢查您是否已將主要叢集從寫入流量隔離,請使用 <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."
  3. 若要取消隔離叢集並恢復主要叢集的寫入流量,請使用 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
  4. 若要將叢集從所有流量隔離,請使用 Cluster.fenceAllTraffic 命令,如下所示

          <Cluster>.fenceAllTraffic()

    super_read_only 狀態會在叢集實例的主要實例上啟用。在啟用叢集中的所有實例上的 offline_mode 之前

          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
  5. 若要取消隔離叢集的所有流量,請使用 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>