Skip to content

Commit

Permalink
fix: stmt bindParam length not free
Browse files Browse the repository at this point in the history
  • Loading branch information
DuanKuanJun committed Aug 23, 2024
1 parent 6ff8d21 commit b6341fd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
25 changes: 17 additions & 8 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -3050,14 +3050,11 @@ static int parseBufferToStmtBatch(SSuperTable* stbInfo, uint64_t *bind_ts_array)

for (int c = 0; c < columnCount; c++) {
Field *col = benchArrayGet(stbInfo->cols, c);
char dataType = col->type;

char *is_null = benchCalloc(
1, sizeof(char) *g_arguments->prepared_rand, false);
char *is_null = benchCalloc(1, sizeof(char) * g_arguments->prepared_rand, false);
tmfree(col->stmtData.is_null);
col->stmtData.is_null = is_null;

initStmtData(dataType, &(col->stmtData.data), col->length);
initStmtData(col->type, &(col->stmtData.data), col->length);
}

return initStmtDataValue(stbInfo, NULL, bind_ts_array);
Expand Down Expand Up @@ -3525,13 +3522,16 @@ int32_t initInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr
goto END;
}

int32_t max_cnt = g_arguments->prepared_rand > g_arguments->reqPerReq ? g_arguments->prepared_rand : g_arguments->reqPerReq;

// malloc bind
pThreadInfo->bind_ts = benchCalloc(1, sizeof(int64_t), true);
pThreadInfo->bind_ts_array = benchCalloc(1, sizeof(int64_t)*max_cnt, true);
pThreadInfo->bind_ts_array = benchCalloc(1, sizeof(int64_t)*g_arguments->reqPerReq, true);
pThreadInfo->bindParams = benchCalloc(1, sizeof(TAOS_MULTI_BIND)*(stbInfo->cols->size + 1), true);
pThreadInfo->is_null = benchCalloc(1, g_arguments->reqPerReq, true);
// have ts columns, so size + 1
pThreadInfo->lengths = benchCalloc(stbInfo->cols->size + 1, sizeof(int32_t*), true);
for(int32_t c = 0; c <= stbInfo->cols->size; c++) {
pThreadInfo->lengths[c] = benchCalloc(g_arguments->reqPerReq, sizeof(int32_t), true);
}

parseBufferToStmtBatch(stbInfo, pThreadInfo->bind_ts_array);
for (int64_t child = 0; child < stbInfo->childTblCount; child++) {
Expand Down Expand Up @@ -3844,6 +3844,15 @@ int32_t exitInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr
tmfree(pThreadInfo->bind_ts_array);
tmfree(pThreadInfo->bindParams);
tmfree(pThreadInfo->is_null);

// free lengths
if(pThreadInfo->lengths) {
for(int c = 0; c <= stbInfo->cols->size; c++) {
tmfree(pThreadInfo->lengths[c]);
}
free(pThreadInfo->lengths);
pThreadInfo->lengths = NULL;
}
break;

case TAOSC_IFACE:
Expand Down
57 changes: 32 additions & 25 deletions src/benchJsonOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ static int getColumnAndTagTypeFromInsertJsonFile(
int count = 1;
int64_t max = RAND_MAX >> 1;
int64_t min = 0;
double maxInDbl = max;
double minInDbl = min;
uint32_t scalingFactor = 1;
double maxInDbl = max;
double minInDbl = min;
uint32_t scalingFactor = 1;
int32_t length = 4;
// fun type
uint8_t funType = FUNTYPE_NONE;
Expand Down Expand Up @@ -260,25 +260,25 @@ static int getColumnAndTagTypeFromInsertJsonFile(
}

double valueRange = maxInDbl - minInDbl;
tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor");
if (tools_cJSON_IsNumber(dataScalingFactor)) {
scalingFactor = dataScalingFactor->valueint;
if (scalingFactor > 1) {
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
} else {
if (0 < valueRange && valueRange <= 1) {
scalingFactor = 1000;
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
}

tools_cJSON *dataScalingFactor = tools_cJSON_GetObjectItem(column, "scalingFactor");
if (tools_cJSON_IsNumber(dataScalingFactor)) {
scalingFactor = dataScalingFactor->valueint;
if (scalingFactor > 1) {
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
} else {
if (0 < valueRange && valueRange <= 1) {
scalingFactor = 1000;
max = maxInDbl * scalingFactor;
min = minInDbl * scalingFactor;
} else {
scalingFactor = 1;
}
}

// gen
tools_cJSON *dataGen = tools_cJSON_GetObjectItem(column, "gen");
if (tools_cJSON_IsString(dataGen)) {
Expand Down Expand Up @@ -352,9 +352,9 @@ static int getColumnAndTagTypeFromInsertJsonFile(
col->sma = sma;
col->max = max;
col->min = min;
col->maxInDbl = maxInDbl;
col->minInDbl = minInDbl;
col->scalingFactor = scalingFactor;
col->maxInDbl = maxInDbl;
col->minInDbl = minInDbl;
col->scalingFactor = scalingFactor;
col->gen = gen;
col->fillNull = fillNull;
col->values = dataValues;
Expand Down Expand Up @@ -1635,6 +1635,13 @@ static int getMetaFromInsertJsonFile(tools_cJSON *json) {
g_arguments->prepared_rand = prepareRand->valueint;
}

// check prepared_rand valid
if(g_arguments->prepared_rand < g_arguments->reqPerReq) {
infoPrint("prepared_rand(%"PRId64") < num_of_records_per_req(%"PRId64") , so set prepared_rand = num_of_records_per_req\n",
g_arguments->prepared_rand, g_arguments->reqPerReq);
g_arguments->prepared_rand = g_arguments->reqPerReq;
}

tools_cJSON *chineseOpt =
tools_cJSON_GetObjectItem(json, "chinese"); // yes, no,
if (chineseOpt && chineseOpt->type == tools_cJSON_String
Expand Down

0 comments on commit b6341fd

Please sign in to comment.