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);*/ }
void _regist_msg_proc(slurm_msg_t *msg) { slurm_send_rc_msg(msg, SLURM_SUCCESS); int num_insert_msg_local = 0; pthread_mutex_lock(®ist_mutex); char* target = ((slurm_node_registration_status_msg_t *) msg->data)->node_name; if (find_exist(source, target, part_size) < 0) { strcpy(source[num_regist_recv++], target); strcat(resource,target); if (num_regist_recv == part_size) { c_zht_insert(self_id, resource); ready = 1; num_insert_msg_local++; c_free(resource); c_free_2(source, part_size + 1); } else { strcat(resource, ","); } } pthread_mutex_unlock(®ist_mutex); if (num_insert_msg_local > 0) { pthread_mutex_lock(&insert_msg_mutex); num_insert_msg += num_insert_msg_local; pthread_mutex_unlock(&insert_msg_mutex); } }
/** * Desc: set the open mode of the file * Return: 0 - success, 1 - failed */ int zht_set_openmode(const char *virtualfname, int openmode) { 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*)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"); } /*update the openmode of the package*/ lkPackage->openmode = openmode; lkPackage->operation = 3; //1 for look up, 2 for remove, 3 for insert int len2 = package__get_packed_size(lkPackage); char *buf2 = calloc(len2, sizeof(char)); package__pack(lkPackage, (uint8_t *)buf2); int iret = c_zht_insert(buf2); if (iret) { fprintf(stderr, "c_zht_insert, return code %d. \n", iret); return 1; } free(buf2); package__free_unpacked(lkPackage, NULL); } free(buf); // Free the allocated serialized buffer return 0; }
extern int _c_zht_insert2(char *key, char *value) { char *buf; unsigned len; Package package = PACKAGE__INIT; package.virtualpath = key; if (strcmp(value, "") != 0) //tricky: bypass protocol-buf's bug package.realfullpath = value; package.has_isdir = true; package.isdir = false; package.has_operation = true; package.operation = 3; len = package__get_packed_size(&package); buf = (char*) calloc(len, sizeof(char)); package__pack(&package, buf); int iret = c_zht_insert(buf); free(buf); return iret; }
int zht_insert(const char *key, const char *value) { // fprintf(stderr, "dfz debug: in zht_insert(): key = %s, value = %s. \n", key, value); log_msg("DFZ debug: in zht_insert(): key = %s, value = %s. \n\n", key, value); // return c_zht_insert2(key, value); Package package = PACKAGE__INIT; // Package package.virtualpath = (char*)key; package.realfullpath = (char*)value; package.has_isdir = true; package.isdir = false; 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, (uint8_t *)buf); int ret = c_zht_insert(buf); if (ret) fprintf(stderr, "c_zht_insert, return code %d. \n", ret); /* test ZHT insert */ // char tmpstr[ZHT_MAX_BUFF] = {0}; // zht_lookup(key, tmpstr); // fprintf(stderr, "dfz debug: tmpstr = %s. \n", tmpstr); free(buf); // Free the allocated serialized buffer return 0; }
int zht_insert(const char *key, const char *value) { // return c_zht_insert2(key, value); Package package = PACKAGE__INIT; // Package package.virtualpath = (char*)key; package.realfullpath = (char*)value; 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, (uint8_t *)buf); int ret = c_zht_insert(buf); if (ret) fprintf(stderr, "c_zht_insert, return code %d. \n", ret); free(buf); // Free the allocated serialized buffer return 0; }
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 }