qua_cluster_failover#

Begins a planned failover of a two-node cluster: the instance that serves clients hands the serving role to the other instance, for example before maintenance of its machine. Clients reconnect to the other instance with the same name.

Syntax#

qua_cluster_failover
    [ [ @target_instance_id = ] target_instance_id ] [;]

Arguments#

[ @target_instance_id = ] target_instance_id

The instance identifier of the instance that takes the role, int. Optional; a cluster has two instances, so without it the procedure picks the other one. When given, it must be the other instance.

Result set#

Column

Type

Description

operation_id

uniqueidentifier

Identifier of the failover, also written into the log lines of both instances.

source_instance_id

int

The instance that hands the role over: the one the session is connected to.

target_instance_id

int

The instance that takes the role.

target_incarnation_id

uniqueidentifier

The run of the target instance’s process that reported itself ready; shown for diagnostics.

target_host_name

nvarchar(255)

The machine of the target instance.

Remarks#

Run the procedure on the instance that serves clients; the other instance has no client port. Before it changes anything, the procedure checks the other instance’s status in the metabase: the instance must report regularly, wait as the standby, be able to use the instance master key and run the same build. When a check fails, the procedure is refused with the reasons and nothing changes; the Cluster page of the Admin Portal shows the same checks.

The procedure returns its row once the failover is recorded in the metabase. The serving instance then:

  1. stops accepting connections on its client ports and begins no new request: it closes every connection that waits for its next request, and closes the others as soon as their work ends; a new request on a connection that is still open is refused. Statements that are running, transactions that are open and the cancel of a running request get up to 10 seconds to finish. A job step that was about to start does not start;

  2. ends every session - the session that ran the procedure too - and stops its jobs and background work;

  3. releases the lease to the other instance, which takes the role at once, loads the metadata and opens its client ports. Only the target may take the lease for 30 seconds from the release (the handoff time to live of the cluster configuration).

During the failover no instance accepts connections; clients connecting with MultiSubnetFailover=True retry until the target serves. Every step writes a line starting with Cluster: planned failover into the log of the instance that hands the role over, and the target writes a line when it has completed the failover. The health details of the serving instance show the last failover it began and its step.

A failover that does not finish never leaves the cluster without a serving instance for good: when the source stops during the failover, or the target does not take the role within the handoff time to live, the reservation lapses, and afterwards either instance may take the role as after any failure - the former serving instance when it restarts, the other one in automatic failover mode or with an operator’s authorization.

A failover is moved whatever the failover mode set with qua_cluster_set_failover_mode, and it does not count towards the anti-flapping period of automatic failover. Only one failover runs at a time; while one runs, this procedure and qua_cluster_set_failover_mode are refused at once. When the serving instance is shut down while the procedure runs or before the instance began to stop accepting connections, the failover is cancelled and the instance shuts down as usual; a shutdown requested later shortens the wait for running statements, and the failover finishes. When the procedure reports that the outcome is unknown, the instance keeps serving and cancels the failover if the metabase recorded it; run the procedure again.

Permissions#

Requires the CONTROL SERVER permission.

Example#

Hands the serving role to the other instance of the cluster.

EXEC qua_cluster_failover;

Names the target explicitly.

EXEC qua_cluster_failover @target_instance_id = 2;

See Also#