Class Ha
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
beNone()
Instruct a node to resume the initial state, i.e.void
Instruct an HA node to be primary and also give the node a name.void
beRelay()
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
secondaryDead
(ConfValue nodeId) 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.status()
Query an HA node for its status.
-
Constructor Details
-
Ha
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 sockettoken
- cluster common shared secret- Throws:
IOException
HaException
-
-
Method Details
-
bePrimary
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 nodeprimary
- Primary ConfHaNodewaitForReply
- boolean, set true if call should block until response- Throws:
IOException
HaException
-
beNone
Instruct a node to resume the initial state, i.e. neither primary nor secondary.- Throws:
IOException
HaException
-
beRelay
Instruct a secondary node to be a relay for other secondaries.- Throws:
IOException
HaException
-
status
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
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
-