diff --git a/.travis.yml b/.travis.yml index 06c8b863d3..2c3fd31911 100644 --- a/.travis.yml +++ b/.travis.yml @@ -316,218 +316,19 @@ matrix: fi - make > /dev/null - - os: linux - arch: arm64 - dist: bionic - language: c - compiler: gcc - env: ENV_COVER=true - - git: - - depth: 1 - - addons: - apt: - packages: - - build-essential - - cmake - - net-tools - - python-pip - - python-setuptools - - python3-pip - - python3-setuptools - - lcov - - psmisc - - before_script: - - cd ${TRAVIS_BUILD_DIR} - - mkdir debug - - cd debug - - script: - - if [ "${TRAVIS_CPU_ARCH}" == "arm64" ]; - then cmake -DCOVER=true .. -DCPUTYPE=aarch64 > /dev/null; - else cmake -DCOVER=true .. > /dev/null; - fi - - make > /dev/null - - after_success: - - |- - case $TRAVIS_OS_NAME in - linux) - cd ${TRAVIS_BUILD_DIR}/debug - make install > /dev/null || travis_terminate $? - pip install numpy - pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/ - pip3 install numpy - pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/ - cd ${TRAVIS_BUILD_DIR}/tests - ./test-all.sh smoke COVER - TEST_RESULT=$? - pkill taosd - sleep 1 - cd ${TRAVIS_BUILD_DIR} - lcov -d . --capture --rc lcov_branch_coverage=1 -o coverage.info - lcov --remove coverage.info '*/tests/*' '*/test/*' '*/deps/*' '*/plugins/*' -o coverage.info - lcov -l --rc lcov_branch_coverage=1 coverage.info || travis_terminate $? - gem install coveralls-lcov - # Color setting - RED='\033[0;31m' - GREEN='\033[1;32m' - GREEN_DARK='\033[0;32m' - GREEN_UNDERLINE='\033[4;32m' - NC='\033[0m' - coveralls-lcov coverage.info - if [ "$?" -eq "0" ]; then - echo -e "${GREEN} ## Uploaded to Coveralls.io! ## ${NC}" - else - echo -e "${RED} ## Coveralls.io not collect coverage report! ## ${NC} " - fi - bash <(curl -s https://codecov.io/bash) -y .codecov.yml -f coverage.info - if [ "$?" -eq "0" ]; then - echo -e "${GREEN} ## Uploaded to Codecov! ## ${NC} " - else - echo -e "${RED} ## Codecov did not collect coverage report! ## ${NC} " - fi - if [ "$TEST_RESULT" -ne "0" ]; then - travis_terminate $? - fi - ;; - esac - - - os: linux - arch: arm64 - dist: bionic - language: c - - git: - - depth: 1 - - compiler: gcc - env: DESC="linux/gcc build and test" - - addons: - apt: - packages: - - build-essential - - cmake - - net-tools - - python-pip - - python-setuptools - - python3-pip - - python3-setuptools - - valgrind - - psmisc - - before_script: - - cd ${TRAVIS_BUILD_DIR} - - mkdir debug - - cd debug - - script: - - if [ "${TRAVIS_CPU_ARCH}" == "arm64" ]; - then cmake .. -DCPUTYPE=aarch64 > /dev/null; - else cmake .. > /dev/null; - fi - - make > /dev/null - - after_success: - - travis_wait 20 - - |- - case $TRAVIS_OS_NAME in - linux) - cd ${TRAVIS_BUILD_DIR}/debug - make install > /dev/null || travis_terminate $? - pip install numpy - pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/ - pip3 install numpy - pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/ - cd ${TRAVIS_BUILD_DIR}/tests - ./test-all.sh smoke || travis_terminate $? - cd ${TRAVIS_BUILD_DIR}/tests/pytest - ./valgrind-test.sh 2>&1 > mem-error-out.log - sleep 1 - # Color setting - RED='\033[0;31m' - GREEN='\033[1;32m' - GREEN_DARK='\033[0;32m' - GREEN_UNDERLINE='\033[4;32m' - NC='\033[0m' - grep 'start to execute\|ERROR SUMMARY' mem-error-out.log|grep -v 'grep'|uniq|tee uniq-mem-error-out.log - for memError in `grep 'ERROR SUMMARY' uniq-mem-error-out.log | awk '{print $4}'` - do - if [ -n "$memError" ]; then - if [ "$memError" -gt 12 ]; then - echo -e "${RED} ## Memory errors number valgrind reports is $memError.\ - More than our threshold! ## ${NC}" - travis_terminate $memError - fi - fi - done - grep 'start to execute\|definitely lost:' mem-error-out.log|grep -v 'grep'|uniq|tee uniq-definitely-lost-out.log - for defiMemError in `grep 'definitely lost:' uniq-definitely-lost-out.log | awk '{print $7}'` - do - if [ -n "$defiMemError" ]; then - if [ "$defiMemError" -gt 13 ]; then - echo -e "${RED} ## Memory errors number valgrind reports \ - Definitely lost is $defiMemError. More than our threshold! ## ${NC}" - travis_terminate $defiMemError - fi - fi - done - ;; - esac - - - os: linux - arch: arm64 - dist: bionic - language: c - compiler: gcc - env: COVERITY_SCAN=true - git: - - depth: 1 - - script: - - echo "this job is for coverity scan" - - addons: - coverity_scan: - # GitHub project metadata - # ** specific to your project ** - project: - name: TDengine - version: 2.x - description: TDengine - - # Where email notification of build analysis results will be sent - notification_email: sdsang@taosdata.com, slguan@taosdata.com - - # Commands to prepare for build_command - # ** likely specific to your build ** - build_command_prepend: cmake . > /dev/null - - # The command that will be added as an argument to "cov-build" to compile your project for analysis, - # ** likely specific to your build ** - build_command: make - - # Pattern to match selecting branches that will run analysis. We recommend leaving this set to 'coverity_scan'. - # Take care in resource usage, and consider the build frequency allowances per - # https://scan.coverity.com/faq#frequency - branch_pattern: coverity_scan - - # - os: osx - # language: c - # compiler: clang - # env: DESC="mac/clang build" - # git: - # - depth: 1 - # addons: - # homebrew: - # - cmake - # - # script: - # - cd ${TRAVIS_BUILD_DIR} - # - mkdir debug - # - cd debug - # - cmake .. > /dev/null - # - make > /dev/null +# - os: osx +# language: c +# compiler: clang +# env: DESC="mac/clang build" +# git: +# - depth: 1 +# addons: +# homebrew: +# - cmake +# +# script: +# - cd ${TRAVIS_BUILD_DIR} +# - mkdir debug +# - cd debug +# - cmake .. > /dev/null +# - make > /dev/null diff --git a/documentation/webdocs/markdowndocs/Super Table-ch.md b/documentation/webdocs/markdowndocs/Super Table-ch.md index 626f695c27..5f592ec339 100644 --- a/documentation/webdocs/markdowndocs/Super Table-ch.md +++ b/documentation/webdocs/markdowndocs/Super Table-ch.md @@ -53,7 +53,7 @@ STable从属于库,一个STable只属于一个库,但一个库可以有一 说明: - 1. TAGS列总长度不能超过64k bytes; + 1. TAGS列总长度不能超过16k bytes; 2. TAGS列的数据类型不能是timestamp; 3. TAGS列名不能与其他列名相同; 4. TAGS列名不能为预留关键字. diff --git a/documentation/webdocs/markdowndocs/Super Table.md b/documentation/webdocs/markdowndocs/Super Table.md index 6c80c2097c..2c1093a3fa 100644 --- a/documentation/webdocs/markdowndocs/Super Table.md +++ b/documentation/webdocs/markdowndocs/Super Table.md @@ -22,7 +22,7 @@ New keyword "tags" is introduced, where tag_name is the tag name, and tag_type i Note: -1. The bytes of all tags together shall be less than 64k +1. The bytes of all tags together shall be less than 16k 2. Tag's data type can not be time stamp 3. Tag name shall be different from the field name 4. Tag name shall not be the same as system keywords diff --git a/documentation/webdocs/markdowndocs/TAOS SQL-ch.md b/documentation/webdocs/markdowndocs/TAOS SQL-ch.md index 7fe396e9e5..0be39ab8e4 100644 --- a/documentation/webdocs/markdowndocs/TAOS SQL-ch.md +++ b/documentation/webdocs/markdowndocs/TAOS SQL-ch.md @@ -63,7 +63,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic | 3 | BIGINT | 8 | 长整型,范围 [-2^63+1, 2^63-1], -2^63用于NULL | | 4 | FLOAT | 4 | 浮点型,有效位数6-7,范围 [-3.4E38, 3.4E38] | | 5 | DOUBLE | 8 | 双精度浮点型,有效位数15-16,范围 [-1.7E308, 1.7E308] | -| 6 | BINARY | 自定义 | 用于记录字符串,理论上,最长可以有65526字节,但由于每行数据最多64K字节,实际上限一般小于理论值。 binary仅支持字符串输入,字符串两端使用单引号引用,否则英文全部自动转化为小写。使用时须指定大小,如binary(20)定义了最长为20个字符的字符串,每个字符占1byte的存储空间。如果用户字符串超出20字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示, 即 **\’**。 | +| 6 | BINARY | 自定义 | 用于记录字符串,理论上,最长可以有16374字节,但由于每行数据最多16K字节,实际上限一般小于理论值。 binary仅支持字符串输入,字符串两端使用单引号引用,否则英文全部自动转化为小写。使用时须指定大小,如binary(20)定义了最长为20个字符的字符串,每个字符占1byte的存储空间。如果用户字符串超出20字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示, 即 **\’**。 | | 7 | SMALLINT | 2 | 短整型, 范围 [-32767, 32767], -32768用于NULL | | 8 | TINYINT | 1 | 单字节整型,范围 [-127, 127], -128用于NULL | | 9 | BOOL | 1 | 布尔型,{true, false} | @@ -106,7 +106,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic ```mysql CREATE TABLE [IF NOT EXISTS] tb_name (timestamp_field_name TIMESTAMP, field1_name data_type1 [, field2_name data_type2 ...]) ``` - 说明:1)表的第一个字段必须是TIMESTAMP,并且系统自动将其设为主键;2)表的每行长度不能超过64K字节;3)使用数据类型binary或nchar,需指定其最长的字节数,如binary(20),表示20字节。 + 说明:1)表的第一个字段必须是TIMESTAMP,并且系统自动将其设为主键;2)表的每行长度不能超过16K字节;3)使用数据类型binary或nchar,需指定其最长的字节数,如binary(20),表示20字节。 - **删除数据表** diff --git a/documentation/webdocs/markdowndocs/TAOS SQL.md b/documentation/webdocs/markdowndocs/TAOS SQL.md index 6c7f25b8f7..72e41dbec4 100644 --- a/documentation/webdocs/markdowndocs/TAOS SQL.md +++ b/documentation/webdocs/markdowndocs/TAOS SQL.md @@ -39,7 +39,7 @@ The full list of data types is listed below. For string types of data, we will | 6 | DOUBLE | 8 | A standard nullable double float type with 15-16 significant digits and a range of [-1.7E308, 1.7E308]​ | | 7 | BOOL | 1 | A nullable boolean type, [**`true`**, **`false`**] | | 8 | TIMESTAMP | 8 | A nullable timestamp type with the same usage as the primary column timestamp | -| 9 | BINARY(*M*) | *M* | A nullable string type whose length is *M*, error should be threw with exceeded chars, the maximum length of *M* is 65526, but as maximum row size is 64K bytes, the actual upper limit will generally less than 65526. This type of string only supports ASCii encoded chars. | +| 9 | BINARY(*M*) | *M* | A nullable string type whose length is *M*, error should be threw with exceeded chars, the maximum length of *M* is 16374, but as maximum row size is 16K bytes, the actual upper limit will generally less than 16374. This type of string only supports ASCii encoded chars. | | 10 | NCHAR(*M*) | 4 * *M* | A nullable string type whose length is *M*, error should be threw with exceeded chars. The **`NCHAR`** type supports Unicode encoded chars. | All the keywords in a SQL statement are case-insensitive, but strings values are case-sensitive and must be quoted by a pair of `'` or `"`. To quote a `'` or a `"` , you can use the escape character `\`. @@ -86,7 +86,7 @@ All the keywords in a SQL statement are case-insensitive, but strings values are 1) The first column must be a `timestamp`, and the system will set it as the primary key. - 2) The record size is limited to 64k bytes + 2) The record size is limited to 16k bytes 3) For `binary` or `nchar` data types, the length must be specified. For example, binary(20) means a binary data type with 20 bytes. diff --git a/src/client/inc/tscLocalMerge.h b/src/client/inc/tscLocalMerge.h index 19230e34f1..c073f40546 100644 --- a/src/client/inc/tscLocalMerge.h +++ b/src/client/inc/tscLocalMerge.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef TDENGINE_TSCSECONARYMERGE_H -#define TDENGINE_TSCSECONARYMERGE_H +#ifndef TDENGINE_TSCLOCALMERGE_H +#define TDENGINE_TSCLOCALMERGE_H #ifdef __cplusplus extern "C" { @@ -27,14 +27,7 @@ extern "C" { #include "tsclient.h" #define MAX_NUM_OF_SUBQUERY_RETRY 3 - -/* - * @version 0.1 - * @date 2018/01/05 - * @author liaohj - * management of client-side reducer for metric query - */ - + struct SQLFunctionCtx; typedef struct SLocalDataSource { @@ -60,7 +53,6 @@ typedef struct SLocalReducer { char * prevRowOfInput; tFilePage * pResultBuf; int32_t nResultBufSize; -// char * pBufForInterpo; // intermediate buffer for interpolation tFilePage * pTempBuffer; struct SQLFunctionCtx *pCtx; int32_t rowSize; // size of each intermediate result. @@ -81,13 +73,8 @@ typedef struct SLocalReducer { } SLocalReducer; typedef struct SSubqueryState { - /* - * the number of completed retrieval subquery, once this value equals to numOfVnodes, - * all retrieval are completed.Local merge is launched. - */ - int32_t numOfCompleted; - int32_t numOfTotal; // number of total sub-queries - int32_t code; // code from subqueries + int32_t numOfRemain; // the number of remain unfinished subquery + int32_t numOfTotal; // the number of total sub-queries uint64_t numOfRetrievedRows; // total number of points in this query } SSubqueryState; @@ -128,4 +115,4 @@ int32_t tscDoLocalMerge(SSqlObj *pSql); } #endif -#endif // TDENGINE_TSCSECONARYMERGE_H +#endif // TDENGINE_TSCLOCALMERGE_H diff --git a/src/client/inc/tscSubquery.h b/src/client/inc/tscSubquery.h index 368fe2250a..82d490376a 100644 --- a/src/client/inc/tscSubquery.h +++ b/src/client/inc/tscSubquery.h @@ -26,11 +26,9 @@ extern "C" { void tscFetchDatablockFromSubquery(SSqlObj* pSql); void tscSetupOutputColumnIndex(SSqlObj* pSql); -int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql); void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code); SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index); -void tscDestroyJoinSupporter(SJoinSupporter* pSupporter); int32_t tscHandleMasterJoinQuery(SSqlObj* pSql); diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 581ce00a62..d6562f008d 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -64,7 +64,8 @@ typedef struct SJoinSupporter { SSubqueryState* pState; SSqlObj* pObj; // parent SqlObj int32_t subqueryIndex; // index of sub query - int64_t interval; // interval time + int64_t intervalTime; // interval time + int64_t slidingTime; // sliding time SLimitVal limit; // limit info uint64_t uid; // query meter uid SArray* colList; // previous query information, no need to use this attribute, and the corresponding attribution diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index a9a34286a8..dc44c8ea26 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -192,7 +192,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv const char *tz1 = (*env)->GetStringUTFChars(env, optionValue, NULL); if (tz1 && strlen(tz1) != 0) { res = taos_options(TSDB_OPTION_TIMEZONE, tz1); - jniTrace("set timezone to %s, result:%d", timezone, res); + jniTrace("set timezone to %s, result:%d", tz1, res); } else { jniTrace("input timezone is empty"); } diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 0dfbf8c487..da06e3e5e2 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -32,7 +32,6 @@ int32_t tscGetNumOfTags(const STableMeta* pTableMeta) { } if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE) { - assert(tinfo.numOfTags >= 0); return tinfo.numOfTags; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 5a2054bbcd..da807b1964 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -646,10 +646,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo); pQueryMsg->numOfOutput = htons(numOfOutput); - if (numOfOutput < 0) { - tscError("%p illegal value of number of output columns in query msg: %d", pSql, numOfOutput); - return -1; - } // set column list ids size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); @@ -663,7 +659,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR) { tscError("%p sid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s", - pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex, + pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex.columnIndex, pColSchema->name); return TSDB_CODE_TSC_INVALID_SQL; @@ -783,7 +779,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { (pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR)) { tscError("%p sid:%d uid:%" PRIu64 " id:%s, tag index out of range, totalCols:%d, numOfTags:%d, index:%d, column name:%s", pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns, - pCol->colIndex, pColSchema->name); + pCol->colIndex.columnIndex, pColSchema->name); return TSDB_CODE_TSC_INVALID_SQL; } @@ -982,7 +978,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strncpy(pDropDbMsg->db, pTableMetaInfo->name, tListLen(pDropDbMsg->db)); + tstrncpy(pDropDbMsg->db, pTableMetaInfo->name, sizeof(pDropDbMsg->db)); pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0; pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DB; @@ -1052,7 +1048,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strcpy(pDropMsg->user, pTableMetaInfo->name); + tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user)); return TSDB_CODE_SUCCESS; } @@ -1812,6 +1808,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { // todo handle out of memory case if (pTableMetaInfo->pTableMeta == NULL) { + free(pTableMeta); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -2324,6 +2321,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { SQueryInfo *pNewQueryInfo = NULL; if ((code = tscGetQueryInfoDetailSafely(&pNew->cmd, 0, &pNewQueryInfo)) != TSDB_CODE_SUCCESS) { + tscFreeSqlObj(pNew); return code; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 126e34704c..b13e7b7ccf 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -584,7 +584,7 @@ char *taos_errstr(TAOS_RES *tres) { void taos_config(int debug, char *log_path) { uDebugFlag = debug; - strcpy(tsLogDir, log_path); + tstrncpy(tsLogDir, log_path, TSDB_FILENAME_LEN); } char *taos_get_server_info(TAOS *taos) { @@ -719,6 +719,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { if (sqlLen > tsMaxSQLStringLen) { tscError("%p sql too long", pSql); pRes->code = TSDB_CODE_TSC_INVALID_SQL; + tfree(pSql); return pRes->code; } @@ -727,6 +728,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); + tfree(pSql); return pRes->code; } @@ -851,6 +853,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (tblListLen > MAX_TABLE_NAME_LENGTH) { tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH); pRes->code = TSDB_CODE_TSC_INVALID_SQL; + tfree(pSql); return pRes->code; } @@ -858,6 +861,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (str == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); + tfree(pSql); return pRes->code; } @@ -873,6 +877,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { free(str); if (pRes->code != TSDB_CODE_SUCCESS) { + tscFreeSqlObj(pSql); return pRes->code; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 7ce86dc1a4..6fc934b6c0 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -125,7 +125,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { } // launch stream computing in a new thread - SSchedMsg schedMsg; + SSchedMsg schedMsg = { 0 }; schedMsg.fp = tscProcessStreamLaunchQuery; schedMsg.ahandle = pStream; schedMsg.thandle = (void *)1; @@ -239,7 +239,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf /* no resuls in the query range, retry */ // todo set retry dynamic time int32_t retry = tsProjectExecInterval; - tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retry); + tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId32 "ms", pSql, pStream, numOfRows, retry); tscSetRetryTimer(pStream, pStream->pSql, retry); return; @@ -250,7 +250,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf } } - tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d", pSql, pStream, pTableMetaInfo->name, + tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name, pStream->numOfRes); // release the metric/meter meta information reference, so data in cache can be updated diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 7e3aaf7fc5..15dc58a713 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -291,7 +291,7 @@ static int tscLoadSubscriptionProgress(SSub* pSub) { fclose(fp); taosArraySort(progress, tscCompareSubscriptionProgress); - tscTrace("subscription progress loaded, %d tables: %s", taosArrayGetSize(progress), pSub->topic); + tscTrace("subscription progress loaded, %z tables: %s", taosArrayGetSize(progress), pSub->topic); return 1; } @@ -350,7 +350,7 @@ TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char pSub->interval = interval; if (fp != NULL) { - tscTrace("asynchronize subscription, create new timer", topic); + tscTrace("asynchronize subscription, create new timer: %s", topic); pSub->fp = fp; pSub->param = param; taosTmrReset(tscProcessSubscriptionTimer, interval, pSub, tscTmr, &pSub->pTimer); @@ -435,7 +435,9 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { } else { char path[256]; sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic); - remove(path); + if (remove(path) != 0) { + tscError("failed to remove progress file, topic = %s, error = %s", pSub->topic, strerror(errno)); + } } tscFreeSqlObj(pSub->pSql); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 4e02325be6..b0a66701c5 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -12,12 +12,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +#include "os.h" #include "tscSubquery.h" -#include -#include -#include -#include "os.h" +#include "qast.h" +#include "tcompare.h" +#include "tschemautil.h" #include "qtsbuf.h" #include "tscLog.h" #include "tsclient.h" @@ -169,7 +169,8 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in pSupporter->subqueryIndex = index; SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex); - pSupporter->interval = pQueryInfo->intervalTime; + pSupporter->intervalTime = pQueryInfo->intervalTime; + pSupporter->slidingTime = pQueryInfo->slidingTime; pSupporter->limit = pQueryInfo->limit; STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, index); @@ -186,7 +187,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in return pSupporter; } -void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { +static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { if (pSupporter == NULL) { return; } @@ -217,7 +218,7 @@ void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { * primary timestamp column , the secondary query is not necessary * */ -bool needSecondaryQuery(SQueryInfo* pQueryInfo) { +static UNUSED_FUNC bool needSecondaryQuery(SQueryInfo* pQueryInfo) { size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); for (int32_t i = 0; i < numOfCols; ++i) { @@ -233,14 +234,11 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) { /* * launch secondary stage query to fetch the result that contains timestamp in set */ -int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { +static int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { int32_t numOfSub = 0; SJoinSupporter* pSupporter = NULL; - /* - * If the columns are not involved in the final select clause, - * the corresponding query will not be issued. - */ + //If the columns are not involved in the final select clause, the corresponding query will not be issued. for (int32_t i = 0; i < pSql->numOfSubs; ++i) { pSupporter = pSql->pSubs[i]->param; if (taosArrayGetSize(pSupporter->exprList) > 0) { @@ -251,13 +249,12 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { assert(numOfSub > 0); // scan all subquery, if one sub query has only ts, ignore it - tscTrace("%p start to launch secondary subquery, total:%d, only:%d needs to query, others are not retrieve in " - "select clause", pSql, pSql->numOfSubs, numOfSub); + tscTrace("%p start to launch secondary subquery, total:%d, only:%d needs to query", pSql, pSql->numOfSubs, numOfSub); //the subqueries that do not actually launch the secondary query to virtual node is set as completed. SSubqueryState* pState = pSupporter->pState; pState->numOfTotal = pSql->numOfSubs; - pState->numOfCompleted = (pSql->numOfSubs - numOfSub); + pState->numOfRemain = numOfSub; bool success = true; @@ -301,7 +298,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { // set the second stage sub query for join process TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE); - pQueryInfo->intervalTime = pSupporter->interval; + pQueryInfo->intervalTime = pSupporter->intervalTime; + pQueryInfo->slidingTime = pSupporter->slidingTime; pQueryInfo->groupbyExpr = pSupporter->groupbyExpr; tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond); @@ -356,7 +354,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { } size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList); - tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s", + tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z, fieldsInfo:%d, name:%s", pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, taosArrayGetSize(pNewQueryInfo->exprList), numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name); } @@ -375,6 +373,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { if (pSql->pSubs[i] == NULL) { continue; } + tscDoQuery(pSql->pSubs[i]); } @@ -405,11 +404,9 @@ void freeJoinSubqueryObj(SSqlObj* pSql) { } static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) { - int32_t numOfTotal = pSupporter->pState->numOfTotal; - int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); - - pSqlObj->res.code = pSupporter->pState->code; - if (finished >= numOfTotal) { + assert(pSupporter->pState->numOfRemain > 0); + + if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) <= 0) { tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code); freeJoinSubqueryObj(pSqlObj); } @@ -421,7 +418,7 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, STimeWindow* win) { pQueryInfo->window = *win; } -static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* pSql) { +static UNUSED_FUNC void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* pSql) { SSqlObj* pParentSql = pSupporter->pObj; SQueryInfo* pParentQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex); @@ -443,22 +440,7 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* // return; // } // } - - int32_t numOfTotal = pSupporter->pState->numOfTotal; - int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); - - if (finished >= numOfTotal) { - assert(finished == numOfTotal); - - if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { - tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, pSql, - pSupporter->subqueryIndex); - freeJoinSubqueryObj(pParentSql); - return; - } - - tscTrace("%p all subqueries retrieve ts complete, do ts block intersect", pParentSql); - + SJoinSupporter* p1 = pParentSql->pSubs[0]->param; SJoinSupporter* p2 = pParentSql->pSubs[1]->param; @@ -471,7 +453,6 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* updateQueryTimeRange(pParentQueryInfo, &win); tscLaunchSecondPhaseSubqueries(pParentSql); } - } } int32_t tscCompareTidTags(const void* p1, const void* p2) { @@ -545,11 +526,13 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj* tscAddSpecialColumnForSelect(pQueryInfo, 0, TSDB_FUNC_TS_COMP, &index, &colSchema, TSDB_COL_NORMAL); // set the tags value for ts_comp function - SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0); - int16_t tagColId = tscGetJoinTagColIdByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid); - pExpr->param->i64Key = tagColId; - pExpr->numOfParams = 1; - + if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0); + int16_t tagColId = tscGetJoinTagColIdByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid); + pExpr->param->i64Key = tagColId; + pExpr->numOfParams = 1; + } + // add the filter tag column if (pSupporter->colList != NULL) { size_t s = taosArrayGetSize(pSupporter->colList); @@ -568,14 +551,14 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj* tscTrace( "%p subquery:%p tableIndex:%d, vgroupIndex:%d, numOfVgroups:%d, type:%d, ts_comp query to retrieve timestamps, " - "numOfExpr:%d, colList:%d, numOfOutputFields:%d, name:%s", + "numOfExpr:%z, colList:%z, numOfOutputFields:%d, name:%s", pParent, pSql, 0, pTableMetaInfo->vgroupIndex, pTableMetaInfo->vgroupList->numOfVgroups, pQueryInfo->type, tscSqlExprNumOfExprs(pQueryInfo), numOfCols, pQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name); tscProcessSql(pSql); } -static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, void* pSql) { +static bool checkForDuplicateTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, SSqlObj* pPSqlObj) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);// todo: tags mismatch, tags not completed @@ -587,8 +570,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, STidTags* p = (STidTags*) varDataVal(p1->pIdTagList + i * p1->tagSize); if (doCompare(prev->tag, p->tag, pColSchema->type, pColSchema->bytes) == 0) { - tscError("%p join tags have same value for different table, free all sub SqlObj and quit", pSql); - p1->pState->code = TSDB_CODE_QRY_DUP_JOIN_KEY; + tscError("%p join tags have same value for different table, free all sub SqlObj and quit", pPSqlObj); + pPSqlObj->res.code = TSDB_CODE_QRY_DUP_JOIN_KEY; return false; } } @@ -596,8 +579,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, return true; } -static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) { - tscTrace("%p all subqueries retrieve tags complete, do tags match", pParentSql); +static void getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) { + tscTrace("%p all subqueries retrieve complete, do tags match", pParentSql); SJoinSupporter* p1 = pParentSql->pSubs[0]->param; SJoinSupporter* p2 = pParentSql->pSubs[1]->param; @@ -613,7 +596,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, *s1 = taosArrayInit(p1->num, p1->tagSize); *s2 = taosArrayInit(p2->num, p2->tagSize); - if (!(checkForIdenticalTagVal(pQueryInfo, p1, pParentSql) && checkForIdenticalTagVal(pQueryInfo, p2, pParentSql))) { + if (!(checkForDuplicateTagVal(pQueryInfo, p1, pParentSql) && checkForDuplicateTagVal(pQueryInfo, p2, pParentSql))) { freeJoinSubqueryObj(pParentSql); pParentSql->res.code = TSDB_CODE_QRY_DUP_JOIN_KEY; tscQueueAsyncRes(pParentSql); @@ -642,7 +625,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, } } -static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { +static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) { SJoinSupporter* pSupporter = (SJoinSupporter*)param; SSqlObj* pParentSql = pSupporter->pObj; @@ -652,239 +635,290 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { SSqlRes* pRes = &pSql->res; SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); + assert(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)); - // response of tag retrieve - if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) { - // todo handle error + // check for the error code firstly + if (taos_errno(pSql) != TSDB_CODE_SUCCESS) { + // todo retry if other subqueries are not failed - if (numOfRows == 0 || pRes->completed) { - if (numOfRows > 0) { - size_t validLen = pSupporter->tagSize * pRes->numOfRows; + assert(numOfRows < 0 && numOfRows == taos_errno(pSql)); + tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex); - size_t length = pSupporter->totalLen + validLen; - char* tmp = realloc(pSupporter->pIdTagList, length); - assert(tmp != NULL); - pSupporter->pIdTagList = tmp; - - memcpy(pSupporter->pIdTagList + pSupporter->totalLen,pRes->data, validLen); - pSupporter->totalLen += validLen; - pSupporter->num += pRes->numOfRows; - } - - // tuples have been retrieved to client, try tuples from the next vnode - if (hasMoreVnodesToTry(pSql)) { - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; - pTableMetaInfo->vgroupIndex += 1; - assert(pTableMetaInfo->vgroupIndex < totalVgroups); - - tscTrace("%p tid_tag from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d", - pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, - pSupporter->num); - - pCmd->command = TSDB_SQL_SELECT; - tscResetForNextRetrieve(&pSql->res); - - // set the callback function - pSql->fp = tscJoinQueryCallback; - tscProcessSql(pSql); - return; - } - - int32_t numOfTotal = pSupporter->pState->numOfTotal; - int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); - if (finished < numOfTotal) { - return; - } - - // all subquery are returned, start to compare the tags - assert(finished == numOfTotal); - - SArray *s1 = NULL, *s2 = NULL; - getIntersectionOfTagVal(pQueryInfo, pParentSql, &s1, &s2); - - if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return. - tscTrace("%p free all sub SqlObj and quit", pParentSql); - freeJoinSubqueryObj(pParentSql); - return; - } else { - SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd; - SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd; - - SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0); - STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0); - tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1); - - SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0); - STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0); - tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2); - - pSupporter->pState->numOfCompleted = 0; - pSupporter->pState->code = 0; - pSupporter->pState->numOfTotal = 2; - - for (int32_t m = 0; m < pParentSql->numOfSubs; ++m) { - SSqlObj* psub = pParentSql->pSubs[m]; - issueTSCompQuery(psub, psub->param, pParentSql); - } - } - - } else { - if (numOfRows < 0) { // error - pSupporter->pState->code = numOfRows; - quitAllSubquery(pParentSql, pSupporter); - - pParentSql->res.code = numOfRows; - tscQueueAsyncRes(pParentSql); - return; - } - - size_t length = pSupporter->totalLen + pRes->rspLen; - assert(length > 0); - - char* tmp = realloc(pSupporter->pIdTagList, length); - assert(tmp != NULL); - - pSupporter->pIdTagList = tmp; - - memcpy(pSupporter->pIdTagList, pRes->data, pRes->rspLen); - pSupporter->totalLen += pRes->rspLen; - pSupporter->num += pRes->numOfRows; - - // continue retrieve data from vnode - taos_fetch_rows_a(tres, joinRetrieveCallback, param); - } + pParentSql->res.code = numOfRows; + quitAllSubquery(pParentSql, pSupporter); + tscQueueAsyncRes(pParentSql); return; } - if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) { - if (numOfRows < 0) { - tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex); - pSupporter->pState->code = numOfRows; + // keep the results in memory + if (numOfRows > 0) { + size_t validLen = pSupporter->tagSize * pRes->numOfRows; + size_t length = pSupporter->totalLen + validLen; + + // todo handle memory error + char* tmp = realloc(pSupporter->pIdTagList, length); + if (tmp == NULL) { + tscError("%p failed to malloc memory", pSql); + + pParentSql->res.code = TAOS_SYSTEM_ERROR(errno); quitAllSubquery(pParentSql, pSupporter); + + tscQueueAsyncRes(pParentSql); return; } - if (numOfRows > 0) { // write the compressed timestamp to disk file - fwrite(pRes->data, pRes->numOfRows, 1, pSupporter->f); - fclose(pSupporter->f); - pSupporter->f = NULL; + pSupporter->pIdTagList = tmp; - STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true); - if (pBuf == NULL) { // in error process, close the fd - tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows); + memcpy(pSupporter->pIdTagList + pSupporter->totalLen, pRes->data, validLen); + pSupporter->totalLen += validLen; + pSupporter->num += pRes->numOfRows; - pSupporter->pState->code = TSDB_CODE_TSC_APP_ERROR; // todo set the informative code - quitAllSubquery(pParentSql, pSupporter); - return; - } + // query not completed, continue to retrieve tid + tag tuples + if (!pRes->completed) { + taos_fetch_rows_a(tres, tidTagRetrieveCallback, param); + return; + } + } - if (pSupporter->pTSBuf == NULL) { - tscTrace("%p create tmp file for ts block:%s, size:%d bytes", pSql, pBuf->path, numOfRows); - pSupporter->pTSBuf = pBuf; - } else { - assert(pQueryInfo->numOfTables == 1); // for subquery, only one - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + // data in current vnode has all returned to client, try next vnode if exits + // tuples have been retrieved to client, try tuples from the next vnode + if (hasMoreVnodesToTry(pSql)) { + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex); - tsBufDestory(pBuf); - } + int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; + pTableMetaInfo->vgroupIndex += 1; + assert(pTableMetaInfo->vgroupIndex < totalVgroups); + + tscTrace("%p tid_tag from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d", + pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pSupporter->num); + + pCmd->command = TSDB_SQL_SELECT; + tscResetForNextRetrieve(&pSql->res); + + // set the callback function + pSql->fp = tscJoinQueryCallback; + tscProcessSql(pSql); + return; + } + + // no data exists in next vnode, mark the query completed + // only when there is no subquery exits any more, proceeds to get the intersect of the tuple sets. + if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) > 0) { + return; + } + + SArray *s1 = NULL, *s2 = NULL; + getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2); + if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return. + tscTrace("%p free all sub SqlObj and quit", pParentSql); + freeJoinSubqueryObj(pParentSql); + + } else { + // proceed to for ts_comp query + SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd; + SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd; + + SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0); + STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0); + tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1); + + SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0); + STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0); + tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2); + + pSupporter->pState->numOfTotal = 2; + pSupporter->pState->numOfRemain = pSupporter->pState->numOfTotal; + + for (int32_t m = 0; m < pParentSql->numOfSubs; ++m) { + SSqlObj* sub = pParentSql->pSubs[m]; + issueTSCompQuery(sub, sub->param, pParentSql); + } + } + + taosArrayDestroy(s1); + taosArrayDestroy(s2); +} + +static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) { + SJoinSupporter* pSupporter = (SJoinSupporter*)param; + + SSqlObj* pParentSql = pSupporter->pObj; + + SSqlObj* pSql = (SSqlObj*)tres; + SSqlCmd* pCmd = &pSql->cmd; + SSqlRes* pRes = &pSql->res; + + SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); + assert(!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)); + + // check for the error code firstly + if (taos_errno(pSql) != TSDB_CODE_SUCCESS) { + // todo retry if other subqueries are not failed yet + assert(numOfRows < 0 && numOfRows == taos_errno(pSql)); + tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex); + + pParentSql->res.code = numOfRows; + quitAllSubquery(pParentSql, pSupporter); + + tscQueueAsyncRes(pParentSql); + return; + } + + if (numOfRows > 0) { // write the compressed timestamp to disk file + fwrite(pRes->data, pRes->numOfRows, 1, pSupporter->f); + fclose(pSupporter->f); + pSupporter->f = NULL; + + STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true); + if (pBuf == NULL) { // in error process, close the fd + tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows); + + pParentSql->res.code = TAOS_SYSTEM_ERROR(errno); + tscQueueAsyncRes(pParentSql); + + return; } - if (pRes->completed) { - if (hasMoreVnodesToTry(pSql)) { - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + if (pSupporter->pTSBuf == NULL) { + tscTrace("%p create tmp file for ts block:%s, size:%d bytes", pSql, pBuf->path, numOfRows); + pSupporter->pTSBuf = pBuf; + } else { + assert(pQueryInfo->numOfTables == 1); // for subquery, only one + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; - pTableMetaInfo->vgroupIndex += 1; - assert(pTableMetaInfo->vgroupIndex < totalVgroups); + tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex); + tsBufDestory(pBuf); + } - tscTrace("%p results from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d", - pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, - pRes->numOfClauseTotal); - - pCmd->command = TSDB_SQL_SELECT; - tscResetForNextRetrieve(&pSql->res); - - assert(pSupporter->f == NULL); - getTmpfilePath("ts-join", pSupporter->path); - pSupporter->f = fopen(pSupporter->path, "w"); - pRes->row = pRes->numOfRows; - - // set the callback function - pSql->fp = tscJoinQueryCallback; - tscProcessSql(pSql); - return; - } else { - tSIntersectionAndLaunchSecQuery(pSupporter, pSql); - } - - } else { // open a new file to save the incoming result + // continue to retrieve ts-comp data from vnode + if (!pRes->completed) { getTmpfilePath("ts-join", pSupporter->path); pSupporter->f = fopen(pSupporter->path, "w"); pRes->row = pRes->numOfRows; - taos_fetch_rows_a(tres, joinRetrieveCallback, param); - } - } else { // secondary stage retrieve, driven by taos_fetch_row or other functions - if (numOfRows < 0) { - pSupporter->pState->code = numOfRows; - tscError("%p retrieve failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex); - } - - if (numOfRows >= 0) { - pRes->numOfTotal += pRes->numOfRows; - } - - if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) { - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - assert(pQueryInfo->numOfTables == 1); - - // for projection query, need to try next vnode if current vnode is exhausted - if ((++pTableMetaInfo->vgroupIndex) < pTableMetaInfo->vgroupList->numOfVgroups) { - pSupporter->pState->numOfCompleted = 0; - pSupporter->pState->numOfTotal = 1; - - pSql->cmd.command = TSDB_SQL_SELECT; - pSql->fp = tscJoinQueryCallback; - tscProcessSql(pSql); - - return; - } - } - - int32_t numOfTotal = pSupporter->pState->numOfTotal; - int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); - - if (finished >= numOfTotal) { - assert(finished == numOfTotal); - tscTrace("%p all %d secondary subquery retrieves completed, global code:%d", tres, numOfTotal, - pParentSql->res.code); - - if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { - pParentSql->res.code = pSupporter->pState->code; - freeJoinSubqueryObj(pParentSql); - pParentSql->res.completed = true; - } - - // update the records for each subquery in parent sql object. - for (int32_t i = 0; i < pParentSql->numOfSubs; ++i) { - if (pParentSql->pSubs[i] == NULL) { - continue; - } - - SSqlRes* pRes1 = &pParentSql->pSubs[i]->res; - pRes1->numOfClauseTotal += pRes1->numOfRows; - } - - // data has retrieved to client, build the join results - tscBuildResFromSubqueries(pParentSql); - } else { - tscTrace("%p sub:%p completed, completed:%d, total:%d", pParentSql, tres, finished, numOfTotal); + taos_fetch_rows_a(tres, tsCompRetrieveCallback, param); + return; } } + + if (hasMoreVnodesToTry(pSql)) { + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + + int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; + pTableMetaInfo->vgroupIndex += 1; + assert(pTableMetaInfo->vgroupIndex < totalVgroups); + + tscTrace("%p results from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d", + pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, + pRes->numOfClauseTotal); + + pCmd->command = TSDB_SQL_SELECT; + tscResetForNextRetrieve(&pSql->res); + + assert(pSupporter->f == NULL); + getTmpfilePath("ts-join", pSupporter->path); + + // TODO check for failure + pSupporter->f = fopen(pSupporter->path, "w"); + pRes->row = pRes->numOfRows; + + // set the callback function + pSql->fp = tscJoinQueryCallback; + tscProcessSql(pSql); + return; + } + + if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) > 0) { + return; + } + + tscTrace("%p all subquery retrieve ts complete, do ts block intersect", pParentSql); + + // proceeds to launched secondary query to retrieve final data + SJoinSupporter* p1 = pParentSql->pSubs[0]->param; + SJoinSupporter* p2 = pParentSql->pSubs[1]->param; + + STimeWindow win = TSWINDOW_INITIALIZER; + int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &win); + if (num <= 0) { // no result during ts intersect + tscTrace("%p no results generated in ts intersection, free all sub SqlObj and quit", pParentSql); + freeJoinSubqueryObj(pParentSql); + + return; + } + + // launch the query the retrieve actual results from vnode along with the filtered timestamp + SQueryInfo* pPQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex); + updateQueryTimeRange(pPQueryInfo, &win); + tscLaunchSecondPhaseSubqueries(pParentSql); +} + +static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfRows) { + SJoinSupporter* pSupporter = (SJoinSupporter*)param; + + SSqlObj* pParentSql = pSupporter->pObj; + SSubqueryState* pState = pSupporter->pState; + + SSqlObj* pSql = (SSqlObj*)tres; + SSqlCmd* pCmd = &pSql->cmd; + SSqlRes* pRes = &pSql->res; + + SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); + + // TODO put to async res? + if (taos_errno(pSql) != TSDB_CODE_SUCCESS) { + assert(numOfRows == taos_errno(pSql)); + + pParentSql->res.code = numOfRows; + tscError("%p retrieve failed, index:%d, code:%s", pSql, pSupporter->subqueryIndex, tstrerror(numOfRows)); + } + + if (numOfRows >= 0) { + pRes->numOfTotal += pRes->numOfRows; + } + + if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) { + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + assert(pQueryInfo->numOfTables == 1); + + // for projection query, need to try next vnode if current vnode is exhausted + if ((++pTableMetaInfo->vgroupIndex) < pTableMetaInfo->vgroupList->numOfVgroups) { + pState->numOfRemain = 1; + pState->numOfTotal = 1; + + pSql->cmd.command = TSDB_SQL_SELECT; + pSql->fp = tscJoinQueryCallback; + tscProcessSql(pSql); + + return; + } + } + + if (atomic_sub_fetch_32(&pState->numOfRemain, 1) > 0) { + tscTrace("%p sub:%p completed, remain:%d, total:%d", pParentSql, tres, pState->numOfRemain, pState->numOfTotal); + return; + } + + tscTrace("%p all %d secondary subqueries retrieval completed, code:%d", tres, pState->numOfTotal, pParentSql->res.code); + + if (pParentSql->res.code != TSDB_CODE_SUCCESS) { + freeJoinSubqueryObj(pParentSql); + pParentSql->res.completed = true; + } + + // update the records for each subquery in parent sql object. + for (int32_t i = 0; i < pParentSql->numOfSubs; ++i) { + if (pParentSql->pSubs[i] == NULL) { + continue; + } + + SSqlRes* pRes1 = &pParentSql->pSubs[i]->res; + pRes1->numOfClauseTotal += pRes1->numOfRows; + } + + // data has retrieved to client, build the join results + tscBuildResFromSubqueries(pParentSql); } static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch) { @@ -902,7 +936,7 @@ static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch } pState->numOfTotal = pSql->numOfSubs; - pState->numOfCompleted = pSql->numOfSubs - numOfFetch; + pState->numOfRemain = numOfFetch; return pSupporter; } @@ -990,7 +1024,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) { pSupporter->subqueryIndex, pTableMetaInfo->vgroupIndex); tscResetForNextRetrieve(pRes1); - pSql1->fp = joinRetrieveCallback; + pSql1->fp = joinRetrieveFinalResCallback; if (pCmd1->command < TSDB_SQL_LOCAL) { pCmd1->command = (pCmd1->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; @@ -1008,8 +1042,9 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { tscTrace("%p all subquery response, retrieve data", pSql); + // the column transfer support struct has been built if (pRes->pColumnIndex != NULL) { - return; // the column transfer support struct has been built + return; } SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); @@ -1045,68 +1080,76 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) { void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) { SSqlObj* pSql = (SSqlObj*)tres; - + SJoinSupporter* pSupporter = (SJoinSupporter*)param; - + SSqlObj* pParentSql = pSupporter->pObj; + // There is only one subquery and table for each subquery. SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); assert(pQueryInfo->numOfTables == 1 && pSql->cmd.numOfClause == 1); - + + // retrieve actual query results from vnode during the second stage join subquery + if (pParentSql->res.code != TSDB_CODE_SUCCESS) { + tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, code, pParentSql->res.code); + quitAllSubquery(pParentSql, pSupporter); + tscQueueAsyncRes(pParentSql); + + return; + } + + // TODO here retry is required, not directly returns to client + if (taos_errno(pSql) != TSDB_CODE_SUCCESS) { + assert(taos_errno(pSql) == code); + + tscError("%p abort query, code:%d, global code:%d", pSql, code, pParentSql->res.code); + pParentSql->res.code = code; + + quitAllSubquery(pParentSql, pSupporter); + tscQueueAsyncRes(pParentSql); + + return; + } + + // retrieve tuples from vnode + if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) { + pSql->fp = tidTagRetrieveCallback; + pSql->cmd.command = TSDB_SQL_FETCH; + tscProcessSql(pSql); + return; + } + + // retrieve ts_comp info from vnode if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) { - if (code != TSDB_CODE_SUCCESS) { // direct call joinRetrieveCallback and set the error code - joinRetrieveCallback(param, pSql, code); - } else { // first stage query, continue to retrieve compressed time stamp data - pSql->fp = joinRetrieveCallback; - pSql->cmd.command = TSDB_SQL_FETCH; - tscProcessSql(pSql); - } + pSql->fp = tsCompRetrieveCallback; + pSql->cmd.command = TSDB_SQL_FETCH; + tscProcessSql(pSql); + return; + } - } else { // second stage join subquery - SSqlObj* pParentSql = pSupporter->pObj; + // wait for the other subqueries response from vnode + if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) > 0) { + return; + } - if (pSupporter->pState->code != TSDB_CODE_SUCCESS) { - tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, code, - pSupporter->pState->code); - quitAllSubquery(pParentSql, pSupporter); + tscSetupOutputColumnIndex(pParentSql); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - return; - } + /** + * if the query is a continue query (vgroupIndex > 0 for projection query) for next vnode, do the retrieval of + * data instead of returning to its invoker + */ + if (pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { + pSupporter->pState->numOfRemain = pSupporter->pState->numOfTotal; // reset the record value - if (code != TSDB_CODE_SUCCESS) { - tscError("%p sub query failed, code:%s, set global code:%s, index:%d", pSql, tstrerror(code), tstrerror(code), - pSupporter->subqueryIndex); - - pSupporter->pState->code = code; - quitAllSubquery(pParentSql, pSupporter); + pSql->fp = joinRetrieveFinalResCallback; // continue retrieve data + pSql->cmd.command = TSDB_SQL_FETCH; + tscProcessSql(pSql); + } else { // first retrieve from vnode during the secondary stage sub-query + // set the command flag must be after the semaphore been correctly set. + if (pParentSql->res.code == TSDB_CODE_SUCCESS) { + (*pParentSql->fp)(pParentSql->param, pParentSql, 0); } else { - int32_t numOfTotal = pSupporter->pState->numOfTotal; - int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1); - - if (finished >= numOfTotal) { - assert(finished == numOfTotal); - - tscSetupOutputColumnIndex(pParentSql); - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - /** - * if the query is a continue query (vgroupIndex > 0 for projection query) for next vnode, do the retrieval of - * data instead of returning to its invoker - */ - if (pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { - pSupporter->pState->numOfCompleted = 0; // reset the record value - - pSql->fp = joinRetrieveCallback; // continue retrieve data - pSql->cmd.command = TSDB_SQL_FETCH; - tscProcessSql(pSql); - } else { // first retrieve from vnode during the secondary stage sub-query - // set the command flag must be after the semaphore been correctly set. - if (pParentSql->res.code == TSDB_CODE_SUCCESS) { - (*pParentSql->fp)(pParentSql->param, pParentSql, 0); - } else { - tscQueueAsyncRes(pParentSql); - } - } - } + tscQueueAsyncRes(pParentSql); } } } @@ -1202,7 +1245,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter tscTrace( "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to tid_tag query to retrieve (tableId, tags), " - "exprInfo:%d, colList:%d, fieldsInfo:%d, tagIndex:%d, name:%s", + "exprInfo:%z, colList:%z, fieldsInfo:%d, tagIndex:%d, name:%s", pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, index.columnIndex, pNewQueryInfo->pTableMetaInfo[0]->name); } else { @@ -1236,8 +1279,8 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList); tscTrace( - "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to ts_comp query to retrieve timestamps, " - "exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s", + "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%u, transfer to ts_comp query to retrieve timestamps, " + "exprInfo:%z, colList:%z, fieldsInfo:%d, name:%s", pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name); } @@ -1257,14 +1300,15 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); pState->numOfTotal = pQueryInfo->numOfTables; - + pState->numOfRemain = pState->numOfTotal; + tscTrace("%p start launch subquery, total:%d", pSql, pQueryInfo->numOfTables); for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i); if (pSupporter == NULL) { // failed to create support struct, abort current query tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); - pState->numOfCompleted = pQueryInfo->numOfTables - i - 1; + pState->numOfRemain = i; pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pSql->res.code; @@ -1342,6 +1386,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { tscTrace("%p retrieved query data from %d vnode(s)", pSql, pSql->numOfSubs); SSubqueryState *pState = calloc(1, sizeof(SSubqueryState)); pState->numOfTotal = pSql->numOfSubs; + pState->numOfRemain = pSql->numOfSubs; + pRes->code = TSDB_CODE_SUCCESS; int32_t i = 0; @@ -1436,7 +1482,7 @@ static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) { static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows); static void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numOfRows); -static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES *tres, int32_t errCode) { +static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES *tres, int32_t code) { // set no disk space error info #ifdef WINDOWS LPVOID lpMsgBuf; @@ -1448,44 +1494,44 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES #else tscError("sub:%p failed to flush data to disk:reason:%s", tres, strerror(errno)); #endif - - trsupport->pState->code = -errCode; + + SSqlObj* pParentSql = trsupport->pParentSqlObj; + + pParentSql->res.code = code; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; pthread_mutex_unlock(&trsupport->queryMutex); - tscHandleSubqueryError(trsupport, tres, trsupport->pState->code); + tscHandleSubqueryError(trsupport, tres, pParentSql->res.code); } void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numOfRows) { - SSqlObj *pPObj = trsupport->pParentSqlObj; + SSqlObj *pParentSql = trsupport->pParentSqlObj; int32_t subqueryIndex = trsupport->subqueryIndex; assert(pSql != NULL); SSubqueryState* pState = trsupport->pState; - assert(pState->numOfCompleted < pState->numOfTotal && pState->numOfCompleted >= 0 && - pPObj->numOfSubs == pState->numOfTotal); + assert(pState->numOfRemain <= pState->numOfTotal && pState->numOfRemain >= 0 && pParentSql->numOfSubs == pState->numOfTotal); // retrieved in subquery failed. OR query cancelled in retrieve phase. - if (pState->code == TSDB_CODE_SUCCESS && pPObj->res.code != TSDB_CODE_SUCCESS) { - pState->code = pPObj->res.code; - + if (taos_errno(pSql) == TSDB_CODE_SUCCESS && pParentSql->res.code != TSDB_CODE_SUCCESS) { + /* * kill current sub-query connection, which may retrieve data from vnodes; * Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED */ pSql->res.numOfRows = 0; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts - tscTrace("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d", trsupport->pParentSqlObj, pSql, - subqueryIndex, pState->code); + tscTrace("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d", pParentSql, pSql, + subqueryIndex, pParentSql->res.code); } if (numOfRows >= 0) { // current query is successful, but other sub query failed, still abort current query. - tscTrace("%p sub:%p retrieve numOfRows:%d,orderOfSub:%d", pPObj, pSql, numOfRows, subqueryIndex); - tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d", pPObj, pSql, - subqueryIndex, pState->code); + tscTrace("%p sub:%p retrieve numOfRows:%d,orderOfSub:%d", pParentSql, pSql, numOfRows, subqueryIndex); + tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d", pParentSql, pSql, + subqueryIndex, pParentSql->res.code); } else { - if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pState->code == TSDB_CODE_SUCCESS) { + if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) { /* * current query failed, and the retry count is less than the available * count, retry query clear previous retrieved data, then launch a new sub query @@ -1503,8 +1549,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO if (pNew == NULL) { tscError("%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry", trsupport->pParentSqlObj, pSql); - - pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY; + + pParentSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; return; } @@ -1512,24 +1558,24 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO tscProcessSql(pNew); return; } else { // reach the maximum retry count, abort - atomic_val_compare_exchange_32(&pState->code, TSDB_CODE_SUCCESS, numOfRows); - tscError("%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s", pPObj, pSql, - tstrerror(numOfRows), subqueryIndex, tstrerror(pState->code)); + atomic_val_compare_exchange_32(&pParentSql->res.code, TSDB_CODE_SUCCESS, numOfRows); + tscError("%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s", pParentSql, pSql, + tstrerror(numOfRows), subqueryIndex, tstrerror(pParentSql->res.code)); } } - - int32_t numOfTotal = pState->numOfTotal; - - int32_t finished = atomic_add_fetch_32(&pState->numOfCompleted, 1); - if (finished < numOfTotal) { - tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pPObj, pSql, trsupport->subqueryIndex, finished); + + int32_t remain = -1; + if ((remain = atomic_sub_fetch_32(&pState->numOfRemain, 1)) > 0) { + tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pParentSql, pSql, trsupport->subqueryIndex, + pState->numOfTotal - remain); + return tscFreeSubSqlObj(trsupport, pSql); } // all subqueries are failed - tscError("%p retrieve from %d vnode(s) completed,code:%s.FAILED.", pPObj, pState->numOfTotal, tstrerror(pState->code)); - pPObj->res.code = pState->code; - + tscError("%p retrieve from %d vnode(s) completed,code:%s.FAILED.", pParentSql, pState->numOfTotal, + tstrerror(pParentSql->res.code)); + // release allocated resource tscLocalReducerEnvDestroy(trsupport->pExtMemBuffer, trsupport->pOrderDescriptor, trsupport->pFinalColModel, pState->numOfTotal); @@ -1538,13 +1584,13 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO tscFreeSubSqlObj(trsupport, pSql); // in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes - SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pPObj->cmd, 0); + SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, 0); if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) { - (*pPObj->fp)(pPObj->param, pPObj, pPObj->res.code); + (*pParentSql->fp)(pParentSql->param, pParentSql, pParentSql->res.code); } else { // regular super table query - if (pPObj->res.code != TSDB_CODE_SUCCESS) { - tscQueueAsyncRes(pPObj); + if (pParentSql->res.code != TSDB_CODE_SUCCESS) { + tscQueueAsyncRes(pParentSql); } } } @@ -1590,14 +1636,11 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE); } - // keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion - // increases the finished value up to pState->numOfTotal value, which means all subqueries are completed. - // In this case, the comparsion between finished value and released pState->numOfTotal is not safe. - int32_t numOfTotal = pState->numOfTotal; - - int32_t finished = atomic_add_fetch_32(&pState->numOfCompleted, 1); - if (finished < numOfTotal) { - tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pPObj, pSql, trsupport->subqueryIndex, finished); + int32_t remain = -1; + if ((remain = atomic_sub_fetch_32(&pState->numOfRemain, 1)) > 0) { + tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pPObj, pSql, trsupport->subqueryIndex, + pState->numOfTotal - remain); + return tscFreeSubSqlObj(trsupport, pSql); } @@ -1632,10 +1675,10 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) { SRetrieveSupport *trsupport = (SRetrieveSupport *)param; - int32_t idx = trsupport->subqueryIndex; - SSqlObj * pPObj = trsupport->pParentSqlObj; tOrderDescriptor *pDesc = trsupport->pOrderDescriptor; - + int32_t idx = trsupport->subqueryIndex; + SSqlObj * pPObj = trsupport->pParentSqlObj; + SSqlObj *pSql = (SSqlObj *)tres; if (pSql == NULL) { // sql object has been released in error process, return immediately tscTrace("%p subquery has been released, idx:%d, abort", pPObj, idx); @@ -1643,13 +1686,12 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR } SSubqueryState* pState = trsupport->pState; - assert(pState->numOfCompleted < pState->numOfTotal && pState->numOfCompleted >= 0 && - pPObj->numOfSubs == pState->numOfTotal); + assert(pState->numOfRemain <= pState->numOfTotal && pState->numOfRemain >= 0 && pPObj->numOfSubs == pState->numOfTotal); // query process and cancel query process may execute at the same time pthread_mutex_lock(&trsupport->queryMutex); - if (numOfRows < 0 || pState->code < 0 || pPObj->res.code != TSDB_CODE_SUCCESS) { + if (numOfRows < 0 || pPObj->res.code != TSDB_CODE_SUCCESS) { return tscHandleSubqueryError(trsupport, pSql, numOfRows); } @@ -1660,11 +1702,11 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR assert(pRes->numOfRows == numOfRows); int64_t num = atomic_add_fetch_64(&pState->numOfRetrievedRows, numOfRows); - tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%s, orderOfSub:%d", pPObj, pSql, + tscTrace("%p sub:%p retrieve numOfRows:%" PRId64 " totalNumOfRows:%" PRIu64 " from ip:%s, orderOfSub:%d", pPObj, pSql, pRes->numOfRows, pState->numOfRetrievedRows, pSql->ipList.fqdn[pSql->ipList.inUse], idx); if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { - tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64, + tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId32 " , current:%" PRId64, pPObj, pSql, tsMaxNumOfOrderedResults, num); tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_SORTED_RES_TOO_MANY); return; @@ -1689,6 +1731,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR pRes->numOfRows, pQueryInfo->groupbyExpr.orderType); if (ret < 0) { // set no disk space error info, and abort retry tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); + pthread_mutex_unlock(&trsupport->queryMutex); } else if (pRes->completed) { tscAllDataRetrievedFromDnode(trsupport, pSql); @@ -1699,7 +1742,6 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR taos_fetch_rows_a(tres, tscRetrieveFromDnodeCallBack, param); } - pthread_mutex_unlock(&trsupport->queryMutex); } else { // all data has been retrieved to client tscAllDataRetrievedFromDnode(trsupport, pSql); } @@ -1738,18 +1780,16 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { SCMVgroupInfo* pVgroup = &pTableMetaInfo->vgroupList->vgroups[0]; SSubqueryState* pState = trsupport->pState; - assert(pState->numOfCompleted < pState->numOfTotal && pState->numOfCompleted >= 0 && - pParentSql->numOfSubs == pState->numOfTotal); - - if (pParentSql->res.code != TSDB_CODE_SUCCESS || pState->code != TSDB_CODE_SUCCESS) { + assert(pState->numOfRemain <= pState->numOfTotal && pState->numOfRemain >= 0 && pParentSql->numOfSubs == pState->numOfTotal); + + // todo set error code + if (pParentSql->res.code != TSDB_CODE_SUCCESS) { // stable query is killed, abort further retry trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; if (pParentSql->res.code != TSDB_CODE_SUCCESS) { code = pParentSql->res.code; - } else { - code = pState->code; } tscTrace("%p query cancelled or failed, sub:%p, orderOfSub:%d abort, code:%s", pParentSql, pSql, @@ -1766,7 +1806,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { if (code != TSDB_CODE_SUCCESS) { if (trsupport->numOfRetry++ >= MAX_NUM_OF_SUBQUERY_RETRY) { tscTrace("%p sub:%p reach the max retry times, set global code:%s", pParentSql, pSql, tstrerror(code)); - atomic_val_compare_exchange_32(&pState->code, 0, code); + atomic_val_compare_exchange_32(&pParentSql->res.code, TSDB_CODE_SUCCESS, code); } else { // does not reach the maximum retry time, go on tscTrace("%p sub:%p failed code:%s, retry:%d", pParentSql, pSql, tstrerror(code), trsupport->numOfRetry); @@ -1775,8 +1815,8 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { if (pNew == NULL) { tscError("%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d", trsupport->pParentSqlObj, pSql, pVgroup->vgId, trsupport->subqueryIndex); - - pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY; + + pParentSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; } else { SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); @@ -1789,11 +1829,11 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { } } - if (pState->code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query - tscTrace("%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql, - pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex, pState->code); + if (pParentSql->res.code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query + tscTrace("%p sub:%p query failed,ip:%s,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql, + pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex, pParentSql->res.code); - tscHandleSubqueryError(param, tres, pState->code); + tscHandleSubqueryError(param, tres, pParentSql->res.code); } else { // success, proceed to retrieve data from dnode tscTrace("%p sub:%p query complete, ip:%s, vgId:%d, orderOfSub:%d, retrieve data", trsupport->pParentSqlObj, pSql, pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex); @@ -1813,8 +1853,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) { SSqlCmd* pParentCmd = &pParentObj->cmd; SSubqueryState* pState = pSupporter->pState; - int32_t total = pState->numOfTotal; - + // increase the total inserted rows if (numOfRows > 0) { pParentObj->res.numOfRows += numOfRows; @@ -1826,8 +1865,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) { } taos_free_result(tres); - int32_t completed = atomic_add_fetch_32(&pState->numOfCompleted, 1); - if (completed < total) { + if (atomic_sub_fetch_32(&pState->numOfRemain, 1) > 0) { return; } @@ -2157,5 +2195,3 @@ static bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) { return hasData; } - - diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index bcd01a322e..a653b83833 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -220,7 +220,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { if (strlen(tsLocale) == 0) { // locale does not set yet char* defaultLocale = setlocale(LC_CTYPE, ""); - strcpy(tsLocale, defaultLocale); + tstrncpy(tsLocale, defaultLocale, sizeof(tsLocale)); } // set the user specified locale @@ -304,7 +304,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - strcpy(tsTimezone, pStr); + tstrncpy(tsTimezone, pStr, sizeof(tsTimezone)); tsSetTimeZone(); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscTrace("timezone set:%s, input:%s by taos_options", tsTimezone, pStr); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 01f2bb7dd5..9a2e028dd1 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1840,7 +1840,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void size_t size = taosArrayGetSize(pNewQueryInfo->colList); tscTrace( - "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d," + "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z," "fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64, pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->window.skey, @@ -2002,7 +2002,7 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) { int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; while (++pTableMetaInfo->vgroupIndex < totalVgroups) { - tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%d", pSql, + tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%" PRId64, pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pRes->numOfClauseTotal); /* diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 30fdd21b99..d971e3ad6d 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -407,11 +407,7 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) { pMnodeInfo->nodeId = htonl(pMnodeInfo->nodeId); } - SDMVgroupAccess *pVgAcccess = pStatusRsp->vgAccess; - for (int32_t i = 0; i < pCfg->numOfVnodes; ++i) { - pVgAcccess[i].vgId = htonl(pVgAcccess[i].vgId); - } - + vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes); dnodeProcessModuleStatus(pCfg->moduleStatus); dnodeUpdateDnodeCfg(pCfg); diff --git a/src/inc/taos.h b/src/inc/taos.h index 9ac97a24e1..d524d95685 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -55,7 +55,7 @@ typedef enum { typedef struct taosField { char name[65]; uint8_t type; - uint16_t bytes; + int16_t bytes; } TAOS_FIELD; #ifdef _TD_GO_DLL_ diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 8b82e1f149..6de7f67291 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -209,8 +209,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MAX_SQL_SHOW_LEN 256 #define TSDB_MAX_ALLOWED_SQL_LEN (8*1024*1024U) // sql length should be less than 8mb -#define TSDB_MAX_BYTES_PER_ROW 65535 -#define TSDB_MAX_TAGS_LEN 65535 +#define TSDB_MAX_BYTES_PER_ROW 16384 +#define TSDB_MAX_TAGS_LEN 16384 #define TSDB_MAX_TAGS 128 #define TSDB_AUTH_LEN 16 diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 6af31734b5..33e0aa24b6 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -113,12 +113,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_QUERY_ID, 0, 0x030C, "mnode inva TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STREAM_ID, 0, 0x030D, "mnode invalid stream id") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONN_ID, 0, 0x030E, "mnode invalid connection") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "[sdb] object already there") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "[sdb] app error") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE, 0, 0x0322, "[sdb] invalid table type") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_NOT_THERE, 0, 0x0323, "[sdb] object not there") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_META_ROW, 0, 0x0324, "[sdb] invalid meta row") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_KEY_TYPE, 0, 0x0325, "[sdb] invalid key type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "sdb object already there") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "sdb app error") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE, 0, 0x0322, "sdb invalid table type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_NOT_THERE, 0, 0x0323, "sdb object not there") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_META_ROW, 0, 0x0324, "sdb invalid meta row") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_KEY_TYPE, 0, 0x0325, "sdb invalid key type") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "mnode dnode already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnode not exist") @@ -179,6 +179,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "vnode no d TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory") TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0214, "vnode no write auth") // tsdb TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id") diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index fcb6d66422..78255a45d5 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -543,6 +543,7 @@ typedef struct { int32_t dnodeId; uint32_t moduleStatus; uint32_t numOfVnodes; + uint32_t reserved; } SDMDnodeCfg; typedef struct { diff --git a/src/inc/vnode.h b/src/inc/vnode.h index 0da1f51e27..9f0c8cc241 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -58,6 +58,7 @@ void* vnodeGetWal(void *pVnode); int32_t vnodeProcessWrite(void *pVnode, int qtype, void *pHead, void *item); void vnodeBuildStatusMsg(void * param); +void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes); int32_t vnodeProcessRead(void *pVnode, SReadMsg *pReadMsg); diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 2baf28f88f..80a638a21e 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -122,7 +122,8 @@ typedef struct SVgObj { int32_t lbDnodeId; int32_t lbTime; int8_t inUse; - int8_t reserved[13]; + int8_t accessState; + int8_t reserved[12]; int8_t updateEnd[1]; int32_t refCount; struct SVgObj *prev, *next; diff --git a/src/mnode/inc/mnodeVgroup.h b/src/mnode/inc/mnodeVgroup.h index d61145d9b8..29a0fe1799 100644 --- a/src/mnode/inc/mnodeVgroup.h +++ b/src/mnode/inc/mnodeVgroup.h @@ -34,7 +34,8 @@ void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb); void * mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup); void mnodeUpdateVgroup(SVgObj *pVgroup); -void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *dnodeId, SVnodeLoad *pVload); +void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload); +void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes); int32_t mnodeCreateVgroup(struct SMnodeMsg *pMsg, SDbObj *pDb); void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 4c79564769..3fcb3849aa 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -39,6 +39,7 @@ static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { static int32_t mnodeAcctActionInsert(SSdbOper *pOper) { SAcctObj *pAcct = pOper->pObj; memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo)); + pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS; pthread_mutex_init(&pAcct->mutex, NULL); return TSDB_CODE_SUCCESS; } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 35f4ea43d3..21de887488 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -335,6 +335,19 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { } int32_t openVnodes = htons(pStatus->openVnodes); + int32_t contLen = sizeof(SDMStatusRsp) + openVnodes * sizeof(SDMVgroupAccess); + SDMStatusRsp *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + mnodeDecDnodeRef(pDnode); + return TSDB_CODE_MND_OUT_OF_MEMORY; + } + + pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId); + pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt); + pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes); + mnodeGetMnodeInfos(&pRsp->mnodes); + SDMVgroupAccess *pAccess = (SDMVgroupAccess *)((char *)pRsp + sizeof(SDMStatusRsp)); + for (int32_t j = 0; j < openVnodes; ++j) { SVnodeLoad *pVload = &pStatus->load[j]; pVload->vgId = htonl(pVload->vgId); @@ -347,6 +360,8 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { mnodeSendDropVnodeMsg(pVload->vgId, &ipSet, NULL); } else { mnodeUpdateVgroupStatus(pVgroup, pDnode, pVload); + pAccess->vgId = htonl(pVload->vgId); + pAccess->accessState = pVgroup->accessState; mnodeDecVgroupRef(pVgroup); } } @@ -366,26 +381,13 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { balanceNotify(); } - mnodeDecDnodeRef(pDnode); - - int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess); - SDMStatusRsp *pRsp = rpcMallocCont(contLen); - if (pRsp == NULL) { - return TSDB_CODE_MND_OUT_OF_MEMORY; + if (openVnodes != pDnode->openVnodes) { + mnodeCheckUnCreatedVgroup(pDnode, pStatus->load, openVnodes); } pDnode->lastAccess = tsAccessSquence; + mnodeDecDnodeRef(pDnode); - mnodeGetMnodeInfos(&pRsp->mnodes); - - pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId); - pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt); - pRsp->dnodeCfg.numOfVnodes = 0; - - contLen = sizeof(SDMStatusRsp); - - //TODO: set vnode access - pMsg->rpcRsp.len = contLen; pMsg->rpcRsp.rsp = pRsp; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 10dfb2a28a..ff09af7611 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -74,6 +74,7 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) { pVgroup->pDb = pDb; pVgroup->prev = NULL; pVgroup->next = NULL; + pVgroup->accessState = TSDB_VN_ALL_ACCCESS; int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *)); @@ -255,6 +256,8 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) { mnodeSendCreateVgroupMsg(pVgroup, NULL); } +void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes) {} + void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload) { bool dnodeExist = false; for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { @@ -324,6 +327,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { strcpy(pVgroup->dbName, pDb->name); pVgroup->numOfVnodes = pDb->cfg.replications; pVgroup->createdTime = taosGetTimestampMs(); + pVgroup->accessState = TSDB_VN_ALL_ACCCESS; if (balanceAllocVnodes(pVgroup) != 0) { mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes); free(pVgroup); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 0728fcaa35..0a25ae3397 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1216,7 +1216,6 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl // interval query with limit applied int32_t numOfRes = 0; - if (isIntervalQuery(pQuery)) { numOfRes = doCheckQueryCompleted(pRuntimeEnv, lastKey, pWindowResInfo); } else { diff --git a/src/util/inc/tstoken.h b/src/util/inc/tstoken.h index 60a79f69af..74687e9c18 100644 --- a/src/util/inc/tstoken.h +++ b/src/util/inc/tstoken.h @@ -120,6 +120,7 @@ static FORCE_INLINE int32_t isValidNumber(const SSQLToken* pToken) { type = TK_FLOAT; goto _end; + break; } case '0': { diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index c75ba24baa..bb74bafbdd 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -117,6 +117,8 @@ extern "C" { #define POW2(x) ((x) * (x)) +int taosRand(void); + int32_t strdequote(char *src); size_t strtrim(char *src); diff --git a/src/util/src/tarray.c b/src/util/src/tarray.c index b99e722262..19225e998a 100755 --- a/src/util/src/tarray.c +++ b/src/util/src/tarray.c @@ -95,9 +95,6 @@ void* taosArrayGetP(const SArray* pArray, size_t index) { assert(index < pArray->size); void* d = TARRAY_GET_ELEM(pArray, index); - if (d == NULL) { - return NULL; - } return *(void**)d; } diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 2b6083a91c..48603a014e 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -119,7 +119,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNo int32_t size = pNode->size; taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize); - uTrace("key:%s is removed from cache,total:%d,size:%ldbytes", pNode->key, pCacheObj->totalSize, size); + uTrace("key:%s is removed from cache,total:%" PRId64 ",size:%dbytes", pNode->key, pCacheObj->totalSize, size); if (pCacheObj->freeFp) pCacheObj->freeFp(pNode->data); free(pNode); } @@ -288,7 +288,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const char *key, const void *pData, siz if (NULL != pNode) { pCacheObj->totalSize += pNode->size; - uTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%d, size:%" PRId64 " bytes", + uTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%" PRId64 ", size:%" PRId64 " bytes", key, pNode, pNode->addedTime, pNode->expiredTime, pCacheObj->totalSize, dataSize); } else { uError("key:%s failed to added into cache, out of memory", key); @@ -433,7 +433,6 @@ void taosCacheEmpty(SCacheObj *pCacheObj) { __cache_wr_lock(pCacheObj); while (taosHashIterNext(pIter)) { if (pCacheObj->deleting == 1) { - taosHashDestroyIter(pIter); break; } @@ -507,7 +506,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) { void taosRemoveFromTrashCan(SCacheObj *pCacheObj, STrashElem *pElem) { if (pElem->pData->signature != (uint64_t)pElem->pData) { - uError("key:sig:%d %p data has been released, ignore", pElem->pData->signature, pElem->pData); + uError("key:sig:0x%" PRIx64 " %p data has been released, ignore", pElem->pData->signature, pElem->pData); return; } @@ -561,7 +560,6 @@ void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) { } } - assert(pCacheObj->numOfElemsInTrash >= 0); __cache_unlock(pCacheObj); } diff --git a/src/util/src/tcompression.c b/src/util/src/tcompression.c index e3b3d65052..b085e26e07 100644 --- a/src/util/src/tcompression.c +++ b/src/util/src/tcompression.c @@ -551,7 +551,7 @@ int tsDecompressTimestampImp(const char *const input, const int nelements, char delta_of_delta = 0; } else { if (is_bigendian()) { - memcpy(&dd1 + LONG_BYTES - nbytes, input + ipos, nbytes); + memcpy(((char *)(&dd1)) + LONG_BYTES - nbytes, input + ipos, nbytes); } else { memcpy(&dd1, input + ipos, nbytes); } @@ -576,7 +576,7 @@ int tsDecompressTimestampImp(const char *const input, const int nelements, char delta_of_delta = 0; } else { if (is_bigendian()) { - memcpy(&dd2 + LONG_BYTES - nbytes, input + ipos, nbytes); + memcpy(((char *)(&dd2)) + LONG_BYTES - nbytes, input + ipos, nbytes); } else { memcpy(&dd2, input + ipos, nbytes); } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 543a84dc44..bcea8d1654 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -74,7 +74,7 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { *option = value; cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; } else { - uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, + uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, tsCfgStatusStr[cfg->cfgStatus], *option); } } @@ -106,7 +106,11 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { } else { if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { wordexp_t full_path; - wordexp(input_value, &full_path, 0); + if (0 != wordexp(input_value, &full_path, 0)) { + printf("\nconfig dir: %s wordexp fail! reason:%s\n", input_value, strerror(errno)); + wordfree(&full_path); + return; + } if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { strcpy(option, full_path.we_wordv[0]); } @@ -115,8 +119,13 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { struct stat dirstat; if (stat(option, &dirstat) < 0) { int code = mkdir(option, 0755); - uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d", - cfg->option, input_value, code); + if (code < 0) { + uError("config option:%s, input value:%s, directory not exist, create fail with return code:%d", + cfg->option, input_value, code); + } else { + uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d", + cfg->option, input_value, code); + } } cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; } else { @@ -240,7 +249,12 @@ void taosReadGlobalLogCfg() { sdbDebugFlag = 135; wordexp_t full_path; - wordexp(configDir, &full_path, 0); + if ( 0 != wordexp(configDir, &full_path, 0)) { + printf("\nconfig file: %s wordexp fail! reason:%s\n", configDir, strerror(errno)); + wordfree(&full_path); + return; + } + if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) { printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1); diff --git a/src/util/src/tdes.c b/src/util/src/tdes.c index 3112fb4111..c76938d3aa 100644 --- a/src/util/src/tdes.c +++ b/src/util/src/tdes.c @@ -140,7 +140,7 @@ void print_char_as_binary(char input) { void generate_key(unsigned char* key) { int i; for (i = 0; i < 8; i++) { - key[i] = rand() % 255; + key[i] = taosRand() % 255; } } diff --git a/src/util/src/terror.c b/src/util/src/terror.c index c040a11362..aa6925464e 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index 6eca141375..1c7d93b307 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -566,5 +566,6 @@ static int tdRestoreKVStore(SKVStore *pStore) { _err: taosHashDestroyIter(pIter); tfree(buf); + taosHashDestroyIter(pIter); return -1; } \ No newline at end of file diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 01a0eabbca..39ec89daf4 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -142,6 +142,10 @@ static void *taosThreadToOpenNewFile(void *param) { umask(0); int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + if (fd < 0) { + uError("open new log file fail! fd:%d reason:%s", fd, strerror(errno)); + return NULL; + } taosLockFile(fd); lseek(fd, 0, SEEK_SET); @@ -184,7 +188,7 @@ void taosResetLog() { tsLogObj.lines = tsLogObj.maxLines + 10; taosOpenNewLogFile(); - remove(lastName); + (void)remove(lastName); uPrint("=================================="); uPrint(" reset log file "); @@ -229,7 +233,9 @@ static void taosGetLogFileName(char *fn) { } } - strcpy(tsLogObj.logName, fn); + if (strlen(fn) < LOG_FILE_NAME_LEN) { + strcpy(tsLogObj.logName, fn); + } } static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { @@ -249,15 +255,20 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { tsLogObj.fileNum = maxFileNum; taosGetLogFileName(fn); - strcpy(name, fn); - strcat(name, ".0"); + if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) { + strcpy(name, fn); + strcat(name, ".0"); + } // if none of the log files exist, open 0, if both exists, open the old one if (stat(name, &logstat0) < 0) { tsLogObj.flag = 0; } else { - strcpy(name, fn); - strcat(name, ".1"); + if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) { + strcpy(name, fn); + strcat(name, ".1"); + } + if (stat(name, &logstat1) < 0) { tsLogObj.flag = 1; } else { @@ -279,7 +290,10 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { // only an estimate for number of lines struct stat filestat; - fstat(tsLogObj.logHandle->fd, &filestat); + if (fstat(tsLogObj.logHandle->fd, &filestat) < 0) { + printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno)); + return -1; + } size = (int32_t)filestat.st_size; tsLogObj.lines = size / 60; diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 31ed6e2f7b..a8d9e8d416 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -169,7 +169,9 @@ void taosGetNoteName(char *fn, taosNoteInfo * pNote) } } - strcpy(pNote->taosNoteName, fn); + if (strlen(fn) < NOTE_FILE_NAME_LEN) { + strcpy(pNote->taosNoteName, fn); + } } int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInfo * pNote) @@ -182,14 +184,18 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf pNote->taosNoteFileNum = maxNoteNum; taosGetNoteName(fn, pNote); + if (strlen(fn) > NOTE_FILE_NAME_LEN * 2 - 2) { + fprintf(stderr, "the len of file name overflow:%s\n", fn); + return -1; + } + strcpy(name, fn); strcat(name, ".0"); // if none of the note files exist, open 0, if both exists, open the old one if (stat(name, ¬estat0) < 0) { pNote->taosNoteFlag = 0; - } - else { + } else { strcpy(name, fn); strcat(name, ".1"); if (stat(name, ¬estat1) < 0) { @@ -214,7 +220,10 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf // only an estimate for number of lines struct stat filestat; - fstat(pNote->taosNoteFd, &filestat); + if (fstat(pNote->taosNoteFd, &filestat) < 0) { + fprintf(stderr, "failed to fstat note file:%s reason:%s\n", name, strerror(errno)); + return -1; + } size = (int)filestat.st_size; pNote->taosNoteLines = size / 60; @@ -226,7 +235,7 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf void taosNotePrint(taosNoteInfo * pNote, const char * const format, ...) { va_list argpointer; - char buffer[MAX_NOTE_LINE_SIZE]; + char buffer[MAX_NOTE_LINE_SIZE+2]; int len; struct tm Tm, *ptm; struct timeval timeSecs; diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 0532b442bb..a65d9b0f31 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 ((rand() % factor) == 0 && n <= pSkipList->maxLevel) { + while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) { n++; } diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 1f4d57115b..98ed8d1ed7 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -278,7 +278,7 @@ int taosOpenUdpSocket(uint32_t ip, uint16_t port) { /* bind socket to local address */ if (bind(sockFd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) { uError("failed to bind udp socket: %d (%s), 0x%x:%hu", errno, strerror(errno), ip, port); - taosCloseSocket(sockFd); + close(sockFd); return -1; } @@ -321,7 +321,7 @@ int taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clientI if (ret != 0) { //uError("failed to connect socket, ip:0x%x, port:%hu(%s)", destIp, destPort, strerror(errno)); - taosCloseSocket(sockFd); + close(sockFd); sockFd = -1; } diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index 4dd6360752..02d72dd1f4 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -72,49 +72,6 @@ void deltaToUtcInitOnce() { return; } -int64_t user_mktime(struct tm * tm) -{ -#define TAOS_MINUTE 60 -#define TAOS_HOUR (60*TAOS_MINUTE) -#define TAOS_DAY (24*TAOS_HOUR) -#define TAOS_YEAR (365*TAOS_DAY) - -static int month[12] = { - 0, - TAOS_DAY*(31), - TAOS_DAY*(31+29), - TAOS_DAY*(31+29+31), - TAOS_DAY*(31+29+31+30), - TAOS_DAY*(31+29+31+30+31), - TAOS_DAY*(31+29+31+30+31+30), - TAOS_DAY*(31+29+31+30+31+30+31), - TAOS_DAY*(31+29+31+30+31+30+31+31), - TAOS_DAY*(31+29+31+30+31+30+31+31+30), - TAOS_DAY*(31+29+31+30+31+30+31+31+30+31), - TAOS_DAY*(31+29+31+30+31+30+31+31+30+31+30) -}; - - int64_t res; - int year; - - year= tm->tm_year - 70; - res= TAOS_YEAR*year + TAOS_DAY*((year+1)/4); - res+= month[tm->tm_mon]; - - if(tm->tm_mon > 1 && ((year+2)%4)) { - res-= TAOS_DAY; - } - - res+= TAOS_DAY*(tm->tm_mday-1); - res+= TAOS_HOUR*tm->tm_hour; - res+= TAOS_MINUTE*tm->tm_min; - res+= tm->tm_sec; - - return res + m_deltaUtc; - -} - - static int64_t parseFraction(char* str, char** end, int32_t timePrec); static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec); static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec); diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index cdb2c6c0be..f7acc1132d 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -139,7 +139,7 @@ static void unlockTimerList(timer_list_t* list) { int64_t tid = taosGetPthreadId(); if (atomic_val_compare_exchange_64(&(list->lockedBy), tid, 0) != tid) { assert(false); - tmrError("%d trying to unlock a timer list not locked by current thread.", tid); + tmrError("%" PRId64 " trying to unlock a timer list not locked by current thread.", tid); } } @@ -290,6 +290,7 @@ static void addToExpired(tmr_obj_t* head) { SSchedMsg schedMsg; schedMsg.fp = NULL; schedMsg.tfp = processExpiredTimer; + schedMsg.msg = NULL; schedMsg.ahandle = head; schedMsg.thandle = NULL; taosScheduleTask(tmrQhandle, &schedMsg); @@ -513,14 +514,17 @@ static void taosTmrModuleInit(void) { tmrError("failed to create the mutex for wheel, reason:%s", strerror(errno)); return; } + pthread_mutex_lock(&wheel->mutex); wheel->nextScanAt = now + wheel->resolution; wheel->index = 0; wheel->slots = (tmr_obj_t**)calloc(wheel->size, sizeof(tmr_obj_t*)); if (wheel->slots == NULL) { tmrError("failed to allocate wheel slots"); + pthread_mutex_unlock(&wheel->mutex); return; } timerMap.size += wheel->size; + pthread_mutex_unlock(&wheel->mutex); } timerMap.count = 0; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 9209117415..a2edce2387 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -27,6 +27,33 @@ #include "tulog.h" #include "taoserror.h" + +#ifdef WINDOWS +int taosRand(void) +{ + return rand(); +} +#else +int taosRand(void) +{ + int fd; + int seed; + + fd = open("/dev/urandom", 0); + if (fd < 0) { + seed = time(0); + } else { + int len = read(fd, &seed, sizeof(seed)); + if (len < 0) { + seed = time(0); + } + close(fd); + } + + return seed; +} +#endif + int32_t strdequote(char *z) { if (z == NULL) { return 0; @@ -434,8 +461,10 @@ void getTmpfilePath(const char *fileNamePrefix, char *dstPath) { strcpy(tmpPath, tmpDir); strcat(tmpPath, tdengineTmpFileNamePrefix); - strcat(tmpPath, fileNamePrefix); - strcat(tmpPath, "-%d-%s"); + if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { + strcat(tmpPath, fileNamePrefix); + strcat(tmpPath, "-%d-%s"); + } char rand[8] = {0}; taosRandStr(rand, tListLen(rand) - 1); @@ -447,7 +476,7 @@ void taosRandStr(char* str, int32_t size) { int32_t len = 39; for(int32_t i = 0; i < size; ++i) { - str[i] = set[rand()%len]; + str[i] = set[taosRand()%len]; } } @@ -557,7 +586,7 @@ bool taosGetVersionNumber(char *versionStr, int *versionNubmer) { return false; } - int versionNumberPos[4] = {0}; + int versionNumberPos[5] = {0}; int len = strlen(versionStr); int dot = 0; for (int pos = 0; pos < len && dot < 4; ++pos) { @@ -709,7 +738,7 @@ void taosRemoveDir(char *rootDir) { if (de->d_type & DT_DIR) { taosRemoveDir(filename); } else { - remove(filename); + (void)remove(filename); uPrint("file:%s is removed", filename); } } @@ -718,4 +747,4 @@ void taosRemoveDir(char *rootDir) { rmdir(rootDir); uPrint("dir:%s is removed", rootDir); -} \ No newline at end of file +} diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h index ab74e329e6..d5a7dbfd2e 100644 --- a/src/vnode/inc/vnodeInt.h +++ b/src/vnode/inc/vnodeInt.h @@ -37,6 +37,7 @@ typedef struct { int32_t refCount; // reference count int status; int8_t role; + int8_t accessState; int64_t version; // current version int64_t fversion; // version on saved data file void *wqueue; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 7985b2d898..ece0c512e3 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -195,6 +195,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { pVnode->version = 0; pVnode->tsdbCfg.tsdbId = pVnode->vgId; pVnode->rootDir = strdup(rootDir); + pVnode->accessState = TSDB_VN_ALL_ACCCESS; int32_t code = vnodeReadCfg(pVnode); if (code != TSDB_CODE_SUCCESS) { @@ -431,6 +432,20 @@ void vnodeBuildStatusMsg(void *param) { taosHashDestroyIter(pIter); } +void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes) { + for (int32_t i = 0; i < numOfVnodes; ++i) { + pAccess[i].vgId = htonl(pAccess[i].vgId); + SVnodeObj *pVnode = vnodeAccquireVnode(pAccess[i].vgId); + if (pVnode != NULL) { + pVnode->accessState = pAccess[i].accessState; + if (pVnode->accessState != TSDB_VN_ALL_ACCCESS) { + vTrace("vgId:%d, access state is set to %d", pAccess[i].vgId) + } + vnodeRelease(pVnode); + } + } +} + static void vnodeCleanUp(SVnodeObj *pVnode) { // remove from hash, so new messages wont be consumed taosHashRemove(tsDnodeVnodesHash, (const char *)&pVnode->vgId, sizeof(int32_t)); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 032dbde9ea..68e98757cc 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -53,6 +53,10 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) { if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL) return TSDB_CODE_VND_MSG_NOT_PROCESSED; + if (!(pVnode->accessState & TSDB_VN_WRITE_ACCCESS)) { + return TSDB_CODE_VND_NO_WRITE_AUTH; + } + if (pHead->version == 0) { // from client or CQ if (pVnode->status != TAOS_VN_STATUS_READY) return TSDB_CODE_VND_INVALID_VGROUP_ID; // it may be in deleting or closing state diff --git a/tests/script/general/parser/alter.sim b/tests/script/general/parser/alter.sim index 018ee924d1..6b28b20fb8 100644 --- a/tests/script/general/parser/alter.sim +++ b/tests/script/general/parser/alter.sim @@ -114,46 +114,46 @@ sql drop table tb sql drop table mt sleep 3000 -## ALTER TABLE WHILE STREAMING [TBASE271] -sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int) -sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s) -sql select * from strm -if $rows != 0 then - return -1 -endi -#sleep 12000 -sql insert into tb1 values (now, 1, 'taos', 1) -sleep 20000 -sql select * from strm -print rows = $rows -if $rows != 1 then - return -1 -endi -if $data04 != 1 then - return -1 -endi -sql alter table tb1 drop column c3 -sleep 6000 -sql insert into tb1 values (now, 2, 'taos') -sleep 30000 -sql select * from strm -if $rows != 2 then - return -1 -endi -if $data04 != 1 then - return -1 -endi -sql alter table tb1 add column c3 int -sleep 6000 -sql insert into tb1 values (now, 3, 'taos', 3); -sleep 3000 -sql select * from strm -if $rows != 3 then - return -1 -endi -if $data04 != 1 then - return -1 -endi +### ALTER TABLE WHILE STREAMING [TBASE271] +#sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int) +#sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s) +#sql select * from strm +#if $rows != 0 then +# return -1 +#endi +##sleep 12000 +#sql insert into tb1 values (now, 1, 'taos', 1) +#sleep 20000 +#sql select * from strm +#print rows = $rows +#if $rows != 1 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi +#sql alter table tb1 drop column c3 +#sleep 6000 +#sql insert into tb1 values (now, 2, 'taos') +#sleep 30000 +#sql select * from strm +#if $rows != 2 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi +#sql alter table tb1 add column c3 int +#sleep 6000 +#sql insert into tb1 values (now, 3, 'taos', 3); +#sleep 3000 +#sql select * from strm +#if $rows != 3 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi ## ALTER TABLE AND INSERT BY COLUMNS sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int) diff --git a/tests/script/general/parser/limit1_tblocks100.sim b/tests/script/general/parser/limit1_tblocks100.sim index 2235e6b424..29b48bdd43 100644 --- a/tests/script/general/parser/limit1_tblocks100.sim +++ b/tests/script/general/parser/limit1_tblocks100.sim @@ -61,6 +61,7 @@ run general/parser/limit1_stb.sim print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 5000 system sh/exec.sh -n dnode1 -s start print ================== server restart completed diff --git a/tests/script/general/parser/null_char.sim b/tests/script/general/parser/null_char.sim index 6da419cd4c..09e761c85e 100644 --- a/tests/script/general/parser/null_char.sim +++ b/tests/script/general/parser/null_char.sim @@ -206,68 +206,70 @@ endi ################# binary sql alter table st41 set tag tag_binary = "shanghai" -sql describe st41 -if $data23 != shanghai then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != shanghai then return -1 endi + ##### test 'space' case -#$tagvalue = ' -#$tagvalue = $tagvalue ' -#sql alter table st41 set tag tag_binary = $tagvalue +system_content echo ' ' | sed 's/ //g' | tr -d '\n' # Construct an empty result for later result checking sql alter table st41 set tag tag_binary = "" -#sql describe st41 -#if $data23 != $tagvalue then -# return -1 -#endi -sql alter table st41 set tag tag_binary = "NULL" -sql describe st41 -if $data23 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != $system_content then + print expect [ $system_content ], actual [ $data00 ] return -1 endi + +sql alter table st41 set tag tag_binary = "NULL" +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != NULL then + return -1 +endi + sql alter table st41 set tag tag_binary = NULL -sql describe st41 -if $data23 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != NULL then print ==8== expect: NULL, actually: $data23 return -1 endi ################### nchar sql alter table st41 set tag tag_nchar = "��˼����" -sql describe st41 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 #sleep 1000 -#if $data33 != ��˼���� then -# print ==== expect ��˼����, actually $data33 +#if $data01 != ��˼���� then +# print ==== expect ��˼����, actually $data01 # return -1 #endi ##### test 'space' case #$tagvalue = ' #$tagvalue = $tagvalue ' sql alter table st41 set tag tag_nchar = '' -#sql describe st41 -#if $data33 != $tagvalue then +#sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +#if $data01 != $tagvalue then # return -1 #endi sql alter table st41 set tag tag_nchar = "NULL" -sql describe st41 -if $data33 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data01 != NULL then return -1 endi sql alter table st41 set tag tag_nchar = NULL -#sql describe st41 -#if $data33 != then -# print ==9== expect , actually $data33 +#sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +#if $data01 != then +# print ==9== expect , actually $data01 # return -1 #endi ################### int sql alter table st41 set tag tag_int = -2147483647 -sql describe st41 -if $data43 != -2147483647 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != -2147483647 then return -1 endi sql alter table st41 set tag tag_int = 2147483647 -sql describe st41 -if $data43 != 2147483647 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != 2147483647 then return -1 endi @@ -275,19 +277,19 @@ sql_error alter table st41 set tag tag_int = -2147483648 sql_error alter table st41 set tag tag_int = 2147483648 sql alter table st41 set tag tag_int = '-379' -sql describe st41 -if $data43 != -379 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != -379 then return -1 endi sql alter table st41 set tag tag_int = -2000 -sql describe st41 -if $data43 != -2000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != -2000 then return -1 endi sql alter table st41 set tag tag_int = NULL -sql describe st41 -if $data43 != NULL then - print ==10== expect: NULL, actually: $data43 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != NULL then + print ==10== expect: NULL, actually: $data02 return -1 endi sql alter table st41 set tag tag_int = 'NULL' @@ -296,34 +298,34 @@ sql_error alter table st41 set tag tag_int = abc379 ################### bool sql alter table st41 set tag tag_bool = 'true' -sql describe st41 -if $data53 != true then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 1 then return -1 endi sql alter table st41 set tag tag_bool = 'false' -sql describe st41 -if $data53 != false then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 0 then return -1 endi sql alter table st41 set tag tag_bool = 0 -sql describe st41 -if $data53 != false then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 0 then return -1 endi sql alter table st41 set tag tag_bool = 123 -sql describe st41 -if $data53 != true then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 1 then return -1 endi sql alter table st41 set tag tag_bool = 'NULL' -sql describe st41 -if $data53 != NULL then - print ==14== expect: NULL, actually: $data53 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != NULL then + print ==14== expect: NULL, actually: $data03 return -1 endi sql alter table st41 set tag tag_bool = NULL -sql describe st41 -if $data53 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != NULL then return -1 endi @@ -333,50 +335,51 @@ sql_error alter table st41 set tag tag_bool = abc379 ################### float sql alter table st41 set tag tag_float = -32 -sql describe st41 -if $data63 != -32.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != -32.00000 then + print expect -32.00000 actual $data04 return -1 endi sql alter table st41 set tag tag_float = 54.123456 -sql describe st41 -if $data63 != 54.123455 then - print ==15== expect: 54.123455, actually: $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.123455 then + print ==15== expect: 54.123455, actually: $data04 # return -1 endi sql alter table st41 set tag tag_float = 54.12345 -sql describe st41 -if $data63 != 54.123451 then - print ==16== expect: 54.123451, actually: $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.12345 then + print ==16== expect: 54.12345, actually: $data04 return -1 endi sql alter table st41 set tag tag_float = 54.12345678 -sql describe st41 -if $data63 != 54.123455 then - print ==11== expect: 54.123455, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.12346 then + print ==11== expect: 54.12346, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = NULL -sql describe st41 -if $data63 != NULL then - print ==12== expect: NULL, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != NULL then + print ==12== expect: NULL, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = 'NULL' -sql describe st41 -if $data63 != NULL then - print ==17== expect: NULL, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != NULL then + print ==17== expect: NULL, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = '54.123456' -sql describe st41 -if $data63 != 54.123455 then - print ==18== expect: 54.123455, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.12346 then + print ==18== expect: 54.12346, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = '-54.123456' -sql describe st41 -if $data63 != -54.123455 then - print ==19== expect: -54.123455, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != -54.12346 then + print ==19== expect: -54.12346, actually : $data04 return -1 endi sql_error alter table st41 set tag tag_float = '' @@ -387,30 +390,32 @@ sql_error alter table st41 set tag tag_float = abc ################### double sql alter table st41 set tag tag_double = -92 -sql describe st41 -if $data73 != -92.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != -92.000000000 then + print expect -92.000000000 actual $data05 return -1 endi sql alter table st41 set tag tag_double = 184 -sql describe st41 -if $data73 != 184.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != 184.000000000 then + print expect 184.000000000 actual $data05 return -1 endi sql alter table st41 set tag tag_double = '-2456' -sql describe st41 -if $data73 != -2456.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != -2456.000000000 then return -1 endi sql alter table st41 set tag tag_double = NULL -sql describe st41 -if $data73 != NULL then - print ==13== expect: NULL, actually : $data73 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != NULL then + print ==13== expect: NULL, actually : $data05 return -1 endi sql alter table st41 set tag tag_double = 'NULL' -sql describe st41 -if $data73 != NULL then - print ==20== expect: NULL, actually : $data73 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != NULL then + print ==20== expect: NULL, actually : $data05 return -1 endi sql_error alter table st41 set tag tag_double = '' @@ -427,23 +432,22 @@ sql alter table st51 set tag tag_bigint = '-379' sql alter table st51 set tag tag_bigint = -2000 sql alter table st51 set tag tag_bigint = NULL sql alter table st51 set tag tag_bigint = 9223372036854775807 -sql describe st51 -if $data23 != 9223372036854775807 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data00 != 9223372036854775807 then return -1 endi sql alter table st51 set tag tag_bigint = 9223372036854775808 -sql describe st51 -if $data23 != 9223372036854775807 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data00 != 9223372036854775807 then return -1 endi sql alter table st51 set tag tag_bigint = -9223372036854775807 -sql describe st51 -if $data23 != -9223372036854775807 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data00 != -9223372036854775807 then return -1 endi sql_error alter table st51 set tag tag_bigint = -9223372036854775808 - sql alter table st51 set tag tag_bigint = 'NULL' sql_error alter table st51 set tag tag_bigint = '' sql_error alter table st51 set tag tag_bigint = abc379 @@ -452,15 +456,15 @@ sql_error alter table st51 set tag tag_bigint = abc379 sql alter table st51 set tag tag_smallint = -2000 sql alter table st51 set tag tag_smallint = NULL sql alter table st51 set tag tag_smallint = 32767 -sql describe st51 -if $data33 != 32767 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data01 != 32767 then return -1 endi sql_error alter table st51 set tag tag_smallint = 32768 sql alter table st51 set tag tag_smallint = -32767 -sql describe st51 -if $data33 != -32767 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data01 != -32767 then return -1 endi sql_error alter table st51 set tag tag_smallint = -32768 @@ -473,13 +477,13 @@ sql_error alter table st51 set tag tag_smallint = abc379 sql alter table st51 set tag tag_tinyint = -127 sql alter table st51 set tag tag_tinyint = NULL sql alter table st51 set tag tag_tinyint = 127 -sql describe st51 -if $data43 != 127 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data02 != 127 then return -1 endi sql alter table st51 set tag tag_tinyint = -127 -sql describe st51 -if $data43 != -127 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data02 != -127 then return -1 endi sql_error alter table st51 set tag tag_tinyint = '-128' @@ -493,4 +497,4 @@ sql_error alter table st51 set tag tag_tinyint = abc379 #sql drop database $db -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index f288288fb7..31acaad143 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -82,26 +82,22 @@ sleep 2000 run general/parser/groupby.sim sleep 2000 run general/parser/set_tag_vals.sim - sleep 2000 run general/parser/slimit_alter_tags.sim # persistent failed - sleep 2000 run general/parser/join.sim sleep 2000 run general/parser/join_multivnode.sim - sleep 2000 -#run general/parser/repeatAlter.sim -sleep 2000 -#run general/parser/repeatStream.sim - +run general/parser/repeatAlter.sim sleep 2000 run general/parser/binary_escapeCharacter.sim sleep 2000 run general/parser/bug.sim -sleep 2000 -run general/parser/stream_on_sys.sim -sleep 2000 -run general/parser/stream.sim \ No newline at end of file +#sleep 2000 +#run general/parser/repeatStream.sim +#sleep 2000 +#run general/parser/stream_on_sys.sim +#sleep 2000 +#run general/parser/stream.sim \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index e90f22b655..75be6943c9 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -100,7 +100,7 @@ cd ../../../debug; make ./test.sh -f general/insert/query_multi_file.sim ./test.sh -f general/insert/tcp.sim -#./test.sh -f general/parser/alter.sim +./test.sh -f general/parser/alter.sim ./test.sh -f general/parser/alter1.sim ./test.sh -f general/parser/alter_stable.sim ./test.sh -f general/parser/auto_create_tb.sim @@ -117,10 +117,10 @@ cd ../../../debug; make ./test.sh -f general/parser/import_commit3.sim ./test.sh -f general/parser/insert_tb.sim ./test.sh -f general/parser/first_last.sim -#unsupport ./test.sh -f general/parser/import_file.sim +#./test.sh -f general/parser/import_file.sim ./test.sh -f general/parser/lastrow.sim ./test.sh -f general/parser/nchar.sim -#unsupport ./test.sh -f general/parser/null_char.sim +#./test.sh -f general/parser/null_char.sim ./test.sh -f general/parser/single_row_in_tb.sim ./test.sh -f general/parser/select_from_cache_disk.sim ./test.sh -f general/parser/mixed_blocks.sim @@ -147,10 +147,10 @@ cd ../../../debug; make ./test.sh -f general/parser/join_multivnode.sim ./test.sh -f general/parser/binary_escapeCharacter.sim ./test.sh -f general/parser/bug.sim -#unsupport ./test.sh -f general/parser/stream_on_sys.sim +#./test.sh -f general/parser/stream_on_sys.sim ./test.sh -f general/parser/stream.sim -#unsupport ./test.sh -f general/parser/repeatAlter.sim -#unsupport ./test.sh -f general/parser/repeatStream.sim +./test.sh -f general/parser/repeatAlter.sim +#./test.sh -f general/parser/repeatStream.sim ./test.sh -f general/stable/disk.sim ./test.sh -f general/stable/dnode3.sim @@ -159,20 +159,20 @@ cd ../../../debug; make ./test.sh -f general/stable/values.sim ./test.sh -f general/stable/vnode3.sim -#./test.sh -f general/stream/metrics_1.sim -#./test.sh -f general/stream/metrics_del.sim -#./test.sh -f general/stream/metrics_n.sim -#./test.sh -f general/stream/metrics_replica1_vnoden.sim +./test.sh general/stream/stream_1.sim +./test.sh general/stream/stream_2.sim +./test.sh general/stream/stream_3.sim +./test.sh general/stream/stream_restart.sim +./test.sh general/stream/table_1.sim +./test.sh general/stream/metrics_1.sim +./test.sh general/stream/table_n.sim +./test.sh general/stream/metrics_n.sim +./test.sh general/stream/table_del.sim +./test.sh general/stream/metrics_del.sim +./test.sh general/stream/table_replica1_vnoden.sim +./test.sh general/stream/metrics_replica1_vnoden.sim #./test.sh -f general/stream/new_stream.sim #./test.sh -f general/stream/restart_stream.sim -#./test.sh -f general/stream/stream_1.sim -#./test.sh -f general/stream/stream_2.sim -#./test.sh -f general/stream/stream_3.sim -#./test.sh -f general/stream/stream_restart.sim -#./test.sh -f general/stream/table_1.sim -#./test.sh -f general/stream/table_del.sim -#./test.sh -f general/stream/table_n.sim -#./test.sh -f general/stream/table_replica1_vnoden.sim ./test.sh -f general/table/autocreate.sim ./test.sh -f general/table/basic1.sim @@ -324,7 +324,7 @@ cd ../../../debug; make ./test.sh -f unique/vnode/replica3_vgroup.sim ./test.sh -f unique/arbitrator/check_cluster_cfg_para.sim -./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim +./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim ./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim ./test.sh -f unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim ./test.sh -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim @@ -337,7 +337,7 @@ cd ../../../debug; make ./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim ./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim ./test.sh -f unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim -#./test.sh -f unique/arbitrator/dn3_mn1_vnode_delDir.sim # unsupport +#./test.sh -f unique/arbitrator/dn3_mn1_vnode_delDir.sim ./test.sh -f unique/arbitrator/dn3_mn1_vnode_nomaster.sim ./test.sh -f unique/arbitrator/dn3_mn2_killDnode.sim ./test.sh -f unique/arbitrator/insert_duplicationTs.sim diff --git a/tests/script/unique/account/usage.sim b/tests/script/unique/account/usage.sim index c1c5d75728..3f12c46137 100644 --- a/tests/script/unique/account/usage.sim +++ b/tests/script/unique/account/usage.sim @@ -1,6 +1,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/exec.sh -n dnode1 -s start +#system sh/exec.sh -n monitor -s 1 +system sh/exec.sh -n monitorInterval -s 1 sleep 3000 sql connect @@ -25,13 +27,16 @@ endi if $data05 != 0/10 then return -1 endi - +if $data06 != 0.000/unlimited then + return -1 +endi + print =============== check usage account -sql create database d1 -sql create database d2 -sql create database d3 -sql create database d4 -sql create database d5 +sql create database d1 wal 2 +sql create database d2 wal 2 +sql create database d3 wal 2 +sql create database d4 wal 2 +sql create database d5 wal 2 sql create table d1.t1 (ts timestamp, i int); sql create user u1 pass "u1" @@ -53,6 +58,75 @@ endi if $data05 != 0/10 then return -1 endi +if $data06 != 0.000/unlimited then + return -1 +endi + +print =============== step2 +sql alter account root pass "taosdata" tseries 10 storage 1073741824 streams 10 dbs 5 users 5 +sql show accounts +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 +if $data00 != root then + return -1 +endi +if $data02 != 4/5 then + return -1 +endi +if $data03 != 5/5 then + return -1 +endi +if $data04 != 1/10 then + return -1 +endi +if $data05 != 0/10 then + return -1 +endi +if $data06 != 0.000/1.000 then + return -1 +endi + +print =============== step3 +sql alter account root pass "taosdata" tseries 10 storage 16 streams 10 dbs 5 users 5 +sql show accounts +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 +if $data00 != root then + return -1 +endi +if $data02 != 4/5 then + return -1 +endi +if $data03 != 5/5 then + return -1 +endi +if $data04 != 1/10 then + return -1 +endi +if $data05 != 0/10 then + return -1 +endi +if $data06 != 0.000/0.000 then + return -1 +endi + +print =============== step4 +sql insert into d1.t1 values(now + 1s, 1) +sql insert into d1.t1 values(now + 2s, 2) + +# no write auth +sleep 3000 +sql_error insert into d1.t1 values(now + 3s, 2) +sql_error insert into d1.t1 values(now + 4s, 2) + +sql alter account root pass "taosdata" tseries 10 storage 36 streams 10 dbs 5 users 5 +sleep 3000 +sql insert into d1.t1 values(now + 5s, 1) +sql insert into d1.t1 values(now + 6s, 2) + +# no write auth +sleep 3000 +sql_error insert into d1.t1 values(now + 7s, 2) +sql_error insert into d1.t1 values(now + 8s, 2) + print =============== check grant sql_error create database d6