void test_case_cbgt_search_one(const UINT32 cbgt_md_id, const char *table_name, const char *row, const char *colf, const char *colq) { CBYTES table_name_bytes; CBYTES row_bytes; CBYTES colf_bytes; CBYTES colq_bytes; CBYTES val_bytes; cbytes_mount(&table_name_bytes, strlen(table_name), (UINT8 *)table_name); cbytes_mount(&row_bytes , strlen(row) , (UINT8 *)row ); cbytes_mount(&colf_bytes , strlen(colf) , (UINT8 *)colf ); cbytes_mount(&colq_bytes , strlen(colq) , (UINT8 *)colq ); cbytes_init(&val_bytes); ASSERT(EC_TRUE == cbgt_search(cbgt_md_id, &table_name_bytes, &row_bytes, &colf_bytes, &colq_bytes, &val_bytes)); sys_log(LOGSTDOUT, "[test_case_cbgt_search_one] searched (%s:%s:%s) in table %s ==> val %.*s\n", row, colf, colq, table_name, cbytes_len(&val_bytes), cbytes_buf(&val_bytes)); return; }
void test_case_cbgt_fetch_group_p(const UINT32 cbgt_md_id, const char *table_name, const UINT32 row_tag) { UINT32 row_idx; UINT32 colf_idx; UINT32 colq_idx; CBYTES table_name_bytes; void *mod_mgr; EC_BOOL continue_flag; ASSERT(32 <= CBGT_KV_VAL_LEN); ASSERT(mod_mgr = mod_mgr_new(cbgt_md_id, LOAD_BALANCING_OBJ)); mod_mgr_incl(CMPI_LOCAL_TCID, CMPI_LOCAL_COMM, CMPI_LOCAL_RANK, cbgt_md_id, mod_mgr); mod_mgr_print(LOGCONSOLE, mod_mgr); cbytes_mount(&table_name_bytes, strlen(table_name), (UINT8 *)table_name); continue_flag = EC_TRUE; for(row_idx = 0; row_idx < CBGT_TEST_ROW_NUM && EC_TRUE == continue_flag; row_idx ++) { char *row; CBYTES *row_bytes; ASSERT(row = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(row, CBGT_STR_MAX_LEN, "row-%08ld-%08ld", row_tag, row_idx); ASSERT(row_bytes = cbytes_new(0)); cbytes_mount(row_bytes , strlen(row) , (UINT8 *)row ); //cvector_push(bytes_vec, (void *)row_bytes); for(colf_idx = 0; colf_idx < CBGT_TEST_COLF_NUM && EC_TRUE == continue_flag; colf_idx ++) { char *colf; CBYTES *colf_bytes; void *task_mgr; void *bytes_vec; EC_BOOL ret[CBGT_TEST_COLQ_NUM]; CBYTES val_bytes[CBGT_TEST_COLQ_NUM]; ASSERT(bytes_vec = cvector_new(0, MM_CBYTES, 0)); ASSERT(colf = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colf, CBGT_STR_MAX_LEN, "colf-%ld", colf_idx); ASSERT(colf_bytes = cbytes_new(0)); cbytes_mount(colf_bytes , strlen(colf) , (UINT8 *)colf ); //cvector_push(bytes_vec, (void *)colf_bytes); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM && EC_TRUE == continue_flag; colq_idx ++) { char *colq; CBYTES *colq_bytes; ASSERT(colq = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colq, CBGT_STR_MAX_LEN, "colq-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); ASSERT(colq_bytes = cbytes_new(0)); cbytes_mount(colq_bytes , strlen(colq) , (UINT8 *)colq ); cvector_push(bytes_vec, (void *)colq_bytes); ret[ colq_idx ] = EC_FALSE; cbytes_init(&(val_bytes[colq_idx])); task_inc(task_mgr, &(ret[ colq_idx ]), FI_cbgt_fetch, ERR_MODULE_ID, &table_name_bytes, row_bytes, colf_bytes, colq_bytes, &(val_bytes[colq_idx])); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM; colq_idx ++) { char *val; CBYTES __val_bytes; #if 0 ASSERT(val = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(val, CBGT_STR_MAX_LEN, "val-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); #else ASSERT(val = (char *)safe_malloc(CBGT_KV_VAL_LEN, 0)); snprintf(val, CBGT_KV_VAL_LEN, "val-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); memset(val + strlen(val), '0', CBGT_KV_VAL_LEN - strlen(val)); val[CBGT_KV_VAL_LEN - 1] = '\0'; #endif cbytes_init(&__val_bytes); cbytes_mount(&__val_bytes, strlen(val), (UINT8 *)val); if(EC_TRUE == ret[ colq_idx ] && EC_TRUE == cbytes_cmp(&__val_bytes, &(val_bytes[colq_idx]))) { #if 0 sys_log(LOGSTDNULL, "[DEBUG] test_case_cbgt_fetch_group_p: [SUCC] fetch %s %s:%s:colq-%08ld-%08ld-%08ld => %.*s\n", table_name, row, colf, row_idx, colf_idx, colq_idx, cbytes_len(&(val_bytes[colq_idx])), (char *)cbytes_buf(&(val_bytes[colq_idx]))); #endif } else { //continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_fetch_group_p: [FAIL] fetch %s %s:%s:colq-%08ld-%08ld-%08ld => %.*s\n", table_name, row, colf, row_idx, colf_idx, colq_idx, cbytes_len(&(val_bytes[colq_idx])), (char *)cbytes_buf(&(val_bytes[colq_idx]))); } cbytes_clean(&__val_bytes, 0); cbytes_clean(&(val_bytes[colq_idx]), 0); } cbytes_free(colf_bytes, 0); cvector_clean_with_location(bytes_vec, (CVECTOR_DATA_LOCATION_CLEANER)cbytes_free, 0); cvector_free(bytes_vec, 0); } if(EC_TRUE == continue_flag) { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_fetch_group_p: [SUCC] row tag %ld, row no. %ld\n", row_tag, row_idx); } else { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_fetch_group_p: [FAIL] row tag %ld, row no. %ld\n", row_tag, row_idx); } cbytes_free(row_bytes, 0); } sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_fetch_group_p: row tag %ld end\n", row_tag); return; }
uint8_t rawDataFlush(RawData *raw_data, const RawFile *raw_file) { if(RAWDATA_IS_DIRTY(raw_data)) { uint8_t *des_buff; word_t des_len; CSTRING *fname_cstr; CBYTES cbytes; fname_cstr = cstring_new(raw_file->file_name, LOC_RAW_0024); if(NULL_PTR == fname_cstr) { dbg_log(SEC_0132_RAW, 0)(LOGSTDOUT, "error:rawDataFlush: new file name string failed\n"); return RAW_FILE_FAIL; } des_buff = (uint8_t *)SAFE_MALLOC(raw_data->cur_size, LOC_RAW_0025); if(NULL == des_buff) { cstring_free(fname_cstr); dbg_log(SEC_0132_RAW, 0)(LOGSTDOUT, "error:rawDataFlush: alloc %d bytes failed\n", raw_data->cur_size); return RAW_FILE_FAIL; } des_len = raw_data->cur_size; if(RAW_FILE_SUCC != rawDataCompress(raw_data, des_buff, &des_len)) { cstring_free(fname_cstr); SAFE_FREE(des_buff, LOC_RAW_0026); dbg_log(SEC_0132_RAW, 0)(LOGSTDOUT, "error:rawDataFlush: compress %d bytes failed\n", raw_data->cur_size); return RAW_FILE_FAIL; } dbg_log(SEC_0132_RAW, 9)(LOGSTDOUT, "[DEBUG] rawDataFlush: compress %d bytes => %d bytes, rate = %.2f\n", raw_data->cur_size, des_len, (des_len + 0.0)/(raw_data->cur_size + 0.0)); /*flush first word + compressed data*/ cbytes_init(&cbytes); cbytes_mount(&cbytes, des_len, des_buff); if(EC_FALSE == cdfs_update(raw_file->cdfs_md_id, fname_cstr, &cbytes)) { cbytes_umount(&cbytes, NULL_PTR, NULL_PTR); cstring_free(fname_cstr); SAFE_FREE(des_buff, LOC_RAW_0027); dbg_log(SEC_0132_RAW, 0)(LOGSTDOUT, "error:rawDataFlush: update %s with %ld bytes failed\n", (char *)raw_file->file_name, des_len); return RAW_FILE_FAIL; } cbytes_umount(&cbytes, NULL_PTR, NULL_PTR); cstring_free(fname_cstr); SAFE_FREE(des_buff, LOC_RAW_0028); RAWDATA_CLEAR_DIRTY(raw_data); dbg_log(SEC_0132_RAW, 9)(LOGSTDNULL, "[DEBUG] rawDataFlush: raw data is dirty, flush %d bytes into file %s where max_size %d\n", des_len, (char *)raw_file->file_name, raw_data->max_size); } else { dbg_log(SEC_0132_RAW, 9)(LOGSTDOUT, "[DEBUG] rawDataFlush: raw data is NOT dirty, NOT flush it\n"); } return RAW_FILE_SUCC; }