From 664bfa3625b8be20f8cbe548dad248eca23e61f0 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 20 Jul 2021 16:03:18 +0800 Subject: [PATCH 01/26] [td-5418]: change the refresh thread generate mechanism to reduce the number of refresh thread. --- src/util/inc/tcache.h | 1 + src/util/src/tcache.c | 156 ++++++++++++++++++++++++++---------------- 2 files changed, 99 insertions(+), 58 deletions(-) diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index efd51f90ce..d381b8b199 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -83,6 +83,7 @@ typedef struct { uint8_t deleting; // set the deleting flag to stop refreshing ASAP. pthread_t refreshWorker; bool extendLifespan; // auto extend life span when one item is accessed. + int64_t checkTick; // tick used to record the check times of the refresh threads #if defined(LINUX) pthread_rwlock_t lock; #else diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 569f9b01bd..c1d3dad61d 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -54,6 +54,44 @@ static FORCE_INLINE void __cache_lock_destroy(SCacheObj *pCacheObj) { #endif } +/** + * do cleanup the taos cache + * @param pCacheObj + */ +static void doCleanupDataCache(SCacheObj *pCacheObj); + +/** + * refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime + * @param handle Cache object handle + */ +static void* taosCacheTimedRefresh(void *handle); + +static pthread_t cacheRefreshWorker = 0; +static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT; +static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER; +static SArray* pCacheArrayList = NULL; + +static void doInitRefreshThread() { + pCacheArrayList = taosArrayInit(4, POINTER_BYTES); + + pthread_attr_t thattr; + pthread_attr_init(&thattr); + pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); + + pthread_create(&cacheRefreshWorker, &thattr, taosCacheTimedRefresh, NULL); + pthread_attr_destroy(&thattr); +} + +pthread_t doRegisterCacheObj(SCacheObj* pCacheObj) { + pthread_once(&cacheThreadInit, doInitRefreshThread); + + pthread_mutex_lock(&guard); + taosArrayPush(pCacheArrayList, &pCacheObj); + pthread_mutex_unlock(&guard); + + return cacheRefreshWorker; +} + /** * @param key key of object for hash, usually a null-terminated string * @param keyLen length of key @@ -142,19 +180,9 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj* pCacheObj, STrashElem free(pElem); } -/** - * do cleanup the taos cache - * @param pCacheObj - */ -static void doCleanupDataCache(SCacheObj *pCacheObj); - -/** - * refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime - * @param handle Cache object handle - */ -static void* taosCacheTimedRefresh(void *handle); - SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char* cacheName) { + const int32_t SLEEP_DURATION = 500; //500 ms + if (refreshTimeInSeconds <= 0) { return NULL; } @@ -174,9 +202,10 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext } // set free cache node callback function - pCacheObj->freeFp = fn; + pCacheObj->freeFp = fn; pCacheObj->refreshTime = refreshTimeInSeconds * 1000; - pCacheObj->extendLifespan = extendLifespan; + pCacheObj->checkTick = pCacheObj->refreshTime / SLEEP_DURATION; + pCacheObj->extendLifespan = extendLifespan; // the TTL after the last access if (__cache_lock_init(pCacheObj) != 0) { taosHashCleanup(pCacheObj->pHashTable); @@ -186,13 +215,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext return NULL; } - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - - pthread_create(&pCacheObj->refreshWorker, &thattr, taosCacheTimedRefresh, pCacheObj); - - pthread_attr_destroy(&thattr); + doRegisterCacheObj(pCacheObj); return pCacheObj; } @@ -364,7 +387,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { if (pCacheObj->extendLifespan && (!inTrashcan) && (!_remove)) { atomic_store_64(&pNode->expireTime, pNode->lifespan + taosGetTimestampMs()); - uDebug("cache:%s data:%p extend expire time: %"PRId64, pCacheObj->name, pNode->data, pNode->expireTime); + uDebug("cache:%s, data:%p extend expire time: %"PRId64, pCacheObj->name, pNode->data, pNode->expireTime); } if (_remove) { @@ -510,8 +533,10 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { } pCacheObj->deleting = 1; - if (taosCheckPthreadValid(pCacheObj->refreshWorker)) { - pthread_join(pCacheObj->refreshWorker, NULL); + + // wait for the refresh thread quit before destroying the cache object. + while(atomic_load_64(&cacheRefreshWorker) != 0) { + taosMsleep(50); } uInfo("cache:%s will be cleaned up", pCacheObj->name); @@ -650,48 +675,63 @@ static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t } void* taosCacheTimedRefresh(void *handle) { - SCacheObj* pCacheObj = handle; - if (pCacheObj == NULL) { - uDebug("object is destroyed. no refresh retry"); - return NULL; - } + assert(pCacheArrayList != NULL); + uDebug("cache refresh thread starts"); const int32_t SLEEP_DURATION = 500; //500 ms - int64_t totalTick = pCacheObj->refreshTime / SLEEP_DURATION; - int64_t count = 0; + while(1) { - taosMsleep(500); + taosMsleep(SLEEP_DURATION); - // check if current cache object will be deleted every 500ms. - if (pCacheObj->deleting) { - uDebug("%s refresh threads quit", pCacheObj->name); - break; + pthread_mutex_lock(&guard); + size_t size = taosArrayGetSize(pCacheArrayList); + pthread_mutex_unlock(&guard); + + count += 1; + + for(int32_t i = 0; i < size; ++i) { + pthread_mutex_lock(&guard); + SCacheObj* pCacheObj = taosArrayGetP(pCacheArrayList, i); + pthread_mutex_unlock(&guard); + + if (pCacheObj == NULL) { + uDebug("object is destroyed. no refresh retry"); + break; + } + + // check if current cache object will be deleted every 500ms. + if (pCacheObj->deleting) { + uDebug("%s is destroying, cache refresh thread quit", pCacheObj->name); + goto _end; + } + + if ((count % pCacheObj->checkTick) != 0) { + continue; + } + + size_t elemInHash = taosHashGetSize(pCacheObj->pHashTable); + if (elemInHash + pCacheObj->numOfElemsInTrash == 0) { + continue; + } + + uDebug("%s refresh thread scan", pCacheObj->name); + pCacheObj->statistics.refreshCount++; + + // refresh data in hash table + if (elemInHash > 0) { + int64_t now = taosGetTimestampMs(); + doCacheRefresh(pCacheObj, now, NULL); + } + + taosTrashcanEmpty(pCacheObj, false); } - - if (++count < totalTick) { - continue; - } - - // reset the count value - count = 0; - size_t elemInHash = taosHashGetSize(pCacheObj->pHashTable); - if (elemInHash + pCacheObj->numOfElemsInTrash == 0) { - continue; - } - - uDebug("%s refresh thread timed scan", pCacheObj->name); - pCacheObj->statistics.refreshCount++; - - // refresh data in hash table - if (elemInHash > 0) { - int64_t now = taosGetTimestampMs(); - doCacheRefresh(pCacheObj, now, NULL); - } - - taosTrashcanEmpty(pCacheObj, false); } + _end: + cacheRefreshWorker = 0; + taosArrayDestroy(pCacheArrayList); + uDebug("cache refresh thread quits"); return NULL; } From 8125b8083525762f178d09ea879b5f448b21941b Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 20 Jul 2021 17:21:44 +0800 Subject: [PATCH 02/26] [td-225]fix compiler error. --- src/util/src/tcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index c1d3dad61d..6c20980e18 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -66,7 +66,7 @@ static void doCleanupDataCache(SCacheObj *pCacheObj); */ static void* taosCacheTimedRefresh(void *handle); -static pthread_t cacheRefreshWorker = 0; +static pthread_t cacheRefreshWorker = {0}; static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT; static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER; static SArray* pCacheArrayList = NULL; From c01f04a2095cdd102b8caba51770605a67480758 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 20 Jul 2021 18:31:11 +0800 Subject: [PATCH 03/26] [td-255]fix compiler error. --- src/util/src/tcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 6c20980e18..434d88894b 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -71,7 +71,7 @@ static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT; static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER; static SArray* pCacheArrayList = NULL; -static void doInitRefreshThread() { +static void doInitRefreshThread(void) { pCacheArrayList = taosArrayInit(4, POINTER_BYTES); pthread_attr_t thattr; From 2e4229717eb4ac24e92657224a7170e1c4714fcd Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 20 Jul 2021 23:04:30 +0800 Subject: [PATCH 04/26] [td-225]fix compiler error. --- src/util/src/tcache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 434d88894b..e847debb89 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -535,7 +535,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { pCacheObj->deleting = 1; // wait for the refresh thread quit before destroying the cache object. - while(atomic_load_64(&cacheRefreshWorker) != 0) { + while(atomic_load_ptr((void**)&pCacheArrayList) != 0) { taosMsleep(50); } @@ -729,8 +729,11 @@ void* taosCacheTimedRefresh(void *handle) { } _end: - cacheRefreshWorker = 0; taosArrayDestroy(pCacheArrayList); + + pCacheArrayList = NULL; + pthread_mutex_destroy(&guard); + uDebug("cache refresh thread quits"); return NULL; } From df284badac17a538144f6af7a2a6065f0ebe0734 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 22 Jul 2021 16:24:42 +0800 Subject: [PATCH 05/26] [TD-5474] fix runtime error --- src/common/src/ttypes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 6021a8f579..13bcfe6480 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -38,7 +38,11 @@ const int32_t TYPE_BYTES[15] = { #define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \ do { \ - (__sum) += (_list)[(_index)]; \ + if (_list[(_index)] >= (INT64_MAX - (__sum))) { \ + __sum = INT64_MAX; \ + } else { \ + (__sum) += (_list)[(_index)]; \ + } \ if ((__min) > (_list)[(_index)]) { \ (__min) = (_list)[(_index)]; \ (__minIndex) = (_index); \ From 97159f54da5217ce08bd98bb6acffdcbde00bc95 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 22 Jul 2021 17:20:33 +0800 Subject: [PATCH 06/26] [td-225]fix bug found by regression test. --- src/util/src/tcache.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index ee7921d4c7..9c156658aa 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -535,7 +535,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { pCacheObj->deleting = 1; // wait for the refresh thread quit before destroying the cache object. - while(atomic_load_ptr((void**)&pCacheArrayList) != 0) { + while(atomic_load_8(&pCacheObj->deleting) != 0) { taosMsleep(50); } @@ -695,19 +695,30 @@ void* taosCacheTimedRefresh(void *handle) { for(int32_t i = 0; i < size; ++i) { pthread_mutex_lock(&guard); SCacheObj* pCacheObj = taosArrayGetP(pCacheArrayList, i); - pthread_mutex_unlock(&guard); if (pCacheObj == NULL) { - uDebug("object is destroyed. no refresh retry"); - break; + uError("object is destroyed. ignore and try next"); + pthread_mutex_unlock(&guard); + continue; } // check if current cache object will be deleted every 500ms. if (pCacheObj->deleting) { - uDebug("%s is destroying, cache refresh thread quit", pCacheObj->name); - goto _end; + taosArrayRemove(pCacheArrayList, i); + size = taosArrayGetSize(pCacheArrayList); + + uDebug("%s is destroying, remove it from refresh list, remain cache obj:%"PRId64, pCacheObj->name, size); + pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj does self destroy process + + // all contained caches has been marked to be removed, destroy the scanner it self. + if (size == 0) { + pthread_mutex_unlock(&guard); + goto _end; + } } + pthread_mutex_unlock(&guard); + if ((count % pCacheObj->checkTick) != 0) { continue; } From 339fe7358b4b2131bd7ddd4a575a4fb04fa11878 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 22 Jul 2021 18:51:43 +0800 Subject: [PATCH 07/26] [td-225]fix compiler error. --- src/util/src/tcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 9c156658aa..fba62fc067 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -707,7 +707,7 @@ void* taosCacheTimedRefresh(void *handle) { taosArrayRemove(pCacheArrayList, i); size = taosArrayGetSize(pCacheArrayList); - uDebug("%s is destroying, remove it from refresh list, remain cache obj:%"PRId64, pCacheObj->name, size); + uDebug("%s is destroying, remove it from refresh list, remain cache obj:%"PRIzu, pCacheObj->name, size); pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj does self destroy process // all contained caches has been marked to be removed, destroy the scanner it self. From c82eecddd03a1abecb670cfb4bd4ea62abfa7b03 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 10:14:52 +0800 Subject: [PATCH 08/26] [TD-5485]:fix memory error due to uninitialized pointer value --- src/client/src/tscParseLineProtocol.c | 1 + tests/examples/c/apitest.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index cccc81274d..98d9c3ec65 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1823,6 +1823,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); + points = TARRAY_GET_START(lpPoints); for (int i=0; i Date: Fri, 23 Jul 2021 11:27:46 +0800 Subject: [PATCH 09/26] [td-225]fix bug found by regression test. --- src/dnode/src/dnodeMain.c | 4 +++- src/util/inc/tcache.h | 5 +++++ src/util/src/tcache.c | 17 +++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 7723b6221b..af63b10bc5 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -40,8 +40,9 @@ #include "dnodeShell.h" #include "dnodeTelemetry.h" #include "module.h" -#include "qScript.h" #include "mnode.h" +#include "qScript.h" +#include "tcache.h" #if !defined(_MODULE) || !defined(_TD_LINUX) int32_t moduleStart() { return 0; } @@ -207,6 +208,7 @@ void dnodeCleanUpSystem() { dnodeCleanupComponents(); taos_cleanup(); taosCloseLog(); + taosStopCacheRefreshWorker(); } } diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index d381b8b199..e41b544d00 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -178,6 +178,11 @@ void taosCacheCleanup(SCacheObj *pCacheObj); */ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp); +/** + * stop background refresh worker thread + */ +void taosStopCacheRefreshWorker(); + #ifdef __cplusplus } #endif diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index fba62fc067..4aa5b4378f 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -70,6 +70,7 @@ static pthread_t cacheRefreshWorker = {0}; static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT; static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER; static SArray* pCacheArrayList = NULL; +static bool stopRefreshWorker = false; static void doInitRefreshThread(void) { pCacheArrayList = taosArrayInit(4, POINTER_BYTES); @@ -685,6 +686,9 @@ void* taosCacheTimedRefresh(void *handle) { while(1) { taosMsleep(SLEEP_DURATION); + if (stopRefreshWorker) { + goto _end; + } pthread_mutex_lock(&guard); size_t size = taosArrayGetSize(pCacheArrayList); @@ -708,13 +712,10 @@ void* taosCacheTimedRefresh(void *handle) { size = taosArrayGetSize(pCacheArrayList); uDebug("%s is destroying, remove it from refresh list, remain cache obj:%"PRIzu, pCacheObj->name, size); - pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj does self destroy process + pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj to continue releasing resources. - // all contained caches has been marked to be removed, destroy the scanner it self. - if (size == 0) { - pthread_mutex_unlock(&guard); - goto _end; - } + pthread_mutex_unlock(&guard); + continue; } pthread_mutex_unlock(&guard); @@ -759,3 +760,7 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) { int64_t now = taosGetTimestampMs(); doCacheRefresh(pCacheObj, now, fp); } + +void taosStopCacheRefreshWorker() { + stopRefreshWorker = false; +} \ No newline at end of file From c50dcb9e6dab161054fad359332e3a59de7dfe6e Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 10:14:52 +0800 Subject: [PATCH 10/26] [TD-5485]:fix memory error due to uninitialized pointer value --- src/client/src/tscParseLineProtocol.c | 2 ++ tests/examples/c/apitest.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index cccc81274d..e0aa2b4327 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1823,6 +1823,8 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); + points = TARRAY_GET_START(lpPoints); + numPoints = taosArrayGetSize(lpPoints); for (int i=0; i Date: Fri, 23 Jul 2021 14:19:19 +0800 Subject: [PATCH 11/26] [TD-5484]:nchar/binary tag length exceed limit error when alter table --- src/query/src/qSqlParser.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index 874ec7b692..eb920b3e17 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -712,9 +712,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { } else { int32_t bytes = -(int32_t)(type->type); if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { - // we have to postpone reporting the error because it cannot be done here - // as pField->bytes is int16_t, use 'TSDB_MAX_NCHAR_LEN + 1' to avoid overflow - bytes = TSDB_MAX_NCHAR_LEN + 1; + // overflowed. set bytes to -1 so that error can be reported + bytes = -1; } else { bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; } @@ -727,8 +726,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { } else { int32_t bytes = -(int32_t)(type->type); if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) { - // refer comment for NCHAR above - bytes = TSDB_MAX_BINARY_LEN + 1; + // overflowed. set bytes to -1 so that error can be reported + bytes = -1; } else { bytes += VARSTR_HEADER_SIZE; } From 269a7cead62f13caf90fd92f60f16f3b7c33641f Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 15:50:53 +0800 Subject: [PATCH 12/26] fix error when modifing tag column causing exceed limit --- src/client/src/tscSQLParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c0627f4c31..5bd981d379 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6073,7 +6073,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { for (i = 0; i < numOfColumns; ++i) { nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; } - if (nLen >= TSDB_MAX_BYTES_PER_ROW) { + if (nLen >= TSDB_MAX_TAGS_LEN) { return invalidOperationMsg(pMsg, msg24); } From 6b8e149d50cddd87831da1628f0cc5ef9cd02554 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 15:53:15 +0800 Subject: [PATCH 13/26] fix uninitialized varaible usage --- src/client/src/tscParseLineProtocol.c | 1 + src/client/src/tscSQLParser.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 98d9c3ec65..e0aa2b4327 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1824,6 +1824,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); points = TARRAY_GET_START(lpPoints); + numPoints = taosArrayGetSize(lpPoints); for (int i=0; ipTableMeta->schema; - int16_t numOfColumns = pTableMetaInfo->pTableMeta->tableInfo.numOfColumns; + SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); + int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta); int16_t i; uint32_t nLen = 0; - for (i = 0; i < numOfColumns; ++i) { + for (i = 0; i < numOfTags; ++i) { nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { From b04048091f115fba76db79e69d74e9640d2e31bb Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 15:53:15 +0800 Subject: [PATCH 14/26] [TD-5484]:fix tag column modify total length check that checked columns instead of tags --- src/client/src/tscParseLineProtocol.c | 1 + src/client/src/tscSQLParser.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 98d9c3ec65..e0aa2b4327 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1824,6 +1824,7 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); points = TARRAY_GET_START(lpPoints); + numPoints = taosArrayGetSize(lpPoints); for (int i=0; ipTableMeta->schema; - int16_t numOfColumns = pTableMetaInfo->pTableMeta->tableInfo.numOfColumns; + SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); + int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta); int16_t i; uint32_t nLen = 0; - for (i = 0; i < numOfColumns; ++i) { + for (i = 0; i < numOfTags; ++i) { nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { From d4737dc1de98182b3bac9f97c0a127fb531c7c57 Mon Sep 17 00:00:00 2001 From: tomchon Date: Fri, 23 Jul 2021 17:48:03 +0800 Subject: [PATCH 15/26] modify release scripts --- packaging/tools/makearbi.sh | 2 +- packaging/tools/makeclient.sh | 2 +- packaging/tools/makepkg.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/tools/makearbi.sh b/packaging/tools/makearbi.sh index 5346a79c8f..6dcabc2a06 100755 --- a/packaging/tools/makearbi.sh +++ b/packaging/tools/makearbi.sh @@ -59,7 +59,7 @@ pkg_name=${install_dir}-${osType}-${cpuType} # exit 1 # fi -if [ "$verType" == "beta" ]; then +if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 97e80088be..8fc431bfbc 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -182,7 +182,7 @@ pkg_name=${install_dir}-${osType}-${cpuType} # exit 1 # fi -if [ "$verType" == "beta" ]; then +if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 56ab24426f..1064f0b0e5 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -215,7 +215,7 @@ pkg_name=${install_dir}-${osType}-${cpuType} # exit 1 # fi -if [ "$verType" == "beta" ]; then +if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} From 69abf1ab3a3c43d1743b31305cd39668d2476a6e Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 23 Jul 2021 17:52:56 +0800 Subject: [PATCH 16/26] fix bug --- src/client/inc/tscUtil.h | 2 +- src/client/src/tscParseInsert.c | 4 ++-- src/client/src/tscPrepare.c | 2 +- src/client/src/tscServer.c | 13 +++++++++---- src/inc/taoserror.h | 1 + src/util/src/terror.c | 2 ++ 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 264070d70f..a4df124fa2 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -273,7 +273,7 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo); int tscGetSTableVgroupInfo(SSqlObj* pSql, SQueryInfo* pQueryInfo); int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo); -int tscGetTableMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists); +int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists, bool onlyLocal); int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo); void tscResetForNextRetrieve(SSqlRes* pRes); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 98a22835e5..f24f7a7ecb 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1482,7 +1482,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; } - code = tscGetTableMetaEx(pSql, pTableMetaInfo, true); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, true, false); if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) { return code; } @@ -1493,7 +1493,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC } sql = sToken.z; - code = tscGetTableMetaEx(pSql, pTableMetaInfo, false); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, false); if (pInsertParam->sql == NULL) { assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS); } diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 7370528851..b32b3f4d98 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1640,7 +1640,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags memcpy(&pTableMetaInfo->name, &fullname, sizeof(fullname)); - code = tscGetTableMeta(pSql, pTableMetaInfo); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, false); if (code != TSDB_CODE_SUCCESS) { STMT_RET(code); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e975dd7b06..f5d6765a5d 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2776,7 +2776,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg return code; } -int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate) { +int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) { assert(tIsValidName(&pTableMetaInfo->name)); uint32_t size = tscGetTableMetaMaxSize(); @@ -2822,15 +2822,20 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool } return TSDB_CODE_SUCCESS; } + + if (onlyLocal) { + return TSDB_CODE_TSC_NO_META_CACHED; + } + return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { - return tscGetTableMetaImpl(pSql, pTableMetaInfo, false); + return tscGetTableMetaImpl(pSql, pTableMetaInfo, false, false); } -int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists) { - return tscGetTableMetaImpl(pSql, pTableMetaInfo, createIfNotExists); +int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists, bool onlyLocal) { + return tscGetTableMetaImpl(pSql, pTableMetaInfo, createIfNotExists, onlyLocal); } int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo) { diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index f57e553e3f..2214078f55 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -102,6 +102,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_EXCEED_SQL_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0219) //"SQL statement too long check maxSQLLength config") #define TSDB_CODE_TSC_FILE_EMPTY TAOS_DEF_ERROR_CODE(0, 0x021A) //"File is empty") #define TSDB_CODE_TSC_LINE_SYNTAX_ERROR TAOS_DEF_ERROR_CODE(0, 0x021B) //"Syntax error in Line") +#define TSDB_CODE_TSC_NO_META_CACHED TAOS_DEF_ERROR_CODE(0, 0x021C) //"No table meta cached") // mnode #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") diff --git a/src/util/src/terror.c b/src/util/src/terror.c index 46a33569b2..42fc76e6c9 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -110,6 +110,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DB_NOT_SELECTED, "Database not specifie TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_NAME, "Table does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_SQL_LIMIT, "SQL statement too long, check maxSQLLength config") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FILE_EMPTY, "File is empty") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_LINE_SYNTAX_ERROR, "Syntax error in Line") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_META_CACHED, "No table meta cached") // mnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed") From b61c267a02befe3e890cc8a66fa9e14d00226031 Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 23 Jul 2021 18:01:16 +0800 Subject: [PATCH 17/26] fix bug --- src/client/src/tscPrepare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index b32b3f4d98..7306523660 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1640,7 +1640,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags memcpy(&pTableMetaInfo->name, &fullname, sizeof(fullname)); - code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, false); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, true); if (code != TSDB_CODE_SUCCESS) { STMT_RET(code); } From 9ec1f11741034bfa870b5ac91d26918dda4ca836 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 23 Jul 2021 18:21:25 +0800 Subject: [PATCH 18/26] fix error of total tags length and total columns length --- src/client/src/tscSQLParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 39b1a5e8d3..9a3b36895d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6020,7 +6020,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int16_t i; uint32_t nLen = 0; for (i = 0; i < numOfColumns; ++i) { - nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; + nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_BYTES_PER_ROW) { return invalidOperationMsg(pMsg, msg24); @@ -6071,7 +6071,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int16_t i; uint32_t nLen = 0; for (i = 0; i < numOfTags; ++i) { - nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; + nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { return invalidOperationMsg(pMsg, msg24); From afaf7d6a13f2caf90ad407be62db18ef2cad519b Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Fri, 23 Jul 2021 18:44:14 +0800 Subject: [PATCH 19/26] [TD-848] : fix description about SPREAD return type. --- documentation20/en/12.taos-sql/docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation20/en/12.taos-sql/docs.md b/documentation20/en/12.taos-sql/docs.md index f215084392..2f344b4529 100644 --- a/documentation20/en/12.taos-sql/docs.md +++ b/documentation20/en/12.taos-sql/docs.md @@ -1132,7 +1132,7 @@ TDengine supports aggregations over data, they are listed below: ``` Function: Return the difference between the max value and the min value of a column in statistics /STable. - Return Data Type: Same as applicable fields. + Return Data Type: Double. Applicable Fields: All types except binary, nchar, bool. From 6ff1991d357255a32e8c041852ba3fbaf8538338 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 24 Jul 2021 15:08:22 +0800 Subject: [PATCH 20/26] Hotfix/sangshuduo/td 5479 taosdump s e (#6994) * [TD-5479]: taosdump -S -E does not work. * taosdemo support timestamp step from command line. * fix help msg. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 4 ++-- src/kit/taosdump/taosdump.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index f9b147d43d..6acb317a9e 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -743,8 +743,8 @@ static void printHelp() { "The number of threads. Default is 10."); printf("%s%s%s%s\n", indent, "-i", indent, "The sleep time (ms) between insertion. Default is 0."); - printf("%s%s%s%s%d\n", indent, "-S", indent, - "The timestamp step between insertion. Default is %d.", + printf("%s%s%s%s%d.\n", indent, "-S", indent, + "The timestamp step between insertion. Default is ", DEFAULT_TIMESTAMP_STEP); printf("%s%s%s%s\n", indent, "-r", indent, "The number of records per request. Default is 30000."); diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 5139f98cde..50a58991b8 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -453,6 +453,8 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case 'E': g_args.end_time = atol(arg); break; + case 'C': + break; case 'B': g_args.data_batch = atoi(arg); if (g_args.data_batch > MAX_RECORDS_PER_REQ) { From 7d2cc83a389a0be16bbaf063af656d4bf38940b4 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Thu, 22 Jul 2021 18:56:48 +0800 Subject: [PATCH 21/26] TD-5478]:add modify child tag value through line protocol --- src/client/src/tscParseLineProtocol.c | 269 +++++++++++++++++++------- tests/examples/c/apitest.c | 18 +- 2 files changed, 202 insertions(+), 85 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index e0aa2b4327..dd24d2c458 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -570,6 +570,40 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa return 0; } + +static int32_t changeChildTableTagValue(TAOS* taos, const char* cTableName, const char* tagName, TAOS_BIND* bind) { + char sql[512]; + sprintf(sql, "alter table %s set tag %s=?", cTableName, tagName); + + int32_t code; + TAOS_STMT* stmt = taos_stmt_init(taos); + code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql)); + + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + code = taos_stmt_bind_param(stmt, bind); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + code = taos_stmt_close(stmt); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + return code; +} + static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, const char* sTableName, SArray* tagsSchema, SArray* tagsBind) { size_t numTags = taosArrayGetSize(tagsSchema); char* sql = malloc(tsMaxSQLStringLen+1); @@ -742,97 +776,192 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu return 0; } -static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints, SArray* stableSchemas) { +static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableName, + SSmlSTableSchema* sTableSchema, SArray* cTablePoints) { + size_t numTags = taosArrayGetSize(sTableSchema->tags); + size_t rows = taosArrayGetSize(cTablePoints); + + TAOS_SML_KV* tagKVs[TSDB_MAX_TAGS] = {0}; + for (int i= 0; i < rows; ++i) { + TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); + for (int j = 0; j < pDataPoint->tagNum; ++j) { + TAOS_SML_KV* kv = pDataPoint->tags + j; + tagKVs[kv->fieldSchemaIdx] = kv; + } + } + + int32_t notNullTagsIndices[TSDB_MAX_TAGS] = {0}; + int32_t numNotNullTags = 0; + for (int32_t i = 0; i < numTags; ++i) { + if (tagKVs[i] != NULL) { + notNullTagsIndices[numNotNullTags] = i; + ++numNotNullTags; + } + } + + SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); + taosArraySetSize(tagBinds, numTags); + int isNullColBind = TSDB_TRUE; + for (int j = 0; j < numTags; ++j) { + TAOS_BIND* bind = taosArrayGet(tagBinds, j); + bind->is_null = &isNullColBind; + } + for (int j = 0; j < numTags; ++j) { + if (tagKVs[j] == NULL) continue; + TAOS_SML_KV* kv = tagKVs[j]; + TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx); + bind->buffer_type = kv->type; + bind->length = malloc(sizeof(uintptr_t*)); + *bind->length = kv->length; + bind->buffer = kv->value; + bind->is_null = NULL; + } + + // select tag1,tag2,... from stable where tbname in (ctable) + char sql[TSDB_MAX_BINARY_LEN]; + int capacity = TSDB_MAX_BINARY_LEN; + snprintf(sql, capacity, "select tbname, "); + for (int i = 0; i < numNotNullTags ; ++i) { + snprintf(sql + strlen(sql), capacity-strlen(sql), "%s,", tagKVs[notNullTagsIndices[i]]->key); + } + + snprintf(sql + strlen(sql) - 1, capacity - strlen(sql) + 1, + " from %s where tbname in (\'%s\')", sTableName, cTableName); + TAOS_RES* result = taos_query(taos, sql); + int32_t code = taos_errno(result); + if (code != 0) { + tscError("%s", taos_errstr(result)); + taos_free_result(result); + goto cleanup; + } + + // check tag value and set tag values if different + TAOS_ROW row = taos_fetch_row(result); + if (row != NULL) { + int numFields = taos_field_count(result); + TAOS_FIELD* fields = taos_fetch_fields(result); + int* lengths = taos_fetch_lengths(result); + for (int i = 1; i < numFields; ++i) { + uint8_t type = fields[i].type; + int32_t length = lengths[i]; + char* val = row[i]; + + TAOS_SML_KV* tagKV = tagKVs[notNullTagsIndices[i-1]]; + if (tagKV->type != type) { + tscError("child table %s tag %s type mismatch. point type : %d, db type : %d", + cTableName, tagKV->key, tagKV->type, type); + return TSDB_CODE_TSC_INVALID_VALUE; + } + + if (memcmp(tagKV->value, val, length) != 0) { + TAOS_BIND* bind = taosArrayGet(tagBinds, tagKV->fieldSchemaIdx); + code = changeChildTableTagValue(taos, cTableName, tagKV->key, bind); + if (code != 0) { + tscError("change child table tag failed. table name %s, tag %s", cTableName, tagKV->key); + goto cleanup; + } + } + + } + } else { + code = creatChildTableIfNotExists(taos, cTableName, sTableName, sTableSchema->tags, tagBinds); + if (code != 0) { + goto cleanup; + } + } + +cleanup: + for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { + TAOS_BIND* bind = taosArrayGet(tagBinds, i); + free(bind->length); + } + taosArrayDestroy(tagBinds); + return code; +} + +static int32_t applyChildTableFields(TAOS* taos, SSmlSTableSchema* sTableSchema, char* cTableName, SArray* cTablePoints) { int32_t code = TSDB_CODE_SUCCESS; - SHashObj* cname2points = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), - true, false); - arrangePointsByChildTableName(points, numPoints, cname2points, stableSchemas); + size_t numCols = taosArrayGetSize(sTableSchema->fields); + size_t rows = taosArrayGetSize(cTablePoints); + SArray* rowsBind = taosArrayInit(rows, POINTER_BYTES); - int isNullColBind = TSDB_TRUE; - SArray** pCTablePoints = taosHashIterate(cname2points, NULL); - while (pCTablePoints) { - SArray* cTablePoints = *pCTablePoints; + for (int i = 0; i < rows; ++i) { + TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, i); - TAOS_SML_DATA_POINT * point = taosArrayGetP(cTablePoints, 0); - SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx); - size_t numTags = taosArrayGetSize(sTableSchema->tags); - size_t numCols = taosArrayGetSize(sTableSchema->fields); + TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); + if (colBinds == NULL) { + tscError("taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, " + "num of rows: %zu, num of cols: %zu", rows, numCols); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } - SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); - taosArraySetSize(tagBinds, numTags); - for (int j = 0; j < numTags; ++j) { - TAOS_BIND* bind = taosArrayGet(tagBinds, j); + int isNullColBind = TSDB_TRUE; + for (int j = 0; j < numCols; ++j) { + TAOS_BIND* bind = colBinds + j; bind->is_null = &isNullColBind; } - for (int j = 0; j < point->tagNum; ++j) { - TAOS_SML_KV* kv = point->tags + j; - TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx); + for (int j = 0; j < point->fieldNum; ++j) { + TAOS_SML_KV* kv = point->fields + j; + TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx; bind->buffer_type = kv->type; bind->length = malloc(sizeof(uintptr_t*)); *bind->length = kv->length; bind->buffer = kv->value; bind->is_null = NULL; } + taosArrayPush(rowsBind, &colBinds); + } - size_t rows = taosArrayGetSize(cTablePoints); - SArray* rowsBind = taosArrayInit(rows, POINTER_BYTES); + code = insertChildTableBatch(taos, cTableName, sTableSchema->fields, rowsBind); + if (code != 0) { + tscError("insert into child table %s failed. error %s", cTableName, tstrerror(code)); + } - for (int i = 0; i < rows; ++i) { - point = taosArrayGetP(cTablePoints, i); - - TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); - if (colBinds == NULL) { - tscError("taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, " - "num of rows: %zu, num of cols: %zu", rows, numCols); - } - for (int j = 0; j < numCols; ++j) { - TAOS_BIND* bind = colBinds + j; - bind->is_null = &isNullColBind; - } - for (int j = 0; j < point->fieldNum; ++j) { - TAOS_SML_KV* kv = point->fields + j; - TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx; - bind->buffer_type = kv->type; - bind->length = malloc(sizeof(uintptr_t*)); - *bind->length = kv->length; - bind->buffer = kv->value; - bind->is_null = NULL; - } - taosArrayPush(rowsBind, &colBinds); - } - - code = creatChildTableIfNotExists(taos, point->childTableName, point->stableName, sTableSchema->tags, tagBinds); - if (code == 0) { - code = insertChildTableBatch(taos, point->childTableName, sTableSchema->fields, rowsBind); - if (code != 0) { - tscError("insert into child table %s failed. error %s", point->childTableName, tstrerror(code)); - } - } else { - tscError("Create Child Table %s failed, error %s", point->childTableName, tstrerror(code)); - } - - for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { - TAOS_BIND* bind = taosArrayGet(tagBinds, i); + for (int i = 0; i < rows; ++i) { + TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); + for (int j = 0; j < numCols; ++j) { + TAOS_BIND* bind = colBinds + j; free(bind->length); } - taosArrayDestroy(tagBinds); - for (int i = 0; i < rows; ++i) { - TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); - for (int j = 0; j < numCols; ++j) { - TAOS_BIND* bind = colBinds + j; - free(bind->length); - } - free(colBinds); - } - taosArrayDestroy(rowsBind); - taosArrayDestroy(cTablePoints); + free(colBinds); + } + taosArrayDestroy(rowsBind); + return code; +} + +static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints, SArray* stableSchemas) { + int32_t code = TSDB_CODE_SUCCESS; + + SHashObj* cname2points = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); + arrangePointsByChildTableName(points, numPoints, cname2points, stableSchemas); + + SArray** pCTablePoints = taosHashIterate(cname2points, NULL); + while (pCTablePoints) { + SArray* cTablePoints = *pCTablePoints; + + TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, 0); + SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx); + code = applyChildTableTags(taos, point->childTableName, point->stableName, sTableSchema, cTablePoints); if (code != 0) { - break; + tscError("apply child table tags failed. child table %s, error %s", point->childTableName, tstrerror(code)); + goto cleanup; } + code = applyChildTableFields(taos, sTableSchema, point->childTableName, cTablePoints); + if (code != 0) { + tscError("Apply child table fields failed. child table %s, error %s", point->childTableName, tstrerror(code)); + goto cleanup; + } + pCTablePoints = taosHashIterate(cname2points, pCTablePoints); } +cleanup: + pCTablePoints = taosHashIterate(cname2points, NULL); + while (pCTablePoints) { + SArray* pPoints = *pCTablePoints; + taosArrayDestroy(pPoints); + } taosHashCleanup(cname2points); return code; } @@ -855,7 +984,7 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { goto clean_up; } - code = insertPoints(taos, points, numPoint, stableSchemas); + code = applyDataPoints(taos, points, numPoint, stableSchemas); if (code != 0) { tscError("error insert points : %s", tstrerror(code)); } diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index cbac1d3de3..37e93cdacb 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -954,7 +954,7 @@ int32_t verify_schema_less(TAOS* taos) { result = taos_query(taos, "drop database if exists test;"); taos_free_result(result); usleep(100000); - result = taos_query(taos, "create database test precision 'us';"); + result = taos_query(taos, "create database test precision 'us' update 1;"); taos_free_result(result); usleep(100000); @@ -963,23 +963,11 @@ int32_t verify_schema_less(TAOS* taos) { taos_free_result(result); usleep(100000); - char* lines[] = { - "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", - "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns", - "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532ns", - "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns", - "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns", - "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns", - "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns", - "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns", - "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns" - }; int code = 0; - code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*)); char* lines2[] = { - "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", - "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns" + "zqlbgs,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000ns", + "zqlbgs,t9=f,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t10=L\"ncharTagValue\" c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\" 1626006833639000000ns" }; code = taos_insert_lines(taos, &lines2[0], 1); code = taos_insert_lines(taos, &lines2[1], 1); From 1347ddf89276bb8931c01fa476f4f01e664da1e3 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Sat, 24 Jul 2021 23:05:58 +0800 Subject: [PATCH 22/26] fix change tag values errors --- src/client/src/tscParseLineProtocol.c | 41 ++++++++++++++++----------- tests/examples/c/apitest.c | 36 ++++++++++++++++++++--- tests/examples/c/schemaless.c | 4 +-- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index dd24d2c458..d5883af7f6 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -474,7 +474,7 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) { return code; } -static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { +static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas) { int32_t code = 0; size_t numStable = taosArrayGetSize(stableSchemas); for (int i = 0; i < numStable; ++i) { @@ -691,7 +691,6 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols } do { - code = taos_stmt_set_tbname(stmt, cTableName); if (code != 0) { tscError("%s", taos_stmt_errstr(stmt)); @@ -818,20 +817,22 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam } // select tag1,tag2,... from stable where tbname in (ctable) - char sql[TSDB_MAX_BINARY_LEN]; - int capacity = TSDB_MAX_BINARY_LEN; - snprintf(sql, capacity, "select tbname, "); + char* sql = malloc(tsMaxSQLStringLen+1); + int freeBytes = tsMaxSQLStringLen + 1; + snprintf(sql, freeBytes, "select tbname, "); for (int i = 0; i < numNotNullTags ; ++i) { - snprintf(sql + strlen(sql), capacity-strlen(sql), "%s,", tagKVs[notNullTagsIndices[i]]->key); + snprintf(sql + strlen(sql), freeBytes-strlen(sql), "%s,", tagKVs[notNullTagsIndices[i]]->key); } - - snprintf(sql + strlen(sql) - 1, capacity - strlen(sql) + 1, + snprintf(sql + strlen(sql) - 1, freeBytes - strlen(sql) + 1, " from %s where tbname in (\'%s\')", sTableName, cTableName); + sql[strlen(sql)] = '\0'; + TAOS_RES* result = taos_query(taos, sql); + free(sql); + int32_t code = taos_errno(result); if (code != 0) { - tscError("%s", taos_errstr(result)); - taos_free_result(result); + tscError("get child table %s tags failed. error string %s", cTableName, taos_errstr(result)); goto cleanup; } @@ -842,18 +843,20 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam TAOS_FIELD* fields = taos_fetch_fields(result); int* lengths = taos_fetch_lengths(result); for (int i = 1; i < numFields; ++i) { - uint8_t type = fields[i].type; + uint8_t dbType = fields[i].type; int32_t length = lengths[i]; char* val = row[i]; TAOS_SML_KV* tagKV = tagKVs[notNullTagsIndices[i-1]]; - if (tagKV->type != type) { + if (tagKV->type != dbType) { tscError("child table %s tag %s type mismatch. point type : %d, db type : %d", - cTableName, tagKV->key, tagKV->type, type); + cTableName, tagKV->key, tagKV->type, dbType); return TSDB_CODE_TSC_INVALID_VALUE; } - if (memcmp(tagKV->value, val, length) != 0) { + assert(tagKV->value); + + if (val == NULL || length != tagKV->length || memcmp(tagKV->value, val, length) != 0) { TAOS_BIND* bind = taosArrayGet(tagBinds, tagKV->fieldSchemaIdx); code = changeChildTableTagValue(taos, cTableName, tagKV->key, bind); if (code != 0) { @@ -861,8 +864,8 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam goto cleanup; } } - } + tscDebug("successfully applied point tags. child table: %s", cTableName); } else { code = creatChildTableIfNotExists(taos, cTableName, sTableName, sTableSchema->tags, tagBinds); if (code != 0) { @@ -871,6 +874,7 @@ static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableNam } cleanup: + taos_free_result(result); for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { TAOS_BIND* bind = taosArrayGet(tagBinds, i); free(bind->length); @@ -953,6 +957,8 @@ static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t goto cleanup; } + tscDebug("successfully applied data points of child table %s", point->childTableName); + pCTablePoints = taosHashIterate(cname2points, pCTablePoints); } @@ -961,6 +967,7 @@ cleanup: while (pCTablePoints) { SArray* pPoints = *pCTablePoints; taosArrayDestroy(pPoints); + pCTablePoints = taosHashIterate(cname2points, pCTablePoints); } taosHashCleanup(cname2points); return code; @@ -978,7 +985,7 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { goto clean_up; } - code = reconcileDBSchemas(taos, stableSchemas); + code = modifyDBSchemas(taos, stableSchemas); if (code != 0) { tscError("error change db schema : %s", tstrerror(code)); goto clean_up; @@ -986,7 +993,7 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { code = applyDataPoints(taos, points, numPoint, stableSchemas); if (code != 0) { - tscError("error insert points : %s", tstrerror(code)); + tscError("error apply data points : %s", tstrerror(code)); } clean_up: diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index 37e93cdacb..fbe6a381df 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -963,11 +963,25 @@ int32_t verify_schema_less(TAOS* taos) { taos_free_result(result); usleep(100000); - int code = 0; + + char* lines[] = { + "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns", + "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532ns", + "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns", + "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns", + "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns", + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns", + "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns", + "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns" + }; + + code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*)); + char* lines2[] = { - "zqlbgs,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000ns", - "zqlbgs,t9=f,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t10=L\"ncharTagValue\" c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\" 1626006833639000000ns" + "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns" }; code = taos_insert_lines(taos, &lines2[0], 1); code = taos_insert_lines(taos, &lines2[1], 1); @@ -983,7 +997,21 @@ int32_t verify_schema_less(TAOS* taos) { "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns" }; code = taos_insert_lines(taos, lines4, 2); - return code; + + char* lines5[] = { + "zqlbgs,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000ns", + "zqlbgs,t9=f,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t10=L\"ncharTagValue\" c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\" 1626006833639000000ns" + }; + code = taos_insert_lines(taos, &lines5[0], 1); + code = taos_insert_lines(taos, &lines5[1], 1); + + + char* lines6[] = { + "st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns" + }; + code = taos_insert_lines(taos, lines6, 2); + return (code); } int main(int argc, char *argv[]) { diff --git a/tests/examples/c/schemaless.c b/tests/examples/c/schemaless.c index d6450914df..8fae408049 100644 --- a/tests/examples/c/schemaless.c +++ b/tests/examples/c/schemaless.c @@ -9,8 +9,8 @@ #include int numSuperTables = 8; -int numChildTables = 1024; -int numRowsPerChildTable = 128; +int numChildTables = 4; +int numRowsPerChildTable = 2048; void shuffle(char**lines, size_t n) { From d6d822b8e94345ea056096ed25e0b74b9182c03d Mon Sep 17 00:00:00 2001 From: Linhe Huo Date: Sun, 25 Jul 2021 22:58:33 +0800 Subject: [PATCH 23/26] [TD-5476]: update to latest grafanaplugin (#6990) --- src/connector/grafanaplugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connector/grafanaplugin b/src/connector/grafanaplugin index 3530c6df09..4a4d79099b 160000 --- a/src/connector/grafanaplugin +++ b/src/connector/grafanaplugin @@ -1 +1 @@ -Subproject commit 3530c6df097134a410bacec6b3cd013ef38a61aa +Subproject commit 4a4d79099b076b8ff12d5b4fdbcba54049a6866d From f043e3a6e3d10f3daa1cff653de55f3216dee44f Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Mon, 26 Jul 2021 09:52:07 +0800 Subject: [PATCH 24/26] Hotfix/sangshuduo/td 3197 fix taosdemo coverity scan (#7012) * [TD-3197] : fix taosdemo coverity scan issues. * [TD-3197] : fix taosdemo coverity scan issue. fix subscribeTest pids uninitialized. * [TD-3197] : fix taosdemo coverity scan issues. * [TD-3197] : fix coverity scan issues. check super tbl info pointer. * [TD-3197] : fix coverity scan issues. move sub tbl query thread join into loop * [TD-3197] : fix coverity scan issues. remove unused variable * [TD-3197] : fix coverity scan issues. use more secure random library * [TD-3197] : fix coverity scan issues. use strncpy for more safe * [TD-3197] : fix taosdemo coverity scan issue. replace arc4random with rand(). * [TD-3197] : fix coverity scan issues. check stb info pointer for start time * [TD-3197] : fix coverity scan issues. fix strcpy vulnerability * [TD-3197] : fix taosdemo coverity scan issue. modify taosdemoTest2. try to check database continously. * [TD-3197] : taosdemo coverity scan issues. * [TD-3197] : fix memory leak when parsing arguments. * [TD-3197] : fix cmake strip arguments. * [TD-3197] : taosdemo coverity scan. fix cmake string manipulation. * [TD-3197]: taosdemo coverity scan issue. configDir buffer overwrite. * [TD-3197]: coverity scan issue. taosdump argument validation. * [TD-3197]: taosdemo and taosdump coverity scan issues. * [TD-3197]: taosdemo coverity scan. append result buf to file. for develop branch. * exit if read sample file failed. * fix converity scan issue. * fix coverity scan issue. * fix coverity scan memory leak. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/taosdemo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 6acb317a9e..439e2a476f 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -5940,14 +5940,15 @@ static int32_t prepareStbStmt( if (-1 == prepareStbStmtBind( tagsArray, stbInfo, tagRand, -1, -1, false /* is tag */)) { - free(tagsArray); + tmfree(tagsValBuf); + tmfree(tagsArray); return -1; } ret = taos_stmt_set_tbname_tags(stmt, tableName, (TAOS_BIND *)tagsArray); tmfree(tagsValBuf); - tmfree((char *)tagsArray); + tmfree(tagsArray); } else { ret = taos_stmt_set_tbname(stmt, tableName); } From 93acca58c5361a7776328104b1a1f4ce819c7c18 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Mon, 26 Jul 2021 11:32:23 +0800 Subject: [PATCH 25/26] [TD-4098] : clarify 'IN' operator on TIMESTAMP. --- documentation20/cn/12.taos-sql/docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index b047bb9bb3..93994f94ad 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -715,7 +715,7 @@ Query OK, 1 row(s) in set (0.001091s) 2. 同时进行多个字段的范围过滤,需要使用关键词 AND 来连接不同的查询条件,暂不支持 OR 连接的不同列之间的查询过滤条件。 3. 针对单一字段的过滤,如果是时间过滤条件,则一条语句中只支持设定一个;但针对其他的(普通)列或标签列,则可以使用 `OR` 关键字进行组合条件的查询过滤。例如: `((value > 20 AND value < 30) OR (value < 12))`。 4. 从 2.0.17.0 版本开始,条件过滤开始支持 BETWEEN AND 语法,例如 `WHERE col2 BETWEEN 1.5 AND 3.25` 表示查询条件为“1.5 ≤ col2 ≤ 3.25”。 -5. 从 2.1.4.0 版本开始,条件过滤开始支持 IN 算子,例如 `WHERE city IN ('Beijing', 'Shanghai')`。说明:BOOL 类型写作 `{true, false}` 或 `{0, 1}` 均可,但不能写作 0、1 之外的整数;FLOAT 和 DOUBLE 类型会受到浮点数精度影响,集合内的值在精度范围内认为和数据行的值完全相等才能匹配成功。 +5. 从 2.1.4.0 版本开始,条件过滤开始支持 IN 算子,例如 `WHERE city IN ('Beijing', 'Shanghai')`。说明:BOOL 类型写作 `{true, false}` 或 `{0, 1}` 均可,但不能写作 0、1 之外的整数;FLOAT 和 DOUBLE 类型会受到浮点数精度影响,集合内的值在精度范围内认为和数据行的值完全相等才能匹配成功;TIMESTAMP 类型支持非主键的列。