Merge pull request #15345 from taosdata/fix/indexMemleak
fix: avoid mem leak
This commit is contained in:
commit
ca7fe4e9b5
|
@ -27,8 +27,8 @@
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
#include "tgrant.h"
|
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
|
#include "tgrant.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "trow.h"
|
#include "trow.h"
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ typedef struct SMetaFltParam {
|
||||||
|
|
||||||
} SMetaFltParam;
|
} SMetaFltParam;
|
||||||
|
|
||||||
int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *results);
|
int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *results);
|
||||||
|
|
||||||
#if 1 // refact APIs below (TODO)
|
#if 1 // refact APIs below (TODO)
|
||||||
typedef SVCreateTbReq STbCfg;
|
typedef SVCreateTbReq STbCfg;
|
||||||
|
@ -118,11 +118,11 @@ int32_t metaTbCursorNext(SMTbCursor *pTbCur);
|
||||||
// typedef struct STsdb STsdb;
|
// typedef struct STsdb STsdb;
|
||||||
typedef struct STsdbReader STsdbReader;
|
typedef struct STsdbReader STsdbReader;
|
||||||
|
|
||||||
#define BLOCK_LOAD_OFFSET_ORDER 1
|
#define BLOCK_LOAD_OFFSET_ORDER 1
|
||||||
#define BLOCK_LOAD_TABLESEQ_ORDER 2
|
#define BLOCK_LOAD_TABLESEQ_ORDER 2
|
||||||
#define BLOCK_LOAD_EXTERN_ORDER 3
|
#define BLOCK_LOAD_EXTERN_ORDER 3
|
||||||
|
|
||||||
#define LASTROW_RETRIEVE_TYPE_ALL 0x1
|
#define LASTROW_RETRIEVE_TYPE_ALL 0x1
|
||||||
#define LASTROW_RETRIEVE_TYPE_SINGLE 0x2
|
#define LASTROW_RETRIEVE_TYPE_SINGLE 0x2
|
||||||
|
|
||||||
int32_t tsdbSetTableId(STsdbReader *pReader, int64_t uid);
|
int32_t tsdbSetTableId(STsdbReader *pReader, int64_t uid);
|
||||||
|
@ -238,8 +238,8 @@ typedef struct {
|
||||||
uint64_t groupId;
|
uint64_t groupId;
|
||||||
} STableKeyInfo;
|
} STableKeyInfo;
|
||||||
|
|
||||||
#define TABLE_ROLLUP_ON ((int8_t)0x1)
|
#define TABLE_ROLLUP_ON ((int8_t)0x1)
|
||||||
#define TABLE_IS_ROLLUP(FLG) (((FLG) & (TABLE_ROLLUP_ON)) != 0)
|
#define TABLE_IS_ROLLUP(FLG) (((FLG) & (TABLE_ROLLUP_ON)) != 0)
|
||||||
#define TABLE_SET_ROLLUP(FLG) ((FLG) |= TABLE_ROLLUP_ON)
|
#define TABLE_SET_ROLLUP(FLG) ((FLG) |= TABLE_ROLLUP_ON)
|
||||||
struct SMetaEntry {
|
struct SMetaEntry {
|
||||||
int64_t version;
|
int64_t version;
|
||||||
|
|
|
@ -765,12 +765,14 @@ typedef struct {
|
||||||
int32_t vLen;
|
int32_t vLen;
|
||||||
} SIdxCursor;
|
} SIdxCursor;
|
||||||
|
|
||||||
int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
SIdxCursor *pCursor = NULL;
|
int32_t ret = 0;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int32_t maxSize = 0;
|
|
||||||
|
|
||||||
int32_t ret = 0, valid = 0;
|
STagIdxKey *pKey = NULL;
|
||||||
|
int32_t nKey = 0;
|
||||||
|
|
||||||
|
SIdxCursor *pCursor = NULL;
|
||||||
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
pCursor->pMeta = pMeta;
|
pCursor->pMeta = pMeta;
|
||||||
pCursor->suid = param->suid;
|
pCursor->suid = param->suid;
|
||||||
|
@ -782,9 +784,8 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
STagIdxKey *pKey = NULL;
|
|
||||||
int32_t nKey = 0;
|
|
||||||
|
|
||||||
|
int32_t maxSize = 0;
|
||||||
int32_t nTagData = 0;
|
int32_t nTagData = 0;
|
||||||
void *tagData = NULL;
|
void *tagData = NULL;
|
||||||
|
|
||||||
|
@ -822,10 +823,12 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *entryKey = NULL, *entryVal = NULL;
|
|
||||||
int32_t nEntryKey, nEntryVal;
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
int32_t valid = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
void *entryKey = NULL, *entryVal = NULL;
|
||||||
|
int32_t nEntryKey, nEntryVal;
|
||||||
|
|
||||||
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
|
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
|
||||||
if (valid < 0) {
|
if (valid < 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -864,10 +867,12 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END:
|
END:
|
||||||
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
||||||
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
|
taosMemoryFree(pKey);
|
||||||
|
|
||||||
taosMemoryFree(pCursor);
|
taosMemoryFree(pCursor);
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,9 @@ static void sifFreeParam(SIFParam *param) {
|
||||||
|
|
||||||
taosArrayDestroy(param->result);
|
taosArrayDestroy(param->result);
|
||||||
taosMemoryFree(param->condValue);
|
taosMemoryFree(param->condValue);
|
||||||
|
param->condValue = NULL;
|
||||||
taosHashCleanup(param->pFilter);
|
taosHashCleanup(param->pFilter);
|
||||||
|
param->pFilter = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sifGetOperParamNum(EOperatorType ty) {
|
static int32_t sifGetOperParamNum(EOperatorType ty) {
|
||||||
|
@ -180,6 +182,7 @@ static int32_t sifInitJsonParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
||||||
param->colId = l->colId;
|
param->colId = l->colId;
|
||||||
param->colValType = l->node.resType.type;
|
param->colValType = l->node.resType.type;
|
||||||
memcpy(param->dbName, l->dbName, sizeof(l->dbName));
|
memcpy(param->dbName, l->dbName, sizeof(l->dbName));
|
||||||
|
if (r->literal == NULL) return TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
memcpy(param->colName, r->literal, strlen(r->literal));
|
memcpy(param->colName, r->literal, strlen(r->literal));
|
||||||
param->colValType = r->typeData;
|
param->colValType = r->typeData;
|
||||||
param->status = SFLT_COARSE_INDEX;
|
param->status = SFLT_COARSE_INDEX;
|
||||||
|
@ -281,6 +284,7 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
_return:
|
_return:
|
||||||
|
for (int i = 0; i < nParam; i++) sifFreeParam(¶mList[i]);
|
||||||
taosMemoryFree(paramList);
|
taosMemoryFree(paramList);
|
||||||
SIF_RET(code);
|
SIF_RET(code);
|
||||||
}
|
}
|
||||||
|
@ -381,7 +385,7 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
|
||||||
.reverse = reverse,
|
.reverse = reverse,
|
||||||
.filterFunc = filterFunc};
|
.filterFunc = filterFunc};
|
||||||
|
|
||||||
ret = metaFilteTableIds(arg->metaEx, ¶m, output->result);
|
ret = metaFilterTableIds(arg->metaEx, ¶m, output->result);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -536,6 +540,7 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||||
SIF_ERR_RET(sifInitOperParams(¶ms, node, ctx));
|
SIF_ERR_RET(sifInitOperParams(¶ms, node, ctx));
|
||||||
|
|
||||||
if (params[0].status == SFLT_NOT_INDEX && (nParam > 1 && params[1].status == SFLT_NOT_INDEX)) {
|
if (params[0].status == SFLT_NOT_INDEX && (nParam > 1 && params[1].status == SFLT_NOT_INDEX)) {
|
||||||
|
for (int i = 0; i < nParam; i++) sifFreeParam(¶ms[i]);
|
||||||
output->status = SFLT_NOT_INDEX;
|
output->status = SFLT_NOT_INDEX;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -545,17 +550,18 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||||
sif_func_t operFn = sifNullFunc;
|
sif_func_t operFn = sifNullFunc;
|
||||||
|
|
||||||
if (!ctx->noExec) {
|
if (!ctx->noExec) {
|
||||||
SIF_ERR_RET(sifGetOperFn(node->opType, &operFn, &output->status));
|
SIF_ERR_JRET(sifGetOperFn(node->opType, &operFn, &output->status));
|
||||||
SIF_ERR_RET(operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output));
|
SIF_ERR_JRET(operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output));
|
||||||
} else {
|
} else {
|
||||||
// ugly code, refactor later
|
// ugly code, refactor later
|
||||||
if (nParam > 1 && params[1].status == SFLT_NOT_INDEX) {
|
if (nParam > 1 && params[1].status == SFLT_NOT_INDEX) {
|
||||||
output->status = SFLT_NOT_INDEX;
|
output->status = SFLT_NOT_INDEX;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
SIF_ERR_RET(sifGetOperFn(node->opType, &operFn, &output->status));
|
SIF_ERR_JRET(sifGetOperFn(node->opType, &operFn, &output->status));
|
||||||
}
|
}
|
||||||
|
_return:
|
||||||
|
for (int i = 0; i < nParam; i++) sifFreeParam(¶ms[i]);
|
||||||
taosMemoryFree(params);
|
taosMemoryFree(params);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -738,6 +744,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status) {
|
||||||
|
|
||||||
sifFreeParam(res);
|
sifFreeParam(res);
|
||||||
taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
||||||
|
taosHashCleanup(ctx.pRes);
|
||||||
|
|
||||||
SIF_RET(code);
|
SIF_RET(code);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue