From 800a112f2ad85a634d39d80dae06ff8c8262d39f Mon Sep 17 00:00:00 2001 From: lichuang Date: Tue, 15 Jun 2021 16:29:43 +0800 Subject: [PATCH 1/4] [TD-4394]fix core when select data after modify tag width --- src/inc/tsdb.h | 2 +- src/query/src/qExecutor.c | 6 +++--- src/tsdb/src/tsdbMeta.c | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 79d9029dbc..7575951246 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -117,7 +117,7 @@ typedef struct { void tsdbClearTableCfg(STableCfg *config); -void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t bytes); +void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t* bytes); char *tsdbGetTableName(void *pTable); #define TSDB_TABLEID(_table) ((STableId*) (_table)) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 77ceabbd63..4a5dc4f506 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2819,7 +2819,7 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, val = tsdbGetTableName(pTable); assert(val != NULL); } else { - val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); + val = tsdbGetTableTagVal(pTable, tagColId, type, &bytes); } if (val == NULL || isNull(val, type)) { @@ -6011,7 +6011,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, &bytes); } doSetTagValueToResultBuf(output, data, type, bytes); @@ -6050,7 +6050,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, &bytes); } dst = pColInfo->pData + count * pExprInfo[j].base.resBytes; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 8174698197..52ba3dfb4e 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -201,7 +201,7 @@ _err: return -1; } -void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes) { +void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t* bytes) { // TODO: this function should be changed also STSchema *pSchema = tsdbGetTableTagSchema((STable*) pTable); @@ -211,8 +211,16 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && bytes == pCol->bytes); + assert(type == pCol->type && + // if var data type,bytes may >= col bytes,in case of tag width has beed modified + ((IS_VAR_DATA_TYPE(type) && *bytes >= pCol->bytes) || + // otherwise, bytes must be equal to colomn bytes + (!IS_VAR_DATA_TYPE(type) && *bytes == pCol->bytes))); + // in case tag width has been modified bigger but vnode has not been notified + if (val != NULL && IS_VAR_DATA_TYPE(type) && *bytes > pCol->bytes) { + *bytes = pCol->bytes; + } // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); // } From 019860111d12856047e84e51e973d3f2c492002d Mon Sep 17 00:00:00 2001 From: lichuang Date: Tue, 15 Jun 2021 20:32:59 +0800 Subject: [PATCH 2/4] [TD-4394]fix core when select data after modify tag width --- src/inc/tsdb.h | 2 +- src/mnode/src/mnodeTable.c | 2 ++ src/query/src/qExecutor.c | 6 +++--- src/tsdb/src/tsdbMeta.c | 14 +++----------- src/util/src/tskiplist.c | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 7575951246..79d9029dbc 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -117,7 +117,7 @@ typedef struct { void tsdbClearTableCfg(STableCfg *config); -void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t* bytes); +void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t bytes); char *tsdbGetTableName(void *pTable); #define TSDB_TABLEID(_table) ((STableId*) (_table)) diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index a225c0d938..032c6ee94b 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1475,6 +1475,7 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg) { SSchema *schema = (SSchema *) (pStable->schema + col); ASSERT(schema->type == TSDB_DATA_TYPE_BINARY || schema->type == TSDB_DATA_TYPE_NCHAR); schema->bytes = pAlter->schema[0].bytes; + pStable->sversion++; mInfo("msg:%p, app:%p stable %s, start to modify column %s len to %d", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, name, schema->bytes); @@ -1504,6 +1505,7 @@ static int32_t mnodeChangeSuperTableTag(SMnodeMsg *pMsg) { SSchema *schema = (SSchema *) (pStable->schema + col + pStable->numOfColumns); ASSERT(schema->type == TSDB_DATA_TYPE_BINARY || schema->type == TSDB_DATA_TYPE_NCHAR); schema->bytes = pAlter->schema[0].bytes; + pStable->tversion++; mInfo("msg:%p, app:%p stable %s, start to modify tag len %s to %d", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId, name, schema->bytes); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 4a5dc4f506..77ceabbd63 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2819,7 +2819,7 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, val = tsdbGetTableName(pTable); assert(val != NULL); } else { - val = tsdbGetTableTagVal(pTable, tagColId, type, &bytes); + val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); } if (val == NULL || isNull(val, type)) { @@ -6011,7 +6011,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, &bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, bytes); } doSetTagValueToResultBuf(output, data, type, bytes); @@ -6050,7 +6050,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, &bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, bytes); } dst = pColInfo->pData + count * pExprInfo[j].base.resBytes; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 52ba3dfb4e..86e3aea4b5 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -148,7 +148,7 @@ int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg) { return 0; _err: - tsdbFreeTable(super); + //tsdbFreeTable(super); tsdbFreeTable(table); return -1; } @@ -201,7 +201,7 @@ _err: return -1; } -void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t* bytes) { +void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes) { // TODO: this function should be changed also STSchema *pSchema = tsdbGetTableTagSchema((STable*) pTable); @@ -211,16 +211,8 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && - // if var data type,bytes may >= col bytes,in case of tag width has beed modified - ((IS_VAR_DATA_TYPE(type) && *bytes >= pCol->bytes) || - // otherwise, bytes must be equal to colomn bytes - (!IS_VAR_DATA_TYPE(type) && *bytes == pCol->bytes))); + assert(type == pCol->type && bytes == pCol->bytes); - // in case tag width has been modified bigger but vnode has not been notified - if (val != NULL && IS_VAR_DATA_TYPE(type) && *bytes > pCol->bytes) { - *bytes = pCol->bytes; - } // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); // } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 842ded19a6..0a394c15c9 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -85,7 +85,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ } void tSkipListDestroy(SSkipList *pSkipList) { - if (pSkipList == NULL) return; + if (pSkipList == NULL || pSkipList->pHead == NULL) return; tSkipListWLock(pSkipList); From c2a558cd21bc4d9e2c3f1eabd3a2d4384c0b95a2 Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 16 Jun 2021 10:44:01 +0800 Subject: [PATCH 3/4] [TD-4394]fix core when select data after modify tag width --- src/query/src/qExecutor.c | 3 ++- src/tsdb/src/tsdbMeta.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 77ceabbd63..3227102559 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7519,7 +7519,8 @@ static void doSetTagValueToResultBuf(char* output, const char* val, int16_t type if (IS_VAR_DATA_TYPE(type)) { // Binary data overflows for sort of unknown reasons. Let trim the overflow data if (varDataTLen(val) > bytes) { - int32_t len = bytes - VARSTR_HEADER_SIZE; // remain available space + int32_t maxLen = bytes - VARSTR_HEADER_SIZE; + int32_t len = (varDataLen(val) > maxLen)? maxLen:varDataLen(val); memcpy(varDataVal(output), varDataVal(val), len); varDataSetLen(output, len); } else { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 86e3aea4b5..17223c99fe 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -211,7 +211,7 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && bytes == pCol->bytes); + assert(type == pCol->type && bytes >= pCol->bytes); // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); From c77c1091a394438054722199fe377ae1a2ea4cfe Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 16 Jun 2021 16:08:24 +0800 Subject: [PATCH 4/4] [TD-4394]fix core when select data after modify tag width --- src/tsdb/src/tsdbMeta.c | 4 +++- src/util/src/tskiplist.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 17223c99fe..b4d41dcd08 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -148,7 +148,9 @@ int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg) { return 0; _err: - //tsdbFreeTable(super); + if (newSuper) { + tsdbFreeTable(super); + } tsdbFreeTable(table); return -1; } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 0a394c15c9..842ded19a6 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -85,7 +85,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ } void tSkipListDestroy(SSkipList *pSkipList) { - if (pSkipList == NULL || pSkipList->pHead == NULL) return; + if (pSkipList == NULL) return; tSkipListWLock(pSkipList);