Code Examples.
More...
Code Examples.
The below code example shows the usage of server based checkpointing.
The usage model of this example is to to have 2 applications running in 1+1 redundancy on 2 worker nodes. The Active application keeps writing a counter value inthe checkpoint and the standby application will be idle. After some time we kill the node running the active instance, which triggers the standby application to now take over as Active. At this point the new active application reads the checkpoint, and starts updating counter from the point where the old active had left it.
Note that the below code snippets are been tested. However please follow the instructions given in the comment blocks before each function.
#include "ckptTest.h"
#define CKPT_NAME "SampleCkptTest"
#define CKPT_SID_NAME "1"
ClUint32T seq;
(ClUint16T)sizeof(CKPT_SID_NAME)-1,
(ClUint8T*)CKPT_SID_NAME
};
int running = 1;
int exiting = 0;
ClAmsHAStateT ha_state = CL_AMS_HA_STATE_NONE;
ClRcT checkpoint_initialize()
{
ClNameT ckpt_name = { strlen(CKPT_NAME), CKPT_NAME };
.checkpointSize = sizeof(ClUint32T),
.maxSections = 2,
.maxSectionSize = sizeof(ClUint32T),
};
NULL,
&ckpt_version);
{
return rc;
}
clOsalPrintf(
"Checkpoint service initialized [handle=0x%x]\n",
ckpt_svc_handle);
&ckpt_name,
&create_atts,
&ckpt_handle);
{
clOsalPrintf(
"clCkptCheckpointOpen failed with [rc=0x%x]\n",rc);
return rc;
}
clOsalPrintf(
"Checkpoint opened [Checkpoint handle=0x%x]\n",
ckpt_handle);
}
ClRcT checkpoint_finalize(
void)
{
{
}
{
clOsalPrintf(
"Checkpoint Finalize failed with rc 0x%x\n",rc);
}
return rc;
}
ClRcT active_replica_set()
{
{
clOsalPrintf(
"Ckpt Active replica set failed with [rc = 0x%x\n",rc);
return rc;
}
return rc;
}
ClRcT checkpoint_section_create()
{
ClUint8T initData = 0;
};
active_replica_set();
§ion_atts,
&initData,
{
return rc;
}
{
rc = checkpoint_read_seq(&seq);
{
return rc;
}
clOsalPrintf(
"Sequence Number read from chekpoint %lu\n",seq);
}
else
{
}
return rc;
}
ClRcT checkpoint_read_seq(ClUint32T *seq)
{
ClUint32T err_idx;
ClUint32T seq_no = 0xffffffff;
.dataBuffer = (ClPtrT)&seq_no,
.dataSize = sizeof(ClUint32T),
.readSize = sizeof(ClUint32T)
};
{
}
*seq = ntohl(seq_no);
fflush(stdout);
return rc;
}
ClRcT checkpoint_write_seq(ClUint32T seq)
{
ClUint32T seq_no;
seq_no = htonl(seq);
fflush(stdout);
&ckpt_sid,
&seq_no,
sizeof(ClUint32T));
{
clOsalPrintf(
"CheckpointSectionOverWrite failed with rc 0x%x\n",rc);
}
else
{
{
clOsalPrintf(
"Failed [0x%x] to synchronize the checkpoint\n",
rc);
}
}
return rc;
}
{
while (!exiting)
{
if (running && ha_state == CL_AMS_HA_STATE_ACTIVE)
{
rc = checkpoint_write_seq(seq);
{
printf("Checkpoint write failed... Exiting..\n");
break;
}
seq++;
}
sleep(1);
}
return rc;
}
{
checkpoint_initialize();
checkpoint_section_create();
get_into_loop();
}
case CL_AMS_HA_STATE_ACTIVE:
{
active_replica_set();
checkpoint_read_seq(&seq);
ha_state = haState;
}
case CL_AMS_HA_STATE_STANDBY:
{
ha_state = haState;
}
#include <clOmApi.h>
#include <clOampRtApi.h>
#include <clIdlApi.h>
#include <string.h>
#include <netinet/in.h>
extern ClUint32T seq;
extern int running;
extern int exiting;
extern ClAmsHAStateT ha_state;
extern ClRcT checkpoint_initialize();
extern ClRcT checkpoint_finalize(
void);
extern ClRcT checkpoint_section_create();
extern ClRcT checkpoint_read_seq(ClUint32T *seq);
extern ClRcT checkpoint_write_seq(ClUint32T seq);
extern ClRcT get_into_loop();
extern ClRcT active_replica_set();