open
method of standby node returns false
. In case of active
node fault, open
will return true
at standby node.
As soon as application is organized as event serving loop, there is no need to save
and transfer context of program execution. Standby node just continue loop iterations.
So the same program can be used at active and standby nodes. Moreover they can switch their
roles. If active node A is crashed, standby node B continue execution and becomes an active node.
If node A is restarted it connects to node B and now becomes standby node for node B.
If B is crashed, A will continue execution once again.
High availability can be provided with minimal influence on the application code.
HAS provides special operators new
and delete
, which performs
allocation of objects in distributed shared memory. This shared memory segment is mapped to
the same virtual address at active and standby nodes, so normal C++ pointer can be used
by application. HAS provides two modes:
haTransient
class to create private objects.
If you uncomment definition of REDEFINE_GLOBAL_NEW
file, then
default operator new will be redefined. If you o not want to make all objects shared
implicitly just comment this line and rebuild HAS.
To be able to preserve consistency of shared data, HAS requires programmer to periodically
invoke commit
method. This method actually transfer all modified
pages in shared pool to standby node. These pages will be copied to the pool of standby node
only after all of them will be received from active node. So transaction is either
atomically applied or ignored.
HAS use virtual memory protection mechanism to detect modified pages. At the beginning it prohibits modification access to the shared pool pages. Once an application tries to modify data in shared pool, page fault is happen. HAS provides handler of this exception. This handler marks the page in the bitmap and enable write to this page. When transaction is committed, all modified pages are sent to the standby node.
HAS is able to map shared pool on the file, so saving data between sessions or work with swap file. In last case all data is lost after application termination.
HAS throws haException
in case of critical storage error. Programmer can catch
and handle this exception. It contains description of the context where the exception was thrown and
system error code.
haManager
class. Instance of this class should be created by application and used to open/close a
storage. Below is description of haManager
methods:
bool open(char const* fileName, char const* host, int localPort, int remotePort, void* baseAddr = NULL);
fileName
- path to the storage file, if NULL
then
shared pool is not mapped to any OS file and data will be lost after application
termination.
host
- name of the host where the partner (standby/active node) is running.
localPort
- port at local host at which HAS will accept standby node connections
remotePort
- port at the remote computer to which standby node will try to connect
baseAddr
- base address in virtual memory to which shared pool should be mapped,
if NULL
then OS will choose this address automatically (it is necessary that this address
will always be the same at both nodes)
true
- this application is active node
false
- this is standby node and active node closes the storage
void commit();
void close();
void setRootObject(void* obj);
getRootObject
method.
Application should first check if root already set before invoking this method.
obj
- pointer to root object previously allocated in the shared pool.
void* getRootObject() const;
NULL
is root was not yet specified.
haManager(size_t maxSize);
maxSize
- maximal size of the storage. Programmer has to specify maximal size
of the storage at open time. Exceeding this limit will cause application failure.
To run this application, you need to copy guess
executable files to two different
nodes of the net. It is possible to run two applications at the same computer, but in this
case you should run in in the different directories, because otherwise there will be conflict
on accessing the same data file, which cause application failure. Now choose port at both nodes
which will be used by the HAS. At the first node A run the following command:
guess B portA portBAnd at other node B run execute the command:
guess A portB portANode A will become the active node and B - standby node. Now you can input some data and emulate crashes using Ctrl-C.
I will provide e-mail support and help you with development of HAS applications.
Look for new version at my homepage | E-Mail me about bugs and problems