From 6d13cf37ef7b40c3343fc710d79aae0bf3ab9364 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 25 Jun 2020 13:15:45 +0000 Subject: [PATCH 01/12] failed to create table in taosdemo --- src/kit/taosdemo/taosdemo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index e673277a0b..750fb2fd40 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -499,7 +499,7 @@ int main(int argc, char *argv[]) { /* Create all the tables; */ printf("Creating %d table(s)......\n", ntables); for (int i = 0; i < ntables; i++) { - snprintf(command, BUFFER_SIZE, "create table %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); + snprintf(command, BUFFER_SIZE, "create table if not exists %s.%s%d (ts timestamp%s;", db_name, tb_prefix, i, cols); queryDB(taos, command); } @@ -509,7 +509,7 @@ int main(int argc, char *argv[]) { } else { /* Create metric table */ printf("Creating meters super table...\n"); - snprintf(command, BUFFER_SIZE, "create table %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); + snprintf(command, BUFFER_SIZE, "create table if not exists %s.meters (ts timestamp%s tags (areaid int, loc binary(10))", db_name, cols); queryDB(taos, command); printf("meters created!\n"); @@ -523,9 +523,9 @@ int main(int argc, char *argv[]) { j = i % 10; } if (j % 2 == 0) { - snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "shanghai"); + snprintf(command, BUFFER_SIZE, "create table if not exists %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "shanghai"); } else { - snprintf(command, BUFFER_SIZE, "create table %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "beijing"); + snprintf(command, BUFFER_SIZE, "create table if not exists %s.%s%d using %s.meters tags (%d,\"%s\");", db_name, tb_prefix, i, db_name, j, "beijing"); } queryDB(taos, command); } From d0b208755d162963cfef14562bbba5892ee8030c Mon Sep 17 00:00:00 2001 From: dengyihao Date: Thu, 25 Jun 2020 21:27:26 +0800 Subject: [PATCH 02/12] coverity issue --- src/query/src/qExecutor.c | 58 +++++++++++++++++++++++-------------- src/query/src/qpercentile.c | 7 +++-- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index d41bac2a49..ed529db92e 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -767,6 +767,9 @@ static void* getDataBlockImpl(SArray* pDataBlock, int32_t colId) { static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int32_t col, int32_t size, SArray *pDataBlock) { + if (pDataBlock == NULL) { + return NULL; + } char *dataBlock = NULL; SQuery *pQuery = pRuntimeEnv->pQuery; @@ -854,6 +857,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery); if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &win) != TSDB_CODE_SUCCESS) { + tfree(sasArray); return; } @@ -1349,10 +1353,13 @@ static void setCtxTagColumnInfo(SQuery *pQuery, SQLFunctionCtx *pCtx) { // the column may be the normal column, group by normal_column, the functionId is TSDB_FUNC_PRJ } } - - p->tagInfo.pTagCtxList = pTagCtx; - p->tagInfo.numOfTagCols = num; - p->tagInfo.tagsLen = tagLen; + if (p != NULL) { + p->tagInfo.pTagCtxList = pTagCtx; + p->tagInfo.numOfTagCols = num; + p->tagInfo.tagsLen = tagLen; + } else { + tfree(pTagCtx); + } } } @@ -3497,7 +3504,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde continue; } - assert(result[i].numOfRows >= 0 && pQInfo->offset <= 1); + assert(pQInfo->offset <= 1); int32_t numOfRowsToCopy = result[i].numOfRows - pQInfo->offset; int32_t oldOffset = pQInfo->offset; @@ -5295,9 +5302,9 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * bytes = s.bytes; } else{ int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); - assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX); + assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags); - if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX) { + if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX && j >= 0) { SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; type = pCol->type; bytes = pCol->bytes; @@ -5339,8 +5346,6 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * assert(ret == TSDB_CODE_SUCCESS); } } - - tfree(pExprMsg); *pExprInfo = pExprs; return TSDB_CODE_SUCCESS; @@ -5591,11 +5596,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, pQInfo->signature = pQInfo; pQInfo->tableGroupInfo = *pTableGroupInfo; - size_t numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList); + size_t numOfGroups = 0; + if (pTableGroupInfo->pGroupList != NULL) { + numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList); + + pQInfo->tableqinfoGroupInfo.pGroupList = taosArrayInit(numOfGroups, POINTER_BYTES); + pQInfo->tableqinfoGroupInfo.numOfTables = pTableGroupInfo->numOfTables; + } - pQInfo->tableqinfoGroupInfo.pGroupList = taosArrayInit(numOfGroups, POINTER_BYTES); - pQInfo->tableqinfoGroupInfo.numOfTables = pTableGroupInfo->numOfTables; - int tableIndex = 0; STimeWindow window = pQueryMsg->window; taosArraySort(pTableIdList, compareTableIdInfo); @@ -5693,7 +5701,8 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ pTSBuf = tsBufCreateFromCompBlocks(tsBlock, pQueryMsg->tsNumOfBlocks, pQueryMsg->tsLen, pQueryMsg->tsOrder); tsBufResetPos(pTSBuf); - tsBufNextPos(pTSBuf); + bool ret = tsBufNextPos(pTSBuf); + UNUSED(ret); } // only the successful complete requries the sem_post/over = 1 operations. @@ -5839,18 +5848,23 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { // make sure file exist if (FD_VALID(fd)) { - size_t s = lseek(fd, 0, SEEK_END); - qTrace("QInfo:%p ts comp data return, file:%s, size:%zu", pQInfo, pQuery->sdata[0]->data, s); - - lseek(fd, 0, SEEK_SET); - read(fd, data, s); + int32_t s = lseek(fd, 0, SEEK_END); + UNUSED(s); + qTrace("QInfo:%p ts comp data return, file:%s, size:%d", pQInfo, pQuery->sdata[0]->data, s); + s = lseek(fd, 0, SEEK_SET); + if (s >= 0) { + size_t sz = read(fd, data, s); + UNUSED(sz); + } close(fd); - unlink(pQuery->sdata[0]->data); } else { - // todo return the error code to client + // todo return the error code to client and handle invalid fd qError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo, pQuery->sdata[0]->data, strerror(errno)); + if (fd != -1) { + close(fd); + } } // all data returned, set query over @@ -5903,7 +5917,6 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi } if ((code = createQFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { - free(pExprMsg); goto _over; } @@ -5975,6 +5988,7 @@ _over: } free(pTagColumnInfo); free(pExprs); + free(pExprMsg); taosArrayDestroy(pTableIdList); //pQInfo already freed in initQInfo, but *pQInfo may not pointer to null; diff --git a/src/query/src/qpercentile.c b/src/query/src/qpercentile.c index e192cf3873..9de4d3668c 100644 --- a/src/query/src/qpercentile.c +++ b/src/query/src/qpercentile.c @@ -880,8 +880,11 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) for (uint32_t jx = 0; jx < pFlushInfo->numOfPages; ++jx) { size_t sz = fread(pPage, pMemBuffer->pageSize, 1, pMemBuffer->file); - UNUSED(sz); - tMemBucketPut(pMemBucket, pPage->data, pPage->num); + if (sz != pMemBuffer->pageSize) { + uError("MemBucket:%p, read tmp file %s failed", pMemBucket, pMemBuffer->path); + } else { + tMemBucketPut(pMemBucket, pPage->data, pPage->num); + } } fclose(pMemBuffer->file); From 103f6888a33c650017501fa3ad7d28bb33b20ccf Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 25 Jun 2020 13:27:55 +0000 Subject: [PATCH 03/12] scripts --- tests/script/general/parser/auto_create_tb.sim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/script/general/parser/auto_create_tb.sim b/tests/script/general/parser/auto_create_tb.sim index 6065daa6d3..64fec4b56d 100644 --- a/tests/script/general/parser/auto_create_tb.sim +++ b/tests/script/general/parser/auto_create_tb.sim @@ -153,13 +153,13 @@ print $rows $data00 $data10 $data20 if $rows != 3 then return -1 endi -if $data00 != tb3 then +if $data00 != tb1 then return -1 endi if $data10 != tb2 then return -1 endi -if $data20 != tb1 then +if $data20 != tb3 then return -1 endi @@ -221,13 +221,13 @@ sql show tables if $rows != 3 then return -1 endi -if $data00 != tb3 then +if $data00 != tb1 then return -1 endi if $data10 != tb2 then return -1 endi -if $data20 != tb1 then +if $data20 != tb3 then return -1 endi From 03ff8f6519ebdc3f0a6becab208ceaf2b12defd8 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 25 Jun 2020 23:45:24 +0800 Subject: [PATCH 04/12] [td-225] improve the data generation performance. --- src/kit/taosdemo/taosdemo.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index e673277a0b..fa7c4fb7af 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -847,10 +847,10 @@ void *syncWrite(void *sarg) { pstr += sprintf(pstr, "insert into %s.%s%d values", winfo->db_name, winfo->tb_prefix, tID); int k; for (k = 0; k < winfo->nrecords_per_request;) { - int rand_num = trand() % 100; + int rand_num = rand() % 100; int len = -1; if (winfo->data_of_order ==1 && rand_num < winfo->data_of_rate) { - long d = tmp_time - trand() % 1000000 + rand_num; + long d = tmp_time - rand() % 1000000 + rand_num; len = generateData(data, data_type, ncols_per_record, d, len_of_binary); } else { len = generateData(data, data_type, ncols_per_record, tmp_time += 1000, len_of_binary); @@ -942,10 +942,10 @@ void callBack(void *param, TAOS_RES *res, int code) { pstr += sprintf(pstr, "insert into %s values", tb_info->tb_name); for (int i = 0; i < tb_info->nrecords_per_request; i++) { - int rand_num = trand() % 100; + int rand_num = rand() % 100; if (tb_info->data_of_order ==1 && rand_num < tb_info->data_of_rate) { - long d = tmp_time - trand() % 1000000 + rand_num; + long d = tmp_time - rand() % 1000000 + rand_num; generateData(data, datatype, ncols_per_record, d, len_of_binary); } else { @@ -994,20 +994,20 @@ int32_t generateData(char *res, char **data_type, int num_of_cols, int64_t times for (int i = 0; i < num_of_cols; i++) { if (strcasecmp(data_type[i % c], "tinyint") == 0) { - pstr += sprintf(pstr, ", %d", (int)(trand() % 128)); + pstr += sprintf(pstr, ", %d", (int)(rand() % 128)); } else if (strcasecmp(data_type[i % c], "smallint") == 0) { - pstr += sprintf(pstr, ", %d", (int)(trand() % 32767)); + pstr += sprintf(pstr, ", %d", (int)(rand() % 32767)); } else if (strcasecmp(data_type[i % c], "int") == 0) { - pstr += sprintf(pstr, ", %d", (int)(trand() % 10)); + pstr += sprintf(pstr, ", %d", (int)(rand() % 10)); } else if (strcasecmp(data_type[i % c], "bigint") == 0) { - pstr += sprintf(pstr, ", %" PRId64, trand() % 2147483648); + pstr += sprintf(pstr, ", %" PRId64, rand() % 2147483648); } else if (strcasecmp(data_type[i % c], "float") == 0) { - pstr += sprintf(pstr, ", %10.4f", (float)(trand() / 1000.0)); + pstr += sprintf(pstr, ", %10.4f", (float)(rand() / 1000.0)); } else if (strcasecmp(data_type[i % c], "double") == 0) { - double t = (double)(trand() / 1000000.0); + double t = (double)(rand() / 1000000.0); pstr += sprintf(pstr, ", %20.8f", t); } else if (strcasecmp(data_type[i % c], "bool") == 0) { - bool b = trand() & 1; + bool b = rand() & 1; pstr += sprintf(pstr, ", %s", b ? "true" : "false"); } else if (strcasecmp(data_type[i % c], "binary") == 0) { char s[len_of_binary]; @@ -1033,7 +1033,7 @@ void rand_string(char *str, int size) { --size; int n; for (n = 0; n < size; n++) { - int key = trand() % (int)(sizeof charset - 1); + int key = rand() % (int)(sizeof charset - 1); str[n] = charset[key]; } str[n] = 0; From dc92ea0d8fc184d5d6aff8c065ded11932b8b4e8 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 00:13:58 +0800 Subject: [PATCH 05/12] [td-225] update the test sim --- tests/script/general/parser/projection_limit_offset.sim | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/general/parser/projection_limit_offset.sim b/tests/script/general/parser/projection_limit_offset.sim index 5f006d0eb7..2b89946ef8 100644 --- a/tests/script/general/parser/projection_limit_offset.sim +++ b/tests/script/general/parser/projection_limit_offset.sim @@ -80,6 +80,7 @@ print $rows sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 0; if $rows != 4008 then + print expect 4008, actual:$rows return -1 endi From 4c97427e0cf7e6cdc86f358428de2f42c6dc1b27 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 00:15:13 +0800 Subject: [PATCH 06/12] [td-225] fix bugs in parse time --- src/common/src/ttimezone.c | 1 + src/util/src/ttime.c | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c index ae6ffea59a..ed62357c4d 100644 --- a/src/common/src/ttimezone.c +++ b/src/common/src/ttimezone.c @@ -20,6 +20,7 @@ #include "tconfig.h" #include "tutil.h" +// TODO refactor to set the tz value through parameter void tsSetTimeZone() { SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); uPrint("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index dfec632012..176f9be7fb 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -48,23 +48,21 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, const unsigned int day, const unsigned int hour, const unsigned int min, const unsigned int sec) { - unsigned int mon = mon0, year = year0; + unsigned int mon = mon0, year = year0; - /* 1..12 -> 11,12,1..10 */ - if (0 >= (int) (mon -= 2)) { - mon += 12; /* Puts Feb last since it has leap day */ - year -= 1; - } + /* 1..12 -> 11,12,1..10 */ + if (0 >= (int) (mon -= 2)) { + mon += 12; /* Puts Feb last since it has leap day */ + year -= 1; + } - //int64_t res = (((((int64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) + - // year*365 - 719499)*24 + hour)*60 + min)*60 + sec); - int64_t res; - res = 367*((int64_t)mon)/12; - res += year/4 - year/100 + year/400 + day + year*365 - 719499; + int64_t res = 367*((int64_t)mon)/12; + + res += ((int64_t)(year/4 - year/100 + year/400 + day + year*365) - 719499); // this value may be less than 0 res = res*24; res = ((res + hour) * 60 + min) * 60 + sec; - return (res + timezone); + return (res + timezone); } // ==== mktime() kernel code =================// static int64_t m_deltaUtc = 0; From b5598b6300546e0a3cfde4c5076380ee71a5acd5 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 00:16:34 +0800 Subject: [PATCH 07/12] [td-225] opt performance for random number generation. --- src/util/src/tskiplist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 2394adc6f3..f3c0babe6b 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -38,7 +38,7 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) { const uint32_t factor = 4; int32_t n = 1; - while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) { + while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) { n++; } From b4a15d01409ec5683f52a8ff771fc123c657f57c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 00:17:43 +0800 Subject: [PATCH 08/12] [td-225] enable the client unit test. --- src/client/CMakeLists.txt | 4 +++- src/client/tests/CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/client/tests/CMakeLists.txt diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index ac1894369d..00fa1a1479 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -34,7 +34,9 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) VERSION_INFO) MESSAGE(STATUS "build version ${VERSION_INFO}") SET_TARGET_PROPERTIES(taos PROPERTIES VERSION ${VERSION_INFO} SOVERSION 1) - + + ADD_SUBDIRECTORY(tests) + ELSEIF (TD_WINDOWS_64) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/jni/windows/win32) diff --git a/src/client/tests/CMakeLists.txt b/src/client/tests/CMakeLists.txt new file mode 100644 index 0000000000..f07af85e25 --- /dev/null +++ b/src/client/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(TDengine) + +FIND_PATH(HEADER_GTEST_INCLUDE_DIR gtest.h /usr/include/gtest /usr/local/include/gtest) +FIND_LIBRARY(LIB_GTEST_STATIC_DIR libgtest.a /usr/lib/ /usr/local/lib) + +IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) + MESSAGE(STATUS "gTest library found, build unit test") + + INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + + ADD_EXECUTABLE(cliTest ${SOURCE_LIST}) + TARGET_LINK_LIBRARIES(cliTest taos tutil common gtest pthread) +ENDIF() \ No newline at end of file From 24a0210d51a108ce83cfae90791871f3a996f3b5 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 00:19:27 +0800 Subject: [PATCH 09/12] [td-225] add log for tsdb --- src/tsdb/src/tsdbMeta.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 6b0224cad2..e8da25d585 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -553,10 +553,18 @@ int tsdbUnlockRepoMeta(STsdbRepo *pRepo) { return 0; } -void tsdbRefTable(STable *pTable) { T_REF_INC(pTable); } +void tsdbRefTable(STable *pTable) { + int16_t ref = T_REF_INC(pTable); + tsdbTrace("ref table:%s, uid:%"PRIu64", tid:%d, ref:%d", TABLE_CHAR_NAME(pTable), pTable->tableId.uid, pTable->tableId.tid, ref); +} void tsdbUnRefTable(STable *pTable) { - if (T_REF_DEC(pTable) == 0) { + int16_t ref = T_REF_DEC(pTable); + tsdbTrace("unref table:%s, uid:%"PRIu64", tid:%d, ref:%d", TABLE_CHAR_NAME(pTable), pTable->tableId.uid, pTable->tableId.tid, ref); + + if (ref == 0) { + tsdbTrace("destroy table:%s uid:%"PRIu64", tid:%d", TABLE_CHAR_NAME(pTable), pTable->tableId.uid, pTable->tableId.tid); + if (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) { tsdbUnRefTable(pTable->pSuper); } From 5835964c15b4ee10f89a8fa8d81283f4c864d4c2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 27 Jun 2020 01:33:47 +0800 Subject: [PATCH 10/12] [td-225] --- src/query/src/qExecutor.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ed529db92e..cdb56e1469 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -822,7 +822,7 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas } /** - * + * todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions * @param pRuntimeEnv * @param forwardStep * @param tsCols @@ -1064,16 +1064,18 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS SQuery *pQuery = pRuntimeEnv->pQuery; STableQueryInfo* item = pQuery->current; - - TSKEY *tsCols = (TSKEY*) ((SColumnInfoData *)taosArrayGet(pDataBlock, 0))->pData; - bool groupbyStateValue = isGroupbyNormalCol(pQuery->pGroupbyExpr); + + SColumnInfoData* pColumnInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock, 0); + + TSKEY *tsCols = (pColumnInfoData->info.type == TSDB_DATA_TYPE_TIMESTAMP)? (TSKEY*) pColumnInfoData->pData:NULL; + bool groupbyColumnValue = isGroupbyNormalCol(pQuery->pGroupbyExpr); SArithmeticSupport *sasArray = calloc((size_t)pQuery->numOfOutput, sizeof(SArithmeticSupport)); int16_t type = 0; int16_t bytes = 0; char *groupbyColumnData = NULL; - if (groupbyStateValue) { + if (groupbyColumnValue) { groupbyColumnData = getGroupbyColumnData(pQuery, &type, &bytes, pDataBlock); } @@ -1161,7 +1163,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS pWindowResInfo->curIndex = index; } else { // other queries // decide which group this rows belongs to according to current state value - if (groupbyStateValue) { + if (groupbyColumnValue) { char *val = groupbyColumnData + bytes * offset; int32_t ret = setGroupResultOutputBuf(pRuntimeEnv, val, type, bytes); @@ -1186,9 +1188,14 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS } } } - - item->lastKey = tsCols[offset] + step; - + + assert(offset >= 0); + if (tsCols != NULL) { + item->lastKey = tsCols[offset] + step; + } else { + item->lastKey = (QUERY_IS_ASC_QUERY(pQuery)? pDataBlockInfo->window.ekey:pDataBlockInfo->window.skey) + step; + } + // todo refactor: extract method for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { if (pQuery->pSelectExpr[i].base.functionId != TSDB_FUNC_ARITHM) { From f5faa8061ed5203a898bc7ccf3e6100578cb145c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Jun 2020 03:00:44 +0000 Subject: [PATCH 11/12] fix crash generate by crash_gen.sh -p -t 5 -s 100 --- src/mnode/src/mnodeDb.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 5ec5aebf14..81b703b740 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -968,6 +968,17 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { return mnodeAlterDb(pMsg->pDb, pAlter, pMsg); } +static int32_t mnodeDropDbCb(SMnodeMsg *pMsg, int32_t code) { + SDbObj *pDb = pMsg->pDb; + if (code != TSDB_CODE_SUCCESS) { + mError("db:%s, failed to drop from sdb, reason:%s", pDb->name, tstrerror(code)); + } else { + mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); + } + + return code; +} + static int32_t mnodeDropDb(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; @@ -978,12 +989,12 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { .type = SDB_OPER_GLOBAL, .table = tsDbSdb, .pObj = pDb, - .pMsg = pMsg + .pMsg = pMsg, + .cb = mnodeDropDbCb }; int32_t code = sdbDeleteRow(&oper); if (code == TSDB_CODE_SUCCESS) { - mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } From cc79eedd93dfa39e2f54863f4ab7acc271f9a0f7 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Jun 2020 03:14:37 +0000 Subject: [PATCH 12/12] invalid write while drop stable --- src/mnode/src/mnodeTable.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 4906aeaeb0..88ed0e90eb 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -854,13 +854,15 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; - if (pTable != NULL) { - mLPrint("app:%p:%p, stable:%s, is dropped from sdb, result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, - tstrerror(code)); + if (code != TSDB_CODE_SUCCESS) { + mError("app:%p:%p, table:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); + } else { + mLPrint("app:%p:%p, stable:%s, is dropped from sdb", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); } return code; } + static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; @@ -899,12 +901,10 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { }; int32_t code = sdbDeleteRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - mError("app:%p:%p, table:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); - return code; - } else { + if (code == TSDB_CODE_SUCCESS) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } + return code; } static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char *tagName) {