Package com.tailf.ha

Class Ha

Object
com.tailf.ha.Ha

public class Ha extends Object
Main class for the HA cluster management. The HA functionality makes it possible to replicate the configuration data on several nodes in a cluster. The details on usage of the HA api is described in the UserGuide.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Ha(Socket socket, String token)
    Constructor for management of an HA Cluster node.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Instruct a node to resume the initial state, i.e.
    void
    bePrimary(ConfValue myNodeId)
    Instruct an HA node to be primary and also give the node a name.
    void
    Instruct a secondary node to be a relay for other secondaries.
    void
    beSecondary(ConfValue myNodeId, ConfHaNode primary, boolean waitForReply)
    Instruct an HA node to be a secondary to a named primary.
    void
    This function must be used by the application to inform the HA subsystem that another node which is possibly connected to the server is dead.
    Query an HA node for its status.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Ha

      public Ha(Socket socket, String token) throws IOException, HaException

      Constructor for management of an HA Cluster node. This constructor implicitly connects an HA socket which can be used to control a ConfD/NCS HA node. The token is a secret string that must be shared by all participants in the cluster. There can only be one HA socket towards the server, which implies only on HA instance. If a new HA instance is created the previous connection is closed and the cluster node is reset with the new token value.

      Since the ConfD/NCS daemon expects initialization within 5 seconds after a new socket is established, this constructor should be called immediately for a new socket. For instance:

       // int port = Conf.PORT for ConfD or Conf.NCS_PORT for NCS
       Ha ha = new Ha(new Socket("localhost", port), "xyz");
       

      If encrypted communication towards ConfD/NCS is desired, an environment variable "CONFD_IPC_ACCESS_FILE" or "NCS_IPC_ACCESS_FILE" need to be set. This variable is expected to point to a file containing a secret salt. Example:

       export CONFD_IPC_ACCESS_FILE=./secret_file.txt
       

      An alternative to the environment variable is to set a java system property with the same name pointing to the file.

      Note, if this constructor fails the socket must be closed and a new socket created before the call is re-attempted.

      Parameters:
      socket - Ha control socket
      token - cluster common shared secret
      Throws:
      IOException
      HaException
  • Method Details

    • bePrimary

      public void bePrimary(ConfValue myNodeId) throws IOException, HaException
      Instruct an HA node to be primary and also give the node a name.
      Parameters:
      myNodeId - ConfValue naming the ha node
      Throws:
      IOException
      HaException
    • beSecondary

      public void beSecondary(ConfValue myNodeId, ConfHaNode primary, boolean waitForReply) throws IOException, HaException
      Instruct an HA node to be a secondary to a named primary. The waitreply is a boolean. If true, the function is synchronous and it will hang until the node has initialized its CDB database. This may mean that the CDB database is copied in its entirety from the primary. If false, we do not wait for the reply, but it is possible to use a notifications socket and get notified asynchronously via an HA_INFO_BESECONDARY_RESULT notification. In both cases, it is also possible to use a notifications socket and get notified asynchronously when CDB at the secondary is initialized.
      Parameters:
      myNodeId - ConfValue naming the ha node
      primary - Primary ConfHaNode
      waitForReply - boolean, set true if call should block until response
      Throws:
      IOException
      HaException
    • beNone

      public void beNone() throws IOException, HaException
      Instruct a node to resume the initial state, i.e. neither primary nor secondary.
      Throws:
      IOException
      HaException
    • beRelay

      public void beRelay() throws IOException, HaException
      Instruct a secondary node to be a relay for other secondaries.
      Throws:
      IOException
      HaException
    • status

      public HaStatus status() throws IOException, HaException
      Query an HA node for its status. If successful, the function returns an HaStatus object.
      Returns:
      HaStatus enum indicating the status of the node
      Throws:
      IOException
      HaException
    • secondaryDead

      public void secondaryDead(ConfValue nodeId) throws IOException, HaException
      This function must be used by the application to inform the HA subsystem that another node which is possibly connected to the server is dead.
      Parameters:
      nodeId - ConfValue naming the cluster node
      Throws:
      IOException
      HaException