Client connections to a cluster#

Clients connect to a cluster by one name, the cluster name, and reach whichever node serves. Only the serving node opens the client ports; nothing listens on them on the standby node, so a client that tries the standby’s address is never served there. What the client sees depends on the hosts: in the client tests the standby’s address refused the connection at once, while on the Windows nodes of the cluster tests the standby did not answer the connection request at all, and a client on Windows tried the next address only after its connect timeout of about 21 seconds (see Web and Data API clients). There are two ways to make the name lead to the serving node.

A: two address records

B: a load balancer

The cluster name points to

Both nodes’ IP addresses

The load balancer’s virtual address

Clients find the serving node by

Trying both addresses, with MultiSubnetFailover=True

The load balancer, which probes each node

Use it for

The clients listed under Supported clients, with MultiSubnetFailover=True (the default)

Every other client, or where a load balancer is available

Querona never changes DNS during a failover: both variants keep the same records all the time.

A: a name with two address records#

Create a DNS name of its own for the cluster, for example db-cluster.contoso.com, with two static address (A) records, one per node. Never use a computer’s name, and never an alias (CNAME): clients that dial a computer’s name reach that computer whichever node serves, and provisioning refuses a cluster name that names either node.

Clients connect with MultiSubnetFailover=True. The client then tries both addresses at once and keeps the connection that the serving node accepts, as it does for a SQL Server availability group listener:

Server=tcp:db-cluster.contoso.com,1433;Database=Sales;Integrated Security=True;Encrypt=True;
MultiSubnetFailover=True

Microsoft recommends MultiSubnetFailover=True for such names even when both addresses are in one subnet; see Listener, client connectivity, application failover. Do not use Failover Partner to connect to a cluster: it belongs to database mirroring.

Note

A node that hangs. Both addresses stay in DNS. When the Querona process on a node hangs while its TDS port is still open, the operating system still accepts connections on that port, and nothing answers them, so a share of the connections of a client with MultiSubnetFailover=True fail after the connect timeout until the hung process is stopped. How large a share depends on the order in which DNS lists the addresses: in two runs of the client tests, with the hung node’s address listed first, 7 to 9 of 10 connections of each tested driver still reached the serving node, many only after several seconds, and the others failed after the 15-second connect timeout; with the hung node’s address listed second, every connection reached the serving node. A client without MultiSubnetFailover whose first address is the hung node fails after the connect timeout. Stop the Querona service on that node (see Cluster operations and recovery). A load balancer (variant B), which probes each node, sends no connection to such a node.

B: a load balancer#

Point the cluster name at a load balancer’s virtual address, and give the load balancer both nodes as back ends for the TDS port and the web port. Configure its health probe as an HTTP probe of /health/ready on each node’s administrative port (8080 by default), healthy on 200:

  • /health/ready answers 200 only on the serving node. The standby node, a node that is starting, a node in a planned failover, and a node that resumed after a pause and has not confirmed its lease yet answer 503, so the load balancer sends connections to the serving node alone;

  • a node that is down, or whose process hangs, does not answer, so the load balancer stops sending it connections.

Clients not listed under Supported clients connect through the load balancer. The health endpoints are described in Health endpoints; give qua_cluster_preflight the argument @resolution_mode = N'load_balancer' so that it checks the name against this variant.

Supported clients#

Variant A is supported with these client drivers, which passed the cluster’s client tests:

Driver

Tested with

Microsoft.Data.SqlClient 7.0.3 (the version Querona ships)

.NET 10 on Linux, MultiSubnetFailover=True

Microsoft.Data.SqlClient 6.1.6

.NET 10 on Linux, MultiSubnetFailover=True

The tests connected with a SQL Server login; sign-in with Kerberos under the cluster name and validation of the server certificate against the cluster name are checked separately, on two cluster nodes on their own hosts.

With MultiSubnetFailover=True both drivers reached the serving node whichever of the two addresses DNS listed first, when the other node’s address refused the connection (in the client tests, a standby node or a node that is stopped) or did not answer at all (a host that is down). On the Windows nodes of the cluster tests, where the standby’s address did not answer, a client with MultiSubnetFailover=True connected in about 0.4 seconds.

Read-only intent (ApplicationIntent=ReadOnly) connected to the serving node like any other connection, and an application that kept opening connections, with pooling on or off, reached the node that took over after a failover (see During a failover). A node that stops serving closes its client ports before it refuses anything, so its address behaves like a standby’s: in the client tests, with the address of a node that had stopped serving after its process was suspended past its lease and resumed listed first, every connection reached the serving node, with and without MultiSubnetFailover=True.

Two cases fail even with MultiSubnetFailover=True when the other node’s address is listed first, because the driver keeps the first connection that a server accepts:

  • a node whose process hangs (see the note above): a share of the connections fail after the connect timeout;

  • a connection that is accepted and then reset before the server answers, for example by a network device between the client and the node: in the tests the connection failed within a fraction of a second, and the application has to open it again. A node that stops serving ends only the connections its port had already accepted at that moment - those still signing in, and those the operating system had accepted just before the port closed - and the application opens them again.

Connect every other client through a load balancer (variant B). This includes a client without MultiSubnetFailover=True, also the drivers named above: in the tests it tried the next address only after the first one refused the connection; when the first address was a host that is down, or a node whose process hangs, it waited for its whole connect timeout and failed, although the other node served. On the Windows nodes of the cluster tests the standby’s address did not answer either, and such a client failed after about 21 seconds whenever DNS listed the standby’s address first. Drivers that were not tested - for example the native network layer of Microsoft.Data.SqlClient on Windows, the ODBC Driver for SQL Server, JDBC drivers and System.Data.SqlClient - are not named as supported for variant A either.

Do not use Failover Partner in a connection string to a cluster. In the tests a client whose server was the standby node and whose failover partner was the serving node was refused with database ... is not configured for database mirroring, and the drivers refuse Failover Partner together with MultiSubnetFailover=True before they connect.

The drivers resolved the cluster name each time they opened a new connection, and kept no answer of their own; a connection taken from the pool was reused without a new lookup.

The Administrative Portal and the API#

The Administrative Portal and the API are served on the web port of the serving node only. Open them under the cluster name, for example https://db-cluster.contoso.com/, so that the same address works on both sides of a failover. The standby node serves no portal: its state is on the Cluster page of the serving node and on its own node management page (see Cluster and Node management page).

With variant A, what a web client does depends on the client and the hosts. In the client tests:

  • where the standby node’s address refused the connection, .NET’s HttpClient and curl 8.11 moved on to the serving node at once;

  • an HttpClient that kept its connection open across a planned failover had its requests refused for about 2 to 3 seconds and then reached the node that took over;

  • when the first address was a host that is down, HttpClient waited until its own timeout (30 seconds in the test) and never tried the other address, while curl reached the serving node after about 8 seconds, half of its 15-second connect timeout.

Browsers were not tested. When web clients must keep working while a node’s host is down, use a load balancer (variant B).

Web and Data API clients#

HTTP clients that connect through the cluster name do not fail over by themselves. This covers the Administrative Portal in a browser, clients of the management API, and clients of Data API instances, which run on the serving node.

A cluster name with two address records (variant A) resolves to both nodes. An HTTP client, such as a browser or .NET’s HttpClient, tries one address at a time; it has no option like MultiSubnetFailover. On the Windows nodes of the cluster tests, the standby node, which has no listener on the web port or the Data API port, did not answer the connection request at all. A client that tried the standby’s address first therefore waited for its operating system’s connect timeout before it tried the other address - about 21 seconds on Windows. In the cluster tests, every request to a Data API instance through the cluster name took about 21 seconds while DNS listed the standby’s address first; the TCP connect to the serving node itself took 17 milliseconds.

TDS clients with MultiSubnetFailover=True are not affected: they try both addresses at once.

For HTTP clients, use one of these:

  • A load balancer in front of the nodes (variant B, see B: a load balancer), with an HTTP probe of /health/ready on each node’s administrative port. Only the serving node answers 200; the standby node, and a node that resumed after a pause and has not confirmed its lease yet, answer 503. Give the load balancer the web port and the port of each Data API instance as well as the TDS port.

  • A DNS name that follows the serving node, maintained outside Querona. Querona never changes DNS itself.

During a failover#

A failover moves the whole instance. What a client sees is what it sees when a SQL Server failover cluster instance fails over:

  • The connection breaks. Every TDS session on the node that stops serving is ended. A node that loses the lease breaks its sessions as soon as it stops acting, and refuses every later request on them without an answer, also after it resumes from a suspension (see Clustering). Nothing is resumed on the other node: the client opens a new connection, and its session settings, temporary tables and open transactions are gone.

  • A planned failover closes idle connections first. When a planned failover begins, the serving node closes every connection that waits for its next request, and closes the others as soon as their work ends. A connection pool finds such a connection closed when the application opens it again and opens a new one, which is retried within the connect timeout and reaches the node that takes over. A request sent on a connection that is still open is refused without an answer - with Microsoft.Data.SqlClient, error 10054 at severity 20, a transport error the driver does not retry by itself - unless it finishes work begun before the failover: the statements and the commit of a transaction that was open, or the cancel of a running request.

  • A running batch stops at its next statement. A node that no longer serves runs no further statement or step of a batch it had accepted, and answers it with error 3980 (The request failed to run because the batch is aborted ...) at severity 20, which makes the client driver end the connection.

  • A statement in flight has an unknown outcome. A statement that was running when the connection broke may have completed or not, including statements Querona had sent to a data source. Check before you run it again; see What a failover can leave unknown.

  • For a while, no node accepts connections. Between the moment the old node closes its client ports and the moment the new node opens them, connections are refused; clients retry until the new node serves.

How long the client ports stay closed:

Failover

Client ports closed for about

Planned failover with qua_cluster_failover

Up to 10 seconds for running statements to finish, then the time the other node takes to load the metadata.

Takeover after a failure, in manual mode

Until an operator authorizes the takeover; the standby node then takes the lease at its next acquisition attempt after the lease has expired - about 30 to 35 seconds after the failed node’s last renewal with the default timings (the lease time to live plus up to one acquisition interval) - and then loads the metadata.

The metadata load takes longer the more objects the metabase holds. Measure it on your own metabase with a planned failover before production.

In the client tests, on a small metabase, an application that opened a new connection every quarter of a second with Microsoft.Data.SqlClient saw a planned failover as one Open that took about 2 to 3 seconds and then reached the node that took over, with pooling on and off and with no Open failing: while the client ports were closed, the driver kept trying within its connect timeout (15 seconds by default). A gap longer than the connect timeout - a takeover after a failure takes about 30 to 35 seconds with the default timings, see the table above - makes the Open calls made meanwhile fail, and the application has to open them again.

Sign-ins and tokens are per node#

Each node signs its own sessions and tokens, so the other node does not accept them after a failover, and a node that loses the serving role ends every portal and API session it held. Sign in again after a failover:

  • Administrative Portal. While the role moves, the portal waits for the server and loads its data again, but does not send a change again. Its first request to the new serving node is refused and the portal shows the sign-in page; it returns to the page that was open after the sign-in. A user whose login requires multi-factor authentication enters a code again. See Cluster.

  • REST API bearer tokens. Request a new token from the node that serves now. A request that reaches a node after it stopped serving is answered 503 Service Unavailable with Retry-After and runs nothing: send it again, and the new connection reaches the node that serves.

  • Data API tokens. Data API instances run on the serving node and start anew on the node that takes over; clients authenticate again.

The same happens on a single installation when the Querona service restarts.

What clients and tools see#

@@SERVERNAME, SERVERPROPERTY('ServerName') and the job history’s server column report the first label of the cluster name on both nodes, so they stay the same across a failover, while SERVERPROPERTY('ComputerNamePhysicalNetBIOS') reports the host name of the serving node. The full list is on Cluster.

See also#