void _step_complete_msg_proc(slurm_msg_t* msg) { slurm_send_rc_msg(msg, SLURM_SUCCESS); step_complete_msg_t *complete = (step_complete_msg_t*) msg->data; /* get the job id */ char str_job_id[20] = { 0 }; sprintf(str_job_id, "%u", complete->job_id); /* lookup for the origin controller id of this job */ char *origin_ctrlid = c_calloc(30); c_zht_lookup(str_job_id, origin_ctrlid); pthread_mutex_lock(&lookup_msg_mutex); num_lookup_msg++; pthread_mutex_unlock(&lookup_msg_mutex); /* concat to get the jobid+origin_ctrlid */ char *jobid_origin_ctrlid = c_calloc(strlen(origin_ctrlid) + 30 + 2); strcat(jobid_origin_ctrlid, str_job_id); strcat(jobid_origin_ctrlid, origin_ctrlid); /* create the job resource from looking up zht */ job_resource *a_job_res = _create_job_resource(jobid_origin_ctrlid); release_res(a_job_res); free_job_resource(a_job_res); /* check to see whether this job belongs to the controller */ if (!strcmp(self_id, origin_ctrlid)) { pthread_mutex_lock(&num_job_fin_mutex); num_job_fin++; pthread_mutex_unlock(&num_job_fin_mutex); unsigned long time_in_micros = get_current_time(); pthread_mutex_lock(&job_output_mutex); fprintf(job_output_file, "%u\tend time\t%lu\n", complete->job_id, time_in_micros); pthread_mutex_unlock(&job_output_mutex); } else // if it is not, then insert a notification message { char *key = c_calloc(strlen(jobid_origin_ctrlid) + 5); strcat(key, jobid_origin_ctrlid); strcat(key, "Fin"); c_zht_insert(key, "Finished"); pthread_mutex_lock(&insert_msg_mutex); num_insert_msg++; pthread_mutex_unlock(&insert_msg_mutex); c_free(key); } c_free(origin_ctrlid); c_free(jobid_origin_ctrlid); /*pthread_mutex_lock(&lookup_msg_mutex); num_lookup_msg += num_lookup_msg_local; pthread_mutex_unlock(&lookup_msg_mutex); pthread_mutex_lock(&insert_msg_mutex); num_insert_msg += num_insert_msg_local; pthread_mutex_unlock(&insert_msg_mutex); pthread_mutex_lock(&cswap_msg_mutex); num_cswap_msg += num_comswap_msg_local; pthread_mutex_unlock(&cswap_msg_mutex);*/ }
/** * Desc: get the open mode of the file: * Return: 000 - not open; 001 - read only; 010 - write only; 011 - read and write; -1 - failed */ int zht_get_openmode(const char *virtualfname) { char *buf; // Buffer to store serialized data unsigned len; // Length of serialized data char result[ZHT_MAX_BUFF] = {0}; //return result size_t ln; //return length int rtn; Package package = PACKAGE__INIT; // Package package.virtualpath = (char*)virtualfname; package.realfullpath = ""; package.has_operation = true; package.operation = 1; //1 for look up, 2 for remove, 3 for insert len = package__get_packed_size(&package); buf = (char*) calloc(len, sizeof(char)); package__pack(&package, (uint8_t *)buf); int lret = c_zht_lookup(buf, result, &ln); if (lret == 0 && ln > 0) { Package *lkPackage; lkPackage = package__unpack(NULL, ln, (const uint8_t *)result); if (lkPackage == NULL) { fprintf(stderr, "error unpacking lookup result\n"); } rtn = lkPackage->openmode; package__free_unpacked(lkPackage, NULL); } free(buf); // Free the allocated serialized buffer return rtn; }
int zht_lookup(const char *key, char *val) { // return c_zht_lookup2(key, val); // size_t len; // return c_zht_lookup2(key, val, &len); char *buf; // Buffer to store serialized data unsigned len; // Length of serialized data char result[ZHT_MAX_BUFF] = {0}; //return result size_t ln; //return length Package package = PACKAGE__INIT; // Package package.virtualpath = (char*)key; // package.realfullpath = ""; // package.has_operation = true; package.operation = 1; //1 for look up, 2 for remove, 3 for insert len = package__get_packed_size(&package); buf = (char*) calloc(len, sizeof(char)); package__pack(&package, (uint8_t *)buf); int lret = c_zht_lookup(buf, result, &ln); if (lret == 0 && ln > 0) { Package *lkPackage; // char *lkBuf = (char*) calloc(ln, sizeof(char)); // char lkBuf[ln + 1] = {0}; // strncpy(lkBuf, result, ln); lkPackage = package__unpack(NULL, ln, (const uint8_t *)result); if (lkPackage == NULL) { fprintf(stderr, "error unpacking lookup result\n"); } // else { // fprintf(stderr, // "c_zht_lookup, return {key}:{value} ==>\n{%s}:{%s}\n", // lkPackage->virtualpath, lkPackage->realfullpath); // } // free(lkBuf); strcpy(val, lkPackage->realfullpath); package__free_unpacked(lkPackage, NULL); } //fprintf(stderr, "dfz debug: in zht_lookup(): val = %s. \n", val); log_msg("DFZ debug: in zht_lookup(): key = %s, val = %s. \n\n", key, val); free(buf); // Free the allocated serialized buffer return 0; }
job_resource *_create_job_resource(char* jobid_origin_ctrlid) { long num_lookup_msg_local = 0L; job_resource *a_job_res = init_job_resource(); /* get the involved controller list in one dimension array*/ char *jobid_origin_ctrlid_ctrls = c_calloc(strlen(jobid_origin_ctrlid) + 7); strcat(jobid_origin_ctrlid_ctrls, jobid_origin_ctrlid); strcat(jobid_origin_ctrlid_ctrls, "ctrls"); c_zht_lookup(jobid_origin_ctrlid_ctrls, a_job_res->ctrl_ids_1); num_lookup_msg_local++; c_free(jobid_origin_ctrlid_ctrls); /* split the one dimension of involved controller list to two dimension */ char *ctrl_ids_1_backup = strdup(a_job_res->ctrl_ids_1); a_job_res->num_ctrl = split_str(ctrl_ids_1_backup, ",", a_job_res->ctrl_ids_2); /* get the allocated nodelist for each involved controller*/ char *jobid_origin_ctrlid_invid = c_calloc(strlen(jobid_origin_ctrlid) + 30 + 2); int i = 0; for (; i < a_job_res->num_ctrl; i++) { strcat(jobid_origin_ctrlid_invid, jobid_origin_ctrlid); strcat(jobid_origin_ctrlid_invid, a_job_res->ctrl_ids_2[i]); c_zht_lookup(jobid_origin_ctrlid_invid, a_job_res->node_alloc[i]); num_lookup_msg_local++; c_memset(jobid_origin_ctrlid_invid, strlen(jobid_origin_ctrlid_invid)); } pthread_mutex_lock(&lookup_msg_mutex); num_lookup_msg += num_lookup_msg_local; pthread_mutex_unlock(&lookup_msg_mutex); return a_job_res; }
extern void _c_zht_lookup2(char *key, char *ret) { Package package2 = PACKAGE__INIT; package2.virtualpath = key; package2.operation = 1; unsigned len = package__get_packed_size(&package2); char *buf = (char*) calloc(len, sizeof(char)); package__pack(&package2, buf); size_t ln; char *result = (char*)calloc(1024 * 10, sizeof(char)); if (result != NULL) { int lret = c_zht_lookup(buf, result, &ln); free(buf); if (lret == 0 && ln > 0) { //printf("OK, seems fine!\n"); Package * lPackage; char *lBuf = (char*) calloc(ln, sizeof(char)); strncpy(lBuf, result, ln); lPackage = package__unpack(NULL, ln, lBuf); free(lBuf); free(result); if (lPackage == NULL) { printf("error unpacking lookup result\n"); } else { //printf("The value is:%s\n", lPackage->realfullpath); strcpy(ret, lPackage->realfullpath); } } else { free(result); } } }
void test_pass_package() { char *key = "hello"; char *value = "zht"; Package package = PACKAGE__INIT; // Package package.virtualpath = key; package.realfullpath = value; package.has_isdir = true; package.isdir = true; package.has_operation = true; package.operation = 3; //1 for look up, 2 for remove, 3 for insert char *buf; // Buffer to store serialized data unsigned len; // Length of serialized data len = package__get_packed_size(&package); buf = (char*) calloc(len, sizeof(char)); package__pack(&package, buf); /* * test c_zht_insert * */ int iret = c_zht_insert(buf); fprintf(stderr, "c_zht_insert, return code: %d\n", iret); /* * test c_zht_lookup * */ memset(buf, 0, len); package.operation = 1; //1 for look up, 2 for remove, 3 for insert package.realfullpath = ""; package__pack(&package, buf); size_t ln; char *result = (char*) calloc(LOOKUP_SIZE, sizeof(char)); if (result != NULL) { int lret = c_zht_lookup(buf, result, &ln); fprintf(stderr, "c_zht_lookup, return code(length): %d(%lu)\n", lret, ln); if (lret == 0 && ln > 0) { Package *lkPackage; char *lkBuf = (char*) calloc(ln, sizeof(char)); strncpy(lkBuf, result, ln); lkPackage = package__unpack(NULL, ln, lkBuf); if (lkPackage == NULL) { fprintf(stderr, "error unpacking lookup result\n"); } else { fprintf(stderr, "c_zht_lookup, return {key}:{value} ==>\n{%s}:{%s}\n", lkPackage->virtualpath, lkPackage->realfullpath); } free(lkBuf); package__free_unpacked(lkPackage, NULL); } } free(result); /* * test c_zht_remove * */ memset(buf, 0, len); package.operation = 2; //1 for look up, 2 for remove, 3 for insert package__pack(&package, buf); int rret = c_zht_remove(buf); fprintf(stderr, "c_zht_remove, return code: %d\n", rret); free(buf); // Free the allocated serialized buffer }