下面是我们在使用alwayson过程中遇到的一个切换案例。这个案例发生在2014年8月,虽然时间相对久远了,但是对我们学习理解alwayson的failover原理和过程还是很有帮助的。本次failover的触发原因是系统i/o问题。大家需要理解,操作系统i/o出现了问题不一定立即触发sql server发生漂移,因为坏的槽点可能不在sql server实例所用到的位置,但是随着时间持续 和数据堆积,问题槽点可能扩大升级。我们可以看到在本例中,第一次出现i/o问题到sql server 漂移间隔了16分钟,所以大家不要奇怪。我们重点可以failover的过程和触发条件设置上,即文章的第二和第三部分。
一 . 系统 i/o 异常 log追踪
1.1 10:36:12 发现i/o异常
1.2 10:45:43 显示个别读写花费时间较长
1.3 10:45:28 看似i/o严重
1.4 10:52:20 出现个别连接fail现象
(查看表中的最后一笔数据显示为10:53:17)
二 . alwayson failover 过程
2.1 系统提示需要failover
2.2 高可用性组的本地副本需要离线。
(相关知识:lease expired event from the cluster. possible causes include loss of lease, possible network issues and sp_server_diagnostic query timeout. )
2.3 错误提示信息显示,sql instance和wsfc连接异常。
2.4 可用性副本的角色发生变换。
2.5 角色为resolving无法访问db
(相关知识:when the role of an availability replica is indeterminate, such as during a failover, its databases are temporarily in a not synchronizing state. their role is set to resolving until the role of the availability replica has resolved.)
此时: 通过ssms管理器,连接数据也是不可以访问的,显示状态为不同步了。
三 . 相关知识点
3.1 什么是resourcedell?resourcedell的用途?
由于alwayson可用性组是建立在windows故障转移群集之上的,alwayson可用性组需要一个群集resourcedell来连接windows群集和sqlserver实例。由于可用性组是一个群集资源,windows群集需要透过alwayson的resourcedell来控制资源的上线/离线,检查资源是否失败,更改资源的状态和属性,以及发生各种命令给可用性副本实例。(alwayson可用性组的资源类型是“sqlserver availability group”)
alwayson通过sp_server_diagnostics来检查可用性组的健康状况,不断地获得诊断信息。sp_server_diagnostics的评估结果会被用来和alwayson可用性组的failureconditionlevel设置相比较,来约定是否符合发生故障转移的条件。一旦条件满足,则可用性组就被切换到新的可用性副本上。
3.2 healthchecktimeout
the healthchecktimeout setting is used to specify the length of time, in milliseconds, that the sql server resource dll should wait for information returned by the sp_server_diagnostics stored procedure before reporting the alwayson failover cluster instance (fci) as unresponsive. changes that are made to the timeout settings are effective immediately and do not require a restart of the sql server resource.
the resource dll determines the responsiveness of the sql instance using a health check timeout. the healthchecktimeout property defines how long the resource dll should wait for the sp_server_diagnostics stored procedure before it reports the sql instance as unresponsive to the wsfc service.
the following items describe how this property affects timeout and repeat interval settings:
- the resource dll calls the sp_server_diagnostics stored procedure and sets the repeat interval to one-third of the healthchecktimeout setting.
- if the sp_server_diagnostics stored procedure is slow or is not returning information, the resource dll will wait for the interval specified by healthchecktimeout before it reports to the wsfc service that the sql instance is unresponsive.
- if the dedicated connection is lost, the resource dll will retry the connection to the sql instance for the interval specified by healthchecktimeout before it reports to the wsfc service that the sql instance is unresponsive.
3.3 failureconditionlevel
the sql server database engine resource dll determines whether the detected health status is a condition for failure using the failureconditionlevel property. the failureconditionlevel property defines which detected health statuses cause restarts or failovers.
review sp_server_diagnostics (transact-sql) as this system stored procedure plays in important role in the failure condition levels.
level |
condition |
description |
0 |
no automatic failover or restart |
|
1 |
failover or restart on server down |
indicates that a server restart or failover will be triggered if the following condition is raised: sql server service is down. |
2 |
failover or restart on server unresponsive |
indicates that a server restart or failover will be triggered if any of the following conditions are raised: sql server service is down. sql server instance is not responsive (resource dll cannot receive data from sp_server_diagnostics within the healthchecktimeout settings). |
3 |
failover or restart on critical server errors |
indicates that a server restart or failover will be triggered if any of the following conditions are raised: sql server service is down. sql server instance is not responsive (resource dll cannot receive data from sp_server_diagnostics within the healthchecktimeout settings). system stored procedure sp_server_diagnostics returns ‘system error’. |
4 |
failover or restart on moderate server errors |
indicates that a server restart or failover will be triggered if any of the following conditions are raised: sql server service is down. sql server instance is not responsive (resource dll cannot receive data from sp_server_diagnostics within the healthchecktimeout settings). system stored procedure sp_server_diagnostics returns ‘system error’. system stored procedure sp_server_diagnostics returns ‘resource error’. |
5 |
failover or restart on any qualified failure conditions |
indicates that a server restart or failover will be triggered if any of the following conditions are raised: sql server service is down. sql server instance is not responsive (resource dll cannot receive data from sp_server_diagnostics within the healthchecktimeout settings). system stored procedure sp_server_diagnostics returns ‘system error’. system stored procedure sp_server_diagnostics returns ‘resource error’. system stored procedure sp_server_diagnostics returns ‘query_processing error’. |
3.4 通过sql更改相关配置。
the following example sets the healthchecktimeout option to 15,000 milliseconds (15 seconds).
alter server configuration
set failover cluster property healthchecktimeout = 15000;
the following example sets the failureconditionlevel property to 0, indicating that failover or restart will not be triggered automatically on any failure conditions.
alter server configuration set failover cluster property failureconditionlevel = 0;
四 . 结语
可用性副本的failover不仅仅取决于availability mode 和failover mode,还要受限于failureconditionlevel。
本文版权归作者所有,未经作者同意不得转载,谢谢配合!!!