Code Examples.
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();
Typical defines found in any software project.
Header file of Alarm Service related APIs.
Header file for the APIs and data types exposed by the CPM.
Header file of Server based Checkpoint Service Related APIs.
Header file of Debug Service Related APIs.
Header file of EO related APIs.
Header file of Reserved Communication Ports.
Operating System Abstraction Layer API.
Header file of Provision Library related APIs.
Header file of RMD Interface.
ClRcT clCkptCheckpointClose(CL_IN ClCkptHdlT checkpointHandle)
Closes the checkpoint designated by the checkpointHandle.
#define CL_CKPT_WR_ACTIVE_REPLICA_WEAK
Asynchronous checkpoint.
Definition: clCkptApi.h:71
ClHandleT ClCkptHdlT
The handle used to identify a checkpoint.
Definition: clCkptApi.h:141
ClRcT clCkptInitialize(CL_OUT ClCkptSvcHdlT *ckptSvcHandle, CL_IN const ClCkptCallbacksT *callbacks, CL_INOUT ClVersionT *version)
Initializes the checkpoint service client and registers the various callbacks.
ClRcT clCkptCheckpointOpen(CL_IN ClCkptSvcHdlT ckptHandle, CL_IN const ClNameT *ckeckpointName, CL_IN const ClCkptCheckpointCreationAttributesT *checkpointCreationAttributes, CL_IN ClCkptOpenFlagsT checkpointOpenFlags, CL_IN ClTimeT timeout, CL_IN ClCkptHdlT *checkpointHandle)
Opens an existing checkpoint.
#define CL_CKPT_CHECKPOINT_WRITE
Checkpoint open for write.
Definition: clCkptApi.h:115
ClRcT clCkptCheckpointSynchronize(CL_IN ClCkptHdlT ckeckpointHandle, CL_IN ClTimeT timeout)
Synchronizes the replicas of a checkpoint.
ClRcT clCkptCheckpointRead(CL_IN ClCkptHdlT checkpointHandle, CL_INOUT ClCkptIOVectorElementT *ioVector, CL_IN ClUint32T numberOfElements, CL_OUT ClUint32T *erroneousVectorIndex)
Reads multiple sections at a time.
#define CL_CKPT_CHECKPOINT_COLLOCATED
Collocated checkpoint.
Definition: clCkptApi.h:77
ClRcT clCkptActiveReplicaSet(CL_IN ClCkptHdlT checkpointHandle)
Sets the local replica to be active replica.
ClHandleT ClCkptSvcHdlT
The type of the handle for the the checkpoint service library.
Definition: clCkptApi.h:136
ClRcT clCkptSectionCreate(CL_IN ClCkptHdlT checkpointHandle, CL_IN ClCkptSectionCreationAttributesT *sectionCreationAttributes, CL_IN const ClUint8T *initialData, CL_IN ClSizeT initialDataSize)
Creates a section in the checkpoint.
ClRcT clCkptSectionOverwrite(CL_IN ClCkptHdlT checkpointHandle, CL_IN const ClCkptSectionIdT *sectionId, CL_IN const void *dataBuffer, CL_IN ClSizeT dataSize)
Writes a single section in a given checkpoint.
ClRcT clCkptFinalize(CL_IN ClCkptSvcHdlT ckptHandle)
Closes the checkpoint service client and cancels all pending callbacks related to the handle.
#define CL_CKPT_CHECKPOINT_READ
Checkpoint open for read.
Definition: clCkptApi.h:110
#define CL_CKPT_CHECKPOINT_CREATE
Checkpoint open for create.
Definition: clCkptApi.h:120
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
ClInt64T ClTimeT
Time duration specified in nanoseconds.
Definition: clCommon.h:154
ClInt64T ClOffsetT
Offset of a buffer or object within another
Definition: clCommon.h:159
#define CL_GET_ERROR_CODE(RC)
This macro extracts the error code from the return code.
Definition: clCommonErrors.h:297
ClUint64T ClSizeT
Definition: clCommon.h:157
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
#define CL_TIME_END
In practice, this will never time out, since it is 292 years.
Definition: clCommon.h:149
#define CL_ERR_ALREADY_EXIST
An entry is already existing.
Definition: clCommonErrors.h:148
ClRcT clOsalPrintf(const ClCharT *fmt,...)
Prints to the standard output.
A name.
Definition: clCommon.h:197
Version Information for various services.
Definition: clCommon.h:250
This structure represents the properties of checkpoint that can be specified during the creation proc...
Definition: clCkptApi.h:165
ClCkptCreationFlagsT creationFlags
Create time attributes.
Definition: clCkptApi.h:170
This structure represents a section identifier.
Definition: clCkptApi.h:201
This structure represents section attributes that can be specified during the creation process.
Definition: clCkptApi.h:218
ClCkptSectionIdT * sectionId
Section identifier.
Definition: clCkptApi.h:223
This structure represents an IO vector which will be used for dealing with more than zero sections.
Definition: clCkptApi.h:309
ClCkptSectionIdT sectionId
Identifier of the section.
Definition: clCkptApi.h:314