DataAction / AdoNetCore.AseClient

AdoNetCore.AseClient - a .NET Core DB Provider for SAP ASE
Apache License 2.0
108 stars 45 forks source link

Add failover support #64

Open formicas opened 6 years ago

senseibaka commented 6 years ago

From https://www.connectionstrings.com/ase-ado-net-data-provider/ We need to support the following parameters:

Also, it sounds like once the client establishes a connection with one of the servers specified, the client will receive a list of all available failover targets (servers).

Planned behaviour (still being thought about. not final):

senseibaka commented 6 years ago

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc20066.1500/html/adonet/CIHGAJHI.htm talks about this as well.

senseibaka commented 6 years ago

There are a few TDS_MSG types, prefixed with TDS_MSG_MIG_, which appear to be related to failover.

In the normal case:

  1. Primary will signal to the client that they need to prepare to migrate (TDS_MSG_MIG_REQ) to a different server (address gets provided as another token).
  2. The client will acknowledge it (TDS_MSG_MIG_SYNC)
  3. Primary will signal to initiate migration (TDS_MSG_MIG_CONT) or cancel migration (TDS_MSG_MIG_IGN).
  4. Client will login to the secondary (providing some sort of migration ID).
  5. If the client fails, it will tell the Primary (TDS_MSG_MIG_FAIL).

In the normal case, it sounds like the Primary will send data to the client until it's time to migrate, and then the client will receive the rest of the data from the new server.

I'm not sure what behaviour should be in other circumstances, not sure when AseFailoverException comes into it.

c-j-hughes commented 5 years ago

Will have an HADR environment to test against available from 14th-18th January so we can suss this out. The AseFailoverException could just be some legacy thing from a previous failover mechanism maybe just associated with the HASession, AlternateServers, Secondary Data Source, and Secondary Server Port connection string properties.

Connection failover enhancement Existing connection failover allows a client application to switch to an alternate ASE server if the primary server becomes unavailable due to an unplanned event, like power outage or a socket failure. This feature is enhanced to allow client applications to failover numerous times to multiple servers using dynamic failover addresses.

With the High Availability enabled, the client application does not need to be configured to know the possible failover targets. ASE keeps the client updated with the best failover list based on cluster membership, logical cluster usage and load distribution. During failover, the client refers to the ordered failover list while attempting to reconnect. If the driver successfully connects to a server, the driver internally updates the list of host values based on the list returned. Otherwise, the driver throws a connection failure exception.

Enabling extended connection failover in ADO.NET To enable the extended failover, you need to set the HASession connection string property to 1. For example:

Data Source=server1;Port=port1;User ID=sa;Password=; Initial Catalog=sdc;HASession=1; AlternateServers=server2:port2,...,serverN:portN;

In the preceding example, Data Source defines the primary server and port. ADO.NET Provider by Sybase will try to establish connection to the primary server first and, if unsuccessful, will go through the servers listed in Alternate Servers until a connection is established or until the end of the list is reached.

Note - The list of alternate servers specified in the connection string is used only during initial connection. After the connection is established with any available instance, and the client supports high-availability, the client will receive an updated list of the best possible failover targets from the server. This new list overrides the specified list.

Source: Software Developer Kit 15.0 > New Features Open Server and SDK 15.0 for Windows, Linux, and UNIX > New features in ESD #12 > jConnect, ODBC, OLEDB and ADO.NET support for Adaptive Server Cluster Edition

Not necessarily a priority for us, but it sounds like the mechanic of getting the list of other servers in the response from the logon server is the same in this model as it is in the HA/DR one, so maybe we can support both at the same time...