void* csa103CkptActive(ClPtrT unused) { SaAisErrorT rc = SA_AIS_OK; /* This thread will only be started when the application becomes active */ assert(ha_state == SA_AMF_HA_ACTIVE); clprintf(CL_LOG_SEV_INFO,"Active thread has started"); /* Set this replica "active" so I can write to the checkpoint */ if ((rc = saCkptActiveReplicaSet(ckpt_handle)) != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR, "checkpoint_replica_activate failed [0x%x] in ActiveReplicaSet", rc); } /* Attempt to recover the state of the prior active */ checkpoint_read_seq(&seq); while (!unblockNow) { clprintf(CL_LOG_SEV_INFO,"Hello World! (seq=%d)", seq++); /* Checkpoint new sequence number */ checkpoint_write_seq(seq); sleep(1); } return CL_OK; }
SaAisErrorT alarmClockCkptActivate(SaCkptCheckpointHandleT ckptHdl, ClUint32T section_num) { SaAisErrorT rc = SA_AIS_OK; SaCkptSectionIdT id; id.idLen = sizeof(section_num); id.id = (ClUint8T*)§ion_num; rc = saCkptActiveReplicaSet(ckptHdl); if(rc != SA_AIS_OK) { alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockReplicaSet: returned [%#x]", rc); return rc; } rc = clCkptSectionCheck(ckptHdl, (ClCkptSectionIdT*)&id); if(rc != CL_OK) { if(CL_GET_ERROR_CODE(rc) == CL_ERR_NOT_EXIST) { SaCkptSectionCreationAttributesT attr; attr.sectionId = &id; attr.expirationTime = (ClTimeT)CL_TIME_END; rc = saCkptSectionCreate(ckptHdl, &attr, NULL, 0); if(rc == SA_AIS_OK) { alarmClockLogWrite(CL_LOG_SEV_INFO, "alarmClockActivate: Section [%d] created successfully", section_num); } } else rc = SA_AIS_ERR_UNAVAILABLE; /* internal error */ } else rc = SA_AIS_OK; if(rc != SA_AIS_OK) { alarmClockLogWrite(CL_LOG_SEV_INFO, "alarmClockActivate: Section operation on section [%d] " "failed with [%#x]", section_num, rc); } return rc; }
SaAisErrorT checkpoint_read_seq(ClUint32T *seq) { SaAisErrorT rc = SA_AIS_OK; ClUint32T err_idx; /* Error index in ioVector */ ClUint32T seq_no = 0xffffffff; SaCkptIOVectorElementT iov = { .sectionId = ckpt_sid, .dataBuffer = (ClPtrT)&seq_no, .dataSize = sizeof(ClUint32T), .dataOffset = (ClOffsetT)0, .readSize = sizeof(ClUint32T) }; rc = saCkptCheckpointRead(ckpt_handle, &iov, 1, &err_idx); if (rc != SA_AIS_OK) { if (rc != SA_AIS_ERR_NOT_EXIST) /* NOT_EXIST is ok, just means no active has written */ return SA_AIS_OK; clprintf(CL_LOG_SEV_ERROR,"Error: [0x%x] from checkpoint read, err_idx = %u", rc, err_idx); } *seq = ntohl(seq_no); return SA_AIS_OK; } SaAisErrorT checkpoint_replica_activate(void) { SaAisErrorT rc = SA_AIS_OK; if ((rc = saCkptActiveReplicaSet(ckpt_handle)) != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR, "checkpoint_replica_activate failed [0x%x] in ActiveReplicaSet", rc); } else rc = SA_AIS_OK; return rc; }
static SaAisErrorT checkpoint_read_seq(ClUint32T *seq) { SaAisErrorT rc = SA_AIS_OK; SaUint32T err_idx; /* Error index in ioVector */ SaUint32T seq_no = 0xffffffff; SaCkptIOVectorElementT iov = { .sectionId = ckpt_sid, .dataBuffer = (void *)&seq_no, .dataSize = sizeof(SaUint32T), .dataOffset = (SaSizeT)0, .readSize = sizeof(SaUint32T) }; rc = saCkptCheckpointRead(ckpt_handle, &iov, 1, &err_idx); if (rc != SA_AIS_OK ) { clprintf(CL_LOG_SEV_ERROR,"Error: [0x%x] from checkpoint read, err_idx = %u\n", rc, err_idx); } /* FIXME: How to process this err_idx? */ *seq = ntohl(seq_no); // clOsalPrintf("checkpoint_read_seq: seq_no = %lu, seq = %lu\n", seq_no, *seq); fflush(stdout); return rc; } static SaAisErrorT checkpoint_replica_activate(void) { SaAisErrorT rc = SA_AIS_OK; if ((rc = saCkptActiveReplicaSet(ckpt_handle)) != SA_AIS_OK) { clprintf( CL_LOG_SEV_ERROR, "checkpoint_replica_activate failed [0x%x] in ActiveReplicaSet", rc); } return rc; }
/**************************************************************************** * Name : cpsv_test_sync_app_process * * Description : This is the function which is given as the input to the * Application task. * * Arguments : info - This is the information which is passed during * spawing Application task. * * Return Values : None. * * Notes : None. *****************************************************************************/ void cpsv_test_sync_app_process(void *info) { SaCkptHandleT ckptHandle; SaCkptCheckpointHandleT checkpointHandle; SaCkptCallbacksT callbk; SaVersionT version; SaNameT ckptName; SaAisErrorT rc; SaCkptCheckpointCreationAttributesT ckptCreateAttr; SaCkptCheckpointOpenFlagsT ckptOpenFlags; SaCkptSectionCreationAttributesT sectionCreationAttributes; SaCkptIOVectorElementT writeVector, readVector; SaUint32T erroneousVectorIndex; void *initialData = "Default data in the section"; unsigned char read_buff[100] = {0}; SaTimeT timeout = 1000000000; unsigned int temp_var = (unsigned int)(long)info; memset(&ckptName, 0, 255); ckptName.length = strlen(DEMO_CKPT_NAME); memcpy(ckptName.value,DEMO_CKPT_NAME,strlen(DEMO_CKPT_NAME)); callbk.saCkptCheckpointOpenCallback = AppCkptOpenCallback; callbk.saCkptCheckpointSynchronizeCallback = AppCkptSyncCallback; version.releaseCode= 'B'; version.majorVersion = 2; version.minorVersion = 2; printf("*******************************************************************\n"); printf("Demonstrating Checkpoint Service Usage with a collocated Checkpoint \n"); printf("*******************************************************************\n"); sleep(2); printf("Initialising With Checkpoint Service....\n"); rc = saCkptInitialize(&ckptHandle,&callbk,&version); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); ckptCreateAttr.creationFlags = SA_CKPT_CHECKPOINT_COLLOCATED|SA_CKPT_WR_ACTIVE_REPLICA; ckptCreateAttr.checkpointSize = 1024; ckptCreateAttr.retentionDuration= 100000; ckptCreateAttr.maxSections= 2; ckptCreateAttr.maxSectionSize = 700; ckptCreateAttr.maxSectionIdSize = 4; ckptOpenFlags = SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE; printf("Opening Collocated Checkpoint = %s with create flags....\n",ckptName.value); rc = saCkptCheckpointOpen(ckptHandle,&ckptName,&ckptCreateAttr,ckptOpenFlags,timeout,&checkpointHandle); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); if(temp_var == 1) { printf("Setting the Active Replica for my checkpoint ....\t"); rc = saCkptActiveReplicaSet(checkpointHandle); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); sectionCreationAttributes.sectionId = (SaCkptSectionIdT*) malloc(sizeof \ (SaCkptSectionIdT)); sectionCreationAttributes.sectionId->id = (unsigned char *)"11"; sectionCreationAttributes.sectionId->idLen = 2; sectionCreationAttributes.expirationTime = 3600000000000ll; /* One Hour */ printf("Created Section ....\t"); rc = saCkptSectionCreate(checkpointHandle,§ionCreationAttributes,initialData,28); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); writeVector.sectionId.id = (unsigned char *)"11"; writeVector.sectionId.idLen = 2; writeVector.dataBuffer = "The Checkpoint Service provides a facility for processes to store checkpoint data"; writeVector.dataSize = strlen(writeVector.dataBuffer); writeVector.dataOffset = 0; writeVector.readSize = 0; printf("Writing to Checkpoint %s ....\n",DEMO_CKPT_NAME); printf("Section-Id = %s ....\n",writeVector.sectionId.id); printf("CheckpointData being written = \"%s\"\n",(char *)writeVector.dataBuffer); printf("DataOffset = %llu ....\n",writeVector.dataOffset); rc = saCkptCheckpointWrite(checkpointHandle,&writeVector,1,&erroneousVectorIndex); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); sleep(1); printf("Press <Enter> key to continue...\n"); getchar(); } else { sleep(4); readVector.sectionId.id = (unsigned char *)"11"; readVector.sectionId.idLen = 2; readVector.dataBuffer = read_buff; readVector.dataSize = 90; readVector.dataOffset = 0; printf("Waiting to Read from Checkpoint %s....\n",DEMO_CKPT_NAME); printf("Press <Enter> key to continue...\n"); getchar(); rc = saCkptCheckpointRead(checkpointHandle,&readVector,1,&erroneousVectorIndex); printf("Checkpoint Data Read = \"%s\"\n",(char *)readVector.dataBuffer); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); } printf("Synchronizing My Checkpoint being called ....\n"); rc = saCkptCheckpointSynchronize(checkpointHandle,timeout); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); if(temp_var==1) { printf("Unlink My Checkpoint ....\t"); rc = saCkptCheckpointUnlink(ckptHandle,&ckptName); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); } printf("Ckpt Closed ....\t"); rc = saCkptCheckpointClose(checkpointHandle); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); printf("Ckpt Finalize being called ....\t"); rc = saCkptFinalize(ckptHandle); if(rc == SA_AIS_OK) printf("PASSED \n"); else printf("Failed \n"); sleep(2); return; }