What a failover can leave unknown#

The lease protects the metabase: a node that has lost the lease can no longer commit anything to it, so the metadata, the job definitions and the job history are never changed by two nodes at once. The lease does not reach beyond the metabase. A statement Querona sends to a data source, a file a job step writes or a tool a job step runs are not checked against the lease, and when a failover interrupts them, nobody can tell afterwards whether they completed.

Querona never guesses such an outcome, and it never repeats interrupted work by itself. It marks the work whose outcome is unknown and leaves the decision to an operator, as SQL Server leaves an in-doubt distributed transaction to an administrator. This page lists those cases and how to handle them.

Jobs#

Jobs run only on the serving node. Before every step, the node checks that it still holds the lease; a node that has lost it starts no further step. How an interrupted execution ends depends on how the node stopped serving:

What happened

Status

What the execution history shows

A planned failover, or a clean stop of the service

Canceled

SQL Server Agent’s shutdown text, The job was stopped prior to completion by Shutdown Sequence 0., followed by who or which schedule started the job and the last step that ran. The running step was asked to stop. A step that was about to start during a planned failover or a clean stop did not start; the text names it as the last step.

A planned failover or a clean stop, and the job did not stop within 15 seconds

Failed, outcome unknown

The same texts as in the next row: the job kept running after the node stopped waiting for it.

The node lost the lease while the job ran: its server or process failed, it froze, or it lost the metabase

Failed, outcome unknown

The job was stopped prior to completion because the Engine process ended while it ran; its outcome is unknown. The text is the same as after a crash of a single installation, also when the process of the node kept running. The running step ends with The step did not complete because the Engine process ended while it ran; its outcome is unknown.

The job was requested, for example with sp_start_job, but had not begun

Canceled

The shutdown text, without the last step, since no step ran.

Nothing runs unrecorded. A node that has lost its metabase keeps serving until its lease budget runs out, and a job its schedule starts meanwhile does not run: a job, and each of its steps, starts only once the execution history in the metabase holds its start. A short metabase outage, such as a failover of the metabase’s availability group, delays the start by about the length of the outage, because the node writes the start again, for up to about a minute and only while it holds the lease. A job whose start could not be written leaves no entry in the execution history, since nothing of it ran; see Jobs and the metabase in Jobs and Schedules.

An execution of unknown outcome is recorded by the node that serves next, when its job scheduler starts, and the execution keeps the node that ran it (the Node column of the execution history). The Administrative Portal shows it as Failed in a yellow frame, with Outcome unknown in the execution summary; in msdb it reads as failed (run_status 0). See Jobs and Schedules.

Nothing is run again by itself. Neither the interrupted job nor a job requested just before the failover is started again on the other node, and schedules missed while no node served are not caught up, as in SQL Server Agent. The next run is the job’s next scheduled time, or a start by an operator.

A job can run twice at the same time. A job that does not stop within 15 seconds of being asked to keeps running on the node that lost the role, and the node that takes over can start the same job from its schedule meanwhile. Its changes to the metabase are refused, but its effects outside the metabase go on.

Make jobs safe to run again#

Write every job so that running it again, or running it twice, gives the same result as running it once:

  • load with MERGE or with a delete-and-insert of the period the job covers, not with a plain INSERT;

  • write into a staging table and switch it in at the end, so that an interrupted run leaves the target as it was;

  • record in the target which run or which period has been loaded, and let the job skip what is already there;

  • for a step that calls a tool or sends a file, make the receiving side reject a duplicate.

A job that cannot be made safe to run again needs an operator after every failover that interrupted it.

Statements sent to data sources#

Statements that Querona sends to a data source - an INSERT, UPDATE or DELETE on a table of a source, a procedure called on it - are not fenced by the lease as metabase changes are. Before every statement, and before every step of its plan - every statement of a batch, every pass of a WHILE loop, every statement of a procedure - the node checks that it still serves: that it holds the lease, its lease budget has not run out and it has not started to stop serving. A node that no longer serves runs nothing more of the batch, from any client, the REST API and job steps included, and answers the batch with error 3980 at severity 20, which makes the client end its connection. The check narrows the window but cannot close it, so when a failover interrupts such statements, the source may or may not have committed them:

  • A client whose connection broke during such a statement does not know its outcome, as after the failover of a SQL Server failover cluster instance. Check the source before running the statement again.

  • A statement the source has already received may complete there, and a statement the node started just before it stopped serving, or before it was suspended, still runs. On a virtual machine that was paused or saved past the lease, such a statement runs until the node has asked the metabase whether it still holds the lease - at most the confirmation window, 17 seconds with the default timings, after the resume; the node starts nothing new meanwhile.

  • A job step that ran such a statement ends as described above. When the node stops serving while the step runs and can still record it, the step ends Canceled, is not retried, and its history says that the cluster node stopped serving, followed by the text of error 3980.

Job steps that run tools#

A KSeF step runs a tool as a separate process. A step that is stopped keeps what it has downloaded and its checkpoint, and the next run continues from there; a run that ends abruptly leaves its folder readable (see KSeF). The company folder is wherever the step command names it: a folder on one node’s local disk is not seen by the other node, so after a failover the next run on the other node does not find the checkpoint there.

Handle an outcome that is unknown#

After a failover, on the node that serves now:

  1. Find the executions of unknown outcome: the yellow Failed entries of the execution history, or in SQL:

    SELECT h.job_id, h.run_date, h.run_time, h.message
    FROM msdb.dbo.sysjobhistory AS h
    WHERE h.step_id = 0 AND h.run_status = 0 AND h.message LIKE N'%outcome is unknown%';
    

    msdb.dbo.sysjobhistory reads the job history recorded in the metabase, so every node reports the same history, also right after a failover. An execution the failover interrupted gets its row once the job scheduler of the new serving node has started and closed it. A login without the VIEW ANY JOB permission sees only the jobs it owns, also before that scheduler has started. A query of msdb.dbo.sysjobs, which gives the job names, gets error 22022 until then, as in SQL Server while its Agent is not running. See sysjobhistory and When the job scheduler is not running.

  2. For each of them, check what its interrupted step changes - the target tables, the files, the external system - and whether that change was made.

  3. Start the job again if its work was not done, or was done only in part and the job is safe to run again. Otherwise complete or undo the work by hand first.

  4. Check also the jobs that were requested just before the failover and recorded as canceled: they did not run.

See also#