void *th_dispatch (void *arg) { struct thread_data *td = (struct thread_data *)arg; SaCkptHandleT ckptHandle; SaCkptCheckpointHandleT handle; SaAisErrorT error; int i; SaUint32T erroroneousVectorIndex = 0; error = saCkptInitialize (&ckptHandle, &callbacks, &version); error = saCkptCheckpointOpen (ckptHandle, &checkpointName, &checkpointCreationAttributes, SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, 0, &handle); for (i = 0; i < 1000; i++) { error = saCkptCheckpointWrite (handle, WriteVectorElements, 1, &erroroneousVectorIndex); printf ("Thread %d: Attempt %d: error %d\n", td->thread_no, i, error); if (error != SA_AIS_OK) { printf ("Thread %d: Error from write.\n", td->thread_no); } } error = saCkptFinalize (ckptHandle); return (0); }
int main (void) { SaCkptHandleT ckpt_handles[CHECKPOINT_THREADS_MAX]; SaCkptCheckpointHandleT checkpoint_handles[CHECKPOINT_THREADS_MAX]; SaAisErrorT error; int size; int i, j; signal (SIGALRM, sigalrm_handler); printf ("Creating (%d) checkpoints.\n", CHECKPOINT_THREADS_MAX); /* * Create CHECPOINT_THREADS_MAX checkpoints */ for (i = 0; i < CHECKPOINT_THREADS_MAX; i++) { sprintf ((char *)checkpointName.value, "checkpoint (%d)", i); checkpointName.length = strlen ((char *)checkpointName.value); do { error = saCkptInitialize (&ckpt_handles[i], &callbacks, &version); } while (error == SA_AIS_ERR_TRY_AGAIN); assert (error == SA_AIS_OK); do { error = saCkptCheckpointOpen (ckpt_handles[i], &checkpointName, &checkpointCreationAttributes, SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, SA_TIME_END, &checkpoint_handles[i]); } while (error == SA_AIS_ERR_TRY_AGAIN); assert (error == SA_AIS_OK); do { error = saCkptSectionCreate (checkpoint_handles[i], §ionCreationAttributes1, "Initial Data #0", strlen ("Initial Data #0") + 1); } while (error == SA_AIS_ERR_TRY_AGAIN); assert (error == SA_AIS_OK); do { error = saCkptSectionCreate (checkpoint_handles[i], §ionCreationAttributes2, "Initial Data #0", strlen ("Initial Data #0") + 1); } while (error == SA_AIS_ERR_TRY_AGAIN); assert (error == SA_AIS_OK); } for (i = CHECKPOINT_THREADS_START; i < CHECKPOINT_THREADS_MAX; i++) { /* i threads */ printf ("Starting benchmark with (%d) threads.\n", i); size = 10000; /* initial size */ for (j = 0; j < 5; j++) { /* number of runs with i threads */ alarm (10); threaded_bench (ckpt_handles, checkpoint_handles, i, size); size += 1000; } } return (0); }
SaAisErrorT checkpoint_initialize(void) { SaAisErrorT rc = SA_AIS_OK; SaVersionT ckpt_version = {'B', 1, 1}; SaNameT ckpt_name = { strlen(CKPT_NAME), CKPT_NAME }; SaCkptCallbacksT callbacks; SaCkptCheckpointCreationAttributesT attrs; /* Set up the checkpoint configuration */ attrs.creationFlags = SA_CKPT_WR_ACTIVE_REPLICA_WEAK | SA_CKPT_CHECKPOINT_COLLOCATED; attrs.checkpointSize = sizeof(ClUint32T); attrs.retentionDuration = (ClTimeT) 10; /* How long to keep the checkpoint around even if noone has it open */ attrs.maxSections = 2; /* Max number of 'rows' in the table */ attrs.maxSectionSize = sizeof(ClUint32T); /* Max 'row' size */ attrs.maxSectionIdSize = (ClSizeT)64; /* Max 'row' identifier size */ /* These callbacks are only called when an Async style function call completes */ callbacks.saCkptCheckpointOpenCallback = checkpointOpenCompleted; callbacks.saCkptCheckpointSynchronizeCallback = checkpointSynchronizeCompleted; clprintf(CL_LOG_SEV_INFO,"Checkpoint Initialize"); /* Initialize checkpointing library */ rc = saCkptInitialize(&ckptLibraryHandle, /* Checkpoint service handle */ &callbacks, /* Optional callbacks table */ &ckpt_version); /* Required verison number */ if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"Failed to initialize checkpoint service with rc [%#x]", rc); return rc; } clprintf(CL_LOG_SEV_INFO,"Checkpoint service initialized (handle=0x%llx)", ckptLibraryHandle); /* Create the checkpoint table for read and write. */ rc = saCkptCheckpointOpen(ckptLibraryHandle, // Service handle &ckpt_name, // Checkpoint name &attrs, // Optional creation attr. (SA_CKPT_CHECKPOINT_READ | SA_CKPT_CHECKPOINT_WRITE | SA_CKPT_CHECKPOINT_CREATE), (SaTimeT)SA_TIME_MAX, // No timeout &ckpt_handle); // Checkpoint handle if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"Failed [0x%x] to open checkpoint",rc); } else { clprintf(CL_LOG_SEV_INFO,"Checkpoint opened (handle=0x%llx)", ckpt_handle); } return rc; }
int main () { SaAisErrorT error; SaNameT* WriteCheckpointName = (SaNameT*) malloc(sizeof(SaNameT)); char name[10]; SaCkptHandleT ckptHandle; sprintf(name,"ckpt%d",1); int namelen = strlen(name) + 1; memcpy(WriteCheckpointName->value, name, namelen); WriteCheckpointName->length = namelen; error = saCkptInitialize (&ckptHandle, &callbacks, &version); error = saCkptCheckpointOpen ( ckptHandle, WriteCheckpointName, &checkpointCreationAttributes, SA_CKPT_CHECKPOINT_WRITE, 1000000000, /* 1 Second */ &WriteCheckpointHandle); if (error != SA_AIS_OK) { fprintf(stderr,"saCkptCheckpointOpen result %d (should be 1)\n", error); return error; } error = saCkptSectionCreate ( WriteCheckpointHandle, §ionCreationAttributes, "Initial Data #0", strlen ("Initial Data #0") + 1); if (error != SA_AIS_OK) { fprintf(stderr,"saCkptSectionCreate result = %d\n", error); return error; } struct timespec tv; tv.tv_sec = 0; tv.tv_nsec = 15000000; //15 milliseconds while(1) { process_message(); nanosleep(&tv,NULL); } return 1; }
int main (void) { SaCkptHandleT ckptHandle; SaCkptCheckpointHandleT checkpointHandle; SaAisErrorT error; int i; pthread_t dispatch_thread; error = saCkptInitialize (&ckptHandle, &callbacks, &version); error = saCkptCheckpointOpen (ckptHandle, &checkpointName, &checkpointCreationAttributes, SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, 0, &checkpointHandle); printf ("first open result %d (should be 1)\n", error); error = saCkptSectionCreate (checkpointHandle, §ionCreationAttributes1, "Initial Data #0", strlen ("Initial Data #0") + 1); printf ("create2 error is %d\n", error); error = saCkptSectionCreate (checkpointHandle, §ionCreationAttributes2, "Initial Data #0", strlen ("Initial Data #0") + 1); printf ("create2 error is %d\n", error); for (i = 0; i < 40; i++) { struct thread_data *td; td = malloc (sizeof (struct thread_data)); td->thread_no = i; pthread_create (&dispatch_thread, NULL, th_dispatch, td); } pthread_join (dispatch_thread, NULL); error = saCkptInitialize (&ckptHandle, &callbacks, &version); return (0); }
int main (void) { SaCkptHandleT ckptHandle; SaCkptCheckpointHandleT checkpointHandle; SaAisErrorT error; int size; int i; signal (SIGALRM, sigalrm_handler); error = saCkptInitialize (&ckptHandle, &callbacks, &version); fail_on_error(error, "saCkptInitialize"); error = saCkptCheckpointOpen (ckptHandle, &checkpointName, &checkpointCreationAttributes, SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, 0, &checkpointHandle); fail_on_error(error, "saCkptCheckpointOpen"); error = saCkptSectionCreate (checkpointHandle, §ionCreationAttributes1, "Initial Data #0", strlen ("Initial Data #0") + 1); fail_on_error(error, "saCkptCheckpointSectionCreate"); error = saCkptSectionCreate (checkpointHandle, §ionCreationAttributes2, "Initial Data #0", strlen ("Initial Data #0") + 1); fail_on_error(error, "saCkptCheckpointSectionCreate"); size = 1; for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */ ckpt_benchmark (checkpointHandle, size); size += 1000; } error = saCkptFinalize (ckptHandle); return (0); }
/**************************************************************************** * 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; }
/******************************************************************************* Feature API: alarmClockCkptCreate Description : Create a checkpoint given a name and the number of sections. In addition the nature of the checkpoint needs to be specified, synchronous versus asynchronous. If asynchronous collocated versus non collocated. Arguments In: 1. Checkpoint Name 2. Number of Sections 3. Size of section *******************************************************************************/ SaAisErrorT alarmClockCkptCreate ( const SaStringT ckpt_name, SaUint32T num_sections, SaSizeT section_size, SaCkptCheckpointHandleT *ckpt_hdl ) { SaAisErrorT ret_code = SA_AIS_OK; SaNameT ckpt_name_t; SaCkptCheckpointCreationAttributesT ckpt_cr_attr; SaCkptCheckpointOpenFlagsT ckpt_open_flags; SaTimeT timeout; /* Initiailze name struct for ckpt */ ckpt_name_t.length = strlen(ckpt_name); strcpy( ( SaStringT )ckpt_name_t.value,ckpt_name); /* Initialize check point creation flags */ ckpt_cr_attr.creationFlags = CL_CKPT_DISTRIBUTED | CL_CKPT_PEER_TO_PEER_REPLICA; /* Maximum checkpoint size = size of all checkpoints combined */ ckpt_cr_attr.checkpointSize = 0; /* Retention time: forever */ ckpt_cr_attr.retentionDuration = (SaTimeT)-1; if ( num_sections == 1 ) { /* use a named section instead of the default section */ ckpt_cr_attr.maxSections = num_sections + 1; } else { ckpt_cr_attr.maxSections = num_sections; } ckpt_cr_attr.maxSectionSize = 0; ckpt_cr_attr.maxSectionIdSize = 256; /* forever */ timeout = (SaTimeT)-1; /* Initialize the checkpoint open flags */ ckpt_open_flags = (SA_CKPT_CHECKPOINT_READ | SA_CKPT_CHECKPOINT_WRITE | SA_CKPT_CHECKPOINT_CREATE); /* forever */ timeout = (SaTimeT)-1; ret_code = saCkptCheckpointOpen(ckpt_svc_hdl, &ckpt_name_t, &ckpt_cr_attr, ckpt_open_flags, timeout, ckpt_hdl); if ((ret_code != SA_AIS_OK)||(*ckpt_hdl == 0)) { alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptCreate: Failed to create ckpt:0x%x\n", ret_code); return ret_code; } alarmClockLogWrite(CL_LOG_SEV_DEBUG, "alarmClockCkptCreate: Successful creation ckpt [%llx]\n", *ckpt_hdl); return SA_AIS_OK; }
static int ckpt_open(ckpt_handle *h, const char *ckpt_name, int maxsize, int maxsec, int maxsecsize, int timeout) { SaCkptCheckpointCreationAttributesT attrs; SaCkptCheckpointOpenFlagsT flags; SaNameT cpname; #if 0 SaCkptCheckpointDescriptorT status; #endif SaAisErrorT err = SA_AIS_OK; VALIDATE(h); flags = SA_CKPT_CHECKPOINT_READ | SA_CKPT_CHECKPOINT_WRITE; snprintf((char *)cpname.value, SA_MAX_NAME_LENGTH-1, "%s", ckpt_name); cpname.length = strlen(ckpt_name); h->ck_timeout = timeout; err = saCkptCheckpointOpen(h->ck_handle, &cpname, NULL, flags, timeout, &h->ck_checkpoint); if (err == SA_AIS_OK) { #if 0 saCkptCheckpointStatusGet(h->ck_handle, &status); printf("Checkpoint Size = %d bytes\n", (int) status.checkpointCreationAttributes.checkpointSize); printf("Flags = "); if (status.checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ALL_REPLICAS) { printf("%s ", "SA_CKPT_WR_ALL_REPLICAS"); } if (status.checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ACTIVE_REPLICA) { printf("%s ", "SA_CKPT_WR_ACTIVE_REPLICA"); } if (status.checkpointCreationAttributes.creationFlags & SA_CKPT_WR_ACTIVE_REPLICA_WEAK) { printf("%s ", "SA_CKPT_WR_ACTIVE_REPLICA_WEAK"); } if (status.checkpointCreationAttributes.creationFlags & SA_CKPT_CHECKPOINT_COLLOCATED) { printf("%s ", "SA_CKPT_CHECKPOINT_COLLOCATED"); } printf("\nMax sections = %d\n", (int)status.checkpointCreationAttributes.maxSections); printf("Max section size = %d\n", (int)status.checkpointCreationAttributes.maxSectionSize); printf("Max section ID size = %d\n", (int)status.checkpointCreationAttributes.maxSectionIdSize); printf("Section count = %d\n", status.numberOfSections); printf("\n"); #endif goto good; } attrs.creationFlags = SA_CKPT_WR_ALL_REPLICAS; attrs.checkpointSize = (SaSizeT)maxsize; attrs.retentionDuration = SA_TIME_ONE_HOUR; attrs.maxSections = maxsec; attrs.maxSectionSize = (SaSizeT)maxsecsize; attrs.maxSectionIdSize = (SaSizeT)32; flags = SA_CKPT_CHECKPOINT_READ | SA_CKPT_CHECKPOINT_WRITE | SA_CKPT_CHECKPOINT_CREATE; err = saCkptCheckpointOpen(h->ck_handle, &cpname, &attrs, flags, timeout, &h->ck_checkpoint); if (err == SA_AIS_OK) goto good; /* No checkpoint */ errno = ais_to_posix(err); return (errno == 0 ? 0 : -1); good: printf("Opened ckpt %s\n", ckpt_name); h->ck_name = strdup(ckpt_name); errno = ais_to_posix(err); return (errno == 0 ? 0 : -1); }
static ClRcT checkpoint_initialize() { SaAisErrorT rc = SA_AIS_OK; SaVersionT ckpt_version = {'B', 1, 1}; SaNameT ckpt_name = { strlen(CKPT_NAME), CKPT_NAME }; SaUint32T seq_no; SaCkptCheckpointCreationAttributesT create_atts = { .creationFlags = SA_CKPT_WR_ACTIVE_REPLICA_WEAK | SA_CKPT_CHECKPOINT_COLLOCATED, .checkpointSize = sizeof(SaUint32T), .retentionDuration = (SaTimeT)0, .maxSections = 2, // default section, plus section we create .maxSectionSize = sizeof(SaSizeT), .maxSectionIdSize = (SaSizeT)64 }; SaCkptSectionCreationAttributesT section_atts = { .sectionId = &ckpt_sid, .expirationTime = SA_TIME_END }; clprintf(CL_LOG_SEV_INFO,"%s: checkpoint_initialize\n", appname); /* Initialize checkpointing service instance */ rc = saCkptInitialize(&ckpt_svc_handle, /* Checkpoint service handle */ NULL, /* Optional callbacks table */ &ckpt_version); /* Required verison number */ if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"%s: ERROR: Failed to initialize checkpoint service\n", appname); return rc; } clprintf(CL_LOG_SEV_INFO,"%s: Checkpoint service initialized (handle=0x%x)\n", appname,(unsigned int) ckpt_svc_handle); // // Create the checkpoint for read and write. If we fail to open it // then open it without CREATE. The retry loop is to deal with the // possibility that multiple processes might all come along here // and fail to open the checkpoint because it hasn't been created // yet and then they all try to create the checkpoint. All but // the first would fail. This retry allows all the rest of the // processes to come through and open without CREATE // TODO: change it to a straight retry loop where we start off with // mode = (CL_CKPT_CHECKPOINT_READ | CL_CKPT_CHECKPOINT_WRITE) // and on each iteration of the loop we xor in // CL_CKPT_CHECKPOINT_CREATE. That should let us do the same thing // but without the duplication of the clCkptCheckpointOpen call rc = saCkptCheckpointOpen(ckpt_svc_handle, // Service handle &ckpt_name, // Checkpoint name &create_atts, // Optional creation attr. (SA_CKPT_CHECKPOINT_READ | SA_CKPT_CHECKPOINT_WRITE | SA_CKPT_CHECKPOINT_CREATE), (SaTimeT)-1, // No timeout &ckpt_handle); // Checkpoint handle if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"%s: ERROR: Failed [0x%x] to open checkpoint\n", appname, rc); (void)saCkptFinalize(ckpt_svc_handle); return rc; } clprintf(CL_LOG_SEV_INFO,"%s: Checkpoint opened (handle=0x%x)\n", appname, (unsigned int) ckpt_handle); /* * Try to create a section so that updates can operate by overwriting * the section over and over again. * If subsequent processes come through here, they will fail to create * the section. That is OK, even though it will cause an error message * If the section create fails because the section is already there, then * read the sequence number */ // Put data in network byte order seq_no = htonl(seq); // Creating the section checkpoint_replica_activate(); rc = saCkptSectionCreate(ckpt_handle, // Checkpoint handle §ion_atts, // Section attributes (SaUint8T*)&seq_no, // Initial data (SaSizeT)sizeof(seq_no)); // Size of data if (rc != SA_AIS_OK && rc != SA_AIS_ERR_EXIST) { clprintf(CL_LOG_SEV_ERROR,"%s: ERROR: Failed [0x %x] to create checkpoint section\n", appname, rc); (void)saCkptCheckpointClose(ckpt_handle); (void)saCkptFinalize(ckpt_svc_handle); return rc; } else if (rc != SA_AIS_OK && rc == SA_AIS_ERR_EXIST) { rc = checkpoint_read_seq(&seq); if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"%s: ERROR: Failed [0x%x] to read checkpoint section\n", appname, rc); (void)saCkptCheckpointClose(ckpt_handle); (void)saCkptFinalize(ckpt_svc_handle); return rc; } } else { clprintf(CL_LOG_SEV_INFO,"%s: Section created\n", appname); } /* Open checkpoint for read to write depending on input argument */ return rc; } static SaAisErrorT checkpoint_finalize(void) { SaAisErrorT rc; rc = saCkptCheckpointClose(ckpt_handle); if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"%s: failed: [0x%x] to close checkpoint handle %d\n", appname, rc, (unsigned int) ckpt_handle); } rc = saCkptFinalize(ckpt_svc_handle); if (rc != SA_AIS_OK) { clprintf(CL_LOG_SEV_ERROR,"%s: failed: [0x%x] to finalize checkpoint\n", appname, rc); } return SA_AIS_OK; }
/******************************************************************************* Feature API: alarmClockCkptCreate Description : Create a checkpoint given a name and the number of sections. In addition the nature of the checkpoint needs to be specified, synchronous versus asynchronous. If asynchronous collocated versus non collocated. Arguments In: 1. Checkpoint Name 2. Number of Sections 3. Size of section *******************************************************************************/ SaAisErrorT alarmClockCkptCreate ( const SaStringT ckpt_name, SaUint32T num_sections, SaSizeT section_size, SaCkptCheckpointHandleT *ckpt_hdl ) { SaAisErrorT ret_code = SA_AIS_OK; SaNameT ckpt_name_t; SaCkptCheckpointCreationAttributesT ckpt_cr_attr; SaCkptCheckpointOpenFlagsT ckpt_open_flags; SaTimeT timeout; /* Initiailze name struct for ckpt */ ckpt_name_t.length = strlen(ckpt_name); strcpy( ( SaStringT )ckpt_name_t.value,ckpt_name); /* Initialize check point creation flags */ ckpt_cr_attr.creationFlags = SA_CKPT_CHECKPOINT_COLLOCATED | CL_CKPT_DISTRIBUTED; /* Maximum checkpoint size = size of all checkpoints combined */ ckpt_cr_attr.checkpointSize = num_sections * section_size; /* Retention time: forever */ ckpt_cr_attr.retentionDuration = (SaTimeT)-1; if ( num_sections == 1 ) { /* use a named section instead of the default section */ ckpt_cr_attr.maxSections = num_sections + 1; } else { ckpt_cr_attr.maxSections = num_sections; } ckpt_cr_attr.maxSectionSize = section_size; ckpt_cr_attr.maxSectionIdSize = sizeof(SaUint32T); /* forever */ timeout = (SaTimeT)-1; /* Initialize the checkpoint open flags */ ckpt_open_flags = (SA_CKPT_CHECKPOINT_READ | SA_CKPT_CHECKPOINT_WRITE | SA_CKPT_CHECKPOINT_CREATE); /* forever */ timeout = (SaTimeT)-1; ret_code = saCkptCheckpointOpen(ckpt_svc_hdl, &ckpt_name_t, &ckpt_cr_attr, ckpt_open_flags, timeout, ckpt_hdl); if ((ret_code != SA_AIS_OK)||(*ckpt_hdl == 0)) { alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptCreate: Failed to create ckpt:0x%x\n", ret_code); return ret_code; } if (1) // *ckpt_hot_standby == CL_TRUE) { /* * Register checkpoint for immediate consumption, all components that * register using this API for a checkpoint will be notified through * the callback function provided when a checkpoint update occurs * All components except the one that actually updates the checkpoint. */ /* When the standby becomes Active it checks this flag to see whether * it needs to perform a checkpoint read or not. If TRUE then the * assumption is that the checkpoint updates on standby have happened * via the callback */ g_hot_standby = HOT_STANDBY_IDLE; ret_code = clCkptImmediateConsumptionRegister(*ckpt_hdl, alarmClockCkptCallback, NULL); if (ret_code != CL_OK) { alarmClockLogWrite( CL_LOG_SEV_ERROR, "alarmClockCkptCreate(pid=%d): Failed to register ckpt callback rc[0x%x]\n", getpid(), ret_code); alarmClockLogWrite(CL_LOG_SEV_WARNING, "alarmClockCkptCreate(pid=%d): Falling back to warm standby mode\n", getpid()); //*ckpt_hot_standby = CL_FALSE; return ret_code; } alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptCreate: Successfully registered for callbacks"); } alarmClockLogWrite(CL_LOG_SEV_ERROR, "alarmClockCkptCreate: Successful creation ckpt [%llx]\n", *ckpt_hdl); return SA_AIS_OK; }
int main (void) { SaCkptHandleT ckptHandle; SaCkptCheckpointHandleT checkpointHandle; SaAisErrorT error; char data[MAX_DATA_SIZE]; struct timespec delay; struct timespec delay2; SaCkptIOVectorElementT writeElement; long count = 0; SaUint32T erroroneousVectorIndex = 0; delay.tv_sec = 1; delay.tv_nsec = 0; error = saCkptInitialize (&ckptHandle, &callbacks, &version); error = saCkptCheckpointOpen (ckptHandle, &checkpointName, &checkpointCreationAttributes, SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE, 0, &checkpointHandle); printf ("%s: initial open of checkpoint\n", get_test_output (error, SA_AIS_OK)); do{ error = saCkptCheckpointRead (checkpointHandle, ReadVectorElements, 1, &erroroneousVectorIndex); if (error != SA_AIS_OK) { if (error == SA_AIS_ERR_TRY_AGAIN) { continue; } printf ("error is %d\n", error); return (0); } if (ReadVectorElements->dataBuffer == 0) { printf ("Default Checkpoint has no data\n"); } else { count = atol((char *)ReadVectorElements->dataBuffer); } count++; sprintf((char*)&data, "%d",(int)count); writeElement.sectionId = (SaCkptSectionIdT)SA_CKPT_DEFAULT_SECTION_ID; writeElement.dataBuffer = data; writeElement.dataSize = strlen (data) + 1; writeElement.dataOffset = 0; writeElement.readSize = 0; do { error = saCkptCheckpointWrite (checkpointHandle, &writeElement, 1, &erroroneousVectorIndex); printf ("%s: checkpoint write with data %s\n", get_test_output (error, SA_AIS_OK), (char*)data); }while (error == SA_AIS_ERR_TRY_AGAIN); nanosleep(&delay,&delay2); }while (1); return (0); }