Automatic HA

Automatic HA is a set of time-saving StreamBase configuration settings that let you quickly and automatically implement support for failover in a high-availability design pattern.

Automatic HA Leadership Control

Automatic HA leadership control is based on a design pattern where each server in the HA cluster runs at least two HA applications in addition to running the core application. One of the HA applications (called the HA detection application) performs monitoring and detection, and the other HA applications (called the HA application control handlers) specify behavior of the core application in case of a failover.

When you use automatic HA leadership control StreamBase provides the detection application, and you must provide the applications that control the behavior of the core application.

Monitoring and detection

When you enable automatic HA, StreamBase creates the HA detection application and adds a new container. This application, haleadershipcontrol.sbapp, uses an HA Heartbeat adapter to determine whether the other server in the pair has stopped running.

If the HA detection module on the nonleader in a two-server cluster determines that the other server is no longer running, it changes the status of its server from nonleader to leader.

Behavior of core application

When you use automatic HA leadership control you must specify what should occur when there is a change in leadership status. To do this, create one or more HA application control handlers based on your particular requirements.

The HA Sample shows a simple case, namely hacontrolcontainer.sbapp, which specifies that the core application on the new leader should start dequeuing results as soon as there is a leadership change.

How to control tuples being sent from the new leader

When a server becomes the leader you control the output from its core application by means of your HA application control handler application.

For example, to enable dequeuing from the container running the core application you could use sbadmin modifyContainer with the --dequeue=ENABLED option. For an example of this technique, see the hacontrolcontainer.sbapp in the HA sample, which uses this kind of expression to specify the output from the EnableEnqCmd Map operator.

How to control the adapters in the server that becomes the leader

The HA detection application on each server in an HA pair uses an HA Heartbeat adapter for monitoring and detection. You can change the behavior of this adapter by setting the properties in the server configuration file. Properties include how often to send a heartbeat message, and how long to wait before declaring a timeout.

Enabling Automatic Leadership Control

Enable automatic HA processing in the server configuration file for a pair of StreamBase Servers. This configures StreamBase to automatically add a new container for both servers, which tracks and manages their leadership status in the event of failover; this means that you do not have to write a separate high-availability module for the purpose of shifting I/O and its processes from a primary server to a secondary server.

Automatic leadership control does not cover the requirements of failback, which is the process of re-synchronizing data back to the primary server, halting I/O and application activity again, and cutting back over to the original server.

The following example configuration file has sample settings.

To use automatic leadership control, edit the <high-availability> element of the configuration file for each HA container as follows:

  1. Enable automatic leadership control by setting the enabled parameter to auto.

  2. Set the leadership status for each container by setting the value of the leadership-status parameter.

  3. Edit the <ha-application> section to specify parameters such as the port to be used by the Heartbeat adapter, the host name of the server paired with this one, and timing.

The sample values for the required settings are as follows:

<high-availability>    
  <param name="leadership-status" value="LEADER"/>      
  <param name="enabled" value="auto"/>    
  <ha-application>        
    <param name="HB_OTHER_SERVER" value="leader-name"/>        
    <param name="HB_PORT" value="12345"/>        
    <param name="HB_TIMEOUT" value="3333"/>
  </ha-application>
</high-availability>
You can also use automatic leadership control in conjunction with your own HA container, instead of using an automatically created HA container (which is named SB_ha). This allows you to specify container connections and other relationships in your own HA container. In this case, use the ha-container parameter, but do not use the <ha-application> element.
<high-availability>
  <param name="leadership-status" value="LEADER"/>
  <param name="enabled" value="auto"/>
  <param name="ha-container" value="myHAcontainer"/>
</high-availability>

If you prefer to customize your HA solution instead of using automatic leadership control, make the following edits in the server configuration file:

  1. Set the value of the enabled parameter to custom for the <high-availability> element.

  2. Specify the ha-container parameter, but do not use the <ha-application> element.

  3. Create an HA module reference to handle the high availability.

  4. Specify the HA module in the <application> element of a StreamBase deployment file (preferred) or in the <runtime> section of the server configuration file (deprecated).

<high-availability>    
  <param name="leadership-status" value="LEADER"/>
  <param name="enabled" value="custom"/>
  <param name="ha-container" value="ha_custom"/>
</high-availability>
<runtime>     
  <application file="name_of_ha_monitoring_module.sbapp" 
    container="ha">
    <module-parameters>
      <param name="HB_OTHER_SERVER" value="leader-name"/>
      <param name="HB_PORT" value="8888"/>
      <param name="HB_TIMEOUT" value="3000"/>
    </module-parameters>
  </application>
</runtime>

Enabling Automatic Table Replication

High-availability design patterns typically require that disk-based Query Tables be replicated so that a backup table can be made available in the event of a server failover. Using StreamBase Studio, you can set a property on a StreamBase table indicating it should be replicated. See Replication of Query Tables.