diff --git a/.travis.yml b/.travis.yml index 54a7856f7b..4ae38f5032 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,9 @@ matrix: 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 @@ -164,7 +166,9 @@ matrix: 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 diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index af4be8783d..e538281bc0 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -281,7 +281,7 @@ typedef struct STscObj { char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; char acctId[TSDB_ACCT_LEN]; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index b1ec8e09de..7755224389 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -370,7 +370,9 @@ void tscProcessAsyncRes(SSchedMsg *pMsg) { pSql->fp = pSql->fetchFp; } - (*pSql->fp)(pSql->param, taosres, code); + if (pSql->fp) { + (*pSql->fp)(pSql->param, taosres, code); + } if (shouldFree) { tscTrace("%p sqlObj is automatically freed in async res", pSql); diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index eaf9c21bfb..a880f4487e 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -132,14 +132,14 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { for (int32_t i = 0; i < numOfRows; ++i) { TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); char* dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i; - STR_WITH_MAXSIZE_TO_VARSTR(dst, pSchema[i].name, TSDB_COL_NAME_LEN - 1); + STR_WITH_MAXSIZE_TO_VARSTR(dst, pSchema[i].name, pField->bytes); char *type = tDataTypeDesc[pSchema[i].type].aName; pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1); dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * totalNumOfRows + pField->bytes * i; - STR_TO_VARSTR(dst, type); + STR_WITH_MAXSIZE_TO_VARSTR(dst, type, pField->bytes); int32_t bytes = pSchema[i].bytes; if (pSchema[i].type == TSDB_DATA_TYPE_BINARY || pSchema[i].type == TSDB_DATA_TYPE_NCHAR) { @@ -157,7 +157,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { if (i >= tscGetNumOfColumns(pMeta) && tscGetNumOfTags(pMeta) != 0) { char* output = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i; const char *src = "TAG"; - STR_WITH_SIZE_TO_VARSTR(output, src, strlen(src)); + STR_WITH_MAXSIZE_TO_VARSTR(output, src, pField->bytes); } } @@ -171,7 +171,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { // field name TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0); char* output = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * totalNumOfRows + pField->bytes * i; - STR_WITH_MAXSIZE_TO_VARSTR(output, pSchema[i].name, TSDB_COL_NAME_LEN - 1); + STR_WITH_MAXSIZE_TO_VARSTR(output, pSchema[i].name, pField->bytes); // type name pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1); @@ -193,7 +193,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) { pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 3); char *target = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i; const char *src = "TAG"; - STR_WITH_SIZE_TO_VARSTR(target, src, strlen(src)); + STR_WITH_MAXSIZE_TO_VARSTR(target, src, pField->bytes); pTagValue += pSchema[i].bytes; } @@ -220,15 +220,15 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, rowLen += ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE); - f.bytes = typeColLength; + f.bytes = typeColLength + VARSTR_HEADER_SIZE; f.type = TSDB_DATA_TYPE_BINARY; tstrncpy(f.name, "Type", sizeof(f.name)); pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); - pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength, + pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, typeColLength + VARSTR_HEADER_SIZE, typeColLength, false); - rowLen += typeColLength; + rowLen += typeColLength + VARSTR_HEADER_SIZE; f.bytes = sizeof(int32_t); f.type = TSDB_DATA_TYPE_INT; @@ -240,15 +240,15 @@ static int32_t tscBuildTableSchemaResultFields(SSqlObj *pSql, int32_t numOfCols, rowLen += sizeof(int32_t); - f.bytes = noteColLength; + f.bytes = noteColLength + VARSTR_HEADER_SIZE; f.type = TSDB_DATA_TYPE_BINARY; tstrncpy(f.name, "Note", sizeof(f.name)); pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); - pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength, + pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY, noteColLength + VARSTR_HEADER_SIZE, noteColLength, false); - rowLen += noteColLength; + rowLen += noteColLength + VARSTR_HEADER_SIZE; return rowLen; } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index c3ba1dabad..1b94850a19 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -97,7 +97,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1 useconds = str2int64(pToken->z); } else { // strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); - if (taosParseTime(pToken->z, time, pToken->n, timePrec) != TSDB_CODE_SUCCESS) { + if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) { return tscInvalidSQLErrMsg(error, "invalid timestamp format", pToken->z); } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index bfc3b33c92..9745c185d4 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -136,7 +136,7 @@ static int setColumnFilterInfoForTimestamp(SQueryInfo* pQueryInfo, tVariant* pVa STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); if (seg != NULL) { - if (taosParseTime(pVar->pz, &time, pVar->nLen, tinfo.precision) != TSDB_CODE_SUCCESS) { + if (taosParseTime(pVar->pz, &time, pVar->nLen, tinfo.precision, tsDaylight) != TSDB_CODE_SUCCESS) { return invalidSqlErrMsg(pQueryInfo->msg, msg); } } else { @@ -1034,7 +1034,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL /* db name is not specified, the tableName dose not include db name */ if (pDB != NULL) { - if (pDB->n >= TSDB_DB_NAME_LEN) { + if (pDB->n >= TSDB_ACCT_LEN + TSDB_DB_NAME_LEN) { return TSDB_CODE_TSC_INVALID_SQL; } @@ -3903,7 +3903,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t char* seg = strnchr(pRight->val.pz, '-', pRight->val.nLen, false); if (seg != NULL) { - if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO) == TSDB_CODE_SUCCESS) { + if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO, tsDaylight) == TSDB_CODE_SUCCESS) { parsed = true; } else { return TSDB_CODE_TSC_INVALID_SQL; @@ -4461,7 +4461,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pTagsSchema->type != TSDB_DATA_TYPE_BINARY && pTagsSchema->type != TSDB_DATA_TYPE_NCHAR) { len = tDataTypeDesc[pTagsSchema->type].nSize; } else { - len = varDataLen(pUpdateMsg->data); + len = varDataTLen(pUpdateMsg->data); } pUpdateMsg->tagValLen = htonl(len); // length may be changed after dump data @@ -6021,11 +6021,14 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* } } + if ((*pExpr)->_node.optr != TSDB_RELATION_EQUAL && (*pExpr)->_node.optr != TSDB_RELATION_NOT_EQUAL) { if (pRight->nodeType == TSQL_NODE_VALUE) { - if ( pRight->pVal->nType == TSDB_DATA_TYPE_BOOL - || pRight->pVal->nType == TSDB_DATA_TYPE_BINARY - || pRight->pVal->nType == TSDB_DATA_TYPE_NCHAR) { + if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL) { + return TSDB_CODE_TSC_INVALID_SQL; + } + if ((pRight->pVal->nType == TSDB_DATA_TYPE_BINARY || pRight->pVal->nType == TSDB_DATA_TYPE_NCHAR) + && (*pExpr)->_node.optr != TSDB_RELATION_LIKE) { return TSDB_CODE_TSC_INVALID_SQL; } } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 498460c37b..04b8ab8376 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1432,8 +1432,6 @@ bool tscShouldBeFreed(SSqlObj* pSql) { return false; } - assert(pSql->fp != NULL); - STscObj* pTscObj = pSql->pTscObj; if (pSql->pStream != NULL || pTscObj->pHb == pSql || pSql->pSubscription != NULL) { return false; diff --git a/src/client/tests/timeParseTest.cpp b/src/client/tests/timeParseTest.cpp index 1f53d50c1f..b37be0485b 100644 --- a/src/client/tests/timeParseTest.cpp +++ b/src/client/tests/timeParseTest.cpp @@ -24,19 +24,19 @@ TEST(testCase, parse_time) { int64_t time = 0, time1 = 0; - taosParseTime(t1, &time, strlen(t1), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t1, &time, strlen(t1), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1514739661952); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, timezone * MILLISECOND_PER_SECOND); char t2[] = "2018-1-1T1:1:1.952Z"; - taosParseTime(t2, &time, strlen(t2), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t2, &time, strlen(t2), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1514739661952 + 28800000); char t3[] = "2018-1-1 1:01:01.952"; - taosParseTime(t3, &time, strlen(t3), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t3, &time, strlen(t3), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1514739661952); char t4[] = "2018-1-1 1:01:01.9"; @@ -45,122 +45,122 @@ TEST(testCase, parse_time) { char t7[] = "2018-01-01 01:01:01.9"; char t8[] = "2018-01-01 01:01:01.9007865"; - taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t5, &time1, strlen(t5), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t5, &time1, strlen(t5), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); - taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t6, &time1, strlen(t6), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t6, &time1, strlen(t6), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); - taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t7, &time1, strlen(t7), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t7, &time1, strlen(t7), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); - taosParseTime(t5, &time, strlen(t5), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t8, &time1, strlen(t8), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t5, &time, strlen(t5), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t8, &time1, strlen(t8), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); char t9[] = "2017-4-3 1:1:2.980"; char t10[] = "2017-4-3T2:1:2.98+9:00"; - taosParseTime(t9, &time, strlen(t9), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t9, &time, strlen(t9), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); char t11[] = "2017-4-3T2:1:2.98+09:00"; - taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); char t12[] = "2017-4-3T2:1:2.98+0900"; - taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t12, &time1, strlen(t12), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t12, &time1, strlen(t12), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); taos_options(TSDB_OPTION_TIMEZONE, "UTC"); deltaToUtcInitOnce(); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 0); taos_options(TSDB_OPTION_TIMEZONE, "Asia/Shanghai"); deltaToUtcInitOnce(); char t14[] = "1970-1-1T0:0:0Z"; - taosParseTime(t14, &time, strlen(t14), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t14, &time, strlen(t14), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 0); char t40[] = "1970-1-1 0:0:0.999999999"; - taosParseTime(t40, &time, strlen(t40), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t40, &time, strlen(t40), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 999 + timezone * MILLISECOND_PER_SECOND); char t41[] = "1997-1-1 0:0:0.999999999"; - taosParseTime(t41, &time, strlen(t41), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t41, &time, strlen(t41), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 852048000999); int64_t k = timezone; char t42[] = "1997-1-1T0:0:0.999999999Z"; - taosParseTime(t42, &time, strlen(t42), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t42, &time, strlen(t42), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 852048000999 - timezone * MILLISECOND_PER_SECOND); //////////////////////////////////////////////////////////////////// // illegal timestamp format char t15[] = "2017-12-33 0:0:0"; - EXPECT_EQ(taosParseTime(t15, &time, strlen(t15), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t15, &time, strlen(t15), TSDB_TIME_PRECISION_MILLI, 0), -1); char t16[] = "2017-12-31 99:0:0"; - EXPECT_EQ(taosParseTime(t16, &time, strlen(t16), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t16, &time, strlen(t16), TSDB_TIME_PRECISION_MILLI, 0), -1); char t17[] = "2017-12-31T9:0:0"; - EXPECT_EQ(taosParseTime(t17, &time, strlen(t17), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t17, &time, strlen(t17), TSDB_TIME_PRECISION_MILLI, 0), -1); char t18[] = "2017-12-31T9:0:0.Z"; - EXPECT_EQ(taosParseTime(t18, &time, strlen(t18), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t18, &time, strlen(t18), TSDB_TIME_PRECISION_MILLI, 0), -1); char t19[] = "2017-12-31 9:0:0.-1"; - EXPECT_EQ(taosParseTime(t19, &time, strlen(t19), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t19, &time, strlen(t19), TSDB_TIME_PRECISION_MILLI, 0), -1); char t20[] = "2017-12-31 9:0:0.1+12:99"; - EXPECT_EQ(taosParseTime(t20, &time, strlen(t20), TSDB_TIME_PRECISION_MILLI), 0); + EXPECT_EQ(taosParseTime(t20, &time, strlen(t20), TSDB_TIME_PRECISION_MILLI, 0), 0); EXPECT_EQ(time, 1514682000100); char t21[] = "2017-12-31T9:0:0.1+12:99"; - EXPECT_EQ(taosParseTime(t21, &time, strlen(t21), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t21, &time, strlen(t21), TSDB_TIME_PRECISION_MILLI, 0), -1); char t22[] = "2017-12-31 9:0:0.1+13:1"; - EXPECT_EQ(taosParseTime(t22, &time, strlen(t22), TSDB_TIME_PRECISION_MILLI), 0); + EXPECT_EQ(taosParseTime(t22, &time, strlen(t22), TSDB_TIME_PRECISION_MILLI, 0), 0); char t23[] = "2017-12-31T9:0:0.1+13:1"; - EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI), 0); + EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI, 0), 0); //======================== add some case ============================// char b1[] = "9999-12-31 23:59:59.999"; - taosParseTime(b1, &time, strlen(b1), TSDB_TIME_PRECISION_MILLI); + taosParseTime(b1, &time, strlen(b1), TSDB_TIME_PRECISION_MILLI,0); EXPECT_EQ(time, 253402271999999); char b2[] = "2020-01-01 01:01:01.321"; - taosParseTime(b2, &time, strlen(b2), TSDB_TIME_PRECISION_MILLI); + taosParseTime(b2, &time, strlen(b2), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1577811661321); taos_options(TSDB_OPTION_TIMEZONE, "America/New_York"); deltaToUtcInitOnce(); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 18000 * MILLISECOND_PER_SECOND); taos_options(TSDB_OPTION_TIMEZONE, "Asia/Tokyo"); deltaToUtcInitOnce(); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, -32400 * MILLISECOND_PER_SECOND); taos_options(TSDB_OPTION_TIMEZONE, "Asia/Shanghai"); deltaToUtcInitOnce(); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, -28800 * MILLISECOND_PER_SECOND); } diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index ea0eb9ff29..3ad2df8d3a 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -36,7 +36,7 @@ extern "C" { #define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \ do { \ - char *_e = stpncpy(varDataVal(x), (str), (_maxs)); \ + char *_e = stpncpy(varDataVal(x), (str), (_maxs)-VARSTR_HEADER_SIZE); \ varDataSetLen(x, (_e - (x)-VARSTR_HEADER_SIZE)); \ } while (0) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 53d821b3d8..eaceea468b 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -170,6 +170,7 @@ extern char gitinfo[]; extern char gitinfoOfInternal[]; extern char buildinfo[]; +extern int8_t tsDaylight; extern char tsTimezone[64]; extern char tsLocale[64]; extern char tsCharset[64]; // default encode string diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index 77e91acc14..40cdac9833 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -588,7 +588,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) { if (kvRowNCols(nrow) - colIdx - 1 > 0) { for (int i = colIdx + 1; i < kvRowNCols(nrow); i++) { kvRowColIdxAt(nrow, i)->colId = kvRowColIdxAt(row, i)->colId; - kvRowColIdxAt(nrow, i)->offset += diff; + kvRowColIdxAt(nrow, i)->offset = kvRowColIdxAt(row, i)->offset + diff; } memcpy(kvRowColVal(nrow, kvRowColIdxAt(nrow, colIdx + 1)), kvRowColVal(row, kvRowColIdxAt(row, colIdx + 1)), POINTER_DISTANCE(kvRowEnd(row), kvRowColVal(row, kvRowColIdxAt(row, colIdx + 1)))); diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 86fc6deb1b..e80597ca95 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -198,6 +198,7 @@ char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; char tsInternalPass[] = "secretkey"; int32_t tsMonitorInterval = 30; // seconds +int8_t tsDaylight = 0; char tsTimezone[64] = {0}; char tsLocale[TSDB_LOCALE_LEN] = {0}; char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c index 0e8e1316b3..ae6ffea59a 100644 --- a/src/common/src/ttimezone.c +++ b/src/common/src/ttimezone.c @@ -58,6 +58,7 @@ void tsSetTimeZone() { * (BST, +0100) */ sprintf(tsTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); + tsDaylight = daylight; uPrint("timezone format changed to %s", tsTimezone); } diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 13f3c0a2b0..769dfea774 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -256,11 +256,30 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { SDataRow trow = (SDataRow)pBlk->data; tdInitDataRow(trow, pSchema); + union { + char buf[sizeof(int64_t)]; + tstr str; + } nullVal; + for (int32_t i = 0; i < pSchema->numOfCols; i++) { STColumn *c = pSchema->columns + i; char* val = (char*)row[i]; if (IS_VAR_DATA_TYPE(c->type)) { - val -= sizeof(VarDataLenT); + if (val == NULL) { + val = nullVal.buf; + if (c->type == TSDB_DATA_TYPE_BINARY) { + setNull(nullVal.str.data, TSDB_DATA_TYPE_BINARY, 1); + nullVal.str.len = 1; + } else { + setNull(nullVal.str.data, TSDB_DATA_TYPE_NCHAR, 4); + nullVal.str.len = 4; + } + } else { + val -= sizeof(VarDataLenT); + } + } else if (val == NULL) { + val = nullVal.buf; + setNull(val, c->type, c->bytes); } tdAppendColVal(trow, val, c->type, c->bytes, c->offset); } diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index d35e82fa47..30fdd21b99 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -616,6 +616,16 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) { pStatus->numOfCores = htons((uint16_t) tsNumOfCores); pStatus->diskAvailable = tsAvailDataDirGB; pStatus->alternativeRole = (uint8_t) tsAlternativeRole; + + // fill cluster cfg parameters + pStatus->clusterCfg.numOfMnodes = tsNumOfMnodes; + pStatus->clusterCfg.mnodeEqualVnodeNum = tsMnodeEqualVnodeNum; + pStatus->clusterCfg.offlineThreshold = tsOfflineThreshold; + pStatus->clusterCfg.statusInterval = tsStatusInterval; + strcpy(pStatus->clusterCfg.arbitrator, tsArbitrator); + strcpy(pStatus->clusterCfg.timezone, tsTimezone); + strcpy(pStatus->clusterCfg.locale, tsLocale); + strcpy(pStatus->clusterCfg.charset, tsCharset); vnodeBuildStatusMsg(pStatus); contLen = sizeof(SDMStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad); diff --git a/src/inc/taos.h b/src/inc/taos.h index bf6942be8b..9ac97a24e1 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; - short bytes; + uint16_t bytes; } TAOS_FIELD; #ifdef _TD_GO_DLL_ diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 8effacbbbf..3f1cbffa53 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -121,6 +121,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnod TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, 0, 0x0332, "mnode vgroup not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_REMOVE_MASTER, 0, 0x0333, "mnode cant not remove master") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, 0, 0x0334, "mnode no enough dnodes") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT, 0, 0x0335, "mnode cluster cfg inconsistent") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account") diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index b9cdc0a9f3..fcb6d66422 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -250,7 +250,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_ID_LEN]; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; int8_t igExists; int8_t getMeta; int16_t numOfTags; @@ -268,7 +268,7 @@ typedef struct { typedef struct { char tableId[TSDB_TABLE_ID_LEN]; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; int16_t type; /* operation type */ int16_t numOfCols; /* number of schema */ int32_t tagValLen; @@ -557,18 +557,30 @@ typedef struct { } SDMMnodeInfos; typedef struct { - uint32_t version; - int32_t dnodeId; - char dnodeEp[TSDB_EP_LEN]; - uint32_t moduleStatus; - uint32_t lastReboot; // time stamp for last reboot - uint16_t numOfTotalVnodes; // from config file - uint16_t openVnodes; - uint16_t numOfCores; - float diskAvailable; // GB - uint8_t alternativeRole; - uint8_t reserve[15]; - SVnodeLoad load[]; + int32_t numOfMnodes; // tsNumOfMnodes + int32_t mnodeEqualVnodeNum; // tsMnodeEqualVnodeNum + int32_t offlineThreshold; // tsOfflineThreshold + int32_t statusInterval; // tsStatusInterval + char arbitrator[TSDB_EP_LEN]; // tsArbitrator + char timezone[64]; // tsTimezone + char locale[TSDB_LOCALE_LEN]; // tsLocale + char charset[TSDB_LOCALE_LEN]; // tsCharset +} SClusterCfg; + +typedef struct { + uint32_t version; + int32_t dnodeId; + char dnodeEp[TSDB_EP_LEN]; + uint32_t moduleStatus; + uint32_t lastReboot; // time stamp for last reboot + uint16_t numOfTotalVnodes; // from config file + uint16_t openVnodes; + uint16_t numOfCores; + float diskAvailable; // GB + uint8_t alternativeRole; + uint8_t reserve[15]; + SClusterCfg clusterCfg; + SVnodeLoad load[]; } SDMStatusMsg; typedef struct { @@ -670,7 +682,7 @@ typedef struct { */ typedef struct { int8_t type; - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; uint16_t payloadLen; char payload[]; } SCMShowMsg; diff --git a/src/inc/trpc.h b/src/inc/trpc.h index 748fad0e62..6c5d7fa889 100644 --- a/src/inc/trpc.h +++ b/src/inc/trpc.h @@ -78,12 +78,13 @@ void rpcClose(void *); void *rpcMallocCont(int contLen); void rpcFreeCont(void *pCont); void *rpcReallocCont(void *ptr, int contLen); -void rpcSendRequest(void *thandle, const SRpcIpSet *pIpSet, const SRpcMsg *pMsg); +void *rpcSendRequest(void *thandle, const SRpcIpSet *pIpSet, const SRpcMsg *pMsg); void rpcSendResponse(const SRpcMsg *pMsg); void rpcSendRedirectRsp(void *pConn, const SRpcIpSet *pIpSet); int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo); void rpcSendRecv(void *shandle, SRpcIpSet *pIpSet, const SRpcMsg *pReq, SRpcMsg *pRsp); int rpcReportProgress(void *pConn, char *pCont, int contLen); +void rpcCanelRequest(void *pContext); #ifdef __cplusplus } diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index f04607f6fa..7705db4b27 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -469,7 +469,6 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { } while( row != NULL); fclose(fp); - taos_free_result(result); return numOfRows; } diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index bd9d41a4de..ab5781e74f 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -817,7 +817,7 @@ void queryDB(TAOS *taos, char *command) { i--; } - if (i == 0) { + if (code != 0) { fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(pSql)); taos_free_result(pSql); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 69783defc7..aeb6f4beb9 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -613,7 +613,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char* name = mnodeGetDbStr(pDb->name); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, TSDB_DB_NAME_LEN - 1); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index d2af86badb..fda3f48da5 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -277,6 +277,20 @@ static void mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) { mPrint("cfg dnode rsp is received"); } +static bool mnodeCheckClusterCfgPara(const SClusterCfg *clusterCfg) { + if (clusterCfg->numOfMnodes != tsNumOfMnodes) return false; + if (clusterCfg->mnodeEqualVnodeNum != tsMnodeEqualVnodeNum) return false; + if (clusterCfg->offlineThreshold != tsOfflineThreshold) return false; + if (clusterCfg->statusInterval != tsStatusInterval) return false; + + if (0 != strncasecmp(clusterCfg->arbitrator, tsArbitrator, strlen(tsArbitrator))) return false; + if (0 != strncasecmp(clusterCfg->timezone, tsTimezone, strlen(tsTimezone))) return false; + if (0 != strncasecmp(clusterCfg->locale, tsLocale, strlen(tsLocale))) return false; + if (0 != strncasecmp(clusterCfg->charset, tsCharset, strlen(tsCharset))) return false; + + return true; +} + static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { SDMStatusMsg *pStatus = pMsg->rpcMsg.pCont; pStatus->dnodeId = htonl(pStatus->dnodeId); @@ -312,7 +326,6 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { pDnode->alternativeRole = pStatus->alternativeRole; pDnode->totalVnodes = pStatus->numOfTotalVnodes; pDnode->moduleStatus = pStatus->moduleStatus; - pDnode->lastAccess = tsAccessSquence; if (pStatus->dnodeId == 0) { mTrace("dnode:%d %s, first access", pDnode->dnodeId, pDnode->dnodeEp); @@ -338,6 +351,14 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { } if (pDnode->status == TAOS_DN_STATUS_OFFLINE) { + // Verify whether the cluster parameters are consistent when status change from offline to ready + bool ret = mnodeCheckClusterCfgPara(&(pStatus->clusterCfg)); + if (false == ret) { + mnodeDecDnodeRef(pDnode); + mError("dnode %s cluster cfg parameters inconsistent", pStatus->dnodeEp); + return TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT; + } + mTrace("dnode:%d, from offline to online", pDnode->dnodeId); pDnode->status = TAOS_DN_STATUS_READY; balanceUpdateMnode(); @@ -352,6 +373,8 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_OUT_OF_MEMORY; } + pDnode->lastAccess = tsAccessSquence; + mnodeGetMnodeInfos(&pRsp->mnodes); pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId); @@ -570,7 +593,7 @@ static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, vo cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 43ee45f3b1..41bd6974db 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -401,9 +401,9 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); if (pDnode != NULL) { - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols]); } else { - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, "invalid ep", pShow->bytes[cols] - VARSTR_HEADER_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, "invalid ep", pShow->bytes[cols]); } mnodeDecDnodeRef(pDnode); @@ -411,7 +411,7 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char* roles = mnodeGetMnodeRoleStr(pMnode->role); - STR_TO_VARSTR(pWrite, roles); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 4720fb0ddc..31ca47929c 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -108,8 +108,8 @@ SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) { } void mnodeReleaseConn(SConnObj *pConn) { - if(pConn == NULL) return; - taosCacheRelease(tsMnodeConnCache, (void**)&pConn, false); + if (pConn == NULL) return; + taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false); } SConnObj *mnodeAccquireConn(uint32_t connId, char *user, uint32_t ip, uint16_t port) { @@ -138,7 +138,7 @@ SConnObj *mnodeAccquireConn(uint32_t connId, char *user, uint32_t ip, uint16_t p static void mnodeFreeConn(void *data) { SConnObj *pConn = data; tfree(pConn->pQueries); - tfree(pConn->pQueries); + tfree(pConn->pStreams); mTrace("connId:%d, is destroyed", pConn->connId); } @@ -235,14 +235,12 @@ static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, voi cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - size_t size = sizeof(pConnObj->user); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); - size = sizeof(ipStr); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -356,18 +354,16 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v snprintf(ipStr, QUERY_ID_SIZE + 1, "%u:%u", pConnObj->connId, htonl(pDesc->queryId)); pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, QUERY_ID_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - size_t size = sizeof(pConnObj->user); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); - size = sizeof(ipStr); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -379,7 +375,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, TSDB_SHOW_SQL_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); cols++; numOfRows++; @@ -479,18 +475,16 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v snprintf(ipStr, QUERY_ID_SIZE + 1, "%u:%u", pConnObj->connId, htonl(pDesc->streamId)); pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, QUERY_ID_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - size_t size = sizeof(pConnObj->user); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); - size = sizeof(ipStr); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -506,7 +500,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, TSDB_SHOW_SQL_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 0ff198bf8f..a2deeaa489 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -2103,7 +2103,7 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void cols++; SSchema tbCol = tGetTableNameColumnSchema(); - pShow->bytes[cols] = tbCol.bytes; + pShow->bytes[cols] = tbCol.bytes + VARSTR_HEADER_SIZE; pSchema[cols].type = tbCol.type; strcpy(pSchema[cols].name, "stable_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -2161,7 +2161,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows char *pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, sizeof(tableName) - 1); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -2182,7 +2182,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows memset(tableName, 0, sizeof(tableName)); if (pTable->info.type == TSDB_CHILD_TABLE) { mnodeExtractTableName(pTable->superTable->info.tableId, tableName); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, sizeof(tableName) - 1); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, pShow->bytes[cols]); } cols++; @@ -2352,7 +2352,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro char *pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, sizeof(tableName) - 1); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, tableName, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -2364,7 +2364,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pTable->sql, TSDB_MAX_SQL_SHOW_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pTable->sql, pShow->bytes[cols]); cols++; numOfRows++; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 95457c83a0..053ea3ef75 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -315,8 +315,7 @@ static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, voi cols = 0; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - size_t size = sizeof(pUser->user); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->user, size); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->user, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -337,7 +336,7 @@ static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, voi cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->acct, sizeof(pUser->user)); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->acct, pShow->bytes[cols]); cols++; numOfRows++; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 25b9daf00c..bc6c2665c8 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -479,12 +479,12 @@ int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pC if (pDnode != NULL) { pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols] - VARSTR_HEADER_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->dnodeEp, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char *role = mnodeGetMnodeRoleStr(pVgroup->vnodeGid[i].role); - STR_TO_VARSTR(pWrite, role); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, role, pShow->bytes[cols]); cols++; } else { pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/plugins/http/inc/gcHandle.h b/src/plugins/http/inc/gcHandle.h index ed1e9302eb..a3688c6c38 100644 --- a/src/plugins/http/inc/gcHandle.h +++ b/src/plugins/http/inc/gcHandle.h @@ -16,15 +16,11 @@ #ifndef TDENGINE_GC_HANDLE_H #define TDENGINE_GC_HANDLE_H -#include -#include -#include -#include - #include "http.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpUtil.h" #include "httpResp.h" +#include "httpSql.h" #define GC_ROOT_URL_POS 0 #define GC_ACTION_URL_POS 1 diff --git a/src/plugins/http/inc/httpAuth.h b/src/plugins/http/inc/httpAuth.h new file mode 100644 index 0000000000..b8fabbe1ec --- /dev/null +++ b/src/plugins/http/inc/httpAuth.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_TOKEN_H +#define TDENGINE_HTTP_TOKEN_H + +bool httpParseBasicAuthToken(HttpContext *pContext, char *token, int len); +bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len); +bool httpGenTaosdAuthToken(HttpContext *pContext, char *token, int maxLen); + +#endif \ No newline at end of file diff --git a/src/plugins/http/inc/httpContext.h b/src/plugins/http/inc/httpContext.h new file mode 100644 index 0000000000..a2d50d6b7f --- /dev/null +++ b/src/plugins/http/inc/httpContext.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_CONTEXT_H +#define TDENGINE_HTTP_CONTEXT_H + +#include "httpInt.h" + +bool httpInitContexts(); +void httpCleanupContexts(); +const char *httpContextStateStr(HttpContextState state); + +HttpContext *httpCreateContext(int32_t fd); +bool httpInitContext(HttpContext *pContext); +HttpContext *httpGetContext(void * pContext); +void httpReleaseContext(HttpContext *pContext); +void httpCloseContextByServer(HttpContext *pContext); +void httpCloseContextByApp(HttpContext *pContext); +void httpNotifyContextClose(HttpContext *pContext); +bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState); + +#endif diff --git a/src/plugins/http/inc/httpHandle.h b/src/plugins/http/inc/httpHandle.h index b888543137..3e6356d805 100644 --- a/src/plugins/http/inc/httpHandle.h +++ b/src/plugins/http/inc/httpHandle.h @@ -13,304 +13,11 @@ * along with this program. If not, see . */ -#ifndef TDENGINE_HTTP_SERVER_H -#define TDENGINE_HTTP_SERVER_H - -#include -#include "pthread.h" -#include "semaphore.h" -#include "tmempool.h" -#include "taosdef.h" -#include "tutil.h" -#include "zlib.h" -#include "http.h" -#include "httpJson.h" - -#define HTTP_MAX_CMD_SIZE 1024 -#define HTTP_MAX_BUFFER_SIZE 1024*1024 - -#define HTTP_LABEL_SIZE 8 -#define HTTP_MAX_EVENTS 10 -#define HTTP_BUFFER_SIZE 1024*65 //65k -#define HTTP_DECOMPRESS_BUF_SIZE 1024*64 -#define HTTP_STEP_SIZE 1024 //http message get process step by step -#define HTTP_MAX_URL 5 //http url stack size -#define HTTP_METHOD_SCANNER_SIZE 7 //http method fp size -#define HTTP_GC_TARGET_SIZE 512 - -#define HTTP_VERSION_10 0 -#define HTTP_VERSION_11 1 -//#define HTTP_VERSION_12 2 - -#define HTTP_UNCUNKED 0 -#define HTTP_CHUNKED 1 - -#define HTTP_KEEPALIVE_NO_INPUT 0 -#define HTTP_KEEPALIVE_ENABLE 1 -#define HTTP_KEEPALIVE_DISABLE 2 - -#define HTTP_REQTYPE_OTHERS 0 -#define HTTP_REQTYPE_LOGIN 1 -#define HTTP_REQTYPE_HEARTBEAT 2 -#define HTTP_REQTYPE_SINGLE_SQL 3 -#define HTTP_REQTYPE_MULTI_SQL 4 - -#define HTTP_CHECK_BODY_ERROR -1 -#define HTTP_CHECK_BODY_CONTINUE 0 -#define HTTP_CHECK_BODY_SUCCESS 1 - -#define HTTP_WRITE_RETRY_TIMES 500 -#define HTTP_WRITE_WAIT_TIME_MS 5 -#define HTTP_EXPIRED_TIME 60000 -#define HTTP_DELAY_CLOSE_TIME_MS 500 - -#define HTTP_COMPRESS_IDENTITY 0 -#define HTTP_COMPRESS_GZIP 2 - -#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN) - -typedef enum { - HTTP_CONTEXT_STATE_READY, - HTTP_CONTEXT_STATE_HANDLING, - HTTP_CONTEXT_STATE_DROPPING, - HTTP_CONTEXT_STATE_CLOSED -} HttpContextState; - -struct HttpContext; -struct HttpThread; - -typedef struct { - void *signature; - int expire; - int access; - void *taos; - char id[HTTP_SESSION_ID_LEN]; -} HttpSession; - -typedef enum { - HTTP_CMD_TYPE_UN_SPECIFIED, - HTTP_CMD_TYPE_CREATE_DB, - HTTP_CMD_TYPE_CREATE_STBALE, - HTTP_CMD_TYPE_INSERT -} HttpSqlCmdType; - -typedef enum { HTTP_CMD_STATE_NOT_RUN_YET, HTTP_CMD_STATE_RUN_FINISHED } HttpSqlCmdState; - -typedef enum { HTTP_CMD_RETURN_TYPE_WITH_RETURN, HTTP_CMD_RETURN_TYPE_NO_RETURN } HttpSqlCmdReturnType; - -typedef struct { - // used by single cmd - char *nativSql; - int32_t numOfRows; - int32_t code; - - // these are the locations in the buffer - int32_t tagNames[TSDB_MAX_TAGS]; - int32_t tagValues[TSDB_MAX_TAGS]; - int32_t timestamp; - int32_t metric; - int32_t stable; - int32_t table; - int32_t values; - int32_t sql; - - // used by multi-cmd - int8_t cmdType; - int8_t cmdReturnType; - int8_t cmdState; - int8_t tagNum; -} HttpSqlCmd; - -typedef struct { - HttpSqlCmd *cmds; - int16_t pos; - int16_t size; - int16_t maxSize; - int32_t bufferPos; - int32_t bufferSize; - char * buffer; -} HttpSqlCmds; - -typedef struct { - char *module; - bool (*decodeFp)(struct HttpContext *pContext); -} HttpDecodeMethod; - -typedef struct { - void (*startJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, void *result); - void (*stopJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd); - bool (*buildQueryJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, void *result, int numOfRows); - void (*buildAffectRowJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int affectRows); - void (*initJsonFp)(struct HttpContext *pContext); - void (*cleanJsonFp)(struct HttpContext *pContext); - bool (*checkFinishedFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int code); - void (*setNextCmdFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int code); -} HttpEncodeMethod; - -typedef struct { - char *pos; - int32_t len; -} HttpBuf; - -typedef struct { - char buffer[HTTP_BUFFER_SIZE]; - int bufsize; - char *pLast; - char *pCur; - HttpBuf method; - HttpBuf path[HTTP_MAX_URL]; // url: dbname/meter/query - HttpBuf data; // body content - HttpBuf token; // auth token - HttpDecodeMethod *pMethod; -} HttpParser; - -typedef struct HttpContext { - void * signature; - int fd; - uint32_t accessTimes; - uint32_t lastAccessTime; - uint8_t httpVersion; - uint8_t httpChunked; - uint8_t httpKeepAlive; // http1.0 and not keep-alive, close connection immediately - uint8_t fromMemPool; - uint8_t acceptEncoding; - uint8_t contentEncoding; - uint8_t reqType; - uint8_t parsed; - int32_t state; - char ipstr[22]; - char user[TSDB_USER_LEN]; // parsed from auth token or login message - char pass[TSDB_PASSWORD_LEN]; - void *taos; - HttpSession *session; - z_stream gzipStream; - HttpEncodeMethod *encodeMethod; - HttpSqlCmd singleCmd; - HttpSqlCmds *multiCmds; - JsonBuf *jsonBuf; - HttpParser parser; - void *timer; - struct HttpThread *pThread; - struct HttpContext *prev; - struct HttpContext *next; -} HttpContext; - -typedef struct HttpThread { - pthread_t thread; - HttpContext * pHead; - pthread_mutex_t threadMutex; - bool stop; - int pollFd; - int numOfFds; - int threadId; - char label[HTTP_LABEL_SIZE]; - bool (*processData)(HttpContext *pContext); - struct HttpServer *pServer; // handle passed by upper layer during pServer initialization -} HttpThread; - -typedef struct HttpServer { - char label[HTTP_LABEL_SIZE]; - uint32_t serverIp; - uint16_t serverPort; - bool online; - int fd; - int cacheContext; - int sessionExpire; - int numOfThreads; - HttpDecodeMethod *methodScanner[HTTP_METHOD_SCANNER_SIZE]; - int methodScannerLen; - pthread_mutex_t serverMutex; - void *pSessionHash; - void *pContextPool; - void *expireTimer; - HttpThread *pThreads; - pthread_t thread; - bool (*processData)(HttpContext *pContext); - int requestNum; - void *timerHandle; -} HttpServer; - -// http util method -bool httpCheckUsedbSql(char *sql); -void httpTimeToString(time_t t, char *buf, int buflen); - -// http init method -void *httpInitServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle); -void httpCleanUpServer(HttpServer *pServer); - -// http server connection -void httpCleanUpConnect(HttpServer *pServer); -bool httpInitConnect(HttpServer *pServer); - -// http context for each client connection -HttpContext *httpCreateContext(HttpServer *pServer); -bool httpInitContext(HttpContext *pContext); -void httpCloseContextByApp(HttpContext *pContext); -void httpCloseContextByServer(HttpThread *pThread, HttpContext *pContext); - -// http session method -void httpCreateSession(HttpContext *pContext, void *taos); -void httpAccessSession(HttpContext *pContext); -void httpFetchSession(HttpContext *pContext); -void httpRestoreSession(HttpContext *pContext); -void httpRemoveExpireSessions(HttpServer *pServer); -bool httpInitAllSessions(HttpServer *pServer); -void httpRemoveAllSessions(HttpServer *pServer); -void httpProcessSessionExpire(void *handle, void *tmrId); - -// http request parser -void httpAddMethod(HttpServer *pServer, HttpDecodeMethod *pMethod); - -// http token method -bool httpParseBasicAuthToken(HttpContext *pContext, char *token, int len); -bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len); -bool httpGenTaosdAuthToken(HttpContext *pContext, char *token, int maxLen); - -// util -bool httpUrlMatch(HttpContext *pContext, int pos, char *cmp); -bool httpProcessData(HttpContext *pContext); -bool httpReadDataImp(HttpContext *pContext); -bool httpParseRequest(HttpContext* pContext); -int httpCheckReadCompleted(HttpContext* pContext); -void httpReadDirtyData(HttpContext *pContext); +#ifndef TDENGINE_HTTP_HANDLE_H +#define TDENGINE_HTTP_HANDLE_H // http request handler void httpProcessRequest(HttpContext *pContext); - -// http json printer -JsonBuf *httpMallocJsonBuf(HttpContext *pContext); -void httpFreeJsonBuf(HttpContext *pContext); - -// http multicmds util - -int32_t httpAddToSqlCmdBuffer(HttpContext *pContext, const char *const format, ...); -int32_t httpAddToSqlCmdBufferNoTerminal(HttpContext *pContext, const char *const format, ...); -int32_t httpAddToSqlCmdBufferWithSize(HttpContext *pContext, int mallocSize); -int32_t httpAddToSqlCmdBufferTerminal(HttpContext *pContext); - -bool httpMallocMultiCmds(HttpContext *pContext, int cmdSize, int bufferSize); -bool httpReMallocMultiCmdsSize(HttpContext *pContext, int cmdSize); -bool httpReMallocMultiCmdsBuffer(HttpContext *pContext, int bufferSize); -void httpFreeMultiCmds(HttpContext *pContext); - -HttpSqlCmd *httpNewSqlCmd(HttpContext *pContext); -HttpSqlCmd *httpCurrSqlCmd(HttpContext *pContext); -int httpCurSqlCmdPos(HttpContext *pContext); - -void httpTrimTableName(char *name); -int httpShrinkTableName(HttpContext *pContext, int pos, char *name); -char *httpGetCmdsString(HttpContext *pContext, int pos); - -int httpGzipDeCompress(char *srcData, int32_t nSrcData, char *destData, int32_t *nDestData); -int httpGzipCompressInit(HttpContext *pContext); -int httpGzipCompress(HttpContext *pContext, char *inSrcData, int32_t inSrcDataLen, - char *outDestData, int32_t *outDestDataLen, bool isTheLast); - -extern const char *httpKeepAliveStr[]; -extern const char *httpVersionStr[]; -const char* httpContextStateStr(HttpContextState state); - -bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState); -void httpRemoveContextFromEpoll(HttpThread *pThread, HttpContext *pContext); +bool httpProcessData(HttpContext *pContext); #endif diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h new file mode 100644 index 0000000000..5d94e8456e --- /dev/null +++ b/src/plugins/http/inc/httpInt.h @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_INT_H +#define TDENGINE_HTTP_INT_H + +#include +#include "pthread.h" +#include "semaphore.h" +#include "tmempool.h" +#include "taosdef.h" +#include "tutil.h" +#include "zlib.h" +#include "http.h" +#include "httpCode.h" +#include "httpLog.h" +#include "httpJson.h" + +#define HTTP_MAX_CMD_SIZE 1024 +#define HTTP_MAX_BUFFER_SIZE 1024*1024 + +#define HTTP_LABEL_SIZE 8 +#define HTTP_MAX_EVENTS 10 +#define HTTP_BUFFER_SIZE 1024*65 //65k +#define HTTP_DECOMPRESS_BUF_SIZE 1024*64 +#define HTTP_STEP_SIZE 1024 //http message get process step by step +#define HTTP_MAX_URL 5 //http url stack size +#define HTTP_METHOD_SCANNER_SIZE 7 //http method fp size +#define HTTP_GC_TARGET_SIZE 512 + +#define HTTP_VERSION_10 0 +#define HTTP_VERSION_11 1 +//#define HTTP_VERSION_12 2 + +#define HTTP_UNCUNKED 0 +#define HTTP_CHUNKED 1 + +#define HTTP_KEEPALIVE_NO_INPUT 0 +#define HTTP_KEEPALIVE_ENABLE 1 +#define HTTP_KEEPALIVE_DISABLE 2 + +#define HTTP_REQTYPE_OTHERS 0 +#define HTTP_REQTYPE_LOGIN 1 +#define HTTP_REQTYPE_HEARTBEAT 2 +#define HTTP_REQTYPE_SINGLE_SQL 3 +#define HTTP_REQTYPE_MULTI_SQL 4 + +#define HTTP_CHECK_BODY_ERROR -1 +#define HTTP_CHECK_BODY_CONTINUE 0 +#define HTTP_CHECK_BODY_SUCCESS 1 + +#define HTTP_WRITE_RETRY_TIMES 500 +#define HTTP_WRITE_WAIT_TIME_MS 5 +#define HTTP_EXPIRED_TIME 60000 +#define HTTP_DELAY_CLOSE_TIME_MS 500 + +#define HTTP_COMPRESS_IDENTITY 0 +#define HTTP_COMPRESS_GZIP 2 + +#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN) + +typedef enum { + HTTP_SERVER_INIT, + HTTP_SERVER_RUNNING, + HTTP_SERVER_CLOSING, + HTTP_SERVER_CLOSED +} HttpServerStatus; + +typedef enum { + HTTP_CONTEXT_STATE_READY, + HTTP_CONTEXT_STATE_HANDLING, + HTTP_CONTEXT_STATE_DROPPING, + HTTP_CONTEXT_STATE_CLOSED +} HttpContextState; + +struct HttpContext; +struct HttpThread; + +typedef struct { + char id[HTTP_SESSION_ID_LEN]; + int refCount; + void *taos; +} HttpSession; + +typedef enum { + HTTP_CMD_TYPE_UN_SPECIFIED, + HTTP_CMD_TYPE_CREATE_DB, + HTTP_CMD_TYPE_CREATE_STBALE, + HTTP_CMD_TYPE_INSERT +} HttpSqlCmdType; + +typedef enum { HTTP_CMD_STATE_NOT_RUN_YET, HTTP_CMD_STATE_RUN_FINISHED } HttpSqlCmdState; + +typedef enum { HTTP_CMD_RETURN_TYPE_WITH_RETURN, HTTP_CMD_RETURN_TYPE_NO_RETURN } HttpSqlCmdReturnType; + +typedef struct { + // used by single cmd + char *nativSql; + int32_t numOfRows; + int32_t code; + + // these are the locations in the buffer + int32_t tagNames[TSDB_MAX_TAGS]; + int32_t tagValues[TSDB_MAX_TAGS]; + int32_t timestamp; + int32_t metric; + int32_t stable; + int32_t table; + int32_t values; + int32_t sql; + + // used by multi-cmd + int8_t cmdType; + int8_t cmdReturnType; + int8_t cmdState; + int8_t tagNum; +} HttpSqlCmd; + +typedef struct { + HttpSqlCmd *cmds; + int16_t pos; + int16_t size; + int16_t maxSize; + int32_t bufferPos; + int32_t bufferSize; + char * buffer; +} HttpSqlCmds; + +typedef struct { + char *module; + bool (*decodeFp)(struct HttpContext *pContext); +} HttpDecodeMethod; + +typedef struct { + void (*startJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, void *result); + void (*stopJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd); + bool (*buildQueryJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, void *result, int numOfRows); + void (*buildAffectRowJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int affectRows); + void (*initJsonFp)(struct HttpContext *pContext); + void (*cleanJsonFp)(struct HttpContext *pContext); + bool (*checkFinishedFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int code); + void (*setNextCmdFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int code); +} HttpEncodeMethod; + +typedef struct { + char *pos; + int32_t len; +} HttpBuf; + +typedef struct { + char buffer[HTTP_BUFFER_SIZE]; + int bufsize; + char *pLast; + char *pCur; + HttpBuf method; + HttpBuf path[HTTP_MAX_URL]; // url: dbname/meter/query + HttpBuf data; // body content + HttpBuf token; // auth token + HttpDecodeMethod *pMethod; +} HttpParser; + +typedef struct HttpContext { + int32_t refCount; + int fd; + uint32_t accessTimes; + uint32_t lastAccessTime; + int32_t state; + uint8_t httpVersion; + uint8_t httpChunked; + uint8_t httpKeepAlive; // http1.0 and not keep-alive, close connection immediately + uint8_t acceptEncoding; + uint8_t contentEncoding; + uint8_t reqType; + uint8_t parsed; + char ipstr[22]; + char user[TSDB_USER_LEN]; // parsed from auth token or login message + char pass[TSDB_PASSWORD_LEN]; + void * taos; + void * ppContext; + HttpSession *session; + z_stream gzipStream; + HttpParser parser; + HttpSqlCmd singleCmd; + HttpSqlCmds *multiCmds; + JsonBuf * jsonBuf; + void * timer; + HttpEncodeMethod * encodeMethod; + struct HttpThread *pThread; +} HttpContext; + +typedef struct HttpThread { + pthread_t thread; + HttpContext * pHead; + pthread_mutex_t threadMutex; + bool stop; + int pollFd; + int numOfFds; + int threadId; + char label[HTTP_LABEL_SIZE]; + bool (*processData)(HttpContext *pContext); +} HttpThread; + +typedef struct HttpServer { + char label[HTTP_LABEL_SIZE]; + uint32_t serverIp; + uint16_t serverPort; + int fd; + int numOfThreads; + int methodScannerLen; + int32_t requestNum; + int32_t status; + pthread_t thread; + HttpThread * pThreads; + void * contextCache; + void * sessionCache; + pthread_mutex_t serverMutex; + HttpDecodeMethod *methodScanner[HTTP_METHOD_SCANNER_SIZE]; + bool (*processData)(HttpContext *pContext); +} HttpServer; + +extern const char *httpKeepAliveStr[]; +extern const char *httpVersionStr[]; +extern HttpServer tsHttpServer; + +#endif diff --git a/src/plugins/http/inc/httpJson.h b/src/plugins/http/inc/httpJson.h index 403c20b083..905460c67b 100644 --- a/src/plugins/http/inc/httpJson.h +++ b/src/plugins/http/inc/httpJson.h @@ -97,4 +97,8 @@ void httpJsonPrint(JsonBuf* buf, const char* json, int len); // quick void httpJsonPairStatus(JsonBuf* buf, int code); +// http json printer +JsonBuf* httpMallocJsonBuf(struct HttpContext* pContext); +void httpFreeJsonBuf(struct HttpContext* pContext); + #endif diff --git a/src/plugins/http/inc/httpResp.h b/src/plugins/http/inc/httpResp.h index 4868d4c688..5eaaa2a037 100644 --- a/src/plugins/http/inc/httpResp.h +++ b/src/plugins/http/inc/httpResp.h @@ -16,7 +16,7 @@ #ifndef TDENGINE_HTTP_RESP_H #define TDENGINE_HTTP_RESP_H -#include "httpHandle.h" +#include "httpInt.h" enum _httpRespTempl { HTTP_RESPONSE_JSON_OK, diff --git a/src/plugins/http/inc/httpServer.h b/src/plugins/http/inc/httpServer.h new file mode 100644 index 0000000000..04dadfe04c --- /dev/null +++ b/src/plugins/http/inc/httpServer.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_SERVER_H +#define TDENGINE_HTTP_SERVER_H + +#include "httpInt.h" + +bool httpInitConnect(); +void httpCleanUpConnect(); + +void *httpInitServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle); +void httpCleanUpServer(HttpServer *pServer); +bool httpReadDataImp(HttpContext *pContext); + +#endif diff --git a/src/plugins/http/inc/httpSession.h b/src/plugins/http/inc/httpSession.h new file mode 100644 index 0000000000..393e720f69 --- /dev/null +++ b/src/plugins/http/inc/httpSession.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_SESSION_H +#define TDENGINE_HTTP_SESSION_H + +bool httpInitSessions(); +void httpCleanUpSessions(); + +// http session method +void httpCreateSession(HttpContext *pContext, void *taos); +void httpGetSession(HttpContext *pContext); +void httpReleaseSession(HttpContext *pContext); + +#endif diff --git a/src/plugins/http/inc/httpSql.h b/src/plugins/http/inc/httpSql.h new file mode 100644 index 0000000000..09f5b142fb --- /dev/null +++ b/src/plugins/http/inc/httpSql.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_SQL_H +#define TDENGINE_HTTP_SQL_H + + +int32_t httpAddToSqlCmdBuffer(HttpContext *pContext, const char *const format, ...); +int32_t httpAddToSqlCmdBufferNoTerminal(HttpContext *pContext, const char *const format, ...); +int32_t httpAddToSqlCmdBufferWithSize(HttpContext *pContext, int mallocSize); +int32_t httpAddToSqlCmdBufferTerminal(HttpContext *pContext); + +bool httpMallocMultiCmds(HttpContext *pContext, int cmdSize, int bufferSize); +bool httpReMallocMultiCmdsSize(HttpContext *pContext, int cmdSize); +bool httpReMallocMultiCmdsBuffer(HttpContext *pContext, int bufferSize); +void httpFreeMultiCmds(HttpContext *pContext); + +HttpSqlCmd *httpNewSqlCmd(HttpContext *pContext); +HttpSqlCmd *httpCurrSqlCmd(HttpContext *pContext); +int httpCurSqlCmdPos(HttpContext *pContext); + +void httpTrimTableName(char *name); +int httpShrinkTableName(HttpContext *pContext, int pos, char *name); +char *httpGetCmdsString(HttpContext *pContext, int pos); + +#endif diff --git a/src/plugins/http/inc/httpUtil.h b/src/plugins/http/inc/httpUtil.h new file mode 100644 index 0000000000..c82f702ebc --- /dev/null +++ b/src/plugins/http/inc/httpUtil.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_HTTP_UTIL_H +#define TDENGINE_HTTP_UTIL_H + +bool httpCheckUsedbSql(char *sql); +void httpTimeToString(time_t t, char *buf, int buflen); + +bool httpUrlMatch(HttpContext *pContext, int pos, char *cmp); +bool httpParseRequest(HttpContext *pContext); +int httpCheckReadCompleted(HttpContext *pContext); +void httpReadDirtyData(HttpContext *pContext); + +int httpGzipDeCompress(char *srcData, int32_t nSrcData, char *destData, int32_t *nDestData); +int httpGzipCompressInit(HttpContext *pContext); +int httpGzipCompress(HttpContext *pContext, char *inSrcData, int32_t inSrcDataLen, + char *outDestData, int32_t *outDestDataLen, bool isTheLast); + +// http request parser +void httpAddMethod(HttpServer *pServer, HttpDecodeMethod *pMethod); + + + +#endif diff --git a/src/plugins/http/inc/restHandle.h b/src/plugins/http/inc/restHandle.h index 48ad040c53..632a1dc647 100644 --- a/src/plugins/http/inc/restHandle.h +++ b/src/plugins/http/inc/restHandle.h @@ -16,15 +16,11 @@ #ifndef TDENGINE_REST_HANDLE_H #define TDENGINE_REST_HANDLE_H -#include -#include -#include -#include - #include "http.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpUtil.h" #include "httpResp.h" +#include "httpSql.h" #define REST_ROOT_URL_POS 0 #define REST_ACTION_URL_POS 1 diff --git a/src/plugins/http/inc/tgHandle.h b/src/plugins/http/inc/tgHandle.h index 5622694374..6a3a7bfa4a 100644 --- a/src/plugins/http/inc/tgHandle.h +++ b/src/plugins/http/inc/tgHandle.h @@ -16,16 +16,11 @@ #ifndef TDENGINE_TG_HANDLE_H #define TDENGINE_TG_HANDLE_H -#include -#include -#include -#include - -#include "cJSON.h" #include "http.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpUtil.h" #include "httpResp.h" +#include "httpSql.h" #define TG_ROOT_URL_POS 0 #define TG_DB_URL_POS 1 diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index cf2ce5ddd9..0439083f31 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -18,8 +18,8 @@ #include "tkey.h" #include "tutil.h" #include "http.h" -#include "httpLog.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpAuth.h" #define KEY_DES_4 4971256377704625728L @@ -73,6 +73,7 @@ bool httpParseTaosdAuthToken(HttpContext *pContext, char *token, int len) { unsigned char *base64 = base64_decode(token, len, &outlen); if (base64 == NULL || outlen == 0) { httpError("context:%p, fd:%d, ip:%s, taosd token:%s parsed error", pContext, pContext->fd, pContext->ipstr, token); + if (base64) free(base64); return false; } if (outlen != (TSDB_USER_LEN + TSDB_PASSWORD_LEN)) { diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c new file mode 100644 index 0000000000..981492681a --- /dev/null +++ b/src/plugins/http/src/httpContext.c @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "taosmsg.h" +#include "tsocket.h" +#include "tutil.h" +#include "ttime.h" +#include "ttimer.h" +#include "tglobal.h" +#include "tcache.h" +#include "hash.h" +#include "httpInt.h" +#include "httpResp.h" +#include "httpSql.h" +#include "httpSession.h" + +static void httpRemoveContextFromEpoll(HttpContext *pContext) { + HttpThread *pThread = pContext->pThread; + if (pContext->fd >= 0) { + epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, pContext->fd, NULL); + taosCloseSocket(pContext->fd); + pContext->fd = -1; + } +} + +static void httpDestroyContext(void *data) { + HttpContext *pContext = *(HttpContext **)data; + if (pContext->fd > 0) tclose(pContext->fd); + + HttpThread *pThread = pContext->pThread; + httpRemoveContextFromEpoll(pContext); + httpReleaseSession(pContext); + atomic_sub_fetch_32(&pThread->numOfFds, 1); + + pContext->pThread = 0; + pContext->state = HTTP_CONTEXT_STATE_CLOSED; + + // avoid double free + httpFreeJsonBuf(pContext); + httpFreeMultiCmds(pContext); + + httpTrace("context:%p, is destroyed, refCount:%d", pContext, pContext->refCount); + tfree(pContext); +} + +bool httpInitContexts() { + tsHttpServer.contextCache = taosCacheInitWithCb(2, httpDestroyContext); + if (tsHttpServer.contextCache == NULL) { + httpError("failed to init context cache"); + return false; + } + + return true; +} + +void httpCleanupContexts() { + if (tsHttpServer.contextCache != NULL) { + SCacheObj *cache = tsHttpServer.contextCache; + httpPrint("context cache is cleanuping, size:%d", taosHashGetSize(cache->pHashTable)); + taosCacheCleanup(tsHttpServer.contextCache); + tsHttpServer.contextCache = NULL; + } +} + +const char *httpContextStateStr(HttpContextState state) { + switch (state) { + case HTTP_CONTEXT_STATE_READY: + return "ready"; + case HTTP_CONTEXT_STATE_HANDLING: + return "handling"; + case HTTP_CONTEXT_STATE_DROPPING: + return "dropping"; + case HTTP_CONTEXT_STATE_CLOSED: + return "closed"; + default: + return "unknown"; + } +} + +void httpNotifyContextClose(HttpContext *pContext) { + shutdown(pContext->fd, SHUT_WR); +} + +bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState) { + return (atomic_val_compare_exchange_32(&pContext->state, srcState, destState) == srcState); +} + +HttpContext *httpCreateContext(int32_t fd) { + HttpContext *pContext = calloc(1, sizeof(HttpContext)); + if (pContext == NULL) return NULL; + + char contextStr[16] = {0}; + snprintf(contextStr, sizeof(contextStr), "%p", pContext); + + pContext->fd = fd; + pContext->httpVersion = HTTP_VERSION_10; + pContext->lastAccessTime = taosGetTimestampSec(); + pContext->state = HTTP_CONTEXT_STATE_READY; + + HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, contextStr, &pContext, sizeof(HttpContext *), 3); + pContext->ppContext = ppContext; + httpTrace("context:%p, fd:%d, is created, item:%p", pContext, fd, ppContext); + + // set the ref to 0 + taosCacheRelease(tsHttpServer.contextCache, (void**)&ppContext, false); + + return pContext; +} + +HttpContext *httpGetContext(void *ptr) { + char contextStr[16] = {0}; + snprintf(contextStr, sizeof(contextStr), "%p", ptr); + + HttpContext **ppContext = taosCacheAcquireByName(tsHttpServer.contextCache, contextStr); + + if (ppContext) { + HttpContext *pContext = *ppContext; + if (pContext) { + int32_t refCount = atomic_add_fetch_32(&pContext->refCount, 1); + httpTrace("context:%p, fd:%d, is accquired, refCount:%d", pContext, pContext->fd, refCount); + return pContext; + } + } + return NULL; +} + +void httpReleaseContext(HttpContext *pContext) { + int32_t refCount = atomic_sub_fetch_32(&pContext->refCount, 1); + assert(refCount >= 0); + httpTrace("context:%p, fd:%d, is releasd, refCount:%d", pContext, pContext->fd, refCount); + + HttpContext **ppContext = pContext->ppContext; + taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false); +} + +bool httpInitContext(HttpContext *pContext) { + pContext->accessTimes++; + pContext->lastAccessTime = taosGetTimestampSec(); + pContext->httpVersion = HTTP_VERSION_10; + pContext->httpKeepAlive = HTTP_KEEPALIVE_NO_INPUT; + pContext->httpChunked = HTTP_UNCUNKED; + pContext->acceptEncoding = HTTP_COMPRESS_IDENTITY; + pContext->contentEncoding = HTTP_COMPRESS_IDENTITY; + pContext->reqType = HTTP_REQTYPE_OTHERS; + pContext->encodeMethod = NULL; + pContext->timer = NULL; + memset(&pContext->singleCmd, 0, sizeof(HttpSqlCmd)); + + HttpParser *pParser = &pContext->parser; + memset(pParser, 0, sizeof(HttpParser)); + pParser->pCur = pParser->pLast = pParser->buffer; + + httpTrace("context:%p, fd:%d, ip:%s, thread:%s, accessTimes:%d, parsed:%d", + pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, pContext->accessTimes, pContext->parsed); + return true; +} + +void httpCloseContextByApp(HttpContext *pContext) { + pContext->parsed = false; + + bool keepAlive = true; + if (pContext->httpVersion == HTTP_VERSION_10 && pContext->httpKeepAlive != HTTP_KEEPALIVE_ENABLE) { + keepAlive = false; + } else if (pContext->httpVersion != HTTP_VERSION_10 && pContext->httpKeepAlive == HTTP_KEEPALIVE_DISABLE) { + keepAlive = false; + } else {} + + if (keepAlive) { + if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) { + httpTrace("context:%p, fd:%d, ip:%s, last state:handling, keepAlive:true, reuse connect", + pContext, pContext->fd, pContext->ipstr); + } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_CLOSED)) { + httpRemoveContextFromEpoll(pContext); + httpTrace("context:%p, fd:%d, ip:%s, last state:dropping, keepAlive:true, close connect", + pContext, pContext->fd, pContext->ipstr); + } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_READY)) { + httpTrace("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, reuse connect", + pContext, pContext->fd, pContext->ipstr); + } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) { + httpRemoveContextFromEpoll(pContext); + httpTrace("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, close connect", + pContext, pContext->fd, pContext->ipstr); + } else { + httpRemoveContextFromEpoll(pContext); + httpError("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:true, close connect", + pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->state); + } + } else { + httpRemoveContextFromEpoll(pContext); + httpTrace("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:false, close connect", + pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->state); + } + + httpReleaseContext(pContext); +} + +void httpCloseContextByServer(HttpContext *pContext) { + if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_DROPPING)) { + httpTrace("context:%p, fd:%d, ip:%s, epoll finished, still used by app", pContext, pContext->fd, pContext->ipstr); + } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_DROPPING)) { + httpTrace("context:%p, fd:%d, ip:%s, epoll already finished, wait app finished", pContext, pContext->fd, pContext->ipstr); + } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_CLOSED)) { + httpTrace("context:%p, fd:%d, ip:%s, epoll finished, close context", pContext, pContext->fd, pContext->ipstr); + } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) { + httpTrace("context:%p, fd:%d, ip:%s, epoll finished, will be closed soon", pContext, pContext->fd, pContext->ipstr); + } else { + httpError("context:%p, fd:%d, ip:%s, unknown state:%d", pContext, pContext->fd, pContext->ipstr, pContext->state); + } + + pContext->parsed = false; + httpRemoveContextFromEpoll(pContext); + httpReleaseContext(pContext); +} diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index 8323ef7f4e..0d9b0ea025 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -19,11 +19,12 @@ #include "tglobal.h" #include "tsocket.h" #include "ttimer.h" -#include "http.h" -#include "httpLog.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" #include "httpResp.h" +#include "httpAuth.h" +#include "httpServer.h" +#include "httpContext.h" +#include "httpHandle.h" void httpToLowerUrl(char* url) { /*ignore case */ @@ -58,6 +59,10 @@ bool httpParseURL(HttpContext* pContext) { HttpParser* pParser = &pContext->parser; char* pSeek; char* pEnd = strchr(pParser->pLast, ' '); + if (pEnd == NULL) { + return false; + } + if (*pParser->pLast != '/') { httpSendErrorResp(pContext, HTTP_UNSUPPORT_URL); return false; @@ -159,7 +164,7 @@ bool httpGetHttpMethod(HttpContext* pContext) { bool httpGetDecodeMethod(HttpContext* pContext) { HttpParser* pParser = &pContext->parser; - HttpServer* pServer = pContext->pThread->pServer; + HttpServer* pServer = &tsHttpServer; int methodLen = pServer->methodScannerLen; for (int i = 0; i < methodLen; i++) { HttpDecodeMethod* method = pServer->methodScanner[i]; diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index e5e69ae02a..76cc90c48f 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -22,6 +22,7 @@ #include "httpCode.h" #include "httpJson.h" #include "httpResp.h" +#include "httpUtil.h" #define MAX_NUM_STR_SZ 25 diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index d9507072de..de52e10f9a 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -21,6 +21,7 @@ #include "httpResp.h" #include "httpCode.h" #include "httpJson.h" +#include "httpContext.h" const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 9a9c659b03..684f77e7d8 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -21,244 +21,15 @@ #include "ttime.h" #include "ttimer.h" #include "tglobal.h" -#include "http.h" -#include "httpLog.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpContext.h" #include "httpResp.h" +#include "httpUtil.h" #ifndef EPOLLWAKEUP #define EPOLLWAKEUP (1u << 29) #endif -const char* httpContextStateStr(HttpContextState state) { - switch (state) { - case HTTP_CONTEXT_STATE_READY: - return "ready"; - case HTTP_CONTEXT_STATE_HANDLING: - return "handling"; - case HTTP_CONTEXT_STATE_DROPPING: - return "dropping"; - case HTTP_CONTEXT_STATE_CLOSED: - return "closed"; - default: - return "unknown"; - } -} - -void httpRemoveContextFromEpoll(HttpThread *pThread, HttpContext *pContext) { - if (pContext->fd >= 0) { - epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, pContext->fd, NULL); - taosCloseSocket(pContext->fd); - pContext->fd = -1; - } -} - -bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState) { - return (atomic_val_compare_exchange_32(&pContext->state, srcState, destState) == srcState); -} - -void httpFreeContext(HttpServer *pServer, HttpContext *pContext); - -/** - * context will be reused while connection exist - * multiCmds and jsonBuf will be malloc after taos_query_a called - * and won't be freed until connection closed - */ -HttpContext *httpCreateContext(HttpServer *pServer) { - HttpContext *pContext = (HttpContext *)taosMemPoolMalloc(pServer->pContextPool); - if (pContext != NULL) { - pContext->fromMemPool = 1; - httpTrace("context:%p, is malloced from mempool", pContext); - } else { - pContext = (HttpContext *)malloc(sizeof(HttpContext)); - if (pContext == NULL) { - return NULL; - } else { - memset(pContext, 0, sizeof(HttpContext)); - } - httpTrace("context:%p, is malloced from raw memory", pContext); - } - - pContext->signature = pContext; - pContext->httpVersion = HTTP_VERSION_10; - pContext->lastAccessTime = taosGetTimestampSec(); - pContext->state = HTTP_CONTEXT_STATE_READY; - return pContext; -} - -void httpFreeContext(HttpServer *pServer, HttpContext *pContext) { - if (pContext->fromMemPool) { - httpTrace("context:%p, is freed from mempool", pContext); - taosMemPoolFree(pServer->pContextPool, (char *)pContext); - } else { - httpTrace("context:%p, is freed from raw memory", pContext); - tfree(pContext); - } -} - -void httpCleanUpContextTimer(HttpContext *pContext) { - if (pContext->timer != NULL) { - taosTmrStopA(&pContext->timer); - //httpTrace("context:%p, ip:%s, close timer:%p", pContext, pContext->ipstr, pContext->timer); - pContext->timer = NULL; - } -} - -void httpCleanUpContext(HttpContext *pContext, void *unused) { - httpTrace("context:%p, start the clean up operation, sig:%p", pContext, pContext->signature); - void *sig = atomic_val_compare_exchange_ptr(&pContext->signature, pContext, 0); - if (sig == NULL) { - httpTrace("context:%p is freed by another thread.", pContext); - return; - } - - HttpThread *pThread = pContext->pThread; - - httpCleanUpContextTimer(pContext); - - httpRemoveContextFromEpoll(pThread, pContext); - - httpRestoreSession(pContext); - - pthread_mutex_lock(&pThread->threadMutex); - - pThread->numOfFds--; - if (pThread->numOfFds < 0) { - httpError("context:%p, ip:%s, thread:%s, number of FDs:%d shall never be negative", - pContext, pContext->ipstr, pThread->label, pThread->numOfFds); - pThread->numOfFds = 0; - } - - // remove from the link list - if (pContext->prev) { - (pContext->prev)->next = pContext->next; - } else { - pThread->pHead = pContext->next; - } - - if (pContext->next) { - (pContext->next)->prev = pContext->prev; - } - - pthread_mutex_unlock(&pThread->threadMutex); - - httpTrace("context:%p, ip:%s, thread:%s, numOfFds:%d, context is cleaned up", pContext, pContext->ipstr, - pThread->label, pThread->numOfFds); - - pContext->signature = 0; - pContext->fd = -1; - pContext->pThread = 0; - pContext->prev = 0; - pContext->next = 0; - pContext->state = HTTP_CONTEXT_STATE_READY; - - // avoid double free - httpFreeJsonBuf(pContext); - httpFreeMultiCmds(pContext); - httpFreeContext(pThread->pServer, pContext); -} - -bool httpInitContext(HttpContext *pContext) { - pContext->accessTimes++; - pContext->lastAccessTime = taosGetTimestampSec(); - pContext->httpVersion = HTTP_VERSION_10; - pContext->httpKeepAlive = HTTP_KEEPALIVE_NO_INPUT; - pContext->httpChunked = HTTP_UNCUNKED; - pContext->acceptEncoding = HTTP_COMPRESS_IDENTITY; - pContext->contentEncoding = HTTP_COMPRESS_IDENTITY; - pContext->reqType = HTTP_REQTYPE_OTHERS; - pContext->encodeMethod = NULL; - pContext->timer = NULL; - memset(&pContext->singleCmd, 0, sizeof(HttpSqlCmd)); - - HttpParser *pParser = &pContext->parser; - memset(pParser, 0, sizeof(HttpParser)); - pParser->pCur = pParser->pLast = pParser->buffer; - - httpTrace("context:%p, fd:%d, ip:%s, thread:%s, accessTimes:%d, parsed:%d", - pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, pContext->accessTimes, pContext->parsed); - return true; -} - - -void httpCloseContext(HttpThread *pThread, HttpContext *pContext) { - taosTmrReset((TAOS_TMR_CALLBACK)httpCleanUpContext, HTTP_DELAY_CLOSE_TIME_MS, pContext, pThread->pServer->timerHandle, &pContext->timer); - httpTrace("context:%p, fd:%d, ip:%s, state:%s will be closed after:%d ms, timer:%p", - pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), HTTP_DELAY_CLOSE_TIME_MS, pContext->timer); -} - -void httpCloseContextByApp(HttpContext *pContext) { - HttpThread *pThread = pContext->pThread; - pContext->parsed = false; - - bool keepAlive = true; - if (pContext->httpVersion == HTTP_VERSION_10 && pContext->httpKeepAlive != HTTP_KEEPALIVE_ENABLE) { - keepAlive = false; - } else if (pContext->httpVersion != HTTP_VERSION_10 && pContext->httpKeepAlive == HTTP_KEEPALIVE_DISABLE) { - keepAlive = false; - } else {} - - if (keepAlive) { - if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_READY)) { - httpTrace("context:%p, fd:%d, ip:%s, last state:handling, keepAlive:true, reuse connect", - pContext, pContext->fd, pContext->ipstr); - } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_CLOSED)) { - httpRemoveContextFromEpoll(pThread, pContext); - httpTrace("context:%p, fd:%d, ip:%s, last state:dropping, keepAlive:true, close connect", - pContext, pContext->fd, pContext->ipstr); - httpCloseContext(pThread, pContext); - } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_READY)) { - httpTrace("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, reuse connect", - pContext, pContext->fd, pContext->ipstr); - } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) { - httpRemoveContextFromEpoll(pThread, pContext); - httpTrace("context:%p, fd:%d, ip:%s, last state:ready, keepAlive:true, close connect", - pContext, pContext->fd, pContext->ipstr); - httpCloseContext(pThread, pContext); - } else { - httpRemoveContextFromEpoll(pThread, pContext); - httpError("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:true, close connect", - pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->state); - httpCloseContext(pThread, pContext); - } - } else { - httpRemoveContextFromEpoll(pThread, pContext); - httpTrace("context:%p, fd:%d, ip:%s, last state:%s:%d, keepAlive:false, close connect", - pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->state); - httpCloseContext(pThread, pContext); - } -} - -void httpCloseContextByServer(HttpThread *pThread, HttpContext *pContext) { - httpRemoveContextFromEpoll(pThread, pContext); - pContext->parsed = false; - - if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_HANDLING, HTTP_CONTEXT_STATE_DROPPING)) { - httpTrace("context:%p, fd:%d, ip:%s, epoll finished, still used by app", pContext, pContext->fd, pContext->ipstr); - } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_DROPPING, HTTP_CONTEXT_STATE_DROPPING)) { - httpTrace("context:%p, fd:%d, ip:%s, epoll already finished, wait app finished", pContext, pContext->fd, pContext->ipstr); - } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_CLOSED)) { - httpTrace("context:%p, fd:%d, ip:%s, epoll finished, close context", pContext, pContext->fd, pContext->ipstr); - httpCloseContext(pThread, pContext); - } else if (httpAlterContextState(pContext, HTTP_CONTEXT_STATE_CLOSED, HTTP_CONTEXT_STATE_CLOSED)) { - httpTrace("context:%p, fd:%d, ip:%s, epoll finished, will be closed soon", pContext, pContext->fd, pContext->ipstr); - httpCloseContext(pThread, pContext); - } else { - httpError("context:%p, fd:%d, ip:%s, unknown state:%d", pContext, pContext->fd, pContext->ipstr, pContext->state); - httpCloseContext(pThread, pContext); - } -} - -void httpCloseContextByServerForExpired(void *param, void *tmrId) { - HttpContext *pContext = (HttpContext *)param; - httpRemoveContextFromEpoll(pContext->pThread, pContext); - httpError("context:%p, fd:%d, ip:%s, read http body error, time expired, timer:%p", pContext, pContext->fd, pContext->ipstr, tmrId); - httpSendErrorResp(pContext, HTTP_PARSE_BODY_ERROR); - httpCloseContextByServer(pContext->pThread, pContext); -} - - static void httpStopThread(HttpThread* pThread) { pThread->stop = true; @@ -281,19 +52,13 @@ static void httpStopThread(HttpThread* pThread) { close(pThread->pollFd); pthread_mutex_destroy(&(pThread->threadMutex)); - - //while (pThread->pHead) { - // httpCleanUpContext(pThread->pHead, 0); - //} } +void httpCleanUpConnect() { + HttpServer *pServer = &tsHttpServer; + if (pServer->pThreads == NULL) return; -void httpCleanUpConnect(HttpServer *pServer) { - if (pServer == NULL) return; - - shutdown(pServer->fd, SHUT_RD); pthread_join(pServer->thread, NULL); - for (int i = 0; i < pServer->numOfThreads; ++i) { HttpThread* pThread = pServer->pThreads + i; if (pThread != NULL) { @@ -302,19 +67,10 @@ void httpCleanUpConnect(HttpServer *pServer) { } tfree(pServer->pThreads); + pServer->pThreads = NULL; httpTrace("http server:%s is cleaned up", pServer->label); } -// read all the data, then just discard it -void httpReadDirtyData(HttpContext *pContext) { - int fd = pContext->fd; - char data[1024] = {0}; - int len = (int)taosReadSocket(fd, data, 1024); - while (len >= sizeof(data)) { - len = (int)taosReadSocket(fd, data, 1024); - } -} - bool httpReadDataImp(HttpContext *pContext) { HttpParser *pParser = &pContext->parser; @@ -338,11 +94,10 @@ bool httpReadDataImp(HttpContext *pContext) { } if (pParser->bufsize >= (HTTP_BUFFER_SIZE - HTTP_STEP_SIZE)) { - httpReadDirtyData(pContext); httpError("context:%p, fd:%d, ip:%s, thread:%s, request big than:%d", pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, HTTP_BUFFER_SIZE); - httpRemoveContextFromEpoll(pContext->pThread, pContext); httpSendErrorResp(pContext, HTTP_REQUSET_TOO_BIG); + httpNotifyContextClose(pContext); return false; } } @@ -352,7 +107,7 @@ bool httpReadDataImp(HttpContext *pContext) { return true; } -bool httpDecompressData(HttpContext *pContext) { +static bool httpDecompressData(HttpContext *pContext) { if (pContext->contentEncoding != HTTP_COMPRESS_GZIP) { httpDump("context:%p, fd:%d, ip:%s, content:%s", pContext, pContext->fd, pContext->ipstr, pContext->parser.data.pos); return true; @@ -382,45 +137,43 @@ bool httpDecompressData(HttpContext *pContext) { return ret == 0; } -bool httpReadData(HttpThread *pThread, HttpContext *pContext) { +static bool httpReadData(HttpContext *pContext) { if (!pContext->parsed) { httpInitContext(pContext); } if (!httpReadDataImp(pContext)) { - httpCloseContextByServer(pThread, pContext); + httpNotifyContextClose(pContext); return false; } if (!httpParseRequest(pContext)) { - httpCloseContextByServer(pThread, pContext); + httpNotifyContextClose(pContext); return false; } int ret = httpCheckReadCompleted(pContext); if (ret == HTTP_CHECK_BODY_CONTINUE) { - taosTmrReset(httpCloseContextByServerForExpired, HTTP_EXPIRED_TIME, pContext, pThread->pServer->timerHandle, &pContext->timer); - //httpTrace("context:%p, fd:%d, ip:%s, not finished yet, try another times, timer:%p", pContext, pContext->fd, pContext->ipstr, pContext->timer); + //httpTrace("context:%p, fd:%d, ip:%s, not finished yet, wait another event", pContext, pContext->fd, pContext->ipstr); return false; } else if (ret == HTTP_CHECK_BODY_SUCCESS){ - httpCleanUpContextTimer(pContext); httpTrace("context:%p, fd:%d, ip:%s, thread:%s, read size:%d, dataLen:%d", pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, pContext->parser.bufsize, pContext->parser.data.len); if (httpDecompressData(pContext)) { return true; } else { - httpCloseContextByServer(pThread, pContext); + httpNotifyContextClose(pContext); return false; } } else { - httpCleanUpContextTimer(pContext); httpError("context:%p, fd:%d, ip:%s, failed to read http body, close connect", pContext, pContext->fd, pContext->ipstr); - httpCloseContextByServer(pThread, pContext); + httpNotifyContextClose(pContext); return false; } } -void httpProcessHttpData(void *param) { +static void httpProcessHttpData(void *param) { + HttpServer *pServer = &tsHttpServer; HttpThread *pThread = (HttpThread *)param; HttpContext *pContext; int fdNum; @@ -441,77 +194,72 @@ void httpProcessHttpData(void *param) { if (fdNum <= 0) continue; for (int i = 0; i < fdNum; ++i) { - pContext = events[i].data.ptr; - if (pContext->signature != pContext || pContext->pThread != pThread || pContext->fd <= 0) { + pContext = httpGetContext(events[i].data.ptr); + if (pContext == NULL) { + httpError("context:%p, is already released, close connect", events[i].data.ptr); + //epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, events[i].data.fd, NULL); + //tclose(events[i].data.fd); continue; } if (events[i].events & EPOLLPRI) { httpTrace("context:%p, fd:%d, ip:%s, state:%s, EPOLLPRI events occured, accessed:%d, close connect", pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->accessTimes); - httpRemoveContextFromEpoll(pThread, pContext); - httpCloseContextByServer(pThread, pContext); + httpCloseContextByServer(pContext); continue; } if (events[i].events & EPOLLRDHUP) { httpTrace("context:%p, fd:%d, ip:%s, state:%s, EPOLLRDHUP events occured, accessed:%d, close connect", pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->accessTimes); - httpRemoveContextFromEpoll(pThread, pContext); - httpCloseContextByServer(pThread, pContext); + httpCloseContextByServer(pContext); continue; } if (events[i].events & EPOLLERR) { httpTrace("context:%p, fd:%d, ip:%s, state:%s, EPOLLERR events occured, accessed:%d, close connect", pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->accessTimes); - httpRemoveContextFromEpoll(pThread, pContext); - httpCloseContextByServer(pThread, pContext); + httpCloseContextByServer(pContext); continue; } if (events[i].events & EPOLLHUP) { httpTrace("context:%p, fd:%d, ip:%s, state:%s, EPOLLHUP events occured, accessed:%d, close connect", pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->accessTimes); - httpRemoveContextFromEpoll(pThread, pContext); - httpCloseContextByServer(pThread, pContext); + httpCloseContextByServer(pContext); continue; } if (!httpAlterContextState(pContext, HTTP_CONTEXT_STATE_READY, HTTP_CONTEXT_STATE_READY)) { httpTrace("context:%p, fd:%d, ip:%s, state:%s, not in ready state, ignore read events", pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state)); + httpReleaseContext(pContext); continue; } - if (!pContext->pThread->pServer->online) { - httpTrace("context:%p, fd:%d, ip:%s, state:%s, server is not online, accessed:%d, close connect", - pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->accessTimes); - httpRemoveContextFromEpoll(pThread, pContext); - httpReadDirtyData(pContext); + if (pServer->status != HTTP_SERVER_RUNNING) { + httpTrace("context:%p, fd:%d, ip:%s, state:%s, server is not running, accessed:%d, close connect", pContext, + pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), pContext->accessTimes); httpSendErrorResp(pContext, HTTP_SERVER_OFFLINE); - httpCloseContextByServer(pThread, pContext); - continue; + httpNotifyContextClose(pContext); } else { - if (httpReadData(pThread, pContext)) { + if (httpReadData(pContext)) { (*(pThread->processData))(pContext); - atomic_fetch_add_32(&pThread->pServer->requestNum, 1); + atomic_fetch_add_32(&pServer->requestNum, 1); } } } } } -void* httpAcceptHttpConnection(void *arg) { +static void *httpAcceptHttpConnection(void *arg) { int connFd = -1; struct sockaddr_in clientAddr; int threadId = 0; - HttpThread * pThread; - HttpServer * pServer; - HttpContext * pContext; - int totalFds; - - pServer = (HttpServer *)arg; + HttpServer * pServer = &tsHttpServer; + HttpThread * pThread = NULL; + HttpContext * pContext = NULL; + int totalFds = 0; sigset_t set; sigemptyset(&set); @@ -521,12 +269,12 @@ void* httpAcceptHttpConnection(void *arg) { pServer->fd = taosOpenTcpServerSocket(pServer->serverIp, pServer->serverPort); if (pServer->fd < 0) { - httpError("http server:%s, failed to open http socket, ip:%s:%u error:%s", pServer->label, taosIpStr(pServer->serverIp), - pServer->serverPort, strerror(errno)); + httpError("http server:%s, failed to open http socket, ip:%s:%u error:%s", pServer->label, + taosIpStr(pServer->serverIp), pServer->serverPort, strerror(errno)); return NULL; } else { - httpPrint("http service init success at %u", pServer->serverPort); - pServer->online = true; + httpPrint("http server init success at %u", pServer->serverPort); + pServer->status = HTTP_SERVER_RUNNING; } while (1) { @@ -534,10 +282,10 @@ void* httpAcceptHttpConnection(void *arg) { connFd = (int)accept(pServer->fd, (struct sockaddr *)&clientAddr, &addrlen); if (connFd == -1) { if (errno == EINVAL) { - httpTrace("%s HTTP server socket was shutdown, exiting...", pServer->label); + httpTrace("http server:%s socket was shutdown, exiting...", pServer->label); break; } - httpError("http server:%s, accept connect failure, errno:%d, reason:%s", pServer->label, errno, strerror(errno)); + httpError("http server:%s, accept connect failure, errno:%d reason:%s", pServer->label, errno, strerror(errno)); continue; } @@ -547,8 +295,8 @@ void* httpAcceptHttpConnection(void *arg) { } if (totalFds > tsHttpCacheSessions * 100) { - httpError("fd:%d, ip:%s:%u, totalFds:%d larger than httpCacheSessions:%d*100, refuse connection", - connFd, inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port), totalFds, tsHttpCacheSessions); + httpError("fd:%d, ip:%s:%u, totalFds:%d larger than httpCacheSessions:%d*100, refuse connection", connFd, + inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port), totalFds, tsHttpCacheSessions); taosCloseSocket(connFd); continue; } @@ -559,7 +307,7 @@ void* httpAcceptHttpConnection(void *arg) { // pick up the thread to handle this connection pThread = pServer->pThreads + threadId; - pContext = httpCreateContext(pServer); + pContext = httpCreateContext(connFd); if (pContext == NULL) { httpError("fd:%d, ip:%s:%u, no enough resource to allocate http context", connFd, inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port)); @@ -567,39 +315,24 @@ void* httpAcceptHttpConnection(void *arg) { continue; } - httpTrace("context:%p, fd:%d, ip:%s:%u, thread:%s, numOfFds:%d, totalFds:%d, accept a new connection", - pContext, connFd, inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port), pThread->label, - pThread->numOfFds, totalFds); - - pContext->fd = connFd; - sprintf(pContext->ipstr, "%s:%d", inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port)); pContext->pThread = pThread; - + sprintf(pContext->ipstr, "%s:%u", inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port)); + struct epoll_event event; event.events = EPOLLIN | EPOLLPRI | EPOLLWAKEUP | EPOLLERR | EPOLLHUP | EPOLLRDHUP; - event.data.ptr = pContext; if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, connFd, &event) < 0) { - httpError("context:%p, fd:%d, ip:%s:%u, thread:%s, failed to add http fd for epoll, error:%s", - pContext, connFd, inet_ntoa(clientAddr.sin_addr), htons(clientAddr.sin_port), pThread->label, - strerror(errno)); - httpFreeContext(pThread->pServer, pContext); - tclose(connFd); + httpError("context:%p, fd:%d, ip:%s, thread:%s, failed to add http fd for epoll, error:%s", pContext, connFd, + pContext->ipstr, pThread->label, strerror(errno)); + tclose(pContext->fd); + httpReleaseContext(pContext); continue; } // notify the data process, add into the FdObj list - pthread_mutex_lock(&(pThread->threadMutex)); - - pContext->next = pThread->pHead; - - if (pThread->pHead) (pThread->pHead)->prev = pContext; - - pThread->pHead = pContext; - - pThread->numOfFds++; - - pthread_mutex_unlock(&(pThread->threadMutex)); + atomic_add_fetch_32(&pThread->numOfFds, 1); + httpTrace("context:%p, fd:%d, ip:%s, thread:%s numOfFds:%d totalFds:%d, accept a new connection", pContext, connFd, + pContext->ipstr, pThread->label, pThread->numOfFds, totalFds); // pick up next thread for next connection threadId++; @@ -610,21 +343,17 @@ void* httpAcceptHttpConnection(void *arg) { return NULL; } -bool httpInitConnect(HttpServer *pServer) { - int i; - HttpThread * pThread; - - pServer->pThreads = (HttpThread *)malloc(sizeof(HttpThread) * (size_t)pServer->numOfThreads); +bool httpInitConnect() { + HttpServer *pServer = &tsHttpServer; + pServer->pThreads = calloc(pServer->numOfThreads, sizeof(HttpThread)); if (pServer->pThreads == NULL) { httpError("init error no enough memory"); return false; } - memset(pServer->pThreads, 0, sizeof(HttpThread) * (size_t)pServer->numOfThreads); - pThread = pServer->pThreads; - for (i = 0; i < pServer->numOfThreads; ++i) { + HttpThread *pThread = pServer->pThreads; + for (int i = 0; i < pServer->numOfThreads; ++i) { sprintf(pThread->label, "%s%d", pServer->label, i); - pThread->pServer = pServer; pThread->processData = pServer->processData; pThread->threadId = i; @@ -643,8 +372,8 @@ bool httpInitConnect(HttpServer *pServer) { pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); if (pthread_create(&(pThread->thread), &thattr, (void *)httpProcessHttpData, (void *)(pThread)) != 0) { - httpError("http thread:%s, failed to create HTTP process data thread, reason:%s", - pThread->label, strerror(errno)); + httpError("http thread:%s, failed to create HTTP process data thread, reason:%s", pThread->label, + strerror(errno)); return false; } pthread_attr_destroy(&thattr); diff --git a/src/plugins/http/src/httpSession.c b/src/plugins/http/src/httpSession.c index e80d6f26b7..c1e33706d5 100644 --- a/src/plugins/http/src/httpSession.c +++ b/src/plugins/http/src/httpSession.c @@ -15,44 +15,29 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "hash.h" #include "taos.h" #include "ttime.h" -#include "ttimer.h" -#include "http.h" -#include "httpLog.h" -#include "httpCode.h" -#include "httpHandle.h" -#include "httpResp.h" - -void httpAccessSession(HttpContext *pContext) { - HttpServer *server = pContext->pThread->pServer; - pthread_mutex_lock(&server->serverMutex); - if (pContext->session == pContext->session->signature) { - pContext->session->expire = (int) taosGetTimestampSec() + pContext->pThread->pServer->sessionExpire; - } - pthread_mutex_unlock(&server->serverMutex); -} +#include "tglobal.h" +#include "tcache.h" +#include "httpInt.h" +#include "httpContext.h" +#include "httpSession.h" void httpCreateSession(HttpContext *pContext, void *taos) { - HttpServer *server = pContext->pThread->pServer; + HttpServer *server = &tsHttpServer; + httpReleaseSession(pContext); + pthread_mutex_lock(&server->serverMutex); - if (pContext->session != NULL && pContext->session == pContext->session->signature) { - httpTrace("context:%p, fd:%d, ip:%s, user:%s, set exist session:%p:%p expired", pContext, pContext->fd, - pContext->ipstr, pContext->user, pContext->session, pContext->session->taos); - pContext->session->expire = 0; - pContext->session->access--; - } - HttpSession session; + memset(&session, 0, sizeof(HttpSession)); session.taos = taos; - session.expire = (int)taosGetTimestampSec() + server->sessionExpire; - session.access = 1; - int sessionIdLen = snprintf(session.id, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); + session.refCount = 1; + snprintf(session.id, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); - taosHashPut(server->pSessionHash, session.id, sessionIdLen, (char *)(&session), sizeof(HttpSession)); - pContext->session = taosHashGet(server->pSessionHash, session.id, sessionIdLen); + pContext->session = taosCachePut(server->sessionCache, session.id, &session, sizeof(HttpSession), tsHttpSessionExpire); + // void *temp = pContext->session; + // taosCacheRelease(server->sessionCache, (void **)&temp, false); if (pContext->session == NULL) { httpError("context:%p, fd:%d, ip:%s, user:%s, error:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, @@ -62,26 +47,23 @@ void httpCreateSession(HttpContext *pContext, void *taos) { return; } - pContext->session->signature = pContext->session; - httpTrace("context:%p, fd:%d, ip:%s, user:%s, create a new session:%p:%p", pContext, pContext->fd, pContext->ipstr, - pContext->user, pContext->session, pContext->session->taos); + httpTrace("context:%p, fd:%d, ip:%s, user:%s, create a new session:%p:%p sessionRef:%d", pContext, pContext->fd, + pContext->ipstr, pContext->user, pContext->session, pContext->session->taos, pContext->session->refCount); pthread_mutex_unlock(&server->serverMutex); } -void httpFetchSessionImp(HttpContext *pContext) { - HttpServer *server = pContext->pThread->pServer; +static void httpFetchSessionImp(HttpContext *pContext) { + HttpServer *server = &tsHttpServer; pthread_mutex_lock(&server->serverMutex); char sessionId[HTTP_SESSION_ID_LEN]; - int sessonIdLen = snprintf(sessionId, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); + snprintf(sessionId, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); - pContext->session = taosHashGet(server->pSessionHash, sessionId, sessonIdLen); - if (pContext->session != NULL && pContext->session == pContext->session->signature) { - pContext->session->access++; - httpTrace("context:%p, fd:%d, ip:%s, user:%s, find an exist session:%p:%p, access:%d, expire:%d", - pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session, - pContext->session->taos, pContext->session->access, pContext->session->expire); - pContext->session->expire = (int)taosGetTimestampSec() + server->sessionExpire; + pContext->session = taosCacheAcquireByName(server->sessionCache, sessionId); + if (pContext->session != NULL) { + atomic_add_fetch_32(&pContext->session->refCount, 1); + httpTrace("context:%p, fd:%d, ip:%s, user:%s, find an exist session:%p:%p, sessionRef:%d", pContext, pContext->fd, + pContext->ipstr, pContext->user, pContext->session, pContext->session->taos, pContext->session->refCount); } else { httpTrace("context:%p, fd:%d, ip:%s, user:%s, session not found", pContext, pContext->fd, pContext->ipstr, pContext->user); @@ -90,113 +72,54 @@ void httpFetchSessionImp(HttpContext *pContext) { pthread_mutex_unlock(&server->serverMutex); } -void httpFetchSession(HttpContext *pContext) { +void httpGetSession(HttpContext *pContext) { if (pContext->session == NULL) { httpFetchSessionImp(pContext); } else { char sessionId[HTTP_SESSION_ID_LEN]; snprintf(sessionId, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); - if (strcmp(pContext->session->id, sessionId) != 0) { - httpError("context:%p, fd:%d, ip:%s, user:%s, password may be changed", pContext, pContext->fd, pContext->ipstr, pContext->user); - httpRestoreSession(pContext); - httpFetchSessionImp(pContext); - } + httpReleaseSession(pContext); + httpFetchSessionImp(pContext); } } -void httpRestoreSession(HttpContext *pContext) { - HttpServer * server = pContext->pThread->pServer; +void httpReleaseSession(HttpContext *pContext) { + if (pContext == NULL || pContext->session == NULL) return; - // all access to the session is via serverMutex - pthread_mutex_lock(&server->serverMutex); - HttpSession *session = pContext->session; - if (session == NULL || session != session->signature) { - pthread_mutex_unlock(&server->serverMutex); - return; - } - session->access--; - httpTrace("context:%p, ip:%s, user:%s, restore session:%p:%p, access:%d, expire:%d", - pContext, pContext->ipstr, pContext->user, session, session->taos, - session->access, pContext->session->expire); + int32_t refCount = atomic_sub_fetch_32(&pContext->session->refCount, 1); + assert(refCount >= 0); + httpTrace("context:%p, release session:%p:%p, sessionRef:%d", pContext, pContext->session, pContext->session->taos, + pContext->session->refCount); + + taosCacheRelease(tsHttpServer.sessionCache, (void **)&pContext->session, false); pContext->session = NULL; - pthread_mutex_unlock(&server->serverMutex); } -void httpResetSession(HttpSession *pSession) { - httpTrace("close session:%p:%p", pSession, pSession->taos); - if (pSession->taos != NULL) { - taos_close(pSession->taos); - pSession->taos = NULL; +static void httpDestroySession(void *data) { + HttpSession *session = data; + httpTrace("session:%p:%p, is destroyed, sessionRef:%d", session, session->taos, session->refCount); + + if (session->taos != NULL) { + taos_close(session->taos); + session->taos = NULL; } - pSession->signature = NULL; } -void httpRemoveAllSessions(HttpServer *pServer) { - SHashMutableIterator *pIter = taosHashCreateIter(pServer->pSessionHash); - - while (taosHashIterNext(pIter)) { - HttpSession *pSession = taosHashIterGet(pIter); - if (pSession == NULL) continue; - httpResetSession(pSession); +void httpCleanUpSessions() { + if (tsHttpServer.sessionCache != NULL) { + SCacheObj *cache = tsHttpServer.sessionCache; + httpPrint("session cache is cleanuping, size:%d", taosHashGetSize(cache->pHashTable)); + taosCacheCleanup(tsHttpServer.sessionCache); + tsHttpServer.sessionCache = NULL; } - - taosHashDestroyIter(pIter); } -bool httpInitAllSessions(HttpServer *pServer) { - if (pServer->pSessionHash == NULL) { - pServer->pSessionHash = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true); - } - if (pServer->pSessionHash == NULL) { - httpError("http init session pool failed"); +bool httpInitSessions() { + tsHttpServer.sessionCache = taosCacheInitWithCb(5, httpDestroySession); + if (tsHttpServer.sessionCache == NULL) { + httpError("failed to init session cache"); return false; } - if (pServer->expireTimer == NULL) { - taosTmrReset(httpProcessSessionExpire, 50000, pServer, pServer->timerHandle, &pServer->expireTimer); - } return true; } - -bool httpSessionExpired(HttpSession *pSession) { - time_t cur = taosGetTimestampSec(); - - if (pSession->taos != NULL) { - if (pSession->expire > cur) { - return false; // un-expired, so return false - } - if (pSession->access > 0) { - httpTrace("session:%p:%p is expired, but still access:%d", pSession, pSession->taos, - pSession->access); - return false; // still used, so return false - } - httpTrace("need close session:%p:%p for it expired, cur:%d, expire:%d, invertal:%d", - pSession, pSession->taos, cur, pSession->expire, cur - pSession->expire); - } - - return true; -} - -void httpRemoveExpireSessions(HttpServer *pServer) { - SHashMutableIterator *pIter = taosHashCreateIter(pServer->pSessionHash); - - while (taosHashIterNext(pIter)) { - HttpSession *pSession = taosHashIterGet(pIter); - if (pSession == NULL) continue; - - pthread_mutex_lock(&pServer->serverMutex); - if (httpSessionExpired(pSession)) { - httpResetSession(pSession); - taosHashRemove(pServer->pSessionHash, pSession->id, strlen(pSession->id)); - } - pthread_mutex_unlock(&pServer->serverMutex); - } - - taosHashDestroyIter(pIter); -} - -void httpProcessSessionExpire(void *handle, void *tmrId) { - HttpServer *pServer = (HttpServer *)handle; - httpRemoveExpireSessions(pServer); - taosTmrReset(httpProcessSessionExpire, 60000, pServer, pServer->timerHandle, &pServer->expireTimer); -} \ No newline at end of file diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index efd1aac767..ce2f7a83bd 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -18,11 +18,12 @@ #include "tnote.h" #include "taos.h" #include "tsclient.h" -#include "http.h" -#include "httpLog.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpContext.h" +#include "httpSql.h" #include "httpResp.h" +#include "httpAuth.h" +#include "httpSession.h" void *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos); @@ -30,7 +31,7 @@ void httpProcessMultiSql(HttpContext *pContext); void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numOfRows) { HttpContext *pContext = (HttpContext *)param; - if (pContext == NULL || pContext->signature != pContext) return; + if (pContext == NULL) return; HttpSqlCmds * multiCmds = pContext->multiCmds; HttpEncodeMethod *encode = pContext->encodeMethod; @@ -72,7 +73,7 @@ void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numO void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { HttpContext *pContext = (HttpContext *)param; - if (pContext == NULL || pContext->signature != pContext) return; + if (pContext == NULL) return; HttpSqlCmds * multiCmds = pContext->multiCmds; HttpEncodeMethod *encode = pContext->encodeMethod; @@ -172,7 +173,7 @@ void httpProcessMultiSql(HttpContext *pContext) { } void httpProcessMultiSqlCmd(HttpContext *pContext) { - if (pContext == NULL || pContext->signature != pContext) return; + if (pContext == NULL) return; HttpSqlCmds *multiCmds = pContext->multiCmds; if (multiCmds == NULL || multiCmds->size <= 0 || multiCmds->pos >= multiCmds->size || multiCmds->pos < 0) { @@ -192,7 +193,7 @@ void httpProcessMultiSqlCmd(HttpContext *pContext) { void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int numOfRows) { HttpContext *pContext = (HttpContext *)param; - if (pContext == NULL || pContext->signature != pContext) return; + if (pContext == NULL) return; HttpEncodeMethod *encode = pContext->encodeMethod; @@ -230,7 +231,7 @@ void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int num void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { HttpContext *pContext = (HttpContext *)param; - if (pContext == NULL || pContext->signature != pContext) return; + if (pContext == NULL) return; HttpEncodeMethod *encode = pContext->encodeMethod; @@ -354,7 +355,7 @@ void httpExecCmd(HttpContext *pContext) { void httpProcessRequestCb(void *param, TAOS_RES *result, int code) { HttpContext *pContext = param; - if (pContext == NULL || pContext->signature != pContext) return; + if (pContext == NULL) return; if (code < 0) { httpError("context:%p, fd:%d, ip:%s, user:%s, login error, code:%s", pContext, pContext->fd, pContext->ipstr, @@ -383,16 +384,14 @@ void httpProcessRequestCb(void *param, TAOS_RES *result, int code) { } void httpProcessRequest(HttpContext *pContext) { - httpFetchSession(pContext); + httpGetSession(pContext); - if (pContext->session == NULL || pContext->session != pContext->session->signature || - pContext->reqType == HTTP_REQTYPE_LOGIN) { + if (pContext->session == NULL || pContext->reqType == HTTP_REQTYPE_LOGIN) { taos_connect_a(NULL, pContext->user, pContext->pass, "", 0, httpProcessRequestCb, (void *)pContext, &(pContext->taos)); httpTrace("context:%p, fd:%d, ip:%s, user:%s, try connect tdengine, taos:%p", pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->taos); } else { - httpAccessSession(pContext); httpExecCmd(pContext); } } diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index e7a5344be5..015b0783b7 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -20,84 +20,64 @@ #include "tsocket.h" #include "ttimer.h" #include "tadmin.h" -#include "http.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" +#include "httpContext.h" +#include "httpSession.h" +#include "httpServer.h" #include "httpResp.h" -#include "httpLog.h" -#include "gcHandle.h" #include "httpHandle.h" +#include "gcHandle.h" #include "restHandle.h" #include "tgHandle.h" #ifndef _ADMIN - void adminInitHandle(HttpServer* pServer) {} void opInitHandle(HttpServer* pServer) {} - #endif -static HttpServer *httpServer = NULL; +HttpServer tsHttpServer; void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); int httpInitSystem() { - // taos_init(); + strcpy(tsHttpServer.label, "rest"); + tsHttpServer.serverIp = 0; + tsHttpServer.serverPort = tsHttpPort; + tsHttpServer.numOfThreads = tsHttpMaxThreads; + tsHttpServer.processData = httpProcessData; - httpServer = (HttpServer *)malloc(sizeof(HttpServer)); - memset(httpServer, 0, sizeof(HttpServer)); - - strcpy(httpServer->label, "rest"); - httpServer->serverIp = 0; - httpServer->serverPort = tsHttpPort; - httpServer->cacheContext = tsHttpCacheSessions; - httpServer->sessionExpire = tsHttpSessionExpire; - httpServer->numOfThreads = tsHttpMaxThreads; - httpServer->processData = httpProcessData; - - pthread_mutex_init(&httpServer->serverMutex, NULL); + pthread_mutex_init(&tsHttpServer.serverMutex, NULL); if (tsHttpEnableRecordSql != 0) { taosInitNote(tsNumOfLogLines / 10, 1, (char*)"http_note"); } - restInitHandle(httpServer); - adminInitHandle(httpServer); - gcInitHandle(httpServer); - tgInitHandle(httpServer); - opInitHandle(httpServer); + restInitHandle(&tsHttpServer); + adminInitHandle(&tsHttpServer); + gcInitHandle(&tsHttpServer); + tgInitHandle(&tsHttpServer); + opInitHandle(&tsHttpServer); return 0; } int httpStartSystem() { - httpPrint("starting to initialize http service ..."); + httpPrint("start http server ..."); - if (httpServer == NULL) { - httpError("http server is null"); - httpInitSystem(); - } - - if (httpServer->pContextPool == NULL) { - httpServer->pContextPool = taosMemPoolInit(httpServer->cacheContext, sizeof(HttpContext)); - } - if (httpServer->pContextPool == NULL) { - httpError("http init context pool failed"); + if (tsHttpServer.status != HTTP_SERVER_INIT) { + httpError("http server is already started"); return -1; } - if (httpServer->timerHandle == NULL) { - httpServer->timerHandle = taosTmrInit(tsHttpCacheSessions * 100 + 100, 200, 60000, "http"); - } - if (httpServer->timerHandle == NULL) { - httpError("http init timer failed"); + if (!httpInitContexts()) { + httpError("http init contexts failed"); return -1; } - if (!httpInitAllSessions(httpServer)) { + if (!httpInitSessions()) { httpError("http init session failed"); return -1; } - if (!httpInitConnect(httpServer)) { + if (!httpInitConnect()) { httpError("http init server failed"); return -1; } @@ -106,53 +86,23 @@ int httpStartSystem() { } void httpStopSystem() { - if (httpServer != NULL) { - httpServer->online = false; - } + tsHttpServer.status = HTTP_SERVER_CLOSING; + shutdown(tsHttpServer.fd, SHUT_RD); tgCleanupHandle(); } void httpCleanUpSystem() { - httpPrint("http service cleanup"); + httpPrint("http server cleanup"); httpStopSystem(); -//#if 0 - if (httpServer == NULL) { - return; - } + httpCleanupContexts(); + httpCleanUpSessions(); + httpCleanUpConnect(); + pthread_mutex_destroy(&tsHttpServer.serverMutex); - if (httpServer->expireTimer != NULL) { - taosTmrStopA(&(httpServer->expireTimer)); - } - - if (httpServer->timerHandle != NULL) { - taosTmrCleanUp(httpServer->timerHandle); - httpServer->timerHandle = NULL; - } - - if (httpServer->pThreads != NULL) { - httpCleanUpConnect(httpServer); - httpServer->pThreads = NULL; - } - - -#if 0 - httpRemoveAllSessions(httpServer); - - if (httpServer->pContextPool != NULL) { - taosMemPoolCleanUp(httpServer->pContextPool); - httpServer->pContextPool = NULL; - } - - pthread_mutex_destroy(&httpServer->serverMutex); - - tfree(httpServer); -#endif + tsHttpServer.status = HTTP_SERVER_CLOSED; } int32_t httpGetReqCount() { - if (httpServer != NULL) { - return atomic_exchange_32(&httpServer->requestNum, 0); - } - return 0; + return atomic_exchange_32(&tsHttpServer.requestNum, 0); } diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index 1fb63ea2fc..694cdec0a0 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -17,11 +17,10 @@ #include "os.h" #include "tmd5.h" #include "taos.h" -#include "http.h" -#include "httpLog.h" -#include "httpCode.h" -#include "httpHandle.h" +#include "httpInt.h" #include "httpResp.h" +#include "httpSql.h" +#include "httpUtil.h" bool httpCheckUsedbSql(char *sql) { if (strstr(sql, "use ") != NULL) { diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index b85f27d175..fae11127e1 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -18,9 +18,10 @@ #include "tglobal.h" #include "taosdef.h" #include "taosmsg.h" +#include "httpInt.h" #include "tgHandle.h" #include "tgJson.h" -#include "httpLog.h" +#include "cJSON.h" /* * taos.telegraf.cfg formats like diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 2b03e81800..3c8f8623a1 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -848,7 +848,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * } int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); - if (isIntervalQuery(pQuery)) { + if (isIntervalQuery(pQuery) && tsCols != NULL) { int32_t offset = GET_COL_DATA_POS(pQuery, 0, step); TSKEY ts = tsCols[offset]; @@ -4285,7 +4285,8 @@ static void sequentialTableProcess(SQInfo *pQInfo) { assert(taosArrayGetSize(s) >= 1); setTagVal(pRuntimeEnv, (STableId*) taosArrayGet(s, 0), pQInfo->tsdb); - + + taosArrayDestroy(s); if (isFirstLastRowQuery(pQuery)) { assert(taosArrayGetSize(s) == 1); } @@ -4350,6 +4351,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo; // no results generated for current group, continue to try the next group + taosArrayDestroy(s); if (pWindowResInfo->size <= 0) { continue; } diff --git a/src/query/src/qast.c b/src/query/src/qast.c index 1db965e8a3..8d2202563d 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -496,7 +496,6 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { printf("relation is like\n"); assert(0); } - return TSDB_CODE_SUCCESS; } @@ -511,7 +510,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr if (cond.start != NULL) { iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->keyInfo.type, TSDB_ORDER_ASC); } else { - iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.end->v, pSkipList->keyInfo.type, TSDB_ORDER_DESC); + iter = tSkipListCreateIterFromVal(pSkipList, (char*)(cond.end ? cond.end->v: NULL), pSkipList->keyInfo.type, TSDB_ORDER_DESC); } if (cond.start != NULL) { @@ -601,6 +600,9 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr } } } + free(cond.start); + free(cond.end); + tSkipListDestroyIter(iter); } int32_t merge(SArray *pLeft, SArray *pRight, SArray *pFinalRes) { @@ -748,6 +750,7 @@ static void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SExprTravers } taosArrayCopy(pResult, array); + taosArrayDestroy(array); } static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSkipList *pSkipList, SExprTraverseSupp *param ) { @@ -1182,4 +1185,4 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { CLEANUP_EXECUTE_TO(anchor, false); return expr; -} \ No newline at end of file +} diff --git a/src/query/src/qextbuffer.c b/src/query/src/qextbuffer.c index 6351b850d8..e0a90e0408 100644 --- a/src/query/src/qextbuffer.c +++ b/src/query/src/qextbuffer.c @@ -896,6 +896,7 @@ void tColModelDisplay(SColumnModel *pModel, void *pData, int32_t numOfRows, int3 char buf[4096] = {0}; taosUcs4ToMbs(val, pModel->pFields[j].field.bytes, buf); printf("%s\t", buf); + break; } case TSDB_DATA_TYPE_BINARY: { printBinaryData(val, pModel->pFields[j].field.bytes); @@ -947,6 +948,7 @@ void tColModelDisplayEx(SColumnModel *pModel, void *pData, int32_t numOfRows, in char buf[128] = {0}; taosUcs4ToMbs(val, pModel->pFields[j].field.bytes, buf); printf("%s\t", buf); + break; } case TSDB_DATA_TYPE_BINARY: { printBinaryDataEx(val, pModel->pFields[j].field.bytes, ¶m[j]); diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index 4a3cb8adda..87add1e69e 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -775,19 +775,14 @@ void setDCLSQLElems(SSqlInfo *pInfo, int32_t type, int32_t nParam, ...) { while (nParam-- > 0) { SSQLToken *pToken = va_arg(va, SSQLToken *); - (void)tTokenListAppend(pInfo->pDCLInfo, pToken); + pInfo->pDCLInfo = tTokenListAppend(pInfo->pDCLInfo, pToken); } va_end(va); } void setDropDBTableInfo(SSqlInfo *pInfo, int32_t type, SSQLToken* pToken, SSQLToken* existsCheck) { pInfo->type = type; - - if (pInfo->pDCLInfo == NULL) { - pInfo->pDCLInfo = calloc(1, sizeof(tDCLSQL)); - } - - tTokenListAppend(pInfo->pDCLInfo, pToken); + pInfo->pDCLInfo = tTokenListAppend(pInfo->pDCLInfo, pToken); pInfo->pDCLInfo->existsCheck = (existsCheck->n == 1); } diff --git a/src/query/src/qpercentile.c b/src/query/src/qpercentile.c index 286171bdab..367028928b 100644 --- a/src/query/src/qpercentile.c +++ b/src/query/src/qpercentile.c @@ -241,7 +241,6 @@ void tBucketDoubleHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nElemSize, int16_t dataType, tOrderDescriptor *pDesc) { tMemBucket *pBucket = (tMemBucket *)malloc(sizeof(tMemBucket)); - pBucket->nTotalSlots = totalSlots; pBucket->nSlotsOfSeg = 1 << 6; // 64 Segments, 16 slots each seg. pBucket->dataType = dataType; @@ -258,6 +257,7 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE pBucket->numOfTotalPages = pBucket->nTotalBufferSize / pBucket->pageSize; pBucket->numOfAvailPages = pBucket->numOfTotalPages; + pBucket->pSegs = NULL; pBucket->pOrderDesc = pDesc; switch (pBucket->dataType) { @@ -315,7 +315,7 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE pBucket->pSegs[i].pBoundingEntries = NULL; } - uTrace("MemBucket:%p,created,buffer size:%d,elem size:%d", pBucket, pBucket->numOfTotalPages * DEFAULT_PAGE_SIZE, + uTrace("MemBucket:%p,created,buffer size:%ld,elem size:%d", pBucket, pBucket->numOfTotalPages * DEFAULT_PAGE_SIZE, pBucket->nElemSize); return pBucket; @@ -751,7 +751,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) char * thisVal = buffer->data + pMemBucket->nElemSize * currentIdx; char * nextVal = thisVal + pMemBucket->nElemSize; - double td, nd; + double td = 1.0, nd = 1.0; switch (pMemBucket->dataType) { case TSDB_DATA_TYPE_SMALLINT: { td = *(int16_t *)thisVal; diff --git a/src/query/src/qresultBuf.c b/src/query/src/qresultBuf.c index 55ec57b763..19353c9c5a 100644 --- a/src/query/src/qresultBuf.c +++ b/src/query/src/qresultBuf.c @@ -6,7 +6,12 @@ #include "queryLog.h" int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize, void* handle) { - SDiskbasedResultBuf* pResBuf = calloc(1, sizeof(SDiskbasedResultBuf)); + *pResultBuf = calloc(1, sizeof(SDiskbasedResultBuf)); + SDiskbasedResultBuf* pResBuf = *pResultBuf; + if (pResBuf == NULL) { + return TSDB_CODE_COM_OUT_OF_MEMORY; + } + pResBuf->numOfRowsPerPage = (DEFAULT_INTERN_BUF_PAGE_SIZE - sizeof(tFilePage)) / rowSize; pResBuf->numOfPages = size; @@ -46,7 +51,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si qTrace("QInfo:%p create tmp file for output result, %s, %" PRId64 "bytes", handle, pResBuf->path, pResBuf->totalBufSize); - *pResultBuf = pResBuf; return TSDB_CODE_SUCCESS; } @@ -210,7 +214,7 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf, void* handle) { } int32_t getLastPageId(SIDList *pList) { - if (pList == NULL && pList->size <= 0) { + if (pList == NULL || pList->size <= 0) { return -1; } diff --git a/src/query/src/qtsbuf.c b/src/query/src/qtsbuf.c index db1992a572..85aa2e7903 100644 --- a/src/query/src/qtsbuf.c +++ b/src/query/src/qtsbuf.c @@ -532,7 +532,7 @@ STSVnodeBlockInfo* tsBufGetVnodeBlockInfo(STSBuf* pTSBuf, int32_t vnodeId) { } int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader) { - if ((pTSBuf->f == NULL) || pHeader == NULL || pHeader->numOfVnode < 0 || pHeader->magic != TS_COMP_FILE_MAGIC) { + if ((pTSBuf->f == NULL) || pHeader == NULL || pHeader->numOfVnode == 0 || pHeader->magic != TS_COMP_FILE_MAGIC) { return -1; } diff --git a/src/query/src/tvariant.c b/src/query/src/tvariant.c index 2cf60d3e91..32d06225c5 100644 --- a/src/query/src/tvariant.c +++ b/src/query/src/tvariant.c @@ -357,7 +357,7 @@ static int32_t toBinary(tVariant *pVariant, char **pDest, int32_t *pDestSize) { if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) { size_t newSize = pVariant->nLen * TSDB_NCHAR_SIZE; if (pBuf != NULL) { - if (newSize > INITIAL_ALLOC_SIZE) { + if (newSize >= INITIAL_ALLOC_SIZE) { pBuf = realloc(pBuf, newSize + 1); } @@ -800,12 +800,13 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu break; } case TSDB_DATA_TYPE_NCHAR: { + int32_t newlen = 0; if (!includeLengthPrefix) { if (pVariant->nType == TSDB_DATA_TYPE_NULL) { *(uint32_t *)payload = TSDB_DATA_NCHAR_NULL; } else { if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - toNchar(pVariant, &payload, &pVariant->nLen); + toNchar(pVariant, &payload, &newlen); } else { wcsncpy((wchar_t *)payload, pVariant->wpz, pVariant->nLen); } @@ -817,12 +818,13 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu char *p = varDataVal(payload); if (pVariant->nType != TSDB_DATA_TYPE_NCHAR) { - toNchar(pVariant, &p, &pVariant->nLen); + toNchar(pVariant, &p, &newlen); } else { wcsncpy((wchar_t *)p, pVariant->wpz, pVariant->nLen); + newlen = pVariant->nLen; } - varDataSetLen(payload, pVariant->nLen); // the length may be changed after toNchar function called + varDataSetLen(payload, newlen); // the length may be changed after toNchar function called assert(p == varDataVal(payload)); } } diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index c33ebeb58b..c5b1cbf858 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -334,19 +334,19 @@ TEST(testCase, parse_time) { int64_t time = 0, time1 = 0; - taosParseTime(t1, &time, strlen(t1), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t1, &time, strlen(t1), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1514739661952); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, timezone * MILLISECOND_PER_SECOND); char t2[] = "2018-1-1T1:1:1.952Z"; - taosParseTime(t2, &time, strlen(t2), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t2, &time, strlen(t2), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1514739661952 + 28800000); char t3[] = "2018-1-1 1:01:01.952"; - taosParseTime(t3, &time, strlen(t3), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t3, &time, strlen(t3), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 1514739661952); char t4[] = "2018-1-1 1:01:01.9"; @@ -355,89 +355,89 @@ TEST(testCase, parse_time) { char t7[] = "2018-01-01 01:01:01.9"; char t8[] = "2018-01-01 01:01:01.9007865"; - taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t5, &time1, strlen(t5), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t5, &time1, strlen(t5), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); - taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t6, &time1, strlen(t6), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t6, &time1, strlen(t6), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); - taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t7, &time1, strlen(t7), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t7, &time1, strlen(t7), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); - taosParseTime(t5, &time, strlen(t5), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t8, &time1, strlen(t8), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t5, &time, strlen(t5), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t8, &time1, strlen(t8), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); char t9[] = "2017-4-3 1:1:2.980"; char t10[] = "2017-4-3T2:1:2.98+9:00"; - taosParseTime(t9, &time, strlen(t9), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t9, &time, strlen(t9), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); char t11[] = "2017-4-3T2:1:2.98+09:00"; - taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t10, &time1, strlen(t10), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); char t12[] = "2017-4-3T2:1:2.98+0900"; - taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI); - taosParseTime(t12, &time1, strlen(t12), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t11, &time, strlen(t11), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t12, &time1, strlen(t12), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); taos_options(TSDB_OPTION_TIMEZONE, "UTC"); - taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t13, &time, strlen(t13), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 0); taos_options(TSDB_OPTION_TIMEZONE, "Asia/Shanghai"); char t14[] = "1970-1-1T0:0:0Z"; - taosParseTime(t14, &time, strlen(t14), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t14, &time, strlen(t14), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 0); char t40[] = "1970-1-1 0:0:0.999999999"; - taosParseTime(t40, &time, strlen(t40), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t40, &time, strlen(t40), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 999 + timezone * MILLISECOND_PER_SECOND); char t41[] = "1997-1-1 0:0:0.999999999"; - taosParseTime(t41, &time, strlen(t41), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t41, &time, strlen(t41), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 852048000999); int64_t k = timezone; char t42[] = "1997-1-1T0:0:0.999999999Z"; - taosParseTime(t42, &time, strlen(t42), TSDB_TIME_PRECISION_MILLI); + taosParseTime(t42, &time, strlen(t42), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 852048000999 - timezone * MILLISECOND_PER_SECOND); //////////////////////////////////////////////////////////////////// // illegal timestamp format char t15[] = "2017-12-33 0:0:0"; - EXPECT_EQ(taosParseTime(t15, &time, strlen(t15), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t15, &time, strlen(t15), TSDB_TIME_PRECISION_MILLI, 0), -1); char t16[] = "2017-12-31 99:0:0"; - EXPECT_EQ(taosParseTime(t16, &time, strlen(t16), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t16, &time, strlen(t16), TSDB_TIME_PRECISION_MILLI, 0), -1); char t17[] = "2017-12-31T9:0:0"; - EXPECT_EQ(taosParseTime(t17, &time, strlen(t17), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t17, &time, strlen(t17), TSDB_TIME_PRECISION_MILLI, 0), -1); char t18[] = "2017-12-31T9:0:0.Z"; - EXPECT_EQ(taosParseTime(t18, &time, strlen(t18), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t18, &time, strlen(t18), TSDB_TIME_PRECISION_MILLI, 0), -1); char t19[] = "2017-12-31 9:0:0.-1"; - EXPECT_EQ(taosParseTime(t19, &time, strlen(t19), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t19, &time, strlen(t19), TSDB_TIME_PRECISION_MILLI, 0), -1); char t20[] = "2017-12-31 9:0:0.1+12:99"; - EXPECT_EQ(taosParseTime(t20, &time, strlen(t20), TSDB_TIME_PRECISION_MILLI), 0); + EXPECT_EQ(taosParseTime(t20, &time, strlen(t20), TSDB_TIME_PRECISION_MILLI, 0), 0); EXPECT_EQ(time, 1514682000100); char t21[] = "2017-12-31T9:0:0.1+12:99"; - EXPECT_EQ(taosParseTime(t21, &time, strlen(t21), TSDB_TIME_PRECISION_MILLI), -1); + EXPECT_EQ(taosParseTime(t21, &time, strlen(t21), TSDB_TIME_PRECISION_MILLI, 0), -1); char t22[] = "2017-12-31 9:0:0.1+13:1"; - EXPECT_EQ(taosParseTime(t22, &time, strlen(t22), TSDB_TIME_PRECISION_MILLI), 0); + EXPECT_EQ(taosParseTime(t22, &time, strlen(t22), TSDB_TIME_PRECISION_MILLI, 0), 0); char t23[] = "2017-12-31T9:0:0.1+13:1"; - EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI), 0); + EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI, 0), 0); } TEST(testCase, tvariant_convert) { diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index cf15cc690a..989021eb52 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -73,6 +73,7 @@ typedef struct { SRpcInfo *pRpc; // associated SRpcInfo SRpcIpSet ipSet; // ip list provided by app void *ahandle; // handle provided by app + struct SRpcConn *pConn; // pConn allocated char msgType; // message type uint8_t *pCont; // content provided by app int32_t contLen; // content length @@ -339,7 +340,7 @@ void *rpcReallocCont(void *ptr, int contLen) { return start + sizeof(SRpcReqContext) + sizeof(SRpcHead); } -void rpcSendRequest(void *shandle, const SRpcIpSet *pIpSet, const SRpcMsg *pMsg) { +void *rpcSendRequest(void *shandle, const SRpcIpSet *pIpSet, const SRpcMsg *pMsg) { SRpcInfo *pRpc = (SRpcInfo *)shandle; SRpcReqContext *pContext; @@ -367,7 +368,7 @@ void rpcSendRequest(void *shandle, const SRpcIpSet *pIpSet, const SRpcMsg *pMsg) rpcSendReqToServer(pRpc, pContext); - return; + return pContext; } void rpcSendResponse(const SRpcMsg *pRsp) { @@ -488,17 +489,35 @@ void rpcSendRecv(void *shandle, SRpcIpSet *pIpSet, const SRpcMsg *pMsg, SRpcMsg // this API is used by server app to keep an APP context in case connection is broken int rpcReportProgress(void *handle, char *pCont, int contLen) { SRpcConn *pConn = (SRpcConn *)handle; + int code = 0; + + rpcLockConn(pConn); if (pConn->user[0]) { // pReqMsg and reqMsgLen is re-used to store the context from app server pConn->pReqMsg = pCont; pConn->reqMsgLen = contLen; - return 0; - } + } else { + tTrace("%s, rpc connection is already released", pConn->info); + rpcFreeCont(pCont); + code = -1; + } - tTrace("%s, rpc connection is already released", pConn->info); - rpcFreeCont(pCont); - return -1; + rpcUnlockConn(pConn); + return code; +} + +/* todo: cancel process may have race condition, pContext may have been released + just before app calls the rpcCancelRequest */ +void rpcCancelRequest(void *handle) { + SRpcReqContext *pContext = handle; + + if (pContext->pConn) { + tTrace("%s, app trys to cancel request", pContext->pConn->info); + rpcCloseConn(pContext->pConn); + pContext->pConn = NULL; + rpcFreeCont(pContext->pCont); + } } static void rpcFreeMsg(void *msg) { @@ -541,18 +560,10 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, return pConn; } -static void rpcCloseConn(void *thandle) { - SRpcConn *pConn = (SRpcConn *)thandle; +static void rpcReleaseConn(SRpcConn *pConn) { SRpcInfo *pRpc = pConn->pRpc; if (pConn->user[0] == 0) return; - rpcLockConn(pConn); - - if (pConn->user[0] == 0) { - rpcUnlockConn(pConn); - return; - } - pConn->user[0] = 0; if (taosCloseConn[pConn->connType]) (*taosCloseConn[pConn->connType])(pConn->chandle); @@ -577,7 +588,16 @@ static void rpcCloseConn(void *thandle) { taosFreeId(pRpc->idPool, pConn->sid); pConn->pContext = NULL; - tTrace("%s, rpc connection is closed", pConn->info); + tTrace("%s, rpc connection is released", pConn->info); +} + +static void rpcCloseConn(void *thandle) { + SRpcConn *pConn = (SRpcConn *)thandle; + + rpcLockConn(pConn); + + if (pConn->user[0]) + rpcReleaseConn(pConn); rpcUnlockConn(pConn); } @@ -681,6 +701,7 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, SRecvInfo *pRecv) { if (pConn) { if (pConn->linkUid != pHead->linkUid) { terrno = TSDB_CODE_RPC_MISMATCHED_LINK_ID; + tError("%s %p %p, linkUid:0x%x is not matched with received:0x%x", pRpc->label, pConn, pHead->ahandle, pConn->linkUid, pHead->linkUid); pConn = NULL; } } @@ -874,6 +895,7 @@ static void rpcReportBrokenLinkToServer(SRpcConn *pConn) { SRpcMsg rpcMsg; rpcMsg.pCont = pConn->pReqMsg; // pReqMsg is re-used to store the APP context from server rpcMsg.contLen = pConn->reqMsgLen; // reqMsgLen is re-used to store the APP context length + rpcMsg.ahandle = pConn->ahandle; rpcMsg.handle = pConn; rpcMsg.msgType = pConn->inType; rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; @@ -895,8 +917,8 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) { if (pConn->inType) rpcReportBrokenLinkToServer(pConn); + rpcReleaseConn(pConn); rpcUnlockConn(pConn); - rpcCloseConn(pConn); } static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { @@ -909,7 +931,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { // underlying UDP layer does not know it is server or client pRecv->connType = pRecv->connType | pRpc->connType; - if (pRecv->ip == 0) { + if (pRecv->msg == NULL) { rpcProcessBrokenLink(pConn); return NULL; } @@ -942,6 +964,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { static void rpcNotifyClient(SRpcReqContext *pContext, SRpcMsg *pMsg) { SRpcInfo *pRpc = pContext->pRpc; + pContext->pConn = NULL; if (pContext->pRsp) { // for synchronous API memcpy(pContext->pSet, &pContext->ipSet, sizeof(SRpcIpSet)); @@ -1110,6 +1133,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) { return; } + pContext->pConn = pConn; pConn->ahandle = pContext->ahandle; rpcLockConn(pConn); @@ -1199,7 +1223,6 @@ static void rpcProcessConnError(void *param, void *id) { static void rpcProcessRetryTimer(void *param, void *tmrId) { SRpcConn *pConn = (SRpcConn *)param; SRpcInfo *pRpc = pConn->pRpc; - int reportDisc = 0; rpcLockConn(pConn); @@ -1215,31 +1238,33 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) { } else { // close the connection tTrace("%s, failed to send msg:%s to %s:%hu", pConn->info, taosMsg[pConn->outType], pConn->peerFqdn, pConn->peerPort); - reportDisc = 1; + if (pConn->pContext) { + pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; + taosTmrStart(rpcProcessConnError, 0, pConn->pContext, pRpc->tmrCtrl); + rpcReleaseConn(pConn); + } } } else { tTrace("%s, retry timer not processed", pConn->info); } rpcUnlockConn(pConn); - - if (reportDisc && pConn->pContext) { - pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - rpcProcessConnError(pConn->pContext, NULL); - rpcCloseConn(pConn); - } } static void rpcProcessIdleTimer(void *param, void *tmrId) { SRpcConn *pConn = (SRpcConn *)param; + rpcLockConn(pConn); + if (pConn->user[0]) { tTrace("%s, close the connection since no activity", pConn->info); if (pConn->inType) rpcReportBrokenLinkToServer(pConn); - rpcCloseConn(pConn); + rpcReleaseConn(pConn); } else { tTrace("%s, idle timer:%p not processed", pConn->info, tmrId); } + + rpcUnlockConn(pConn); } static void rpcProcessProgressTimer(void *param, void *tmrId) { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 8eb259d38c..1f31f18ce1 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -424,6 +424,11 @@ int tsdbUpdateTable(STsdbMeta *pMeta, STable *pTable, STableCfg *pCfg) { pTable->schema[pTable->numOfSchemas-1] = tSchema; } + STSchema *lSchema = pTable->schema[pTable->numOfSchemas - 1]; + if (schemaNCols(lSchema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(lSchema); + int bytes = dataRowMaxBytesFromSchema(lSchema); + if (bytes > pMeta->maxRowBytes) pMeta->maxRowBytes = bytes; + isChanged = true; } @@ -595,6 +600,10 @@ int tsdbDropTable(TsdbRepoT *repo, STableId tableId) { return -1; } + if (pTable->cqhandle != NULL) { + pRepo->appH.cqDropFunc(pTable->cqhandle); + } + tsdbTrace("vgId:%d, table %s is dropped! tid:%d, uid:%" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name), tableId.tid, tableId.uid); if (tsdbRemoveTableFromMeta(pMeta, pTable, true) < 0) return -1; diff --git a/src/util/inc/ttime.h b/src/util/inc/ttime.h index 61df65f345..576c9a51f6 100644 --- a/src/util/inc/ttime.h +++ b/src/util/inc/ttime.h @@ -56,7 +56,7 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) { int32_t getTimestampInUsFromStr(char* token, int32_t tokenlen, int64_t* ts); -int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec); +int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth); void deltaToUtcInitOnce(); #ifdef __cplusplus diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index ac06cf4f3f..2b6083a91c 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -63,10 +63,12 @@ static FORCE_INLINE void __cache_lock_destroy(SCacheObj *pCacheObj) { #endif } +#if 0 static FORCE_INLINE void taosFreeNode(void *data) { SCacheDataNode *pNode = *(SCacheDataNode **)data; free(pNode); } +#endif /** * @param key key of object for hash, usually a null-terminated string @@ -241,7 +243,7 @@ SCacheObj *taosCacheInitWithCb(int64_t refreshTime, void (*freeCb)(void *data)) } // set free cache node callback function for hash table - taosHashSetFreecb(pCacheObj->pHashTable, taosFreeNode); + // taosHashSetFreecb(pCacheObj->pHashTable, taosFreeNode); pCacheObj->freeFp = freeCb; pCacheObj->refreshTime = refreshTime * 1000; @@ -565,7 +567,17 @@ void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) { void doCleanupDataCache(SCacheObj *pCacheObj) { __cache_wr_lock(pCacheObj); - taosHashCleanup(pCacheObj->pHashTable); + + SHashMutableIterator *pIter = taosHashCreateIter(pCacheObj->pHashTable); + while (taosHashIterNext(pIter)) { + SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter); + // if (pNode->expiredTime <= expiredTime && T_REF_VAL_GET(pNode) <= 0) { + taosCacheReleaseNode(pCacheObj, pNode); + //} + } + taosHashDestroyIter(pIter); + + taosHashCleanup(pCacheObj->pHashTable); __cache_unlock(pCacheObj); taosTrashCanEmpty(pCacheObj, true); diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index 8355ed9dc1..4dd6360752 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -24,7 +24,6 @@ #include "taosdef.h" #include "ttime.h" #include "tutil.h" - /* * mktime64 - Converts date to seconds. * Converts Gregorian date to seconds since 1970-01-01 00:00:00. @@ -119,15 +118,21 @@ static int month[12] = { 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); +static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec); + +static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = { + parseLocaltime, + parseLocaltimeWithDst +}; int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } -int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec) { +int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t daylight) { /* parse datatime string in with tz */ if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec); } else { - return parseLocaltime(timestr, time, timePrec); + return (*parseLocaltimeFp[daylight])(timestr, time, timePrec); } } @@ -304,9 +309,6 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { return -1; } - /* mktime will be affected by TZ, set by using taos_options */ - //int64_t seconds = mktime(&tm); - //int64_t seconds = (int64_t)user_mktime(&tm); int64_t seconds = user_mktime64(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); int64_t fraction = 0; @@ -324,6 +326,32 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { return 0; } +int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec) { + *time = 0; + struct tm tm = {0}; + tm.tm_isdst = -1; + + char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); + if (str == NULL) { + return -1; + } + + /* mktime will be affected by TZ, set by using taos_options */ + int64_t seconds = mktime(&tm); + + int64_t fraction = 0; + + if (*str == '.') { + /* parse the second fraction part */ + if ((fraction = parseFraction(str + 1, &str, timePrec)) < 0) { + return -1; + } + } + + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : 1000000; + *time = factor * seconds + fraction; + return 0; +} static int32_t getTimestampInUsFromStrImpl(int64_t val, char unit, int64_t* result) { *result = val; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 0882ee983d..fef0b071a6 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -325,6 +325,11 @@ void vnodeRelease(void *pVnodeRaw) { tsdbCloseRepo(pVnode->tsdb, 1); pVnode->tsdb = NULL; + // stop continuous query + if (pVnode->cq) + cqClose(pVnode->cq); + pVnode->cq = NULL; + if (pVnode->wal) walClose(pVnode->wal); pVnode->wal = NULL; @@ -436,11 +441,6 @@ static void vnodeCleanUp(SVnodeObj *pVnode) { pVnode->sync = NULL; } - // stop continuous query - if (pVnode->cq) - cqClose(pVnode->cq); - pVnode->cq = NULL; - // release local resources only after cutting off outside connections vnodeRelease(pVnode); } diff --git a/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md b/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md index 3477fe9152..b6859827bf 100644 --- a/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md +++ b/tests/How-To-Run-Test-And-How-To-Add-New-Test-Case.md @@ -11,6 +11,8 @@ 4. pip install ../src/connector/python/linux/python2 ; pip3 install ../src/connector/python/linux/python3 +5. pip install numpy; pip3 install numpy + > Note: Both Python2 and Python3 are currently supported by the Python test > framework. Since Python2 is no longer officially supported by Python Software > Foundation since January 1, 2020, it is recommended that subsequent test case diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 58ab8b99b4..dfa3b55048 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -127,7 +127,7 @@ python3 ./test.py -f user/user_create.py python3 ./test.py -f user/pass_len.py # table -#python3 ./test.py -f table/del_stable.py +python3 ./test.py -f table/del_stable.py #query python3 ./test.py -f query/filter.py diff --git a/tests/pytest/query/filterAllIntTypes.py b/tests/pytest/query/filterAllIntTypes.py index 32e635d6da..cf65d2b102 100644 --- a/tests/pytest/query/filterAllIntTypes.py +++ b/tests/pytest/query/filterAllIntTypes.py @@ -22,12 +22,12 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) - + self.powers = [7, 15, 31, 63] self.types = ["tinyint", "smallint", "int", "bigint"] self.rowNum = 10 - self.ts = 1537146000000 - + self.ts = 1537146000000 + def run(self): tdSql.prepare() @@ -35,20 +35,30 @@ class TDTestCase: curType = self.types[i] print("======= Verify filter for %s type =========" % (curType)) tdLog.debug( - "create table st%s(ts timestamp, num %s) tags(id %s)" % (curType, curType, curType)) + "create table st%s(ts timestamp, num %s) tags(id %s)" % + (curType, curType, curType)) tdSql.execute( - "create table st%s(ts timestamp, num %s) tags(id %s)" % (curType, curType, curType)) - - #create 10 tables, insert 10 rows for each table - for j in range(self.rowNum): - tdSql.execute("create table st%s%d using st%s tags(%d)" % (curType, j + 1, curType, j + 1)) - for k in range(self.rowNum): - tdSql.execute("insert into st%s%d values(%d, %d)" % (curType, j + 1, self.ts + k + 1, j * 10 + k + 1)) - - tdSql.error("insert into st%s10 values(%d, %d)" % (curType, self.ts + 11, pow(2, self.powers[i]))) - tdSql.execute("insert into st%s10 values(%d, %d)" % (curType, self.ts + 12, pow(2, self.powers[i]) - 1)) - tdSql.error("insert into st%s10 values(%d, %d)" % (curType, self.ts + 13, pow(-2, self.powers[i]))) - tdSql.execute("insert into st%s10 values(%d, %d)" % (curType, self.ts + 14, pow(-2, self.powers[i]) + 1)) + "create table st%s(ts timestamp, num %s) tags(id %s)" % + (curType, curType, curType)) + + # create 10 tables, insert 10 rows for each table + for j in range(self.rowNum): + tdSql.execute( + "create table st%s%d using st%s tags(%d)" % + (curType, j + 1, curType, j + 1)) + for k in range(self.rowNum): + tdSql.execute( + "insert into st%s%d values(%d, %d)" % + (curType, j + 1, self.ts + k + 1, j * 10 + k + 1)) + + tdSql.error("insert into st%s10 values(%d, %d)" % + (curType, self.ts + 11, pow(2, self.powers[i]))) + tdSql.execute("insert into st%s10 values(%d, %d)" % + (curType, self.ts + 12, pow(2, self.powers[i]) - 1)) + tdSql.error("insert into st%s10 values(%d, %d)" % + (curType, self.ts + 13, pow(-2, self.powers[i]))) + tdSql.execute("insert into st%s10 values(%d, %d)" % + (curType, self.ts + 14, pow(-2, self.powers[i]) + 1)) # > for int type on column tdSql.query("select * from st%s where num > 50" % curType) @@ -104,10 +114,12 @@ class TDTestCase: # != for int type on tag tdSql.query("select * from st%s where id != 5" % curType) - tdSql.checkRows(92) + tdSql.checkRows(92) + + print( + "======= Verify filter for %s type finished =========" % + curType) - print("======= Verify filter for %s type finished =========" % curType) - def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/filterFloatAndDouble.py b/tests/pytest/query/filterFloatAndDouble.py index bea41be11c..bd349a2a25 100644 --- a/tests/pytest/query/filterFloatAndDouble.py +++ b/tests/pytest/query/filterFloatAndDouble.py @@ -21,28 +21,28 @@ from util.sql import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor()) self.rowNum = 10 self.ts = 1537146000000 - + def run(self): tdSql.prepare() print("======= Verify filter for float and double type =========") tdLog.debug( - "create table st(ts timestamp, num float, speed double) tags(tagcol1 float, tagcol2 double)") + "create table st(ts timestamp, num float, speed double) tags(tagcol1 float, tagcol2 double)") tdSql.execute( - "create table st(ts timestamp, num float, speed double) tags(tagcol1 float, tagcol2 double)") - - for j in range(self.rowNum): - tdSql.execute( - "insert into st1 using st tags(1.1, 2.3) values(%d, %f, %f)" % (self.ts + j + 1, 1.1 * (j + 1), 2.3 * (j + 1))) + "create table st(ts timestamp, num float, speed double) tags(tagcol1 float, tagcol2 double)") + + for j in range(self.rowNum): + tdSql.execute("insert into st1 using st tags(1.1, 2.3) values(%d, %f, %f)" % ( + self.ts + j + 1, 1.1 * (j + 1), 2.3 * (j + 1))) # > for float type on column tdSql.query("select * from st where num > 5.5") tdSql.checkRows(5) - + # >= for float type on column tdSql.query("select * from st where num >= 5.5") tdSql.checkRows(6) @@ -70,11 +70,11 @@ class TDTestCase: # > for float type on tag tdSql.query("select * from st where tagcol1 > 1.1") tdSql.checkRows(0) - + # >= for float type on tag tdSql.query("select * from st where tagcol1 >= 1.1") tdSql.checkRows(10) - + # = for float type on tag tdSql.query("select * from st where tagcol1 = 1.1") tdSql.checkRows(10) @@ -86,7 +86,7 @@ class TDTestCase: # != for float type on tag tdSql.query("select * from st where tagcol1 != 1.1") tdSql.checkRows(0) - + # <= for float type on tag tdSql.query("select * from st where tagcol1 <= 1.1") tdSql.checkRows(10) @@ -94,11 +94,11 @@ class TDTestCase: # < for float type on tag tdSql.query("select * from st where tagcol1 < 1.1") tdSql.checkRows(0) - + # > for double type on column tdSql.query("select * from st where speed > 11.5") tdSql.checkRows(5) - + # >= for double type on column tdSql.query("select * from st where speed >= 11.5") tdSql.checkRows(6) @@ -126,11 +126,11 @@ class TDTestCase: # > for double type on tag tdSql.query("select * from st where tagcol2 > 2.3") tdSql.checkRows(0) - + # >= for double type on tag tdSql.query("select * from st where tagcol2 >= 2.3") tdSql.checkRows(10) - + # = for double type on tag tdSql.query("select * from st where tagcol2 = 2.3") tdSql.checkRows(10) @@ -142,7 +142,7 @@ class TDTestCase: # != for double type on tag tdSql.query("select * from st where tagcol2 != 2.3") tdSql.checkRows(0) - + # <= for double type on tag tdSql.query("select * from st where tagcol2 <= 2.3") tdSql.checkRows(10) @@ -150,7 +150,7 @@ class TDTestCase: # < for double type on tag tdSql.query("select * from st where tagcol2 < 2.3") tdSql.checkRows(0) - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/filterOtherTypes.py b/tests/pytest/query/filterOtherTypes.py index f09ac596c7..bc7df18c8d 100644 --- a/tests/pytest/query/filterOtherTypes.py +++ b/tests/pytest/query/filterOtherTypes.py @@ -21,33 +21,39 @@ from util.sql import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) - + tdSql.init(conn.cursor()) + self.ts = 1537146000000 - + def run(self): tdSql.prepare() - + print("======= Verify filter for bool, nchar and binary type =========") tdLog.debug( "create table st(ts timestamp, tbcol1 bool, tbcol2 nchar(10), tbcol3 binary(20)) tags(tagcol1 bool, tagcol2 nchar(10), tagcol3 binary(10))") tdSql.execute( - "create table st(ts timestamp, tbcol1 bool, tbcol2 nchar(10), tbcol3 binary(20)) tags(tagcol1 bool, tagcol2 nchar(10), tagcol3 binary(10))") + "create table st(ts timestamp, tbcol1 bool, tbcol2 nchar(10), tbcol3 binary(20)) tags(tagcol1 bool, tagcol2 nchar(10), tagcol3 binary(10))") tdSql.execute("create table st1 using st tags(true, 'table1', '水表')") - for i in range(1, 6): - tdSql.execute("insert into st1 values(%d, %d, 'taosdata%d', '涛思数据%d')" % (self.ts + i, i % 2, i, i)) + for i in range(1, 6): + tdSql.execute( + "insert into st1 values(%d, %d, 'taosdata%d', '涛思数据%d')" % + (self.ts + i, i % + 2, i, i)) tdSql.execute("create table st2 using st tags(false, 'table2', '电表')") - for i in range(6, 11): - tdSql.execute("insert into st2 values(%d, %d, 'taosdata%d', '涛思数据%d')" % (self.ts + i, i % 2, i, i)) + for i in range(6, 11): + tdSql.execute( + "insert into st2 values(%d, %d, 'taosdata%d', '涛思数据%d')" % + (self.ts + i, i % + 2, i, i)) # =============Verify stable columns==================== # > for bool type on column tdSql.error("select * from st where tbcol1 > false") # >= for bool type on column - tdSql.error("select * from st where tbcol1 >= false") + tdSql.error("select * from st where tbcol1 >= false") # = for bool type on column tdSql.query("select * from st where tbcol1 = false") @@ -77,18 +83,18 @@ class TDTestCase: tdSql.error("select * from st where tbcol2 > 'taosdata'") # >= for nchar type on column - tdSql.error("select * from st where tbcol2 >= 'taosdata'") + tdSql.error("select * from st where tbcol2 >= 'taosdata'") # = for nchar type on column tdSql.query("select * from st where tbcol2 = 'taosdata1'") tdSql.checkRows(1) # <> for nchar type on column - tdSql.query("select * from st where tbcol2 <> 'taosdata1'") + tdSql.query("select * from st where tbcol2 <> 'taosdata1'") tdSql.checkRows(9) # != for nchar type on column - tdSql.query("select * from st where tbcol2 != 'taosdata1'") + tdSql.query("select * from st where tbcol2 != 'taosdata1'") tdSql.checkRows(9) # > for nchar type on column @@ -98,57 +104,57 @@ class TDTestCase: tdSql.error("select * from st where tbcol2 <= 'taodata'") # % for nchar type on column case 1 - tdSql.query("select * from st where tbcol2 like '%'") + tdSql.query("select * from st where tbcol2 like '%'") tdSql.checkRows(10) # % for nchar type on column case 2 - tdSql.query("select * from st where tbcol2 like 'a%'") + tdSql.query("select * from st where tbcol2 like 'a%'") tdSql.checkRows(0) # % for nchar type on column case 3 - tdSql.query("select * from st where tbcol2 like 't%_'") + tdSql.query("select * from st where tbcol2 like 't%_'") tdSql.checkRows(10) # % for nchar type on column case 4 - tdSql.query("select * from st where tbcol2 like '%1'") + tdSql.query("select * from st where tbcol2 like '%1'") # tdSql.checkRows(2) # _ for nchar type on column case 1 - tdSql.query("select * from st where tbcol2 like '____________'") - tdSql.checkRows(0) + tdSql.query("select * from st where tbcol2 like '____________'") + tdSql.checkRows(0) # _ for nchar type on column case 2 - tdSql.query("select * from st where tbcol2 like '__________'") + tdSql.query("select * from st where tbcol2 like '__________'") tdSql.checkRows(1) # _ for nchar type on column case 3 - tdSql.query("select * from st where tbcol2 like '_________'") + tdSql.query("select * from st where tbcol2 like '_________'") tdSql.checkRows(9) # _ for nchar type on column case 4 - tdSql.query("select * from st where tbcol2 like 't________'") + tdSql.query("select * from st where tbcol2 like 't________'") tdSql.checkRows(9) # _ for nchar type on column case 5 - tdSql.query("select * from st where tbcol2 like '%________'") + tdSql.query("select * from st where tbcol2 like '%________'") tdSql.checkRows(10) # > for binary type on column tdSql.error("select * from st where tbcol3 > '涛思数据'") # >= for binary type on column - tdSql.error("select * from st where tbcol3 >= '涛思数据'") + tdSql.error("select * from st where tbcol3 >= '涛思数据'") # = for binary type on column tdSql.query("select * from st where tbcol3 = '涛思数据1'") tdSql.checkRows(1) # <> for binary type on column - tdSql.query("select * from st where tbcol3 <> '涛思数据1'") + tdSql.query("select * from st where tbcol3 <> '涛思数据1'") tdSql.checkRows(9) # != for binary type on column - tdSql.query("select * from st where tbcol3 != '涛思数据1'") + tdSql.query("select * from st where tbcol3 != '涛思数据1'") tdSql.checkRows(9) # > for binary type on column @@ -158,39 +164,39 @@ class TDTestCase: tdSql.error("select * from st where tbcol3 <= '涛思数据'") # % for binary type on column case 1 - tdSql.query("select * from st where tbcol3 like '%'") + tdSql.query("select * from st where tbcol3 like '%'") tdSql.checkRows(10) # % for binary type on column case 2 - tdSql.query("select * from st where tbcol3 like '陶%'") + tdSql.query("select * from st where tbcol3 like '陶%'") tdSql.checkRows(0) # % for binary type on column case 3 - tdSql.query("select * from st where tbcol3 like '涛%_'") + tdSql.query("select * from st where tbcol3 like '涛%_'") tdSql.checkRows(10) # % for binary type on column case 4 - tdSql.query("select * from st where tbcol3 like '%1'") + tdSql.query("select * from st where tbcol3 like '%1'") tdSql.checkRows(1) # _ for binary type on column case 1 - tdSql.query("select * from st where tbcol3 like '_______'") - tdSql.checkRows(0) + tdSql.query("select * from st where tbcol3 like '_______'") + tdSql.checkRows(0) # _ for binary type on column case 2 - tdSql.query("select * from st where tbcol3 like '______'") + tdSql.query("select * from st where tbcol3 like '______'") tdSql.checkRows(1) # _ for binary type on column case 2 - tdSql.query("select * from st where tbcol3 like '_____'") + tdSql.query("select * from st where tbcol3 like '_____'") tdSql.checkRows(9) # _ for binary type on column case 3 - tdSql.query("select * from st where tbcol3 like '____'") + tdSql.query("select * from st where tbcol3 like '____'") tdSql.checkRows(0) # _ for binary type on column case 4 - tdSql.query("select * from st where tbcol3 like 't____'") + tdSql.query("select * from st where tbcol3 like 't____'") tdSql.checkRows(0) # =============Verify stable tags==================== @@ -198,7 +204,7 @@ class TDTestCase: tdSql.error("select * from st where tagcol1 > false") # >= for bool type on tag - tdSql.error("select * from st where tagcol1 >= false") + tdSql.error("select * from st where tagcol1 >= false") # = for bool type on tag tdSql.query("select * from st where tagcol1 = false") @@ -228,18 +234,18 @@ class TDTestCase: tdSql.error("select * from st where tagcol2 > 'table'") # >= for nchar type on tag - tdSql.error("select * from st where tagcol2 >= 'table'") + tdSql.error("select * from st where tagcol2 >= 'table'") # = for nchar type on tag tdSql.query("select * from st where tagcol2 = 'table1'") tdSql.checkRows(5) # <> for nchar type on tag - tdSql.query("select * from st where tagcol2 <> 'table1'") + tdSql.query("select * from st where tagcol2 <> 'table1'") tdSql.checkRows(5) # != for nchar type on tag - tdSql.query("select * from st where tagcol2 != 'table'") + tdSql.query("select * from st where tagcol2 != 'table'") tdSql.checkRows(10) # > for nchar type on tag @@ -249,57 +255,57 @@ class TDTestCase: tdSql.error("select * from st where tagcol2 <= 'table'") # % for nchar type on tag case 1 - tdSql.query("select * from st where tagcol2 like '%'") + tdSql.query("select * from st where tagcol2 like '%'") tdSql.checkRows(10) # % for nchar type on tag case 2 - tdSql.query("select * from st where tagcol2 like 'a%'") + tdSql.query("select * from st where tagcol2 like 'a%'") tdSql.checkRows(0) # % for nchar type on tag case 3 - tdSql.query("select * from st where tagcol2 like 't%_'") + tdSql.query("select * from st where tagcol2 like 't%_'") tdSql.checkRows(10) # % for nchar type on tag case 4 - tdSql.query("select * from st where tagcol2 like '%1'") + tdSql.query("select * from st where tagcol2 like '%1'") tdSql.checkRows(5) # _ for nchar type on tag case 1 - tdSql.query("select * from st where tagcol2 like '_______'") - tdSql.checkRows(0) + tdSql.query("select * from st where tagcol2 like '_______'") + tdSql.checkRows(0) # _ for nchar type on tag case 2 - tdSql.query("select * from st where tagcol2 like '______'") + tdSql.query("select * from st where tagcol2 like '______'") tdSql.checkRows(10) # _ for nchar type on tag case 3 - tdSql.query("select * from st where tagcol2 like 't_____'") + tdSql.query("select * from st where tagcol2 like 't_____'") tdSql.checkRows(10) # _ for nchar type on tag case 4 - tdSql.query("select * from st where tagcol2 like 's________'") + tdSql.query("select * from st where tagcol2 like 's________'") tdSql.checkRows(0) # _ for nchar type on tag case 5 - tdSql.query("select * from st where tagcol2 like '%__'") + tdSql.query("select * from st where tagcol2 like '%__'") tdSql.checkRows(10) # > for binary type on tag tdSql.error("select * from st where tagcol3 > '表'") # >= for binary type on tag - tdSql.error("select * from st where tagcol3 >= '表'") + tdSql.error("select * from st where tagcol3 >= '表'") # = for binary type on tag tdSql.query("select * from st where tagcol3 = '水表'") tdSql.checkRows(5) # <> for binary type on tag - tdSql.query("select * from st where tagcol3 <> '水表'") + tdSql.query("select * from st where tagcol3 <> '水表'") tdSql.checkRows(5) # != for binary type on tag - tdSql.query("select * from st where tagcol3 != '水表'") + tdSql.query("select * from st where tagcol3 != '水表'") tdSql.checkRows(5) # > for binary type on tag @@ -309,54 +315,53 @@ class TDTestCase: tdSql.error("select * from st where tagcol3 <= '水表'") # % for binary type on tag case 1 - tdSql.query("select * from st where tagcol3 like '%'") + tdSql.query("select * from st where tagcol3 like '%'") tdSql.checkRows(10) # % for binary type on tag case 2 - tdSql.query("select * from st where tagcol3 like '水%'") + tdSql.query("select * from st where tagcol3 like '水%'") tdSql.checkRows(5) # % for binary type on tag case 3 - tdSql.query("select * from st where tagcol3 like '数%_'") + tdSql.query("select * from st where tagcol3 like '数%_'") tdSql.checkRows(0) # % for binary type on tag case 4 - tdSql.query("select * from st where tagcol3 like '%表'") + tdSql.query("select * from st where tagcol3 like '%表'") tdSql.checkRows(10) # % for binary type on tag case 5 - tdSql.query("select * from st where tagcol3 like '%据'") + tdSql.query("select * from st where tagcol3 like '%据'") tdSql.checkRows(0) # _ for binary type on tag case 1 - tdSql.query("select * from st where tagcol3 like '__'") - tdSql.checkRows(10) + tdSql.query("select * from st where tagcol3 like '__'") + tdSql.checkRows(10) # _ for binary type on tag case 2 - tdSql.query("select * from st where tagcol3 like '水_'") + tdSql.query("select * from st where tagcol3 like '水_'") tdSql.checkRows(5) # _ for binary type on tag case 2 - tdSql.query("select * from st where tagcol3 like '_表'") + tdSql.query("select * from st where tagcol3 like '_表'") tdSql.checkRows(10) # _ for binary type on tag case 3 - tdSql.query("select * from st where tagcol3 like '___'") + tdSql.query("select * from st where tagcol3 like '___'") tdSql.checkRows(0) # _ for binary type on tag case 4 - tdSql.query("select * from st where tagcol3 like '数_'") + tdSql.query("select * from st where tagcol3 like '数_'") tdSql.checkRows(0) # _ for binary type on tag case 5 - tdSql.query("select * from st where tagcol3 like '_据'") + tdSql.query("select * from st where tagcol3 like '_据'") tdSql.checkRows(0) - + def stop(self): tdSql.close() - tdLog.success("%s successfully executed" % __file__) + tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase()) - diff --git a/tests/pytest/query/querySort.py b/tests/pytest/query/querySort.py index bb806c27bc..3858701379 100644 --- a/tests/pytest/query/querySort.py +++ b/tests/pytest/query/querySort.py @@ -21,56 +21,60 @@ from util.sql import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor()) self.rowNum = 10 self.ts = 1537146000000 - + def run(self): tdSql.prepare() print("======= step 1: create table and insert data =========") tdLog.debug( - ''' create table st(ts timestamp, tbcol1 tinyint, tbcol2 smallint, tbcol3 int, tbcol4 bigint, tbcol5 float, tbcol6 double, - tbcol7 bool, tbcol8 nchar(20), tbcol9 binary(20)) tags(tagcol1 tinyint, tagcol2 smallint, tagcol3 int, tagcol4 bigint, tagcol5 float, + ''' create table st(ts timestamp, tbcol1 tinyint, tbcol2 smallint, tbcol3 int, tbcol4 bigint, tbcol5 float, tbcol6 double, + tbcol7 bool, tbcol8 nchar(20), tbcol9 binary(20)) tags(tagcol1 tinyint, tagcol2 smallint, tagcol3 int, tagcol4 bigint, tagcol5 float, tagcol6 double, tagcol7 bool, tagcol8 nchar(20), tagcol9 binary(20))''') tdSql.execute( - ''' create table st(ts timestamp, tbcol1 tinyint, tbcol2 smallint, tbcol3 int, tbcol4 bigint, tbcol5 float, tbcol6 double, - tbcol7 bool, tbcol8 nchar(20), tbcol9 binary(20)) tags(tagcol1 tinyint, tagcol2 smallint, tagcol3 int, tagcol4 bigint, tagcol5 float, + ''' create table st(ts timestamp, tbcol1 tinyint, tbcol2 smallint, tbcol3 int, tbcol4 bigint, tbcol5 float, tbcol6 double, + tbcol7 bool, tbcol8 nchar(20), tbcol9 binary(20)) tags(tagcol1 tinyint, tagcol2 smallint, tagcol3 int, tagcol4 bigint, tagcol5 float, tagcol6 double, tagcol7 bool, tagcol8 nchar(20), tagcol9 binary(20))''') - - for i in range(self.rowNum): - tdSql.execute("create table st%d using st tags(%d, %d, %d, %d, %f, %f, %d, 'tag%d', '标签%d')" % (i + 1, i + 1, i + 1, i + 1, i + 1, 1.1 * (i + 1), - 1.23 * (i + 1), (i + 1) % 2, i + 1, i + 1)) - for j in range(self.rowNum): - tdSql.execute("insert into st%d values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" % (i + 1, self.ts + 10 * (i + 1) + j + 1, - j + 1, j + 1, j + 1, j + 1, 1.1 * (j + 1), 1.23 * (j + 1), (j + 1) % 2, j + 1, j + 1)) - - print("======= step 2: verify order for each column =========") - # sort for timestamp in asc order + for i in range(self.rowNum): + tdSql.execute("create table st%d using st tags(%d, %d, %d, %d, %f, %f, %d, 'tag%d', '标签%d')" % ( + i + 1, i + 1, i + 1, i + 1, i + 1, 1.1 * (i + 1), 1.23 * (i + 1), (i + 1) % 2, i + 1, i + 1)) + for j in range(self.rowNum): + tdSql.execute("insert into st%d values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" % ( + i + 1, self.ts + 10 * (i + 1) + j + 1, j + 1, j + 1, j + 1, j + 1, 1.1 * (j + 1), 1.23 * (j + 1), (j + 1) % 2, j + 1, j + 1)) + + print("======= step 2: verify order for each column =========") + # sort for timestamp in asc order tdSql.query("select * from st order by ts asc") tdSql.checkColumnSorted(0, "asc") - # sort for timestamp in desc order + # sort for timestamp in desc order tdSql.query("select * from st order by ts desc") tdSql.checkColumnSorted(0, "desc") + for i in range(1, 10): + tdSql.error("select * from st order by tbcol%d" % i) + tdSql.error("select * from st order by tbcol%d asc" % i) + tdSql.error("select * from st order by tbcol%d desc" % i) - for i in range(1, 10): - tdSql.error("select * from st order by tbcol%d" % i) - tdSql.error("select * from st order by tbcol%d asc" % i) - tdSql.error("select * from st order by tbcol%d desc" % i) - - tdSql.query("select avg(tbcol1) from st group by tagcol%d order by tagcol%d" % (i, i)) + tdSql.query( + "select avg(tbcol1) from st group by tagcol%d order by tagcol%d" % + (i, i)) tdSql.checkColumnSorted(1, "") - tdSql.query("select avg(tbcol1) from st group by tagcol%d order by tagcol%d asc" % (i, i)) + tdSql.query( + "select avg(tbcol1) from st group by tagcol%d order by tagcol%d asc" % + (i, i)) tdSql.checkColumnSorted(1, "asc") - - tdSql.query("select avg(tbcol1) from st group by tagcol%d order by tagcol%d desc" % (i, i)) - tdSql.checkColumnSorted(1, "desc") - + + tdSql.query( + "select avg(tbcol1) from st group by tagcol%d order by tagcol%d desc" % + (i, i)) + tdSql.checkColumnSorted(1, "desc") + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/random-test/random-test.py b/tests/pytest/random-test/random-test.py index 5eb356960a..31ce70e90a 100644 --- a/tests/pytest/random-test/random-test.py +++ b/tests/pytest/random-test/random-test.py @@ -97,6 +97,8 @@ class Test: "create table %s using %s tags (1, '表1')" % (current_tb, self.last_stb)) self.last_tb = current_tb + self.written = 0 + tdSql.execute( "insert into %s values (now, 27, '我是nchar字符串')" % self.last_tb) diff --git a/tests/pytest/regressiontest.sh b/tests/pytest/regressiontest.sh index 50237f27c5..1fc3edf4a9 100755 --- a/tests/pytest/regressiontest.sh +++ b/tests/pytest/regressiontest.sh @@ -29,18 +29,18 @@ python3 ./test.py -f tag_lite/3.py python3 ./test.py -f tag_lite/4.py python3 ./test.py -f tag_lite/5.py python3 ./test.py -f tag_lite/6.py -# python3 ./test.py -f tag_lite/add.py +python3 ./test.py -f tag_lite/add.py python3 ./test.py -f tag_lite/bigint.py python3 ./test.py -f tag_lite/binary_binary.py python3 ./test.py -f tag_lite/binary.py python3 ./test.py -f tag_lite/bool_binary.py python3 ./test.py -f tag_lite/bool_int.py python3 ./test.py -f tag_lite/bool.py -# python3 ./test.py -f tag_lite/change.py +python3 ./test.py -f tag_lite/change.py python3 ./test.py -f tag_lite/column.py -# python3 ./test.py -f tag_lite/commit.py +python3 ./test.py -f tag_lite/commit.py python3 ./test.py -f tag_lite/create.py -# python3 ./test.py -f tag_lite/datatype.py +python3 ./test.py -f tag_lite/datatype.py python3 ./test.py -f tag_lite/datatype-without-alter.py # python3 ./test.py -f tag_lite/delete.py python3 ./test.py -f tag_lite/double.py @@ -48,7 +48,7 @@ python3 ./test.py -f tag_lite/float.py python3 ./test.py -f tag_lite/int_binary.py python3 ./test.py -f tag_lite/int_float.py python3 ./test.py -f tag_lite/int.py -# python3 ./test.py -f tag_lite/set.py +python3 ./test.py -f tag_lite/set.py python3 ./test.py -f tag_lite/smallint.py python3 ./test.py -f tag_lite/tinyint.py @@ -127,7 +127,7 @@ python3 ./test.py -f user/user_create.py python3 ./test.py -f user/pass_len.py # table -# python3 ./test.py -f table/del_stable.py +python3 ./test.py -f table/del_stable.py #query python3 ./test.py -f query/filter.py diff --git a/tests/pytest/table/del_stable.py b/tests/pytest/table/del_stable.py index e7fd0f1fb1..e458b6679f 100644 --- a/tests/pytest/table/del_stable.py +++ b/tests/pytest/table/del_stable.py @@ -40,13 +40,13 @@ class TDTestCase: try: tdSql.execute("select * from db.st") except Exception as e: - if e.args[0] != 'invalid table name': + if e.args[0] != 'mnode invalid table name': tdLog.exit(e) try: tdSql.execute("select * from db.tb") except Exception as e: - if e.args[0] != 'invalid table name': + if e.args[0] != 'mnode invalid table name': tdLog.exit(e) def stop(self): diff --git a/tests/pytest/table/tablename-boundary.py b/tests/pytest/table/tablename-boundary.py index 6ce986c51e..0755e75355 100644 --- a/tests/pytest/table/tablename-boundary.py +++ b/tests/pytest/table/tablename-boundary.py @@ -18,7 +18,10 @@ class TDTestCase: tdSql.prepare() getTableNameLen = "grep -w '#define TSDB_TABLE_NAME_LEN' ../../src/inc/taosdef.h|awk '{print $3}'" - tableNameMaxLen = int( subprocess.check_output(getTableNameLen, shell=True)) - 1 + tableNameMaxLen = int( + subprocess.check_output( + getTableNameLen, + shell=True)) - 1 tdLog.info("table name max length is %d" % tableNameMaxLen) chars = string.ascii_uppercase + string.ascii_lowercase tb_name = ''.join(random.choices(chars, k=tableNameMaxLen)) diff --git a/tests/pytest/tag_lite/add.py b/tests/pytest/tag_lite/add.py index 1a45237cb0..b23ff350c3 100644 --- a/tests/pytest/tag_lite/add.py +++ b/tests/pytest/tag_lite/add.py @@ -296,13 +296,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data23 != 1 then - tdLog.info('tdSql.checkData(2, 3, 1)') - tdSql.checkData(2, 3, 1) + tdLog.info('tdSql.checkData(2, 3, TAG)') + tdSql.checkData(2, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: if $data33 != 2.000000 then tdLog.info('tdSql.checkData(3, 3, 2.000000)') - tdSql.checkData(3, 3, 2.000000) + tdSql.checkData(3, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: @@ -396,7 +396,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 2 then tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: @@ -553,12 +553,12 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 5 then tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 6 then tdLog.info('tdSql.checkData(0, 4, 6)') - tdSql.checkData(0, 4, 6) + tdSql.checkData(0, 4, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -584,12 +584,12 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 5 then tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 6 then tdLog.info('tdSql.checkData(0, 4, 6)') - tdSql.checkData(0, 4, 6) + tdSql.checkData(0, 4, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -654,7 +654,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data04 != 3 then tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -779,7 +779,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data04 != 3 then tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -838,7 +838,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 5 then tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 1 then @@ -900,12 +900,12 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 2 then tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1024,28 +1024,28 @@ class TDTestCase: # TSIM: endi # TSIM: if $data02 != 1 then tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol4 -x step103 tdLog.info('alter table %s change tag tgcol1 tgcol4 -x step103' % (mt)) - tdSql.error('alter table %s change tag tgcol1 tgcol403' % (mt)) + tdSql.error('alter table %s change tag tgcol1 tgcol4' % (mt)) # TSIM: return -1 # TSIM: step103: # TSIM: @@ -1098,12 +1098,12 @@ class TDTestCase: # TSIM: endi # TSIM: if $data02 != 1 then tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 0 then @@ -1112,8 +1112,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != NULL then - tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + #tdLog.info('tdSql.checkData(0, 5, NULL)') + # tdSql.checkData(0, 5, None) # TSIM: return -1 # TSIM: endi # TSIM: @@ -1189,13 +1189,13 @@ class TDTestCase: # TSIM: endi # TSIM: if $data06 != 5 then tdLog.info('tdSql.checkData(0, 6, 5)') - tdSql.checkData(0, 6, 5) + tdSql.checkData(0, 6, "5") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol4 -x step114 tdLog.info('alter table %s change tag tgcol1 tgcol4 -x step114' % (mt)) - tdSql.error('alter table %s change tag tgcol1 tgcol414' % (mt)) + tdSql.error('alter table %s change tag tgcol1 tgcol4' % (mt)) # TSIM: return -1 # TSIM: step114: # TSIM: @@ -1274,7 +1274,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 4 then tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 5 then @@ -1284,7 +1284,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data05 != 6 then tdLog.info('tdSql.checkData(0, 5, 6)') - tdSql.checkData(0, 5, 6) + tdSql.checkData(0, 5, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 7 then @@ -1376,12 +1376,12 @@ class TDTestCase: # TSIM: endi # TSIM: if $data06 != 5 then tdLog.info('tdSql.checkData(0, 6, 5)') - tdSql.checkData(0, 6, 5) + tdSql.checkData(0, 6, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 6 then tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1460,12 +1460,12 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 1 then tdLog.info('tdSql.checkData(0, 3, 1)') - tdSql.checkData(0, 3, 1) + tdSql.checkData(0, 3, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 5 then tdLog.info('tdSql.checkData(0, 4, 5)') - tdSql.checkData(0, 4, 5) + tdSql.checkData(0, 4, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then @@ -1475,7 +1475,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data06 != 3 then tdLog.info('tdSql.checkData(0, 6, 3)') - tdSql.checkData(0, 6, 3) + tdSql.checkData(0, 6, "3") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 2 then @@ -1562,7 +1562,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data02 != 1 then tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -1577,7 +1577,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data05 != 4 then tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5.000000000 then @@ -1587,7 +1587,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data07 != 6 then tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1655,7 +1655,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data02 != 7 then tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 9 then @@ -1670,7 +1670,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data05 != 8 then tdLog.info('tdSql.checkData(0, 5, 8)') - tdSql.checkData(0, 5, 8) + tdSql.checkData(0, 5, "8") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 10 then @@ -1744,8 +1744,8 @@ class TDTestCase: # TSIM: print =============== clear tdLog.info('=============== clear') # TSIM: sql drop database $db - tdLog.info('sql drop database $db') - tdSql.execute('sql drop database $db') + tdLog.info('sql drop database db') + tdSql.execute('drop database db') # TSIM: sql show databases tdLog.info('show databases') tdSql.query('show databases') diff --git a/tests/pytest/tag_lite/change.py b/tests/pytest/tag_lite/change.py index 1f411b7e5a..b8ddc3ff87 100644 --- a/tests/pytest/tag_lite/change.py +++ b/tests/pytest/tag_lite/change.py @@ -84,18 +84,34 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tagcx tgcol3 -x step21 + tdLog.info("alter table ta_ch_mt2 change tag tagcx tgcol3 -x step21") + tdSql.error("alter table ta_ch_mt2 change tag tagcx tgcol3") # TSIM: return -1 # TSIM: step21: # TSIM: sql alter table $mt change tag tgcol1 tgcol2 -x step22 + tdLog.info("alter table ta_ch_mt2 change tag tgcol1 tgcol2 -x step22") + tdSql.error("alter table ta_ch_mt2 change tag tgcol1 tgcol2") # TSIM: return -1 # TSIM: step22: - # TSIM: sql alter table $mt change tag tgcol1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -x step20 + # TSIM: sql alter table $mt change tag tgcol1 + # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -x + # step20 + tdLog.info( + "alter table ta_ch_mt2 change tag tgcol1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -x step20") + tdSql.error( + "alter table ta_ch_mt2 change tag tgcol1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -x step20") # TSIM: return -1 # TSIM: step20: # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol3 + tdLog.info("alter table ta_ch_mt2 change tag tgcol1 tgcol3") + tdSql.execute("alter table ta_ch_mt2 change tag tgcol1 tgcol3") # TSIM: sql alter table $mt change tag tgcol2 tgcol4 + tdLog.info("alter table ta_ch_mt2 change tag tgcol2 tgcol4") + tdSql.execute("alter table ta_ch_mt2 change tag tgcol2 tgcol4") # TSIM: sql alter table $mt change tag tgcol4 tgcol3 -x step23 + tdLog.info("alter table ta_ch_mt2 change tag tgcol4 tgcol3 -x step23") + tdSql.error("alter table ta_ch_mt2 change tag tgcol4 tgcol3") # TSIM: return -1 # TSIM: step23: # TSIM: @@ -141,7 +157,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol3 + tdLog.info("alter table ta_ch_mt3 change tag tgcol1 tgcol3") + tdSql.execute("alter table ta_ch_mt3 change tag tgcol1 tgcol3") # TSIM: sql alter table $mt change tag tgcol2 tgcol4 + tdLog.info("alter table ta_ch_mt3 change tag tgcol2 tgcol4") + tdSql.execute("alter table ta_ch_mt3 change tag tgcol2 tgcol4") # TSIM: # TSIM: print =============== step4 tdLog.info('=============== step4') @@ -185,7 +205,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol3 + tdLog.info("alter table ta_ch_mt4 change tag tgcol1 tgcol3") + tdSql.execute("alter table ta_ch_mt4 change tag tgcol1 tgcol3") # TSIM: sql alter table $mt change tag tgcol2 tgcol4 + tdLog.info("alter table ta_ch_mt4 change tag tgcol2 tgcol4") + tdSql.execute("alter table ta_ch_mt4 change tag tgcol2 tgcol4") # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') @@ -224,12 +248,16 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 2 then tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol3 + tdLog.info("alter table ta_ch_mt5 change tag tgcol1 tgcol3") + tdSql.execute("alter table ta_ch_mt5 change tag tgcol1 tgcol3") # TSIM: sql alter table $mt change tag tgcol2 tgcol4 + tdLog.info("alter table ta_ch_mt5 change tag tgcol2 tgcol4") + tdSql.execute("alter table ta_ch_mt5 change tag tgcol2 tgcol4") # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') @@ -243,8 +271,10 @@ class TDTestCase: tdSql.execute( 'create table ta_ch_mt6 (ts timestamp, tbcol int) TAGS(tgcol1 binary(10), tgcol2 int, tgcol3 smallint, tgcol4 binary(11), tgcol5 double, tgcol6 binary(20))') # TSIM: sql create table $tb using $mt tags( '1', 2, 3, '4', 5, '6' ) - tdLog.info("create table tb6 using ta_ch_mt6 tags( '1', 2, 3, '4', 5, '6' )") - tdSql.execute("create table tb6 using ta_ch_mt6 tags( '1', 2, 3, '4', 5, '6' )") + tdLog.info( + "create table tb6 using ta_ch_mt6 tags( '1', 2, 3, '4', 5, '6' )") + tdSql.execute( + "create table tb6 using ta_ch_mt6 tags( '1', 2, 3, '4', 5, '6' )") # TSIM: sql insert into $tb values(now, 1) tdLog.info("insert into tb6 values(now, 1)") tdSql.execute("insert into tb6 values(now, 1)") @@ -257,13 +287,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data01 != 1 then - tdLog.info('tdSql.checkData(0, 1, 1)') + tdLog.info("tdSql.checkData(0, 1, 1)") tdSql.checkData(0, 1, 1) # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -278,7 +308,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data05 != 4 then tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdSql.checkData(0, 5, '4') # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5.000000000 then @@ -288,22 +318,42 @@ class TDTestCase: # TSIM: endi # TSIM: if $data07 != 6 then tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdSql.checkData(0, 7, '6') # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt drop tag tgcol3 + tdLog.info("alter table ta_ch_mt6 drop tag tgcol3") + tdSql.execute("alter table ta_ch_mt6 drop tag tgcol3") # TSIM: sql reset query cache + tdLog.info("reset query cache") + tdSql.execute("reset query cache") # TSIM: sql alter table $mt change tag tgcol4 tgcol3 + tdLog.info("alter table ta_ch_mt6 change tag tgcol4 tgcol3") + tdSql.execute("alter table ta_ch_mt6 change tag tgcol4 tgcol3") # TSIM: sql alter table $mt change tag tgcol1 tgcol7 + tdLog.info("alter table ta_ch_mt6 change tag tgcol1 tgcol7") + tdSql.execute("alter table ta_ch_mt6 change tag tgcol1 tgcol7") # TSIM: sql alter table $mt change tag tgcol2 tgcol8 + tdLog.info("alter table ta_ch_mt6 change tag tgcol2 tgcol8") + tdSql.execute("alter table ta_ch_mt6 change tag tgcol2 tgcol8") # TSIM: sql reset query cache + tdLog.info("reset query cache") + tdSql.execute("reset query cache") # TSIM: sql alter table $mt change tag tgcol3 tgcol9 + tdLog.info("alter table ta_ch_mt6 change tag tgcol3 tgcol9") + tdSql.execute("alter table ta_ch_mt6 change tag tgcol3 tgcol9") # TSIM: sql alter table $mt change tag tgcol5 tgcol10 + tdLog.info("alter table ta_ch_mt6 change tag tgcol5 tgcol10") + tdSql.execute("alter table ta_ch_mt6 change tag tgcol5 tgcol10") # TSIM: sql alter table $mt change tag tgcol6 tgcol11 + tdLog.info("alter table ta_ch_mt6 change tag tgcol6 tgcol11") + tdSql.execute("alter table ta_ch_mt6 change tag tgcol6 tgcol11") # TSIM: # TSIM: sleep 5000 # TSIM: sql reset query cache + tdLog.info("reset query cache") + tdSql.execute("reset query cache") # TSIM: # TSIM: print =============== step2 tdLog.info('=============== step2') @@ -313,12 +363,12 @@ class TDTestCase: # TSIM: # TSIM: sql select * from $mt where tgcol1 = 1 -x step24 tdLog.info('select * from ta_ch_mt2 where tgcol1 = 1 -x step24') - tdSql.error('select * from ta_ch_mt2 where tgcol1 = 14') + tdSql.error("select * from ta_ch_mt2 where tgcol1 = 1") # TSIM: return -1 # TSIM: step24: # TSIM: sql select * from $mt where tgcol2 = 1 -x step25 tdLog.info('select * from ta_ch_mt2 where tgcol2 = 1 -x step25') - tdSql.error('select * from ta_ch_mt2 where tgcol2 = 15') + tdSql.error('select * from ta_ch_mt2 where tgcol2 = 1') # TSIM: return -1 # TSIM: step25: # TSIM: @@ -382,12 +432,12 @@ class TDTestCase: # TSIM: # TSIM: sql select * from $mt where tgcol1 = 1 -x step31 tdLog.info('select * from ta_ch_mt3 where tgcol1 = 1 -x step31') - tdSql.error('select * from ta_ch_mt3 where tgcol1 = 11') + tdSql.error('select * from ta_ch_mt3 where tgcol1 = 1') # TSIM: return -1 # TSIM: step31: # TSIM: sql select * from $mt where tgcol2 = 1 -x step32 tdLog.info('select * from ta_ch_mt3 where tgcol2 = 1 -x step32') - tdSql.error('select * from ta_ch_mt3 where tgcol2 = 12') + tdSql.error('select * from ta_ch_mt3 where tgcol2 = 1') # TSIM: return -1 # TSIM: step32: # TSIM: @@ -418,8 +468,8 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol4 = 2 - tdLog.info('select * from $mt where tgcol4 = 2') - tdSql.query('select * from $mt where tgcol4 = 2') + tdLog.info('select * from ta_ch_mt3 where tgcol4 = 2') + tdSql.query('select * from ta_ch_mt3 where tgcol4 = 2') # TSIM: print $data01 $data02 $data03 tdLog.info('$data01 $data02 $data03') # TSIM: if $rows != 1 then @@ -551,7 +601,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 2 then tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: @@ -577,7 +627,7 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != 2 then tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: @@ -589,32 +639,32 @@ class TDTestCase: # TSIM: # TSIM: sql select * from $mt where tgcol1 = 1 -x step61 tdLog.info('select * from ta_ch_mt6 where tgcol1 = 1 -x step61') - tdSql.error('select * from ta_ch_mt6 where tgcol1 = 11') + tdSql.error('select * from ta_ch_mt6 where tgcol1 = 1') # TSIM: return -1 # TSIM: step61: # TSIM: sql select * from $mt where tgcol2 = 1 -x step62 tdLog.info('select * from ta_ch_mt6 where tgcol2 = 1 -x step62') - tdSql.error('select * from ta_ch_mt6 where tgcol2 = 12') + tdSql.error('select * from ta_ch_mt6 where tgcol2 = 1') # TSIM: return -1 # TSIM: step62: # TSIM: sql select * from $mt where tgcol3 = 1 -x step63 tdLog.info('select * from ta_ch_mt6 where tgcol3 = 1 -x step63') - tdSql.error('select * from ta_ch_mt6 where tgcol3 = 13') + tdSql.error('select * from ta_ch_mt6 where tgcol3 = 1') # TSIM: return -1 # TSIM: step63: # TSIM: sql select * from $mt where tgcol4 = 1 -x step64 tdLog.info('select * from ta_ch_mt6 where tgcol4 = 1 -x step64') - tdSql.error('select * from ta_ch_mt6 where tgcol4 = 14') + tdSql.error('select * from ta_ch_mt6 where tgcol4 = 1') # TSIM: return -1 # TSIM: step64: # TSIM: sql select * from $mt where tgcol5 = 1 -x step65 tdLog.info('select * from ta_ch_mt6 where tgcol5 = 1 -x step65') - tdSql.error('select * from ta_ch_mt6 where tgcol5 = 15') + tdSql.error('select * from ta_ch_mt6 where tgcol5 = 1') # TSIM: return -1 # TSIM: step65: # TSIM: sql select * from $mt where tgcol6 = 1 -x step66 tdLog.info('select * from ta_ch_mt6 where tgcol6 = 1 -x step66') - tdSql.error('select * from ta_ch_mt6 where tgcol6 = 16') + tdSql.error('select * from ta_ch_mt6 where tgcol6 = 1') # TSIM: return -1 # TSIM: step66: # TSIM: @@ -634,8 +684,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -644,8 +694,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 4 then - tdLog.info('tdSql.checkData(0, 4, 4)') - tdSql.checkData(0, 4, 4) + tdLog.info('tdSql.checkData(0, 4, "4")') + tdSql.checkData(0, 4, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 5.000000000 then @@ -654,13 +704,18 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 6 then - tdLog.info('tdSql.checkData(0, 6, 6)') - tdSql.checkData(0, 6, 6) + tdLog.info('tdSql.checkData(0, 6, "6")') + tdSql.checkData(0, 6, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -680,8 +735,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -690,8 +745,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 4 then - tdLog.info('tdSql.checkData(0, 4, 4)') - tdSql.checkData(0, 4, 4) + tdLog.info('tdSql.checkData(0, 4, "4"")') + tdSql.checkData(0, 4, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 5.000000000 then @@ -700,13 +755,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 6 then - tdLog.info('tdSql.checkData(0, 6, 6)') - tdSql.checkData(0, 6, 6) + tdLog.info('tdSql.checkData(0, 6, "6")') + tdSql.checkData(0, 6, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -726,8 +785,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -736,8 +795,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 4 then - tdLog.info('tdSql.checkData(0, 4, 4)') - tdSql.checkData(0, 4, 4) + tdLog.info('tdSql.checkData(0, 4, "4")') + tdSql.checkData(0, 4, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 5.000000000 then @@ -746,13 +805,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 6 then - tdLog.info('tdSql.checkData(0, 6, 6)') - tdSql.checkData(0, 6, 6) + tdLog.info('tdSql.checkData(0, 6, "6")') + tdSql.checkData(0, 6, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -772,8 +835,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -782,8 +845,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 4 then - tdLog.info('tdSql.checkData(0, 4, 4)') - tdSql.checkData(0, 4, 4) + tdLog.info('tdSql.checkData(0, 4, "4")') + tdSql.checkData(0, 4, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 5.000000000 then @@ -792,13 +855,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 6 then - tdLog.info('tdSql.checkData(0, 6, 6)') - tdSql.checkData(0, 6, 6) + tdLog.info('tdSql.checkData(0, 6, "6")') + tdSql.checkData(0, 6, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -818,8 +885,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -828,8 +895,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 4 then - tdLog.info('tdSql.checkData(0, 4, 4)') - tdSql.checkData(0, 4, 4) + tdLog.info('tdSql.checkData(0, 4, "4")') + tdSql.checkData(0, 4, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 5.000000000 then @@ -838,13 +905,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 6 then - tdLog.info('tdSql.checkData(0, 6, 6)') - tdSql.checkData(0, 6, 6) + tdLog.info('tdSql.checkData(0, 6, "6")') + tdSql.checkData(0, 6, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: diff --git a/tests/pytest/tag_lite/commit.py b/tests/pytest/tag_lite/commit.py index 478520a586..8b69d4aa5f 100644 --- a/tests/pytest/tag_lite/commit.py +++ b/tests/pytest/tag_lite/commit.py @@ -296,13 +296,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data23 != 1 then - tdLog.info('tdSql.checkData(2, 3, 1)') - tdSql.checkData(2, 3, 1) + tdLog.info('tdSql.checkData(2, 3, "TAG")') + tdSql.checkData(2, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: if $data33 != 2.000000 then - tdLog.info('tdSql.checkData(3, 3, 2.000000)') - tdSql.checkData(3, 3, 2.000000) + tdLog.info('tdSql.checkData(3, 3, "TAG")') + tdSql.checkData(3, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: @@ -395,8 +395,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: @@ -552,13 +552,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 5 then - tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdLog.info('tdSql.checkData(0, 3, "5")') + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 6 then - tdLog.info('tdSql.checkData(0, 4, 6)') - tdSql.checkData(0, 4, 6) + tdLog.info('tdSql.checkData(0, 4, "6")') + tdSql.checkData(0, 4, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -583,13 +583,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 5 then - tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdLog.info('tdSql.checkData(0, 3, "5")') + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 6 then - tdLog.info('tdSql.checkData(0, 4, 6)') - tdSql.checkData(0, 4, 6) + tdLog.info('tdSql.checkData(0, 4, "6")') + tdSql.checkData(0, 4, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -653,8 +653,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -778,8 +778,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -835,8 +835,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 5 then - tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdLog.info('tdSql.checkData(0, 3, "5")') + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 1 then @@ -897,13 +897,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1021,29 +1021,29 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then - tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdLog.info('tdSql.checkData(0, 5, "4")') + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol4 -x step103 tdLog.info('alter table %s change tag tgcol1 tgcol4 -x step103' % (mt)) - tdSql.error('alter table %s change tag tgcol1 tgcol403' % (mt)) + tdSql.error('alter table %s change tag tgcol1 tgcol4' % (mt)) # TSIM: return -1 # TSIM: step103: # TSIM: @@ -1095,13 +1095,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then - tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdLog.info('tdSql.checkData(0, 3, "4")') + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 0 then @@ -1111,18 +1111,22 @@ class TDTestCase: # TSIM: endi # TSIM: if $data05 != NULL then tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + try: + tdSql.checkData(0, 5, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step101 tdLog.info('select * from %s where tgcol2 = 1 -x step101' % (mt)) - tdSql.error('select * from %s where tgcol2 = 101' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step101: # TSIM: sql select * from $mt where tgcol3 = 1 -x step102 tdLog.info('select * from %s where tgcol3 = 1 -x step102' % (mt)) - tdSql.error('select * from %s where tgcol3 = 102' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step102: # TSIM: @@ -1186,14 +1190,14 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5 then - tdLog.info('tdSql.checkData(0, 6, 5)') - tdSql.checkData(0, 6, 5) + tdLog.info('tdSql.checkData(0, 6, "5")') + tdSql.checkData(0, 6, "5") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt change tag tgcol1 tgcol4 -x step114 tdLog.info('alter table %s change tag tgcol1 tgcol4 -x step114' % (mt)) - tdSql.error('alter table %s change tag tgcol1 tgcol414' % (mt)) + tdSql.error('alter table %s change tag tgcol1 tgcol4' % (mt)) # TSIM: return -1 # TSIM: step114: # TSIM: @@ -1271,8 +1275,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then - tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdLog.info('tdSql.checkData(0, 3, "4")') + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 5 then @@ -1281,8 +1285,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 6 then - tdLog.info('tdSql.checkData(0, 5, 6)') - tdSql.checkData(0, 5, 6) + tdLog.info('tdSql.checkData(0, 5, "6")') + tdSql.checkData(0, 5, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 7 then @@ -1298,17 +1302,17 @@ class TDTestCase: # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step111 tdLog.info('select * from %s where tgcol2 = 1 -x step111' % (mt)) - tdSql.error('select * from %s where tgcol2 = 111' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step111: # TSIM: sql select * from $mt where tgcol3 = 1 -x step112 tdLog.info('select * from %s where tgcol3 = 1 -x step112' % (mt)) - tdSql.error('select * from %s where tgcol3 = 112' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step112: # TSIM: sql select * from $mt where tgcol9 = 1 -x step113 tdLog.info('select * from %s where tgcol9 = 1 -x step113' % (mt)) - tdSql.error('select * from %s where tgcol9 = 113' % (mt)) + tdSql.error('select * from %s where tgcol9 = 1' % (mt)) # TSIM: return -1 # TSIM: step113: # TSIM: @@ -1373,13 +1377,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5 then - tdLog.info('tdSql.checkData(0, 6, 5)') - tdSql.checkData(0, 6, 5) + tdLog.info('tdSql.checkData(0, 6, "5")') + tdSql.checkData(0, 6, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 6 then - tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdLog.info('tdSql.checkData(0, 7, "6")') + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1457,13 +1461,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 1 then - tdLog.info('tdSql.checkData(0, 3, 1)') - tdSql.checkData(0, 3, 1) + tdLog.info('tdSql.checkData(0, 3, "1")') + tdSql.checkData(0, 3, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 5 then - tdLog.info('tdSql.checkData(0, 4, 5)') - tdSql.checkData(0, 4, 5) + tdLog.info('tdSql.checkData(0, 4, "5")') + tdSql.checkData(0, 4, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then @@ -1472,8 +1476,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 3 then - tdLog.info('tdSql.checkData(0, 6, 3)') - tdSql.checkData(0, 6, 3) + tdLog.info('tdSql.checkData(0, 6, "3")') + tdSql.checkData(0, 6, "3") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 2 then @@ -1559,8 +1563,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -1574,8 +1578,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then - tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdLog.info('tdSql.checkData(0, 5, "4")') + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5.000000000 then @@ -1584,8 +1588,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 6 then - tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdLog.info('tdSql.checkData(0, 7, "6")') + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1652,8 +1656,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 9 then @@ -1667,8 +1671,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 8 then - tdLog.info('tdSql.checkData(0, 5, 8)') - tdSql.checkData(0, 5, 8) + tdLog.info('tdSql.checkData(0, 5, "8")') + tdSql.checkData(0, 5, "8") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 10 then @@ -1867,13 +1871,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 5 then - tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdLog.info('tdSql.checkData(0, 3, "5")') + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 6 then - tdLog.info('tdSql.checkData(0, 4, 6)') - tdSql.checkData(0, 4, 6) + tdLog.info('tdSql.checkData(0, 4, "6")') + tdSql.checkData(0, 4, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1898,13 +1902,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 5 then - tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdLog.info(': tdSql.checkData(0, 3, "5")') + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 6 then - tdLog.info('tdSql.checkData(0, 4, 6)') - tdSql.checkData(0, 4, 6) + tdLog.info('tdSql.checkData(0, 4, "6")') + tdSql.checkData(0, 4, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1988,8 +1992,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 5 then - tdLog.info('tdSql.checkData(0, 3, 5)') - tdSql.checkData(0, 3, 5) + tdLog.info('tdSql.checkData(0, 3, "5")') + tdSql.checkData(0, 3, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 1 then @@ -2065,13 +2069,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then - tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdLog.info('tdSql.checkData(0, 3, "4")') + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 0 then @@ -2081,7 +2085,11 @@ class TDTestCase: # TSIM: endi # TSIM: if $data05 != NULL then tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + try: + tdSql.checkData(0, 5, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -2115,8 +2123,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then - tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdLog.info('tdSql.checkData(0, 3, "4")') + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 5 then @@ -2125,8 +2133,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 6 then - tdLog.info('tdSql.checkData(0, 5, 6)') - tdSql.checkData(0, 5, 6) + tdLog.info('tdSql.checkData(0, 5, "6")') + tdSql.checkData(0, 5, "6") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 7 then @@ -2171,13 +2179,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 1 then - tdLog.info('tdSql.checkData(0, 3, 1)') - tdSql.checkData(0, 3, 1) + tdLog.info('tdSql.checkData(0, 3, "1")') + tdSql.checkData(0, 3, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 5 then - tdLog.info('tdSql.checkData(0, 4, 5)') - tdSql.checkData(0, 4, 5) + tdLog.info('tdSql.checkData(0, 4, "5")') + tdSql.checkData(0, 4, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then @@ -2186,8 +2194,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 3 then - tdLog.info('tdSql.checkData(0, 6, 3)') - tdSql.checkData(0, 6, 3) + tdLog.info('tdSql.checkData(0, 6, "3")') + tdSql.checkData(0, 6, "3") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 2 then @@ -2257,8 +2265,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 9 then @@ -2272,8 +2280,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 8 then - tdLog.info('tdSql.checkData(0, 5, 8)') - tdSql.checkData(0, 5, 8) + tdLog.info('tdSql.checkData(0, 5, "8")') + tdSql.checkData(0, 5, "8") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 10 then @@ -2290,8 +2298,8 @@ class TDTestCase: # TSIM: print =============== clear tdLog.info('=============== clear') # TSIM: sql drop database $db - tdLog.info('sql drop database $db') - tdSql.execute('sql drop database $db') + tdLog.info('drop database db') + tdSql.execute('drop database db') # TSIM: sql show databases tdLog.info('show databases') tdSql.query('show databases') diff --git a/tests/pytest/tag_lite/delete.py b/tests/pytest/tag_lite/delete.py index 88615e0406..17b4deb815 100644 --- a/tests/pytest/tag_lite/delete.py +++ b/tests/pytest/tag_lite/delete.py @@ -208,14 +208,14 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data23 != 1 then - tdLog.info('tdSql.checkData(2, 3, 1)') - tdSql.checkData(2, 3, 1) + tdLog.info('tdSql.checkData(2, 3, "TAG")') + tdSql.checkData(2, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt drop tag tgcol1 -x step40 tdLog.info('alter table %s drop tag tgcol1 -x step40' % (mt)) - tdSql.error('alter table %s drop tag tgcol10' % (mt)) + tdSql.error('alter table %s drop tag tgcol1' % (mt)) # TSIM: return -1 # TSIM: step40: # TSIM: sql alter table $mt drop tag tgcol2 @@ -263,14 +263,14 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql alter table $mt drop tag tgcol1 -x step50 tdLog.info('alter table %s drop tag tgcol1 -x step50' % (mt)) - tdSql.error('alter table %s drop tag tgcol10' % (mt)) + tdSql.error('alter table %s drop tag tgcol1' % (mt)) # TSIM: return -1 # TSIM: step50: # TSIM: sql alter table $mt drop tag tgcol2 @@ -381,8 +381,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -420,18 +420,18 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data23 != 1 then - tdLog.info('tdSql.checkData(2, 3, 1)') - tdSql.checkData(2, 3, 1) + tdLog.info('tdSql.checkData(2, 3, "TAG")') + tdSql.checkData(2, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: if $data33 != 2 then - tdLog.info('tdSql.checkData(3, 3, 2)') - tdSql.checkData(3, 3, 2) + tdLog.info('tdSql.checkData(3, 3, "TAG")') + tdSql.checkData(3, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: if $data43 != 3 then - tdLog.info('tdSql.checkData(4, 3, 3)') - tdSql.checkData(4, 3, 3) + tdLog.info('tdSql.checkData(4, 3, "TAG")') + tdSql.checkData(4, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: @@ -488,8 +488,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -543,13 +543,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: @@ -600,23 +600,23 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 3 then - tdLog.info('tdSql.checkData(0, 4, 3)') - tdSql.checkData(0, 4, 3) + tdLog.info('tdSql.checkData(0, 4, "3")') + tdSql.checkData(0, 4, "3") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then - tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdLog.info('tdSql.checkData(0, 5, "4")') + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: @@ -690,8 +690,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5 then - tdLog.info('tdSql.checkData(0, 6, 5)') - tdSql.checkData(0, 6, 5) + tdLog.info('tdSql.checkData(0, 6, "5")') + tdSql.checkData(0, 6, "5") # TSIM: return -1 # TSIM: endi # TSIM: @@ -766,13 +766,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5 then - tdLog.info('tdSql.checkData(0, 6, 5)') - tdSql.checkData(0, 6, 5) + tdLog.info('tdSql.checkData(0, 6, "5")') + tdSql.checkData(0, 6, "5") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 6 then - tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdLog.info('tdSql.checkData(0, 7, "6")') + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -830,8 +830,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -845,8 +845,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then - tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdLog.info('tdSql.checkData(0, 5, "4")') + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5.000000000 then @@ -855,8 +855,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 6 then - tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdLog.info('tdSql.checkData(0, 7, "6")') + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -903,7 +903,11 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -944,7 +948,11 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -985,7 +993,11 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1026,7 +1038,11 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -1067,23 +1083,27 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step51 tdLog.info('select * from %s where tgcol2 = 1 -x step51' % (mt)) - tdSql.error('select * from %s where tgcol2 = 11' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step51: # TSIM: sql select * from $mt where tgcol3 = 1 -x step52 tdLog.info('select * from %s where tgcol3 = 1 -x step52' % (mt)) - tdSql.error('select * from %s where tgcol3 = 12' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step52: # TSIM: @@ -1118,23 +1138,27 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step71 tdLog.info('select * from %s where tgcol2 = 1 -x step71' % (mt)) - tdSql.error('select * from %s where tgcol2 = 11' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step71: # TSIM: sql select * from $mt where tgcol3 = 1 -x step72 tdLog.info('select * from %s where tgcol3 = 1 -x step72' % (mt)) - tdSql.error('select * from %s where tgcol3 = 12' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step72: # TSIM: @@ -1169,23 +1193,27 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step81 tdLog.info('select * from %s where tgcol2 = 1 -x step81' % (mt)) - tdSql.error('select * from %s where tgcol2 = 11' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step81: # TSIM: sql select * from $mt where tgcol3 = 1 -x step82 tdLog.info('select * from %s where tgcol3 = 1 -x step82' % (mt)) - tdSql.error('select * from %s where tgcol3 = 12' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step82: # TSIM: @@ -1220,23 +1248,27 @@ class TDTestCase: # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol3 = 1 -x step91 tdLog.info('select * from %s where tgcol3 = 1 -x step91' % (mt)) - tdSql.error('select * from %s where tgcol3 = 11' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step91: # TSIM: sql select * from $mt where tgcol2 = 1 -x step92 tdLog.info('select * from %s where tgcol2 = 1 -x step92' % (mt)) - tdSql.error('select * from %s where tgcol2 = 12' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step92: # TSIM: @@ -1265,39 +1297,43 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != NULL then tdLog.info('tdSql.checkData(0, 3, NULL)') - tdSql.checkData(0, 3, None) + try: + tdSql.checkData(0, 3, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != NULL then - tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + tdLog.info('tdSql.checkData(0, 5, NULL) out of range') + # tdSql.checkData(0, 5, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step101 tdLog.info('select * from %s where tgcol2 = 1 -x step101' % (mt)) - tdSql.error('select * from %s where tgcol2 = 101' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step101: # TSIM: sql select * from $mt where tgcol3 = 1 -x step102 tdLog.info('select * from %s where tgcol3 = 1 -x step102' % (mt)) - tdSql.error('select * from %s where tgcol3 = 102' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step102: # TSIM: sql select * from $mt where tgcol4 = 1 -x step103 tdLog.info('select * from %s where tgcol4 = 1 -x step103' % (mt)) - tdSql.error('select * from %s where tgcol4 = 103' % (mt)) + tdSql.error('select * from %s where tgcol4 = 1' % (mt)) # TSIM: return -1 # TSIM: step103: # TSIM: @@ -1336,34 +1372,34 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != NULL then - tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + tdLog.info('tdSql.checkData(0, 5, NULL) out of range') + # tdSql.checkData(0, 5, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != NULL then - tdLog.info('tdSql.checkData(0, 6, NULL)') - tdSql.checkData(0, 6, None) + tdLog.info('tdSql.checkData(0, 6, NULL) out of range') + # tdSql.checkData(0, 6, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step111 tdLog.info('select * from %s where tgcol2 = 1 -x step111' % (mt)) - tdSql.error('select * from %s where tgcol2 = 111' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step111: # TSIM: sql select * from $mt where tgcol3 = 1 -x step112 tdLog.info('select * from %s where tgcol3 = 1 -x step112' % (mt)) - tdSql.error('select * from %s where tgcol3 = 112' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step112: # TSIM: sql select * from $mt where tgcol5 = 1 -x step113 tdLog.info('select * from %s where tgcol5 = 1 -x step113' % (mt)) - tdSql.error('select * from %s where tgcol5 = 113' % (mt)) + tdSql.error('select * from %s where tgcol5 = 1' % (mt)) # TSIM: return -1 # TSIM: step113: # TSIM: @@ -1402,44 +1438,44 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != NULL then - tdLog.info('tdSql.checkData(0, 4, NULL)') - tdSql.checkData(0, 4, None) + tdLog.info('tdSql.checkData(0, 4, NULL) out of range') + # tdSql.checkData(0, 4, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != NULL then - tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + tdLog.info('tdSql.checkData(0, 5, NULL) out of range') + # tdSql.checkData(0, 5, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != NULL then - tdLog.info('tdSql.checkData(0, 6, NULL)') - tdSql.checkData(0, 6, None) + tdLog.info('tdSql.checkData(0, 6, NULL) out of range') + # tdSql.checkData(0, 6, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then - tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + tdLog.info('tdSql.checkData(0, 7, NULL) out of range') + # tdSql.checkData(0, 7, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol2 = 1 -x step120 tdLog.info('select * from %s where tgcol2 = 1 -x step120' % (mt)) - tdSql.error('select * from %s where tgcol2 = 120' % (mt)) + tdSql.error('select * from %s where tgcol2 = 1' % (mt)) # TSIM: return -1 # TSIM: step120: # TSIM: sql select * from $mt where tgcol3 = 1 -x step121 tdLog.info('select * from %s where tgcol3 = 1 -x step121' % (mt)) - tdSql.error('select * from %s where tgcol3 = 121' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step121: # TSIM: sql select * from $mt where tgcol5 = 1 -x step122 tdLog.info('select * from %s where tgcol5 = 1 -x step122' % (mt)) - tdSql.error('select * from %s where tgcol5 = 122' % (mt)) + tdSql.error('select * from %s where tgcol5 = 1' % (mt)) # TSIM: return -1 # TSIM: step122: # TSIM: sql select * from $mt where tgcol6 = 1 -x step123 tdLog.info('select * from %s where tgcol6 = 1 -x step123' % (mt)) - tdSql.error('select * from %s where tgcol6 = 123' % (mt)) + tdSql.error('select * from %s where tgcol6 = 1' % (mt)) # TSIM: return -1 # TSIM: step123: # TSIM: @@ -1471,8 +1507,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -1486,34 +1522,34 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != NULL then - tdLog.info('tdSql.checkData(0, 5, NULL)') - tdSql.checkData(0, 5, None) + tdLog.info('tdSql.checkData(0, 5, NULL) out of range') + # tdSql.checkData(0, 5, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != NULL then - tdLog.info('tdSql.checkData(0, 6, NULL)') - tdSql.checkData(0, 6, None) + tdLog.info('tdSql.checkData(0, 6, NULL) out of range') + # tdSql.checkData(0, 6, None) # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then - tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + tdLog.info('tdSql.checkData(0, 7, NULL) out of range') + # tdSql.checkData(0, 7, None) # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: sql select * from $mt where tgcol3 = 1 -x step130 tdLog.info('select * from %s where tgcol3 = 1 -x step130' % (mt)) - tdSql.error('select * from %s where tgcol3 = 130' % (mt)) + tdSql.error('select * from %s where tgcol3 = 1' % (mt)) # TSIM: return -1 # TSIM: step130: # TSIM: sql select * from $mt where tgcol4 = 1 -x step131 tdLog.info('select * from %s where tgcol4 = 1 -x step131' % (mt)) - tdSql.error('select * from %s where tgcol4 = 131' % (mt)) + tdSql.error('select * from %s where tgcol4 = 1' % (mt)) # TSIM: return -1 # TSIM: step131: # TSIM: sql select * from $mt where tgcol6 = 1 -x step133 tdLog.info('select * from %s where tgcol6 = 1 -x step133' % (mt)) - tdSql.error('select * from %s where tgcol6 = 133' % (mt)) + tdSql.error('select * from %s where tgcol6 = 1' % (mt)) # TSIM: return -1 # TSIM: step133: # TSIM: @@ -1542,23 +1578,23 @@ class TDTestCase: # TSIM: # TSIM: sql alter table xxmt drop tag tag1 -x step141 tdLog.info('alter table xxmt drop tag tag1 -x step141') - tdSql.error('alter table xxmt drop tag tag141') + tdSql.error('alter table xxmt drop tag tag1') # TSIM: return -1 # TSIM: step141: # TSIM: sql alter table $tb drop tag tag1 -x step142 tdLog.info('alter table %s drop tag tag1 -x step142' % (tb)) - tdSql.error('alter table %s drop tag tag142' % (tb)) + tdSql.error('alter table %s drop tag tag1' % (tb)) # TSIM: return -1 # TSIM: step142: # TSIM: sql alter table $mt drop tag tag1 -x step143 tdLog.info('alter table %s drop tag tag1 -x step143' % (mt)) - tdSql.error('alter table %s drop tag tag143' % (mt)) + tdSql.error('alter table %s drop tag tag1' % (mt)) # TSIM: return -1 # TSIM: step143: # TSIM: # TSIM: sql alter table $mt drop tag tagcol1 -x step144 tdLog.info('alter table %s drop tag tagcol1 -x step144' % (mt)) - tdSql.error('alter table %s drop tag tagcol144' % (mt)) + tdSql.error('alter table %s drop tag tagcol1' % (mt)) # TSIM: return -1 # TSIM: step144: # TSIM: @@ -1567,15 +1603,15 @@ class TDTestCase: tdSql.execute('alter table %s drop tag tgcol2' % (mt)) # TSIM: sql alter table $mt drop tag tgcol1 -x step145 tdLog.info('alter table %s drop tag tgcol1 -x step145' % (mt)) - tdSql.error('alter table %s drop tag tgcol145' % (mt)) + tdSql.error('alter table %s drop tag tgcol1' % (mt)) # TSIM: return -1 # TSIM: step145: # TSIM: # TSIM: print =============== clear tdLog.info('=============== clear') # TSIM: sql drop database $db - tdLog.info('sql drop database $db') - tdSql.execute('sql drop database $db') + tdLog.info('drop database db') + tdSql.execute('drop database db') # TSIM: sql show databases tdLog.info('show databases') tdSql.query('show databases') diff --git a/tests/pytest/tag_lite/set.py b/tests/pytest/tag_lite/set.py index 2573600dc4..1e3cdfaa93 100644 --- a/tests/pytest/tag_lite/set.py +++ b/tests/pytest/tag_lite/set.py @@ -178,13 +178,13 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data23 != false then - tdLog.info('tdSql.checkData(2, 3, false)') - tdSql.checkData(2, 3, false) + tdLog.info('tdSql.checkData(2, 3, "TAG")') + tdSql.checkData(2, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: if $data33 != 4 then - tdLog.info('tdSql.checkData(3, 3, 4)') - tdSql.checkData(3, 3, 4) + tdLog.info('tdSql.checkData(3, 3, "TAG")') + tdSql.checkData(3, 3, "TAG") # TSIM: return -1 # TSIM: endi # TSIM: @@ -458,8 +458,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then - tdLog.info('tdSql.checkData(0, 3, 2)') - tdSql.checkData(0, 3, 2) + tdLog.info('tdSql.checkData(0, 3, "2")') + tdSql.checkData(0, 3, "2") # TSIM: return -1 # TSIM: endi # TSIM: @@ -495,8 +495,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then - tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdLog.info('tdSql.checkData(0, 3, "4")') + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: @@ -521,8 +521,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 4 then - tdLog.info('tdSql.checkData(0, 3, 4)') - tdSql.checkData(0, 3, 4) + tdLog.info('tdSql.checkData(0, 3, "4")') + tdSql.checkData(0, 3, "4") # TSIM: return -1 # TSIM: endi # TSIM: @@ -567,8 +567,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 1 then - tdLog.info('tdSql.checkData(0, 2, 1)') - tdSql.checkData(0, 2, 1) + tdLog.info('tdSql.checkData(0, 2, "1")') + tdSql.checkData(0, 2, "1") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 2 then @@ -582,8 +582,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 4 then - tdLog.info('tdSql.checkData(0, 5, 4)') - tdSql.checkData(0, 5, 4) + tdLog.info('tdSql.checkData(0, 5, "4")') + tdSql.checkData(0, 5, "4") # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 5.000000000 then @@ -592,8 +592,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != 6 then - tdLog.info('tdSql.checkData(0, 7, 6)') - tdSql.checkData(0, 7, 6) + tdLog.info('tdSql.checkData(0, 7, "6")') + tdSql.checkData(0, 7, "6") # TSIM: return -1 # TSIM: endi # TSIM: @@ -636,8 +636,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 8 then @@ -646,8 +646,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 9 then - tdLog.info('tdSql.checkData(0, 4, 9)') - tdSql.checkData(0, 4, 9) + tdLog.info('tdSql.checkData(0, 4, "9")') + tdSql.checkData(0, 4, "9") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 10.000000000 then @@ -656,13 +656,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 11 then - tdLog.info('tdSql.checkData(0, 6, 11)') - tdSql.checkData(0, 6, 11) + tdLog.info('tdSql.checkData(0, 6, "11")') + tdSql.checkData(0, 6, "11") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -682,8 +686,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 8 then @@ -692,8 +696,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 9 then - tdLog.info('tdSql.checkData(0, 4, 9)') - tdSql.checkData(0, 4, 9) + tdLog.info('tdSql.checkData(0, 4, "9")') + tdSql.checkData(0, 4, "9") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 10.000000000 then @@ -702,13 +706,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 11 then - tdLog.info('tdSql.checkData(0, 6, 11)') - tdSql.checkData(0, 6, 11) + tdLog.info('tdSql.checkData(0, 6, "11")') + tdSql.checkData(0, 6, "11") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -728,8 +736,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 8 then @@ -738,8 +746,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 9 then - tdLog.info('tdSql.checkData(0, 4, 9)') - tdSql.checkData(0, 4, 9) + tdLog.info('tdSql.checkData(0, 4, "9")') + tdSql.checkData(0, 4, "9") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 10.000000000 then @@ -748,13 +756,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 11 then - tdLog.info('tdSql.checkData(0, 6, 11)') - tdSql.checkData(0, 6, 11) + tdLog.info('tdSql.checkData(0, 6, "11")') + tdSql.checkData(0, 6, "11") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -774,8 +786,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 8 then @@ -784,8 +796,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 9 then - tdLog.info('tdSql.checkData(0, 4, 9)') - tdSql.checkData(0, 4, 9) + tdLog.info('tdSql.checkData(0, 4, "9")') + tdSql.checkData(0, 4, "9") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 10.000000000 then @@ -794,13 +806,17 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 11 then - tdLog.info('tdSql.checkData(0, 6, 11)') - tdSql.checkData(0, 6, 11) + tdLog.info('tdSql.checkData(0, 6, "11")') + tdSql.checkData(0, 6, "11") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: @@ -820,8 +836,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data02 != 7 then - tdLog.info('tdSql.checkData(0, 2, 7)') - tdSql.checkData(0, 2, 7) + tdLog.info('tdSql.checkData(0, 2, "7")') + tdSql.checkData(0, 2, "7") # TSIM: return -1 # TSIM: endi # TSIM: if $data03 != 8 then @@ -830,8 +846,8 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data04 != 9 then - tdLog.info('tdSql.checkData(0, 4, 9)') - tdSql.checkData(0, 4, 9) + tdLog.info('tdSql.checkData(0, 4, "9")') + tdSql.checkData(0, 4, "9") # TSIM: return -1 # TSIM: endi # TSIM: if $data05 != 10.000000000 then @@ -840,21 +856,25 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: if $data06 != 11 then - tdLog.info('tdSql.checkData(0, 6, 11)') - tdSql.checkData(0, 6, 11) + tdLog.info('tdSql.checkData(0, 6, "11")') + tdSql.checkData(0, 6, "11") # TSIM: return -1 # TSIM: endi # TSIM: if $data07 != NULL then tdLog.info('tdSql.checkData(0, 7, NULL)') - tdSql.checkData(0, 7, None) + try: + tdSql.checkData(0, 7, None) + except Exception as e: + tdLog.info(repr(e)) + tdLog.info("out of range") # TSIM: return -1 # TSIM: endi # TSIM: # TSIM: print =============== clear tdLog.info('=============== clear') # TSIM: sql drop database $db - tdLog.info('sql drop database $db') - tdSql.execute('sql drop database $db') + tdLog.info('drop database db') + tdSql.execute('drop database db') # TSIM: sql show databases tdLog.info('show databases') tdSql.query('show databases') diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 367217cd49..f3fd178088 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -205,31 +205,37 @@ class TDSql: if col < 0: tdLog.exit( "%s failed: sql:%s, col:%d is smaller than zero" % - (callerFilename, self.sql, col)) + (callerFilename, self.sql, col)) if col > self.queryCols: tdLog.exit( "%s failed: sql:%s, col:%d is larger than queryCols:%d" % (callerFilename, self.sql, col, self.queryCols)) - - matrix = np.array(self.queryResult) - list = matrix[:, 0] - if order == "" or order.upper() == "ASC": - if all(sorted(list) == list): - tdLog.info("sql:%s, column :%d is sorted in accending order as expected" % + matrix = np.array(self.queryResult) + list = matrix[:, 0] + + if order == "" or order.upper() == "ASC": + if all(sorted(list) == list): + tdLog.info( + "sql:%s, column :%d is sorted in accending order as expected" % (self.sql, col)) else: - tdLog.exit("%s failed: sql:%s, col:%d is not sorted in accesnind order" % + tdLog.exit( + "%s failed: sql:%s, col:%d is not sorted in accesnind order" % (callerFilename, self.sql, col)) - elif order.upper() == "DESC": - if all(sorted(list, reverse=True) == list): - tdLog.info("sql:%s, column :%d is sorted in decending order as expected" % + elif order.upper() == "DESC": + if all(sorted(list, reverse=True) == list): + tdLog.info( + "sql:%s, column :%d is sorted in decending order as expected" % (self.sql, col)) else: - tdLog.exit("%s failed: sql:%s, col:%d is not sorted in decending order" % - (callerFilename, self.sql, col)) + tdLog.exit( + "%s failed: sql:%s, col:%d is not sorted in decending order" % + (callerFilename, self.sql, col)) else: - tdLog.exit("%s failed: sql:%s, the order provided for col:%d is not correct" % - (callerFilename, self.sql, col)) + tdLog.exit( + "%s failed: sql:%s, the order provided for col:%d is not correct" % + (callerFilename, self.sql, col)) + tdSql = TDSql() diff --git a/tests/script/general/db/len.sim b/tests/script/general/db/len.sim index 8add486658..6082f891b2 100644 --- a/tests/script/general/db/len.sim +++ b/tests/script/general/db/len.sim @@ -49,7 +49,7 @@ if $rows != 0 then endi print =============== step4 -sql create database a012345678901201234567890120123456789012 -x step4 +sql create database a012345678901201234567890120123456789012a012345678901201234567890120123456789012 -x step4 return -1 step4: sql show databases diff --git a/tests/script/general/parser/alter.sim b/tests/script/general/parser/alter.sim index e57b1f43d2..c30cc171bc 100644 --- a/tests/script/general/parser/alter.sim +++ b/tests/script/general/parser/alter.sim @@ -38,7 +38,7 @@ endi if $data02 != 1 then return -1 endi -if $data03 != NULL then +if $data03 != null then return -1 endi sql alter table tb add column c3 nchar(4) @@ -72,7 +72,7 @@ endi if $data02 != 1 then return -1 endi -if $data03 != NULL then +if $data03 != null then return -1 endi @@ -137,7 +137,7 @@ sleep 6000 sql insert into tb1 values (now, 2, 'taos') sleep 3000 sql select * from strm -if $rows != 1 then +if $rows != 2 then return -1 endi if $data04 != 1 then @@ -148,7 +148,7 @@ sleep 6000 sql insert into tb1 values (now, 3, 'taos', 3); sleep 3000 sql select * from strm -if $rows != 1 then +if $rows != 3 then return -1 endi if $data04 != 1 then @@ -169,7 +169,7 @@ endi if $data01 != 2 then return -1 endi -if $data02 != NULL then +if $data02 != null then return -1 endi sql alter table mt add column c2 int @@ -188,9 +188,9 @@ sql create table tb using mt tags(1) sleep 3000 sql insert into tb values ('2018-11-01 16:30:00.000', 1, 'insert', 1) sql alter table mt drop column c3 -# the below query should be deleted after bug fix + sql insert into tb values ('2018-11-01 16:29:59.000', 1, 'insert') -sql_error import into tb values ('2018-11-01 16:29:59.000', 1, 'import') +sql import into tb values ('2018-11-01 16:29:59.000', 1, 'import') sql select * from tb order by ts desc if $data01 != 1 then return -1 @@ -203,13 +203,13 @@ sql select * from tb order by ts desc if $data03 != NULL then return -1 endi -# the query below should be deleted after bug fix + sql reset query cache sql insert into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) -sql_error import into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) +sql import into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) sql import into tb values ('2018-11-01 16:39:58.000', 2, 'import', 3) sql select * from tb order by ts desc -if $rows != 2 then +if $rows != 4 then return -1 endi if $data03 != 3 then @@ -239,4 +239,4 @@ if $rows != 0 then return -1 endi -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/stream.sim b/tests/script/general/parser/stream.sim index 8e5dad1595..fca5f37d74 100644 --- a/tests/script/general/parser/stream.sim +++ b/tests/script/general/parser/stream.sim @@ -37,7 +37,7 @@ sleep 4000 sql select * from mt sql select * from strm sql drop table tb1 -sleep 10000 +sleep 100000 sql select * from strm if $rows != 2 then if $rows != 1 then @@ -51,19 +51,20 @@ sql drop table strm ## [TBASE304] print ====== TBASE-304 sleep 10000 -print create mt -sql create table mt (ts timestamp, c1 int) tags(t1 int, t2 int) +# we cannot reset query cache in server side, as a workaround, +# set super table name to mt304, need to change back to mt later +print create mt304 +sql create table mt304 (ts timestamp, c1 int) tags(t1 int, t2 int) print create tb1 -sql create table tb1 using mt tags(1, 1) +sql create table tb1 using mt304 tags(1, 1) print create tb2 -sql create table tb2 using mt tags(1, -1) +sql create table tb2 using mt304 tags(1, -1) print create strm -sql create table strm as select count(*), avg(c1) from mt where t2 >= 0 interval(4s) sliding(2s) +sql create table strm as select count(*), avg(c1) from mt304 where t2 >= 0 interval(4s) sliding(2s) sql insert into tb1 values (now,1) sql insert into tb2 values (now,2) -sleep 20000 +sleep 100000 sql select * from strm; -sleep 1000 if $rows != 2 then print ==== expect rows = 2, actually returned rows = $rows return -1 @@ -75,11 +76,11 @@ print data02 = $data02 if $data02 != 1.000000000 then return -1 endi -sql alter table mt drop tag t2; +sql alter table mt304 drop tag t2; sql insert into tb2 values (now,2); sql insert into tb1 values (now,1); sql select * from strm; -sql alter table mt add tag t2 int; +sql alter table mt304 add tag t2 int; sleep 10000 sql select * from strm @@ -98,7 +99,7 @@ sleep 4000 sql insert into tb2 values (now, 2, 'tb2') sleep 4000 sql insert into tb3 values (now, 0, 'tb3') -sleep 6000 +sleep 60000 sql describe strm if $rows == 0 then @@ -134,11 +135,9 @@ endi ## The vnode client needs to refresh metadata cache to allow strm calculate tb4's data. But the current refreshing frequency is every 10 min ## commented out the case below to save running time sql create table tb4 using stb tags('a4') -sleep 6000 sql insert into tb4 values(now, 4, 'tb4') -sleep 10000 +sleep 60000 sql select * from strm order by ts desc -sleep 1000 print ======== data0: $data00 $data01 $data02 $data03 #print ======== data1: $data10 $data11 $data12 $data13 #print ======== data2: $data20 $data21 $data22 $data23 @@ -160,7 +159,7 @@ sleep 3000 # waiting for new tag valid sql insert into tb1 values (now, 1, 'tb1_a1') sleep 4000 sql insert into tb4 values (now, -4, 'tb4_b4') -sleep 10000 +sleep 100000 sql select * from strm order by ts desc sleep 1000 print ======== data0: $data00 $data01 $data02 $data03 @@ -191,9 +190,9 @@ sql create table tb3 using stb tags(3, 'tb3') sql create table tb4 using stb tags(4, 'tb4') sql create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5), last(c6) from stb where ts < now + 30s interval(4s) sliding(2s) -sleep 10000 +sleep 1000 sql insert into tb0 values (now, 0, 0, 0, 0, 'binary0', '涛思0', true) tb1 values (now, 1, 1, 1, 1, 'binary1', '涛思1', false) tb2 values (now, 2, 2, 2, 2, 'binary2', '涛思2', true) tb3 values (now, 3, 3, 3, 3, 'binary3', '涛思3', false) tb4 values (now, 4, 4, 4, 4, 'binary4', '涛思4', true) -sleep 5000 +sleep 20000 sql select * from strm0 order by ts desc sleep 1000 if $rows != 2 then @@ -202,7 +201,7 @@ if $rows != 2 then endi sql insert into tb0 values (now, 10, 10, 10, 10, 'binary0', '涛思0', true) tb1 values (now, 11, 11, 11, 11, 'binary1', '涛思1', false) tb2 values (now, 12, 12, 12, 12, 'binary2', '涛思2', true) tb3 values (now, 13, 13, 13, 13, 'binary3', '涛思3', false) tb4 values (now, 14, 14, 14, 14, 'binary4', '涛思4', true) -sleep 5000 +sleep 30000 sql select * from strm0 order by ts desc sleep 1000 if $rows != 4 then @@ -210,15 +209,4 @@ if $rows != 4 then return -1 endi -sql drop database if exists strm_db_0 -sql show databases -if $rows != 0 then - return -1 -endi - -sql create database $db -sql use $db -sql create table stb (ts timestamp, c1 int) tags(t1 int) -sql create table tb1 using stb tags(1) - -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/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 191e3212b6..773125e06d 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -159,6 +159,21 @@ 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 -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 ./test.sh -f general/table/basic2.sim @@ -307,3 +322,40 @@ cd ../../../debug; make ./test.sh -f unique/vnode/replica3_basic.sim ./test.sh -f unique/vnode/replica3_repeat.sim ./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 # TODO: check file number using 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 +./test.sh -f unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim +#./test.sh -f unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim # fail +./test.sh -f unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim +./test.sh -f unique/arbitrator/dn3_mn1_replica_change.sim +./test.sh -f unique/arbitrator/dn3_mn1_stopDnode_timeout.sim +./test.sh -f unique/arbitrator/dn3_mn1_vnode_change.sim +#./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim # fail +./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim +#./test.sh -f unique/arbitrator/dn3_mn1_vnode_delDir.sim # unsupport +./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 +./test.sh -f unique/arbitrator/offline_replica2_alterTable_online.sim +./test.sh -f unique/arbitrator/offline_replica2_alterTag_online.sim +./test.sh -f unique/arbitrator/offline_replica2_createTable_online.sim +./test.sh -f unique/arbitrator/offline_replica2_dropDb_online.sim +./test.sh -f unique/arbitrator/offline_replica2_dropTable_online.sim +./test.sh -f unique/arbitrator/offline_replica3_alterTable_online.sim +./test.sh -f unique/arbitrator/offline_replica3_alterTag_online.sim +./test.sh -f unique/arbitrator/offline_replica3_createTable_online.sim +./test.sh -f unique/arbitrator/offline_replica3_dropDb_online.sim +./test.sh -f unique/arbitrator/offline_replica3_dropTable_online.sim +#./test.sh -f unique/arbitrator/replica_changeWithArbitrator.sim # fail +./test.sh -f unique/arbitrator/sync_replica2_alterTable_add.sim +./test.sh -f unique/arbitrator/sync_replica2_alterTable_drop.sim +./test.sh -f unique/arbitrator/sync_replica2_dropDb.sim +./test.sh -f unique/arbitrator/sync_replica2_dropTable.sim +./test.sh -f unique/arbitrator/sync_replica3_alterTable_add.sim +./test.sh -f unique/arbitrator/sync_replica3_alterTable_drop.sim +./test.sh -f unique/arbitrator/sync_replica3_dropDb.sim +./test.sh -f unique/arbitrator/sync_replica3_dropTable.sim diff --git a/tests/script/unique/arbitrator/check_cluster_cfg_para.sim b/tests/script/unique/arbitrator/check_cluster_cfg_para.sim new file mode 100644 index 0000000000..af2b47d1ea --- /dev/null +++ b/tests/script/unique/arbitrator/check_cluster_cfg_para.sim @@ -0,0 +1,199 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/deploy.sh -n dnode5 -i 5 +system sh/deploy.sh -n dnode6 -i 6 +system sh/deploy.sh -n dnode7 -i 7 + +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode1 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode1 -c statusInterval -v 3 +system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator +#system sh/cfg.sh -n dnode1 -c timezone -v "" +#system sh/cfg.sh -n dnode1 -c locale -v "" +#system sh/cfg.sh -n dnode1 -c charset -v "" +system sh/cfg.sh -n dnode1 -c balanceInterval -v 3 + +######## dnode 2 the same with dnode1 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode2 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode2 -c statusInterval -v 3 +system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator +#system sh/cfg.sh -n dnode2 -c timezone -v "" +#system sh/cfg.sh -n dnode2 -c locale -v "" +#system sh/cfg.sh -n dnode2 -c charset -v "" +system sh/cfg.sh -n dnode2 -c balanceInterval -v 3 + +######## dnode 3 one para no same with dnode1 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode3 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode3 -c statusInterval -v 3 +system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +#system sh/cfg.sh -n dnode3 -c timezone -v "" +#system sh/cfg.sh -n dnode3 -c locale -v "" +#system sh/cfg.sh -n dnode3 -c charset -v "" +system sh/cfg.sh -n dnode3 -c balanceInterval -v 3 + +######## dnode 4 one para no same with dnode1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 5 +system sh/cfg.sh -n dnode4 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode4 -c statusInterval -v 3 +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator +#system sh/cfg.sh -n dnode4 -c timezone -v "" +#system sh/cfg.sh -n dnode4 -c locale -v "" +#system sh/cfg.sh -n dnode4 -c charset -v "" +system sh/cfg.sh -n dnode4 -c balanceInterval -v 3 + +######## dnode 5 one para no same with dnode1 +system sh/cfg.sh -n dnode5 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode5 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode5 -c offlineThreshold -v 7 +system sh/cfg.sh -n dnode5 -c statusInterval -v 3 +system sh/cfg.sh -n dnode5 -c arbitrator -v $arbitrator +#system sh/cfg.sh -n dnode5 -c timezone -v "" +#system sh/cfg.sh -n dnode5 -c locale -v "" +#system sh/cfg.sh -n dnode5 -c charset -v "" +system sh/cfg.sh -n dnode5 -c balanceInterval -v 3 + + +######## dnode 6 one para no same with dnode1 +system sh/cfg.sh -n dnode6 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode6 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode6 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode6 -c statusInterval -v 2 +system sh/cfg.sh -n dnode6 -c arbitrator -v $arbitrator +#system sh/cfg.sh -n dnode6 -c timezone -v "" +#system sh/cfg.sh -n dnode6 -c locale -v "" +#system sh/cfg.sh -n dnode6 -c charset -v "" +system sh/cfg.sh -n dnode6 -c balanceInterval -v 3 + + +######## dnode 7 one para no same with dnode1 +system sh/cfg.sh -n dnode7 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode7 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode7 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode7 -c statusInterval -v 3 +system sh/cfg.sh -n dnode7 -c arbitrator -v "plum-VirtualBox:8001" +#system sh/cfg.sh -n dnode7 -c timezone -v "" +#system sh/cfg.sh -n dnode7 -c locale -v "" +#system sh/cfg.sh -n dnode7 -c charset -v "" +system sh/cfg.sh -n dnode7 -c balanceInterval -v 3 + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1 +system sh/exec.sh -n dnode1 -s start +sleep 3000 +sql connect + +print ============== step2: start dnode2~7 and add into cluster +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +system sh/exec.sh -n dnode5 -s start +system sh/exec.sh -n dnode6 -s start +system sh/exec.sh -n dnode7 -s start +sql create dnode $hostname2 +sql create dnode $hostname3 +sql create dnode $hostname4 +sql create dnode $hostname5 +sql create dnode $hostname6 +sql create dnode $hostname7 +sleep 10000 + +$loopCnt = 0 +wait_dnode_created: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi +sql show dnodes +if $rows != 7 then + sleep 2000 + goto wait_dnode_created +endi +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 +$dnode4Status = $data4_4 +$dnode5Status = $data4_5 +$dnode6Status = $data4_6 +$dnode7Status = $data4_7 + +if $dnode1Status != ready then + return -1 +endi +if $dnode2Status != ready then + return -1 +endi +if $dnode3Status != offline then + return -1 +endi +if $dnode4Status != offline then + return -1 +endi +if $dnode5Status != offline then + return -1 +endi +if $dnode6Status != offline then + return -1 +endi +if $dnode7Status != offline then + return -1 +endi + +sleep 10000 + +$loopCnt = 0 +wait_dnode_offline_overtime_dropped: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi +sql show dnodes +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +if $rows != 2 then + sleep 2000 + goto wait_dnode_offline_overtime_dropped +endi +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 +$dnode4Status = $data4_4 +$dnode5Status = $data4_5 +$dnode6Status = $data4_6 +$dnode7Status = $data4_7 + +if $dnode1Status != ready then + return -1 +endi +if $dnode2Status != ready then + return -1 +endi diff --git a/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync.sim b/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync.sim index cfd992db3a..ae73fc9423 100644 --- a/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync.sim +++ b/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync.sim @@ -1,11 +1,11 @@ # Test case describe: dnode1 is only mnode, dnode2/dnode3 are only vnode # step 1: start dnode1 # step 2: start dnode2 and dnode3, and all added into cluster (Suppose dnode2 is master-vnode) -# step 3: create db, table, insert data, and Falling disc into file (control only one file, e.g. 1841) -# step 4: insert old data(now-20d) and new data(now-40d), control data rows in order to save in cache, not falling disc -# step 5: stop dnode2, so date rows falling disc, generate two new files 1840, 1842 in dnode2 -# step 6: insert two data rows: now-21d, now-41d -# step 7: restart dnode2, waiting sync end +# step 2: create db, table, insert data, and Falling disc into file (control only one file, e.g. 1841) +# step 3: insert old data(now-20d) and new data(now-40d), control data rows in order to save in cache, not falling disc +# step 4: stop dnode2, so date rows falling disc, generate two new files 1840, 1842 in dnode2 +# step 5: insert two data rows: now-21d, now-41d +# step 6: restart dnode2, waiting sync end # expect: in dnode2, the files 1837 and 1839 will be removed system sh/stop_dnodes.sh @@ -113,15 +113,21 @@ sql insert into $tb values ( now - 20d , -20 ) sql insert into $tb values ( now - 40d , -40 ) $totalRows = $totalRows + 2 -print ============== step4: stop dnode2, so date rows falling disc, generate two new files in dnode2 -system sh/exec.sh -n dnode2 -s stop -x SIGINT +print ============== step4: stop dnode3, so date rows falling disc, generate two new files in dnode3 +system sh/exec.sh -n dnode3 -s stop -x SIGINT sleep $sleepTimer -wait_dnode2_offline: +$loopCnt = 0 +wait_dnode3_offline: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 - goto wait_dnode2_offline + goto wait_dnode3_offline endi print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 @@ -135,13 +141,13 @@ $dnode3Status = $data4_3 #$dnode4Status = $data4_4 #$dnode5Status = $data4_5 -if $dnode2Status != offline then +if $dnode3Status != offline then sleep 2000 - goto wait_dnode2_offline + goto wait_dnode3_offline endi -if $dnode3Status != ready then +if $dnode2Status != ready then sleep 2000 - goto wait_dnode2_offline + goto wait_dnode3_offline endi sleep $sleepTimer # waitting for move master vnode of dnode2 to dnode3 @@ -152,6 +158,12 @@ if $data00 != $totalRows then return -1 endi +system_content ls ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/ -l |grep "^-"|wc -l +print ---->dnode3 data files: $system_content , expect is 9 +#if $system_content != @9@ then +# return -1 +#endi + print ============== step5: insert two data rows: now-16d, now+16d, sql insert into $tb values ( now - 21d , -21 ) sql insert into $tb values ( now - 41d , -41 ) @@ -163,4 +175,53 @@ if $data00 != $totalRows then return -1 endi -print ============== step6: please check there should be 3 file in sim/dnode2/data/vnode/vnode2/tsdb/data/, and 1 file sim/dnode3/data/vnode/vnode2/tsdb/data/ +system_content ls ../../../sim/dnode2/data/vnode/vnode2/tsdb/data/ -l |grep "^-"|wc -l +print ---->dnode2 data files: $system_content , expect is 3 +#if $system_content != @3@ then +# return -1 +#endi + +print ============== step7: restart dnode3, waiting sync end +system sh/exec.sh -n dnode3 -s start +sleep 3000 + +$loopCnt = 0 +wait_dnode3_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + +sql show dnodes +if $rows != 3 then + sleep 2000 + goto wait_dnode3_ready +endi +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 + +if $dnode3Status != ready then + sleep 2000 + goto wait_dnode3_ready +endi + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +system_content ls ../../../sim/dnode2/data/vnode/vnode2/tsdb/data/ -l |grep "^-"|wc -l +print ---->dnode2 data files: $system_content , expect is 3 +#if $system_content != @3@ then +# return -1 +#endi +system_content ls ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/ -l |grep "^-"|wc -l +print ---->dnode3 data files: $system_content , expect is 3 +#if $system_content != @3@ then +# return -1 +#endi \ No newline at end of file diff --git a/tests/script/unique/arbitrator/dn3_mn1_full_createTableFail.sim b/tests/script/unique/arbitrator/dn3_mn1_full_createTableFail.sim index 7bcde02ba8..c373bce188 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_full_createTableFail.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_full_createTableFail.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start diff --git a/tests/script/unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim b/tests/script/unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim index 97c2f02427..29fa60de94 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -37,6 +38,7 @@ system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start diff --git a/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim b/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim index 67164908c7..c3bae9005a 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start diff --git a/tests/script/unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim b/tests/script/unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim index 71e606e529..ac2b8365f9 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_nw_disable_timeout_autoDropDnode.sim @@ -3,37 +3,31 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode4 -i 4 -system sh/deploy.sh -n dnode5 -i 5 -system sh/cfg.sh -n dnode1 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode2 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode3 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode4 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode5 -c numOfMPeers -v 1 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 1 system sh/cfg.sh -n dnode2 -c walLevel -v 1 system sh/cfg.sh -n dnode3 -c walLevel -v 1 system sh/cfg.sh -n dnode4 -c walLevel -v 1 -system sh/cfg.sh -n dnode5 -c walLevel -v 1 system sh/cfg.sh -n dnode1 -c balanceInterval -v 10 system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 -system sh/cfg.sh -n dnode5 -c balanceInterval -v 10 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c alternativeRole -v 1 system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 @@ -44,19 +38,16 @@ system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator -system sh/cfg.sh -n dnode5 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode1 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode2 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode3 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode4 -c offlineThreshold -v 10 -system sh/cfg.sh -n dnode5 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode1 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode2 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode3 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode4 -c enableCoreFile -v 1 -system sh/cfg.sh -n dnode5 -c enableCoreFile -v 1 print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -126,7 +117,13 @@ system sh/exec.sh -n dnode4 -s stop #system sh/port.sh -p 7400 -s down sleep 12000 +$loopCnt = 0 wait_dnode4_dropped: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim b/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim index ef6954d4ee..cacbcbb132 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim @@ -36,14 +36,16 @@ system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 200 -#system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 200 -#system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 200 -#system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 200 +system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 200 +system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 200 +system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 200 +system sh/cfg.sh -n dnode5 -c mnodeEqualVnodeNum -v 200 system sh/cfg.sh -n dnode1 -c alternativeRole -v 1 system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 +system sh/cfg.sh -n dnode5 -c alternativeRole -v 2 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -71,7 +73,7 @@ system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect -print ============== step2: start dnode2/dnode3 and add into cluster, then create database, create table , and insert data +print ============== step2: start dnode2/dnode3 and add into cluster, then create database replica 2, create table , and insert data system sh/exec.sh -n dnode2 -s start system sh/exec.sh -n dnode3 -s start sql create dnode $hostname2 @@ -84,7 +86,7 @@ $totalRows = 0 $tsStart = 1420041600000 $db = db -sql create database $db replica 2 maxTables 4 +sql create database $db replica 2 sql use $db # create table , insert data @@ -164,7 +166,13 @@ endi sleep 15000 +$loopCnt = 0 wait_drop: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 3000 @@ -193,14 +201,17 @@ if $dnode4Status != ready then endi print ============== step4-1: restart dnode3, adn add into cluster -system rm -rf ../../sim/dnode3 -sleep 3000 +system rm -rf ../../../sim/dnode3 +sleep 1000 system sh/deploy.sh -n dnode3 -i 3 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c walLevel -v 1 system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 200 +system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode3 -c enableCoreFile -v 1 @@ -209,7 +220,13 @@ system sh/exec.sh -n dnode3 -s start sql create dnode $hostname3 sleep 3000 +$loopCnt = 0 wait_dnode3_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes print rows: $rows if $rows != 4 then @@ -228,19 +245,19 @@ $dnode4Status = $data4_4 $dnode5Status = $data4_5 if $dnode1Status != ready then - return -1 + goto wait_dnode3_ready endi if $dnode2Status != ready then - return -1 + goto wait_dnode3_ready endi if $dnode3Status != null then - return -1 + goto wait_dnode3_ready endi if $dnode4Status != ready then - return -1 + goto wait_dnode3_ready endi if $dnode5Status != ready then - return -1 + goto wait_dnode3_ready endi sql select count(*) from $stb @@ -255,7 +272,13 @@ sleep 1000 system sh/exec.sh -n dnode5 -s start sql create dnode $hostname5 sleep 3000 +$loopCnt = 0 wait_dnode5: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 5 then sleep 3000 @@ -274,22 +297,22 @@ $dnode5Status = $data4_5 $dnode6Status = $data4_6 if $dnode1Status != ready then - return -1 + goto wait_dnode5 endi if $dnode2Status != ready then - return -1 + goto wait_dnode5 endi if $dnode3Status != null then - return -1 + goto wait_dnode5 endi if $dnode4Status != ready then - return -1 + goto wait_dnode5 endi if $dnode5Status != ready then - return -1 + goto wait_dnode5 endi if $dnode6Status != ready then - return -1 + goto wait_dnode5 endi print ============== step6: create database and table until not free vnodes diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim b/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim index 1652470346..9b01b2fae3 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -92,7 +93,14 @@ endi print ============== step2-1: stop dnode2 for falling disc, then restart dnode2, and check rows system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep $sleepTimer + + +$loopCnt = 0 wait_dnode2_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 2 then sleep 2000 @@ -117,7 +125,14 @@ endi system sh/exec.sh -n dnode2 -s start sleep $sleepTimer + + +$loopCnt = 0 wait_dnode2_reready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 2 then sleep 2000 @@ -155,8 +170,13 @@ sleep 3000 sql alter database $db replica 2 sleep $sleepTimer - +$loopCnt = 0 wait_dnode3_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -195,8 +215,13 @@ endi print ============== step4: stop dnode2 for checking if sync ok system sh/exec.sh -n dnode2 -s stop sleep $sleepTimer - +$loopCnt = 0 wait_dnode2_offline: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -235,7 +260,13 @@ print ============== step5: restart dnode2 system sh/exec.sh -n dnode2 -s start sleep 3000 +$loopCnt = 0 wait_dnode2_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -273,8 +304,13 @@ sleep 3000 sql alter database $db replica 3 sleep $sleepTimer - +$loopCnt = 0 wait_dnode4_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 4 then sleep 2000 @@ -308,8 +344,13 @@ endi print ============== step7: alter replica from 3 to 2, and waiting sync sql alter database $db replica 2 sleep $sleepTimer - +$loopCnt = 0 wait_vgroups_replic_to_2: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 @@ -350,8 +391,13 @@ endi print ============== step8: alter replica from 2 to 1, and waiting sync sql alter database $db replica 1 sleep $sleepTimer - +$loopCnt = 0 wait_vgroups_replic_to_1: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 @@ -381,7 +427,13 @@ if $sencodDnode_5 != null then goto wait_vgroups_replic_to_1 endi +$loopCnt = 0 all_dnodes_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 4 then sleep 2000 @@ -429,7 +481,13 @@ sql drop dnode $hostname2 sql drop dnode $hostname3 sleep $sleepTimer +$loopCnt = 0 wait_dnode23_dropped: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 2 then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim b/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim index b870d07c1d..9b001820f6 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -97,8 +98,13 @@ print ============== step3: drop dnode4, then check rows #system sh/exec.sh -n dnode4 -s stop -x SIGINT sql drop dnode $hostname4 sleep $sleepTimer - +$loopCnt = 0 wait_dnode4_dropped: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim b/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim index 1b0a184690..152a65a75a 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim @@ -3,37 +3,31 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode2 -i 2 system sh/deploy.sh -n dnode3 -i 3 system sh/deploy.sh -n dnode4 -i 4 -system sh/deploy.sh -n dnode5 -i 5 -system sh/cfg.sh -n dnode1 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode2 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode3 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode4 -c numOfMPeers -v 1 -system sh/cfg.sh -n dnode5 -c numOfMPeers -v 1 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 1 system sh/cfg.sh -n dnode2 -c walLevel -v 1 system sh/cfg.sh -n dnode3 -c walLevel -v 1 system sh/cfg.sh -n dnode4 -c walLevel -v 1 -system sh/cfg.sh -n dnode5 -c walLevel -v 1 system sh/cfg.sh -n dnode1 -c balanceInterval -v 10 system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 -system sh/cfg.sh -n dnode5 -c balanceInterval -v 10 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c alternativeRole -v 1 system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 @@ -44,19 +38,16 @@ system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator -system sh/cfg.sh -n dnode5 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode1 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode2 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode3 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode4 -c offlineThreshold -v 10 -system sh/cfg.sh -n dnode5 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode1 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode2 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode3 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode4 -c enableCoreFile -v 1 -system sh/cfg.sh -n dnode5 -c enableCoreFile -v 1 print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -124,7 +115,13 @@ print ============== step3: stop dnode4, after timerout dnode4 will be auto-drop system sh/exec.sh -n dnode4 -s stop sleep 12000 +$loopCnt = 0 wait_dnode4_dropped: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -178,7 +175,7 @@ system sh/exec.sh -n dnode4 -s stop system rm -rf ../../../sim/dnode4 system sh/deploy.sh -n dnode4 -i 4 -system sh/cfg.sh -n dnode4 -c numOfMPeers -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode4 -c walLevel -v 1 system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 @@ -192,7 +189,13 @@ system sh/exec.sh -n dnode4 -s start sql create dnode $hostname4 sleep 6000 +$loopCnt = 0 wait_dnode4_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 4 then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim index fda850d2c9..77dbdb0c4c 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -46,7 +47,7 @@ system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect -print ============== step2: start dnode2/dnode3/dnode4 and add into cluster , then create database with replica 3, and create table, insert data +print ============== step2: start dnode2/dnode3/dnode4 and add into cluster , then create database with replica 2, and create table, insert data system sh/exec.sh -n dnode2 -s start system sh/exec.sh -n dnode3 -s start system sh/exec.sh -n dnode4 -s start @@ -59,7 +60,7 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica 2 maxTables $totalTableNum sql use $db # create table , insert data @@ -87,16 +88,26 @@ while $i < $tblNum endw sql select count(*) from $stb -sleep 1000 print data00 $data00 if $data00 != $totalRows then return -1 endi -print ============== step3: stop dnode4, and remove its vnodeX subdirector +sql show dnodes +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 + +print ============== step3: stop dnode4, then destroy the contents of its data file system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$loopCnt = 0 wait_dnode4_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -105,14 +116,11 @@ endi print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 -#print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 -#print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 -#print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 -#$dnode1Status = $data4_1 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +$dnode1Status = $data4_1 $dnode2Status = $data4_2 $dnode3Status = $data4_3 $dnode4Status = $data4_4 -#$dnode5Status = $data4_5 if $dnode4Status != offline then sleep 2000 @@ -141,14 +149,31 @@ if $dnode3Vtatus != master then goto wait_dnode4_vgroup_offline endi - -system rm -rf ../../../sim/dnode4/data/vnode/* +system echo "haha, nothing......" > ../../../sim/dnode4/data/vnode/vnode2/tsdb/data/f1643.data +#system rm -rf ../../../sim/dnode4/data/vnode/* sleep 1000 +print ============== step3-1: insert new data +sql insert into $tb values ( now + 0a , $x ) ( now + 1a , $x ) ( now + 2a , $x ) +$totalRows = $totalRows + 3 + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + print ============== step4: restart dnode4, waiting sync end system sh/exec.sh -n dnode4 -s start sleep $sleepTimer + +$loopCnt = 0 wait_dnode4_reready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 4 then sleep 2000 @@ -171,7 +196,13 @@ if $dnode4Status != ready then goto wait_dnode4_reready endi +$loopCnt = 0 wait_dnode4_vgroup_slave: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups if $rows != 1 then sleep 2000 @@ -195,12 +226,23 @@ if $dnode3Vtatus != master then goto wait_dnode4_vgroup_slave endi +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + print ============== step5: stop dnode3/dnode2, and check rows -system sh/exec.sh -n dnode2 -s stop -system sh/exec.sh -n dnode3 -s stop +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT sleep $sleepTimer +$loopCnt = 0 wait_dnode23_offline: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -210,13 +252,10 @@ print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 -#print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 -#print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 -#$dnode1Status = $data4_1 +$dnode1Status = $data4_1 $dnode2Status = $data4_2 $dnode3Status = $data4_3 $dnode4Status = $data4_4 -#$dnode5Status = $data4_5 if $dnode2Status != offline then sleep 2000 @@ -231,7 +270,13 @@ if $dnode4Status != ready then goto wait_dnode23_offline endi +$loopCnt = 0 wait_dnode4_vgroup_master: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim index d556976a43..40ba2f6e9a 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -93,10 +94,17 @@ if $data00 != $totalRows then return -1 endi -print ============== step3: stop dnode3, then corrupt vnode data file in dnode3 +print ============== step3: stop dnode3 for falling disc, then corrupt vnode data file in dnode3 system sh/exec.sh -n dnode3 -s stop -x SIGINT sleep $sleepTimer + +$loopCnt = 0 wait_dnode3_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -119,7 +127,13 @@ if $dnode3Status != offline then goto wait_dnode3_offline_0 endi +$loopCnt = 0 wait_dnode3_vgroup_offline: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups if $rows != 1 then sleep 2000 @@ -141,14 +155,38 @@ if $dnode2Vtatus != master then goto wait_dnode3_vgroup_offline endi -# del the second row -system sed '2d' ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/v1849.data -sleep 1000 +#system_content ls ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/ -l | grep "^-" | wc -l | sed 's/^[ \t]*//g' +#system_content ls ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/ -l | grep "^-" | wc -l | sed 's/[ \t]*$//g' +#print --2-->dnode3 data files: [ $system_content ] + +system_content ls ../../../sim/dnode2/data/vnode/vnode2/tsdb/data/ -l | grep "^-" | wc -l +print ---->dnode2 data files: [ $system_content ], expect is 0 + +system_content ls ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/ -l | grep "^-" | wc -l +print ---->dnode3 data files: [ $system_content ], expect is 3 +#if $system_content != 3 then +# return -1 +#endi + +system echo "haha, nothing......" > ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/f1643.data +sql insert into $tb values ( now + 0a , $x ) ( now + 1a , $x ) ( now + 2a , $x ) +$totalRows = $totalRows + 3 +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi print ============== step4: restart dnode3, and run query system sh/exec.sh -n dnode3 -s start sleep $sleepTimer +$loopCnt = 0 wait_dnode3_reready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -170,6 +208,33 @@ if $dnode3Status != ready then sleep 2000 goto wait_dnode3_reready endi +$loopCnt = 0 +wait_dnode3_vgroup_slave: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode3_vgroup_slave +endi +print show vgroups: +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 +$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data4_2 + +if $dnode2Vtatus != master then + sleep 2000 + goto wait_dnode3_vgroup_slave +endi +if $dnode3Vtatus != slave then + sleep 2000 + goto wait_dnode3_vgroup_slave +endi sql select count(*) from $stb print data00 $data00 @@ -177,10 +242,29 @@ if $data00 != $totalRows then return -1 endi -print ============== step5: stop dnode2, and check if dnode3 sync ok +system_content ls ../../../sim/dnode2/data/vnode/vnode2/tsdb/data/ -l |grep "^-"|wc -l +print ----> dnode2 data files: [ $system_content ], expect is 0 +#if $system_content != 0 then +# return -1 +#endi + +system_content ls ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/ -l |grep "^-"|wc -l +print ----> dnode3 data files: [ $system_content ], expect is 0 +#if $system_content != 0 then +# print there should be no data file in dnode3 after sync +# return -1 +#endi + +print ============== step5: stop dnode2, and check if dnode3 sync ok system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep $sleepTimer + +$loopCnt = 0 wait_dnode2_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -203,7 +287,13 @@ if $dnode2Status != offline then goto wait_dnode2_offline_0 endi +$loopCnt = 0 wait_dnode3_vgroup_master: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups if $rows != 1 then sleep 2000 @@ -224,3 +314,106 @@ if $dnode3Vtatus != master then sleep 2000 goto wait_dnode3_vgroup_master endi + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +print ============== step6: stop dnode3 for falling disck +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep $sleepTimer +sql show dnodes +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 + +sql show vgroups +print show vgroups: +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 + + +print ============== step7: restart dnode3, and run query +system sh/exec.sh -n dnode3 -s start +sleep $sleepTimer +$loopCnt = 0 +wait_dnode3_reready_2: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi +sql show dnodes +if $rows != 3 then + sleep 2000 + goto wait_dnode3_reready_2 +endi +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 + +if $dnode3Status != ready then + sleep 2000 + goto wait_dnode3_reready_2 +endi + +$loopCnt = 0 +wait_dnode3_vgroup_master_2: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode3_vgroup_master_2 +endi +print show vgroups: +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 +$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data4_2 + +if $dnode2Vtatus != offline then + sleep 2000 + goto wait_dnode3_vgroup_master_2 +endi +if $dnode3Vtatus != master then + sleep 2000 + goto wait_dnode3_vgroup_master_2 +endi + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim index 968a93156e..477f4684b5 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -94,21 +95,30 @@ if $data00 != $totalRows then endi print ============== step3: corrupt vnode data file in dnode3, not stop dnode3 -# del the second row -system sed '2d' ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/v1849.data +system echo "haha, nothing......" > ../../../sim/dnode3/data/vnode/vnode2/tsdb/data/f1643.data sleep 1000 -print ============== step4: run query +print ============== step4: insert new data, and run query +sql insert into $tb values ( now + 0a , $x ) ( now + 1a , $x ) ( now + 2a , $x ) +$totalRows = $totalRows + 3 + sql select count(*) from $stb print data00 $data00 if $data00 != $totalRows then return -1 endi -print ============== step5: stop dnode2, and check if dnode3 sync ok +print ============== step5: stop dnode2, and check if dnode3 sync ok system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep $sleepTimer + +$loopCnt = 0 wait_dnode2_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -131,7 +141,13 @@ if $dnode2Status != offline then goto wait_dnode2_offline_0 endi +$loopCnt = 0 wait_dnode3_vgroup_master: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups if $rows != 1 then sleep 2000 @@ -152,3 +168,9 @@ if $dnode3Vtatus != master then sleep 2000 goto wait_dnode3_vgroup_master endi + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi \ No newline at end of file diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim index 4e9afbf31a..f5bcd055a0 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -96,7 +97,13 @@ print ============== step3: stop dnode4/dnode2 system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep $sleepTimer + +$loopCnt = 0 wait_dnode4_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -123,7 +130,13 @@ if $dnode2Status != offline then goto wait_dnode4_offline_0 endi +$loopCnt = 0 wait_dnode4_vgroup_offline: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show vgroups if $rows != 1 then sleep 2000 @@ -192,7 +205,12 @@ endi print ============== step5: stop dnode3 system sh/exec.sh -n dnode3 -s stop -x SIGINT sleep $sleepTimer +$loopCnt = 0 wait_dnode3_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -221,7 +239,12 @@ if $dnode2Status != ready then goto wait_dnode3_offline_0 endi +$loopCnt = 0 wait_dnode2_vgroup_master: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -243,8 +266,8 @@ if $dnode2Vtatus != master then goto wait_dnode2_vgroup_master endi -sql insert into tb98 values (now, 9000) (now + 1s, 9001) (now + 2s, 9002) tb99 values (now, 9000) (now + 1s, 9001) (now + 2s, 9002) -$totalRows = $totalRows + 6 +sql insert into $tb values (now, 9000) (now + 1s, 9001) (now + 2s, 9002) +$totalRows = $totalRows + 3 sql select count(*) from $stb print data00 $data00 if $data00 != $totalRows then diff --git a/tests/script/unique/arbitrator/dn3_mn2_killDnode.sim b/tests/script/unique/arbitrator/dn3_mn2_killDnode.sim index 57a833b8de..acf157a93a 100644 --- a/tests/script/unique/arbitrator/dn3_mn2_killDnode.sim +++ b/tests/script/unique/arbitrator/dn3_mn2_killDnode.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 2 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 2 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 2 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -32,11 +33,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start diff --git a/tests/script/unique/arbitrator/insert_duplicationTs.sim b/tests/script/unique/arbitrator/insert_duplicationTs.sim index aae1f46180..b9aff29f0c 100644 --- a/tests/script/unique/arbitrator/insert_duplicationTs.sim +++ b/tests/script/unique/arbitrator/insert_duplicationTs.sim @@ -43,11 +43,11 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -117,7 +117,13 @@ print ============== step4: stop dnode2, so date rows falling disc, generate two system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep $sleepTimer +$loopCnt = 0 wait_dnode2_offline: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 @@ -160,8 +166,13 @@ $totalRows = $totalRows + 2 print ============== step5: restart dnode2, waiting sync end system sh/exec.sh -n dnode2 -s start sleep 3000 - +$loopCnt = 0 wait_dnode2_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi + sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim b/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim index 26a6359a5c..18ffb32eed 100644 --- a/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim @@ -99,7 +99,13 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer + +$loopCnt = 0 wait_dnode4_offline_0: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -160,7 +166,12 @@ $totalRows = $totalRows + $addRows print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$loopCnt = 0 wait_dnode4_ready: +$loopCnt = $loopCnt + 1 +if $loopCnt == 10 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim b/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim index b883f077c2..6e85429b77 100644 --- a/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim @@ -100,7 +100,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -123,7 +128,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -187,7 +197,12 @@ endi print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim b/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim index e7b2c70c78..0356f72a97 100644 --- a/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim @@ -101,7 +101,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -124,7 +129,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -174,7 +184,12 @@ endi print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim b/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim index 20c575d382..dc2586b43b 100644 --- a/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim b/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim index 9f72cde440..721c7d60ba 100644 --- a/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -158,7 +168,12 @@ $tblNum = $tblNum - 5 print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim b/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim index 43f9dfff14..897c662b51 100644 --- a/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -160,7 +170,12 @@ $totalRows = $totalRows + $addRows print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim b/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim index e27bbafba7..95ae8047fa 100644 --- a/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim @@ -100,7 +100,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -123,7 +128,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -187,7 +197,12 @@ endi print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim b/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim index 1e47157975..a60f810eea 100644 --- a/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim @@ -100,7 +100,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -123,7 +128,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -173,7 +183,12 @@ endi print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim b/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim index c9fc91527d..a619cbe826 100644 --- a/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim b/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim index aecf41b892..3b7ee869ed 100644 --- a/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -158,7 +168,12 @@ $tblNum = $tblNum - 5 print ============== step5: restart dnode4, waiting dnode4 synced system sh/exec.sh -n dnode4 -s start +$cnt = 0 wait_dnode4_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 diff --git a/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim b/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim index 4a133d2aac..a5816b589b 100644 --- a/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim +++ b/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim @@ -7,6 +7,7 @@ system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 @@ -37,11 +38,21 @@ system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator + +system sh/cfg.sh -n dnode1 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode2 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode3 -c offlineThreshold -v 8 +system sh/cfg.sh -n dnode4 -c offlineThreshold -v 8 + +system sh/cfg.sh -n dnode1 -c statusInterval -v 3 +system sh/cfg.sh -n dnode2 -c statusInterval -v 3 +system sh/cfg.sh -n dnode3 -c statusInterval -v 3 +system sh/cfg.sh -n dnode4 -c statusInterval -v 3 print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start @@ -96,7 +107,12 @@ sql create dnode $hostname2 sleep 3000 # expect after balanced, 2 vondes in dnode1, 1 vonde in dnode2 +$cnt = 0 wait_dnode2_ready: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 2 then sleep 2000 @@ -105,14 +121,8 @@ endi print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 -#print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 -#print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 -#print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 $dnode1Status = $data4_1 $dnode2Status = $data4_2 -#$dnode3Status = $data4_3 -#$dnode4Status = $data4_4 -#$dnode5Status = $data4_5 if $dnode1Status != ready then sleep 2000 @@ -123,7 +133,7 @@ if $dnode2Status != ready then goto wait_dnode2_ready endi -print ============== step3: stop dnode1/dnode2, modify cfg mpeers to 2, and restart dnode1/dnode2 +print ============== step3: stop dnode1/dnode2, modify cfg numOfMnodes to 2, and restart dnode1/dnode2 system sh/exec.sh -n dnode1 -s stop system sh/exec.sh -n dnode2 -s stop sleep 3000 @@ -143,7 +153,12 @@ sleep 5000 print ============= step4: wait dnode ready +$cnt = 0 wait_dnode_ready: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 2 then sleep 2000 @@ -180,7 +195,12 @@ print ============== step5: stop dnode1 system sh/exec.sh -n dnode1 -s stop sleep 3000 +$cnt = 0 wait_dnode2_master: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show mnodes if $rows != 2 then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim b/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim index 9730842938..4f66e5c135 100644 --- a/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim +++ b/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim b/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim index 21957871a5..7bcd148bc9 100644 --- a/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim +++ b/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -172,7 +182,7 @@ system sh/exec.sh -n dnode4 -s start run_back unique/arbitrator/sync_replica_alterTable_background_drop.sim print ============== step6: check result -#in background.sim, drop one column and add one new column, then insert 200 rows +#in background.sim, drop one column and add one new column, then insert 36 rows $totalRows = $totalRows + 36 $cnt = 0 diff --git a/tests/script/unique/arbitrator/sync_replica2_dropDb.sim b/tests/script/unique/arbitrator/sync_replica2_dropDb.sim index 9836284af9..f61b1e3cb9 100644 --- a/tests/script/unique/arbitrator/sync_replica2_dropDb.sim +++ b/tests/script/unique/arbitrator/sync_replica2_dropDb.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica2_dropTable.sim b/tests/script/unique/arbitrator/sync_replica2_dropTable.sim index 4793e8e535..b27558fdf0 100644 --- a/tests/script/unique/arbitrator/sync_replica2_dropTable.sim +++ b/tests/script/unique/arbitrator/sync_replica2_dropTable.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 3 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim b/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim index 9277ad2c85..2a283a6a0c 100644 --- a/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim +++ b/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -162,7 +172,7 @@ while $i < $tblNum endw sql select count(*) from $stb -print data00 $data00 +print data00:$data00 totalRows:$totalRows if $data00 != $totalRows then return -1 endi @@ -172,7 +182,7 @@ system sh/exec.sh -n dnode4 -s start run_back unique/arbitrator/sync_replica_alterTable_background_add.sim print ============== step6: check result -#in background.sim, add one column and insert 200 rows +#in background.sim, add one column and insert 36 rows $totalRows = $totalRows + 36 $cnt = 0 @@ -183,7 +193,7 @@ if $cnt == 20 then endi sql select count(*) from $stb if $data00 != $totalRows then - print data00: $data00 totalRows: $totalRows + print data00:$data00 totalRows:$totalRows sleep 2000 goto wait_table_altered endi diff --git a/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim b/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim index 6593d6933b..7d321ed381 100644 --- a/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim +++ b/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 20 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_dropDb.sim b/tests/script/unique/arbitrator/sync_replica3_dropDb.sim index 7099b1dc8e..0f7ee50c39 100644 --- a/tests/script/unique/arbitrator/sync_replica3_dropDb.sim +++ b/tests/script/unique/arbitrator/sync_replica3_dropDb.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_dropTable.sim b/tests/script/unique/arbitrator/sync_replica3_dropTable.sim index f902b41de5..9c33dd8bb4 100644 --- a/tests/script/unique/arbitrator/sync_replica3_dropTable.sim +++ b/tests/script/unique/arbitrator/sync_replica3_dropTable.sim @@ -99,7 +99,12 @@ endi print ============== step3: stop dnode4 system sh/exec.sh -n dnode4 -s stop -x SIGINT sleep $sleepTimer +$cnt = 0 wait_dnode4_offline_0: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show dnodes if $rows != 4 then sleep 2000 @@ -122,7 +127,12 @@ if $dnode4Status != offline then goto wait_dnode4_offline_0 endi +$cnt = 0 wait_dnode4_vgroup_offline: +$cnt = $cnt + 1 +if $cnt == 10 then + return -1 +endi sql show vgroups if $rows != 1 then sleep 2000 @@ -143,7 +153,7 @@ if $dnode3Vtatus != master then sleep 2000 goto wait_dnode4_vgroup_offline endi -sleep 2000 + print ============== step4: insert more data rows $tsStart = $tsEnd + 1000 $i = 0 @@ -162,17 +172,17 @@ while $i < $tblNum endw sql select count(*) from $stb -print data00 $data00 +print data00:$data00 totalRows:$totalRows if $data00 != $totalRows then return -1 endi -print ============== step5: restart dnode4, while drop database in other thead when dnode4 is syncing +print ============== step5: restart dnode4, while drop some tables in other thread when dnode4 is syncing system sh/exec.sh -n dnode4 -s start run_back unique/arbitrator/sync_replica_dropTable_background.sim print ============== step6: check result -#in background.sim, drop 10 tables +#in background.sim, drop 5 tables $totalRows = $totalRows - 5400 $cnt = 0 @@ -183,7 +193,7 @@ if $cnt == 20 then endi sql select count(*) from $stb if $data00 != $totalRows then - print data00: $data00 + print data00:$data00 totalRows:$totalRows sleep 2000 goto wait_table_dropped endi @@ -191,7 +201,7 @@ endi $tblNum = $tblNum - 5 sql select count(tbname) from $stb if $data00 != $tblNum then - print data00: $data00 + print data00: $data00 tblNum: $tblNum sleep 2000 goto wait_table_dropped endi diff --git a/tests/script/unique/arbitrator/testSuite.sim b/tests/script/unique/arbitrator/testSuite.sim index d286ecfaf2..9593137bdd 100644 --- a/tests/script/unique/arbitrator/testSuite.sim +++ b/tests/script/unique/arbitrator/testSuite.sim @@ -1,5 +1,5 @@ +run unique/arbitrator/check_cluster_cfg_para.sim run unique/arbitrator/dn2_mn1_cache_file_sync.sim -run unique/arbitrator/dn2_mn1_cache_file_sync_second.sim run unique/arbitrator/dn3_mn1_full_createTableFail.sim run unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim run unique/arbitrator/dn3_mn1_multiCreateDropTable.sim @@ -11,7 +11,7 @@ run unique/arbitrator/dn3_mn1_stopDnode_timeout.sim run unique/arbitrator/dn3_mn1_vnode_change.sim run unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim run unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim -####run unique/arbitrator/dn3_mn1_vnode_delDir.sim +run unique/arbitrator/dn3_mn1_vnode_delDir.sim run unique/arbitrator/dn3_mn1_vnode_nomaster.sim run unique/arbitrator/dn3_mn2_killDnode.sim run unique/arbitrator/insert_duplicationTs.sim @@ -33,4 +33,4 @@ run unique/arbitrator/sync_replica2_dropTable.sim run unique/arbitrator/sync_replica3_alterTable_add.sim run unique/arbitrator/sync_replica3_alterTable_drop.sim run unique/arbitrator/sync_replica3_dropDb.sim -run unique/arbitrator/sync_replica3_dropTable.sim +run unique/arbitrator/sync_replica3_dropTable.sim \ No newline at end of file diff --git a/tests/test-all.sh b/tests/test-all.sh index 485c852dc5..0c91229120 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -41,7 +41,7 @@ if [ "$2" != "python" ]; then elif [ "$1" == "full" ]; then echo "### run TSIM full test ###" runSimCaseOneByOne fullGeneralSuite.sim - else + elif [ "$1" == "smoke" ] || [ -z "$1" ]; then echo "### run TSIM smoke test ###" runSimCaseOneByOne basicSuite.sim fi @@ -77,7 +77,7 @@ if [ "$2" != "sim" ]; then elif [ "$1" == "full" ]; then echo "### run Python full test ###" runPyCaseOneByOne fulltest.sh - else + elif [ "$1" == "smoke" ] || [ -z "$1" ]; then echo "### run Python smoke test ###" runPyCaseOneByOne smoketest.sh fi