|
3 、自动故障转移 |
3 、Automatic Failover |
|
在主副本变得不可用之后,自动故障转移将导致合格的辅助副本自动转换为主角色。当承载主副本的WSFC节点对于承载辅助副本的节点而言为本地节点时,自动故障转移最适合。这是因为数据同步最适合于计算机之间的低消息延迟时间情况以及因为客户端连接可以保持为本地。 |
An automatic failover causes a qualified secondary replica to automatically transition to the primary role after the primary replica becomes unavailable. Automatic failover is best suited when the WSFC node that hosts the primary replica is local to the node that hosts the secondary replica. This is because data synchronization works best with low message latency between computers and because client connections can remain local. |
|
3.1 、自动故障转移所需条件 |
3.1 、Conditions Required for an Automatic Failover |
|
仅在以下条件下才发生自动故障转移: |
Automatic failover occurs only under the following conditions: |
|
· 存在自动故障转移集。此自动故障转移集由主要副本和次要副本(自动故障转移目标)构成,主要副本和次要副本都配置为同步提交模式并且设置为自动故障转移。如果主要副本设置为手动故障转移,则自动故障切换将无法发生,即使将某一次要副本设置为自动故障转移。 |
· An automatic failover set exists. This set consists of a primary replica and a secondary replica (the automatic failover target) that are both configured for synchronous-commit mode and set to AUTOMATIC failover. If the primary replica is set to MANUAL failover, automatic failover cannot occur, even if a secondary replica is set to AUTOMATIC failover. |
|
有关详细信息,请参阅 可用性模式(AlwaysOn 可用性组)。 |
For more information, see Availability Modes (Always On Availability Groups). |
|
· 自动故障转移目标具有正常运行的同步状态(这指示故障转移目标上的每个辅助数据库都与其相应的主数据库同步)。 |
· The automatic failover target has a healthy synchronization state (this indicates that every secondary database on the failover target is synchronized with its corresponding primary database). |
|
提示 |
|
|
AlwaysOn 可用性组监视自动故障转移集中两个副本的运行状况。如果任一副本失败,则该可用性组的运行状况状态将设置为“严重”。如果辅助副本失败,则自动故障转移将不可行,因为自动故障转移目标不可用。如果主副本失败,则可用性组将故障转移到辅助副本。在之前的主副本进入联机状态之前,将不存在任何自动故障转移目标。在任一情况下,为了在连续出现失败这种近乎不可能发生的情况下确保可用性,我们建议您将其他辅助副本配置为自动故障转移目标。 |
Always On Availability Groups monitors the health of both replicas in an automatic failover set. If either replica fails, the availability group's health state is set to CRITICAL. If the secondary replica fails, automatic failover is not possible because the automatic failover target is unavailable. If the primary replica fails, the availability group will fail over to the secondary replica. Until the former primary replica comes online, no automatic failover target exists. In either case, to ensure availability in the unlikely case of a sequential failure, we recommend that you configure a different secondary replica as the automatic failover target. |
|
有关详细信息,请参阅 使用AlwaysOn 策略查看可用性组的运行状况(SQL Server)和 更改可用性副本的故障转移模式(SQL Server)。 |
For more information, see Use Always On Policies to View the Health of an Availability Group(SQL Server) and Change the Failover Mode of an Availability Replica(SQL Server). |
|
· Windows Server 故障转移群集(WSFC)群集具有仲裁。有关详细信息,请参阅 WSFC 仲裁模式和投票配置(SQL Server)。 |
· The Windows Server Failover Clustering(WSFC) cluster has quorum. For more information, see WSFC Quorum Modes and Voting Configuration (SQL Server). |
|
· 主副本已变得不可用,并且由灵活的故障转移策略定义的故障转移条件级别已得到满足。有关故障转移条件级别的信息,请参阅 针对可用性组的自动故障转移的灵活的故障转移策略(SQL Server)。 |
· The primary replica has become unavailable, and the failover-condition levels defined by your the flexible failover policy have been met. For information about failover-condition levels, see Flexible Failover Policy for Automatic Failover of an Availability Group (SQL Server). |
|
3.2 、自动故障转移的原理 |
3.2 、How Automatic Failover Works |
|
自动故障转移将启动以下操作序列: |
An automatic failover initiates the following sequence of actions: |
|
1. 如果承载当前主副本的服务器实例仍在运行,则它会将主数据库的状态更改为“已断开连接”并断开所有客户端的连接。 |
1. If the server instance that is hosting the current primary replica is still running, it changes the state of the primary databases to DISCONNECTED and disconnects all clients. |
|
2. 如果在目标辅助副本上有任何日志记录正在恢复队列中处于等待状态,则辅助副本会应用剩下的日志记录,以完成对辅助数据库的前滚操作。 |
2.If any log records are waiting in recovery queues on the target secondary replica, the secondary replica applies the remaining log records to finish rolling forward the secondary databases. |
|
备注 |
Remarks |
|
将日志应用于给定数据库所需的时间取决于系统的速度、最近的工作负载以及恢复队列中的日志量。 |
The amount of time required to apply the log to a given database depends on the speed of the system, the recent work load, and the amount of log in the recovery queue. |
|
3. 先前的辅助副本转换到主角色。其数据库成为主数据库。新的主副本将尽快回滚任何未提交的事务(恢复的撤消阶段)。锁定会分离这些未提交的事务,允许当客户端使用数据库时在后台进行回滚。此过程不会回滚任何已提交的事务。 |
3.The former secondary replica transitions to the primary role. Its databases become the primary databases. The new primary replica rolls back any uncommitted transactions (the undo phase of recovery) as quickly as possible. Locks isolate these uncommitted transactions, allowing roll back to occur in the background while clients use the database. This process does not roll back any committed transactions. |
|
直到连接给定的辅助数据库后,才将其简要标记为 NOT_SYNCHRONIZED。在回滚恢复开始前,辅助数据库可以连接到新的主数据库并快速转换为同步状态。最佳事例是通常用于第三个同步提交的副本,该副本在故障转移之后仍然为辅助角色。 |
Until a given secondary database is connected, it is briefly marked as NOT_SYNCHRONIZED. Before the rollback recovery starts, secondary databases can connect to the new primary databases and quickly transition to the SYNCHRONIZED state. The best case is usually for a third synchronous-commit replica that remains in the secondary role after the failover. |
|
4. 然后,当承载先前主副本的服务器实例重新启动时,它将识别出其他可用性副本现在拥有主角色。以前的主副本将转换为辅助角色,并且其数据库将成为辅助数据库。新的辅助副本连接到当前主副本,并尽快将其数据库更新为当前主数据库。只要新的辅助副本重新同步了其数据库,就可以再次执行故障转移,但按反向执行。 |
4. Later, when the server instance that is hosting the former primary replica restarts, it recognizes that another availability replica now owns the primary role. The former primary replica transitions to the secondary role, and its databases become secondary databases. The new secondary replica connects to the current primary replica and catches its database up to the current primary databases as quickly as possible. As soon as the new secondary replica has resynchronized its databases, failover is again possible, in the reverse direction. |
|
3.3 、配置自动故障转移 |
3.3 、To Configure Automatic Failover |
|
可用性副本可以配置为支持在任何一点进行自动故障转移。 |
An availability replica can be configured to support automatic failover at any point. |
|
1. 确保辅助副本配置为使用同步提交可用性模式。有关详细信息,请参阅 更改可用性副本的可用性模式(SQL Server)。 |
1.Ensure that the secondary replica is configured to use the synchronous-commit availability mode. For more information, see Change the Availability Mode of an Availability Replica (SQL Server). |
|
2. 将故障转移模式设置为自动。有关详细信息,请参阅 更改可用性副本的故障转移模式(SQL Server)。 |
2.Set the failover mode to automatic. For more information, see Change the Failover Mode of an Availability Replica (SQL Server). |
|
3. 更改可用性组的灵活故障转移策略,以指定可以导致自动故障转移的故障类别,此功能为可选的。有关详细信息,请参阅 配置灵活的故障转移策略以控制自动故障转移的条件(AlwaysOn 可用性组)和 故障转移群集实例的故障转移策略。 |
3.Optionally, change the flexible failover policy of the availability group to specify the sorts of failures that can cause an automatic failover to occur. For more information, see Configure the Flexible Failover Policy to Control Conditions for Automatic Failover (Always On Availability Groups) and Failover Policy for Failover Cluster Instances. |
