fix invalid copy

This commit is contained in:
yihaoDeng 2024-03-12 09:47:01 +00:00
parent 5dd4d05b2e
commit 796ff03eb5
5 changed files with 86 additions and 67 deletions

View File

@ -20,13 +20,13 @@
#include "taoserror.h" #include "taoserror.h"
#include "tarray.h" #include "tarray.h"
#include "tcoding.h" #include "tcoding.h"
#include "tcol.h"
#include "tencode.h" #include "tencode.h"
#include "thash.h" #include "thash.h"
#include "tlist.h" #include "tlist.h"
#include "tname.h" #include "tname.h"
#include "trow.h" #include "trow.h"
#include "tuuid.h" #include "tuuid.h"
#include "tcol.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -555,7 +555,7 @@ struct SSchemaExt {
#define COMPRESS_L1_TYPE_U32(type) (((type) >> 24) & 0xFF) #define COMPRESS_L1_TYPE_U32(type) (((type) >> 24) & 0xFF)
#define COMPRESS_L2_TYPE_U32(type) (((type) >> 8) & 0xFFFF) #define COMPRESS_L2_TYPE_U32(type) (((type) >> 8) & 0xFFFF)
#define COMPRESS_L2_TYPE_LEVEL_U32(type) ((type) & 0xFF) #define COMPRESS_L2_TYPE_LEVEL_U32(type) ((type)&0xFF)
// compress flag // compress flag
// |----l2lel--|----l2Alg---|---l1Alg--| // |----l2lel--|----l2Alg---|---l1Alg--|
@ -772,14 +772,14 @@ static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema)
} }
static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) { static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) {
// if (tEncodeI16v(pEncoder, pSchemaExt->colId) < 0) return -1; if (tEncodeI16v(pEncoder, pSchemaExt->colId) < 0) return -1;
// if (tEncodeU32(pEncoder, pSchemaExt->compress) < 0) return -1; if (tEncodeU32(pEncoder, pSchemaExt->compress) < 0) return -1;
return 0; return 0;
} }
static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) { static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) {
// if (tDecodeI16v(pDecoder, &pSchemaExt->colId) < 0) return -1; if (tDecodeI16v(pDecoder, &pSchemaExt->colId) < 0) return -1;
// if (tDecodeU32(pDecoder, &pSchemaExt->compress) < 0) return -1; if (tDecodeU32(pDecoder, &pSchemaExt->compress) < 0) return -1;
return 0; return 0;
} }
@ -4133,8 +4133,8 @@ int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pR
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp); int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
void tFreeSViewMetaRsp(SViewMetaRsp* pRsp); void tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
void setDefaultOptionsForField(SFieldWithOptions *field); void setDefaultOptionsForField(SFieldWithOptions* field);
void setFieldWithOptions(SFieldWithOptions *fieldWithOptions, SField* field); void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field);
#pragma pack(pop) #pragma pack(pop)

View File

@ -4433,10 +4433,12 @@ static int32_t tEncodeSTableMetaRsp(SEncoder *pEncoder, STableMetaRsp *pRsp) {
if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1; if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1;
} }
if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) {
for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { for (int32_t i = 0; i < pRsp->numOfColumns; ++i) {
SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i];
if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1; if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1;
} }
}
return 0; return 0;
} }
@ -4470,6 +4472,8 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
} }
// if (tDecodeIsEnd(pDecoder)) return 0; // if (tDecodeIsEnd(pDecoder)) return 0;
if (!tDecodeIsEnd(pDecoder)) {
if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) {
if (pRsp->numOfColumns > 0) { if (pRsp->numOfColumns > 0) {
pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns);
if (pRsp->pSchemaExt == NULL) return -1; if (pRsp->pSchemaExt == NULL) return -1;
@ -4483,6 +4487,10 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
} else { } else {
pRsp->pSchemaExt = NULL; pRsp->pSchemaExt = NULL;
} }
} else {
pRsp->pSchemaExt = NULL;
}
}
return 0; return 0;
} }

View File

@ -1939,6 +1939,12 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
pRsp->pSchemaExt = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaExt));
if (pRsp->pSchemaExt == NULL) {
taosRUnLockLatch(&pStb->lock);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName)); tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName));
tstrncpy(pRsp->tbName, tbName, sizeof(pRsp->tbName)); tstrncpy(pRsp->tbName, tbName, sizeof(pRsp->tbName));
@ -1972,6 +1978,12 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa
pSchema->colId = pSrcSchema->colId; pSchema->colId = pSrcSchema->colId;
pSchema->bytes = pSrcSchema->bytes; pSchema->bytes = pSrcSchema->bytes;
} }
for (int32_t i = 0; i < pStb->numOfColumns; i++) {
SCmprObj *pCmpr = &pStb->pCmpr[i];
SSchemaExt *pSchEx = &pRsp->pSchemaExt[i];
pSchEx->colId = pCmpr->colId;
pSchEx->compress = pCmpr->cmprAlg;
}
taosRUnLockLatch(&pStb->lock); taosRUnLockLatch(&pStb->lock);
return 0; return 0;
@ -2028,6 +2040,7 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName,
pRsp->pFuncs = taosArrayDup(pStb->pFuncs, NULL); pRsp->pFuncs = taosArrayDup(pStb->pFuncs, NULL);
} }
taosRUnLockLatch(&pStb->lock); taosRUnLockLatch(&pStb->lock);
return 0; return 0;
} }

View File

@ -142,7 +142,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
case TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY: case TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY:
return "Primary timestamp column cannot be dropped"; return "Primary timestamp column cannot be dropped";
case TSDB_CODE_PAR_INVALID_MODIFY_COL: case TSDB_CODE_PAR_INVALID_MODIFY_COL:
return "Only varbinary/binary/nchar/geometry column length could be modified, and the length can only be increased, not decreased"; return "Only varbinary/binary/nchar/geometry column length could be modified, and the length can only be "
"increased, not decreased";
case TSDB_CODE_PAR_INVALID_TBNAME: case TSDB_CODE_PAR_INVALID_TBNAME:
return "Invalid tbname pseudo column"; return "Invalid tbname pseudo column";
case TSDB_CODE_PAR_INVALID_FUNCTION_NAME: case TSDB_CODE_PAR_INVALID_FUNCTION_NAME:
@ -265,14 +266,14 @@ int32_t getNumOfTags(const STableMeta* pTableMeta) { return getTableInfo(pTableM
STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; } STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; }
int32_t getTableTypeFromTableNode(SNode *pTable) { int32_t getTableTypeFromTableNode(SNode* pTable) {
if (NULL == pTable) { if (NULL == pTable) {
return -1; return -1;
} }
if (QUERY_NODE_REAL_TABLE != nodeType(pTable)) { if (QUERY_NODE_REAL_TABLE != nodeType(pTable)) {
return -1; return -1;
} }
return ((SRealTableNode *)pTable)->pMeta->tableType; return ((SRealTableNode*)pTable)->pMeta->tableType;
} }
STableMeta* tableMetaDup(const STableMeta* pTableMeta) { STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
@ -713,7 +714,6 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog
return code; return code;
} }
SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint) { SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint) {
SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT); SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
if (NULL == select) { if (NULL == select) {
@ -948,7 +948,6 @@ int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, ST
return code; return code;
} }
static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) { static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) {
if (NULL == *pDbs) { if (NULL == *pDbs) {
*pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); *pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
@ -1044,15 +1043,13 @@ int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pD
return reserveUserAuthInCacheImpl(key, len, pMetaCache); return reserveUserAuthInCacheImpl(key, len, pMetaCache);
} }
int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type, int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable,
SParseMetaCache* pMetaCache) { AUTH_TYPE type, SParseMetaCache* pMetaCache) {
char key[USER_AUTH_KEY_MAX_LEN] = {0}; char key[USER_AUTH_KEY_MAX_LEN] = {0};
int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, true); int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, true);
return reserveUserAuthInCacheImpl(key, len, pMetaCache); return reserveUserAuthInCacheImpl(key, len, pMetaCache);
} }
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) { int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) {
char key[USER_AUTH_KEY_MAX_LEN] = {0}; char key[USER_AUTH_KEY_MAX_LEN] = {0};
int32_t len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname, int32_t len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname,
@ -1228,5 +1225,3 @@ int64_t int64SafeSub(int64_t a, int64_t b) {
} }
return res; return res;
} }

View File

@ -43,7 +43,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix; pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix;
pOut->dbVgroup->stateTs = usedbRsp->stateTs; pOut->dbVgroup->stateTs = usedbRsp->stateTs;
qDebug("Got %d vgroup for db %s, vgVersion:%d, stateTs:%" PRId64, usedbRsp->vgNum, usedbRsp->db, usedbRsp->vgVersion, usedbRsp->stateTs); qDebug("Got %d vgroup for db %s, vgVersion:%d, stateTs:%" PRId64, usedbRsp->vgNum, usedbRsp->db, usedbRsp->vgVersion,
usedbRsp->stateTs);
if (usedbRsp->vgNum <= 0) { if (usedbRsp->vgNum <= 0) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -408,7 +409,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta *
qError("calloc size[%d] failed", metaSize); qError("calloc size[%d] failed", metaSize);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)pTableMeta + metaSize); SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize);
pTableMeta->vgId = isStb ? 0 : msg->vgId; pTableMeta->vgId = isStb ? 0 : msg->vgId;
pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType; pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType;
@ -421,15 +422,18 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta *
pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.precision = msg->precision;
pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns;
if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_NORMAL_TABLE) {
pTableMeta->schemaExt = pSchemaExt; pTableMeta->schemaExt = pSchemaExt;
memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total);
memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize); memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize);
}
for (int32_t i = 0; i < msg->numOfColumns; ++i) { for (int32_t i = 0; i < msg->numOfColumns; ++i) {
pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
} }
qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 " sver %d tver %d" qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64
" sver %d tver %d"
" tagNum %d colNum %d precision %d rowSize %d", " tagNum %d colNum %d precision %d rowSize %d",
msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
@ -679,7 +683,6 @@ int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void initQueryModuleMsgHandle() { void initQueryModuleMsgHandle() {
queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;