diff --git a/src/client/inc/tscProfile.h b/src/client/inc/tscProfile.h index 16b9efac38..193fac0fb0 100644 --- a/src/client/inc/tscProfile.h +++ b/src/client/inc/tscProfile.h @@ -26,7 +26,7 @@ void tscAddIntoSqlList(SSqlObj *pSql); void tscRemoveFromSqlList(SSqlObj *pSql); void tscAddIntoStreamList(SSqlStream *pStream); void tscRemoveFromStreamList(SSqlStream *pStream, SSqlObj *pSqlObj); -char *tscBuildQueryStreamDesc(char *pMsg, STscObj *pObj); +int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj); void tscKillQuery(STscObj *pObj, uint32_t killId); void tscKillStream(STscObj *pObj, uint32_t killId); void tscKillConnection(STscObj *pObj); diff --git a/src/client/inc/tscSecondaryMerge.h b/src/client/inc/tscSecondaryMerge.h index 3b0e47f216..19230e34f1 100644 --- a/src/client/inc/tscSecondaryMerge.h +++ b/src/client/inc/tscSecondaryMerge.h @@ -63,19 +63,21 @@ typedef struct SLocalReducer { // char * pBufForInterpo; // intermediate buffer for interpolation tFilePage * pTempBuffer; struct SQLFunctionCtx *pCtx; - int32_t rowSize; // size of each intermediate result. - int32_t status; // denote it is in reduce process, in reduce process, it - bool hasPrevRow; // cannot be released + int32_t rowSize; // size of each intermediate result. + int32_t finalRowSize; // final result row size + int32_t status; // denote it is in reduce process, in reduce process, it + bool hasPrevRow; // cannot be released bool hasUnprocessedRow; tOrderDescriptor * pDesc; SColumnModel * resColModel; tExtMemBuffer ** pExtMemBuffer; // disk-based buffer - SFillInfo* pFillInfo; // interpolation support structure + SFillInfo* pFillInfo; // interpolation support structure char * pFinalRes; // result data after interpo tFilePage * discardData; SResultInfo * pResInfo; bool discard; int32_t offset; // limit offset value + bool orderPrjOnSTable; // projection query on stable } SLocalReducer; typedef struct SSubqueryState { diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 8e72850822..d7f1881209 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -285,8 +285,6 @@ typedef struct { typedef struct STscObj { void * signature; void * pTimer; - char mnodeIp[TSDB_USER_LEN]; - uint16_t mnodePort; char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; char acctId[TSDB_DB_NAME_LEN]; @@ -294,6 +292,7 @@ typedef struct STscObj { char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; + uint32_t connId; struct SSqlObj * pHb; struct SSqlObj * sqlList; struct SSqlStream *streamList; diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index cec4737226..459b0f2b98 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -309,7 +309,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getErrCodeImp(JNI TAOS *tscon = (TAOS *)con; if (tscon == NULL) { jniError("jobj:%p, connection is closed", jobj); - return (jint)TSDB_CODE_INVALID_CONNECTION; + return (jint)TSDB_CODE_TSC_INVALID_CONNECTION; } if ((void *)tres == NULL) { diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index ebcdddffde..3414ff8d98 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -53,7 +53,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const sem_init(&pSql->rspSem, 0, 0); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("failed to malloc payload"); - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); return; } @@ -61,7 +61,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const pSql->sqlstr = calloc(1, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); free(pCmd->payload); return; } @@ -73,7 +73,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const tscDump("%p SQL: %s", pSql, pSql->sqlstr); int32_t code = tsParseSql(pSql, true); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; if (code != TSDB_CODE_SUCCESS) { pSql->res.code = code; @@ -89,16 +89,16 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { tscError("bug!!! pObj:%p", pObj); - terrno = TSDB_CODE_DISCONNECTED; - tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); + terrno = TSDB_CODE_TSC_DISCONNECTED; + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED); return; } int32_t sqlLen = strlen(sqlstr); if (sqlLen > tsMaxSQLStringLen) { tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); - terrno = TSDB_CODE_INVALID_SQL; - tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_SQL); + terrno = TSDB_CODE_TSC_INVALID_SQL; + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_SQL); return; } @@ -107,8 +107,8 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { tscError("failed to malloc sqlObj"); - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; - tscQueueAsyncError(fp, param, TSDB_CODE_CLI_OUT_OF_MEMORY); + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_OUT_OF_MEMORY); return; } @@ -203,7 +203,7 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi SSqlObj *pSql = (SSqlObj *)taosa; if (pSql == NULL || pSql->signature != pSql) { tscError("sql object is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED); return; } @@ -212,7 +212,7 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi if (pRes->qhandle == 0) { tscError("qhandle is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_QHANDLE); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE); return; } @@ -260,7 +260,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), SSqlObj *pSql = (SSqlObj *)taosa; if (pSql == NULL || pSql->signature != pSql) { tscError("sql object is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_DISCONNECTED); return; } @@ -269,7 +269,7 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), if (pRes->qhandle == 0) { tscError("qhandle is NULL"); - tscQueueAsyncError(fp, param, TSDB_CODE_INVALID_QHANDLE); + tscQueueAsyncError(fp, param, TSDB_CODE_TSC_INVALID_QHANDLE); return; } @@ -466,7 +466,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { code = tscGetSTableVgroupInfo(pSql, 0); pRes->code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } else { // normal async query continues if (pCmd->parseFinished) { tscTrace("%p re-send data to vnode in table Meta callback since sql parsed completed", pSql); @@ -491,7 +491,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { return; } - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } } @@ -500,13 +500,13 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { code = tscGetTableMeta(pSql, pTableMetaInfo); pRes->code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_SUCCESS && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscGetSTableVgroupInfo(pSql, pCmd->clauseIndex); pRes->code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } } diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index baefdbe102..1cb9ef0d10 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -156,7 +156,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType, dataBytes)) { tscError("Illegal data type %d or data type length %d", dataType, dataBytes); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY || functionId == TSDB_FUNC_TAG_DUMMY || @@ -325,7 +325,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *bytes = (int16_t)dataBytes; *interBytes = dataBytes + sizeof(SLastrowInfo); } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -341,16 +341,6 @@ bool stableQueryFunctChanged(int32_t funcId) { */ void resetResultInfo(SResultInfo *pResInfo) { pResInfo->initialized = false; } -void initResultInfo(SResultInfo *pResInfo) { - pResInfo->initialized = true; // the this struct has been initialized flag - - pResInfo->complete = false; - pResInfo->hasResult = false; - pResInfo->numOfRes = 0; - - memset(pResInfo->interResultBuf, 0, (size_t)pResInfo->bufLen); -} - void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable) { assert(pResInfo->interResultBuf == NULL); @@ -387,9 +377,7 @@ static bool function_setup(SQLFunctionCtx *pCtx) { */ static void function_finalizer(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); - if (pResInfo->hasResult != DATA_SET_FLAG) { - tscTrace("no result generated, result is set to NULL"); if (pCtx->outputType == TSDB_DATA_TYPE_BINARY || pCtx->outputType == TSDB_DATA_TYPE_NCHAR) { setVardataNull(pCtx->aOutputBuf, pCtx->outputType); } else { diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 5ffdcd2167..91e51f16ed 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -26,7 +26,7 @@ #include "tschemautil.h" #include "tname.h" -static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength); +static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength); static int32_t getToStringLength(const char *pData, int32_t length, int32_t type) { char buf[512] = {0}; @@ -275,22 +275,37 @@ static void tscProcessCurrentUser(SSqlObj *pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0); - tscSetLocalQueryResult(pSql, pSql->pTscObj->user, pExpr->aliasName, TSDB_USER_LEN); + pExpr->resBytes = TSDB_USER_LEN + TSDB_DATA_TYPE_BINARY; + pExpr->resType = TSDB_DATA_TYPE_BINARY; + + char* vx = calloc(1, pExpr->resBytes); + STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, TSDB_USER_LEN); + + tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); + free(vx); } static void tscProcessCurrentDB(SSqlObj *pSql) { char db[TSDB_DB_NAME_LEN + 1] = {0}; extractDBName(pSql->pTscObj->db, db); - // no use db is invoked before. - if (strlen(db) == 0) { - setNull(db, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); - } - SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0); - tscSetLocalQueryResult(pSql, db, pExpr->aliasName, TSDB_DB_NAME_LEN); + pExpr->resType = TSDB_DATA_TYPE_BINARY; + + size_t t = strlen(db); + pExpr->resBytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE; + + char* vx = calloc(1, pExpr->resBytes); + if (t == 0) { + setVardataNull(vx, TSDB_DATA_TYPE_BINARY); + } else { + STR_WITH_SIZE_TO_VARSTR(vx, db, t); + } + + tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); + free(vx); } static void tscProcessServerVer(SSqlObj *pSql) { @@ -298,26 +313,44 @@ static void tscProcessServerVer(SSqlObj *pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0); - tscSetLocalQueryResult(pSql, v, pExpr->aliasName, tListLen(pSql->pTscObj->sversion)); + pExpr->resType = TSDB_DATA_TYPE_BINARY; + + size_t t = strlen(v); + pExpr->resBytes = t + VARSTR_HEADER_SIZE; + + char* vx = calloc(1, pExpr->resBytes); + STR_WITH_SIZE_TO_VARSTR(vx, v, t); + tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); + + tfree(vx); } static void tscProcessClientVer(SSqlObj *pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0); - tscSetLocalQueryResult(pSql, version, pExpr->aliasName, strlen(version)); + pExpr->resType = TSDB_DATA_TYPE_BINARY; + + size_t t = strlen(version); + pExpr->resBytes = t + VARSTR_HEADER_SIZE; + + char* v = calloc(1, pExpr->resBytes); + STR_WITH_SIZE_TO_VARSTR(v, version, t); + tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes); + + tfree(v); } static void tscProcessServStatus(SSqlObj *pSql) { STscObj* pObj = pSql->pTscObj; if (pObj->pHb != NULL) { - if (pObj->pHb->res.code == TSDB_CODE_NETWORK_UNAVAIL) { - pSql->res.code = TSDB_CODE_NETWORK_UNAVAIL; + if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { + pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; return; } } else { - if (pSql->res.code == TSDB_CODE_NETWORK_UNAVAIL) { + if (pSql->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { return; } } @@ -325,10 +358,11 @@ static void tscProcessServStatus(SSqlObj *pSql) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0); SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0); - tscSetLocalQueryResult(pSql, "1", pExpr->aliasName, 2); + int32_t val = 1; + tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t)); } -void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength) { +void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; @@ -338,8 +372,10 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa pQueryInfo->order.order = TSDB_ORDER_ASC; tscFieldInfoClear(&pQueryInfo->fieldsInfo); + pQueryInfo->fieldsInfo.pFields = taosArrayInit(1, sizeof(TAOS_FIELD)); + pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(1, sizeof(SFieldSupInfo)); - TAOS_FIELD f = tscCreateField(TSDB_DATA_TYPE_BINARY, columnName, valueLength); + TAOS_FIELD f = tscCreateField(type, columnName, valueLength); tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f); tscInitResObjForLocalQuery(pSql, 1, valueLength); @@ -348,7 +384,7 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0); pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprList, 0); - strncpy(pRes->data, val, pField->bytes); + memcpy(pRes->data, val, pField->bytes); } int tscProcessLocalCmd(SSqlObj *pSql) { @@ -378,14 +414,14 @@ int tscProcessLocalCmd(SSqlObj *pSql) { } else if (pCmd->command == TSDB_SQL_SERV_STATUS) { tscProcessServStatus(pSql); } else { - pSql->res.code = TSDB_CODE_INVALID_SQL; + pSql->res.code = TSDB_CODE_TSC_INVALID_SQL; tscError("%p not support command:%d", pSql, pCmd->command); } // keep the code in local variable in order to avoid invalid read in case of async query int32_t code = pSql->res.code; if (code == TSDB_CODE_SUCCESS) { - (*pSql->fp)(pSql->param, pSql, 0); + (*pSql->fp)(pSql->param, pSql, code); } else { tscQueueAsyncRes(pSql); } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 8f4bcedfd6..e058483781 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -48,7 +48,7 @@ static int32_t tscToInteger(SSQLToken *pToken, int64_t *value, char **endPtr) { int32_t radix = 10; - int32_t radixList[3] = {16, 8, 2}; + int32_t radixList[3] = {16, 8, 2}; // the integer number with different radix: hex, oct, bin if (pToken->type == TK_HEX || pToken->type == TK_OCT || pToken->type == TK_BIN) { radix = radixList[pToken->type - TK_HEX]; } @@ -134,7 +134,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1 } if (getTimestampInUsFromStr(valueToken.z, valueToken.n, &interval) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (timePrec == TSDB_TIME_PRECISION_MILLI) { @@ -423,7 +423,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[ } strcpy(error, "client out of memory"); - *code = TSDB_CODE_CLI_OUT_OF_MEMORY; + *code = TSDB_CODE_TSC_OUT_OF_MEMORY; return -1; } @@ -431,7 +431,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[ if ((type != TK_NOW && type != TK_INTEGER && type != TK_STRING && type != TK_FLOAT && type != TK_BOOL && type != TK_NULL && type != TK_HEX && type != TK_OCT && type != TK_BIN) || (sToken.n == 0) || (type == TK_RP)) { tscInvalidSQLErrMsg(error, "invalid data or symbol", sToken.z); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } @@ -463,13 +463,13 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[ bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); int32_t ret = tsParseOneColumnData(pSchema, &sToken, start, error, str, isPrimaryKey, timePrec); if (ret != TSDB_CODE_SUCCESS) { - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; // NOTE: here 0 mean error! } if (isPrimaryKey && tsCheckTimestamp(pDataBlocks, start) != TSDB_CODE_SUCCESS) { tscInvalidSQLErrMsg(error, "client time/server time can not be mixed up", sToken.z); - *code = TSDB_CODE_INVALID_TIME_STAMP; + *code = TSDB_CODE_TSC_INVALID_TIME_STAMP; return -1; } } @@ -526,7 +526,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe if (spd->hasVal[0] == false) { strcpy(error, "primary timestamp column can not be null"); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } @@ -560,7 +560,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe *str += index; if (sToken.n == 0 || sToken.type != TK_RP) { tscInvalidSQLErrMsg(error, ") expected", *str); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } @@ -569,7 +569,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMe if (numOfRows <= 0) { strcpy(error, "no any data points"); - *code = TSDB_CODE_INVALID_SQL; + *code = TSDB_CODE_TSC_INVALID_SQL; return -1; } else { return numOfRows; @@ -611,7 +611,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 // do nothing, if allocate more memory failed pDataBlock->nAllocSize = nAllocSizeOld; *numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize; - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -687,13 +687,13 @@ static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableList, char **st int32_t maxNumOfRows; ret = tscAllocateMemIfNeed(dataBuf, tinfo.rowSize, &maxNumOfRows); if (TSDB_CODE_SUCCESS != ret) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } - int32_t code = TSDB_CODE_INVALID_SQL; + int32_t code = TSDB_CODE_TSC_INVALID_SQL; char * tmpTokenBuf = calloc(1, 4096); // used for deleting Escape character: \\, \', \" if (NULL == tmpTokenBuf) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } int32_t numOfRows = tsParseValues(str, dataBuf, pTableMeta, maxNumOfRows, spd, pCmd->payload, &code, tmpTokenBuf); @@ -772,7 +772,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { } if (numOfColList == 0 && cstart != NULL) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX); @@ -954,7 +954,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { createTable = true; code = tscGetMeterMetaEx(pSql, pTableMetaInfo, true); - if (TSDB_CODE_ACTION_IN_PROGRESS == code) { + if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) { return code; } @@ -967,7 +967,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { code = tscGetMeterMetaEx(pSql, pTableMetaInfo, false); if (pCmd->curSql == NULL) { - assert(code == TSDB_CODE_ACTION_IN_PROGRESS); + assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS); } } @@ -981,7 +981,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { } if (*sqlstr == NULL) { - code = TSDB_CODE_INVALID_SQL; + code = TSDB_CODE_TSC_INVALID_SQL; } return code; @@ -1046,7 +1046,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) { pSql->cmd.pDataBlocks = tscCreateBlockArrayList(); if (NULL == pCmd->pTableList || NULL == pSql->cmd.pDataBlocks) { - code = TSDB_CODE_CLI_OUT_OF_MEMORY; + code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error_clean; } } else { @@ -1075,7 +1075,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) { * Otherwise, create the first submit block and submit to virtual node. */ if (totalNum == 0) { - code = TSDB_CODE_INVALID_SQL; + code = TSDB_CODE_TSC_INVALID_SQL; goto _error_clean; } else { break; @@ -1103,7 +1103,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) { * And during the getMeterMetaCallback function, the sql string will be parsed from the * interrupted position. */ - if (TSDB_CODE_ACTION_IN_PROGRESS == code) { + if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) { tscTrace("%p waiting for get table meta during insert, then resume from offset: %" PRId64 " , %s", pSql, pos, pCmd->curSql); return code; @@ -1297,7 +1297,7 @@ _clean: int tsParseInsertSql(SSqlObj *pSql) { if (!pSql->pTscObj->writeAuth) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_TSC_NO_WRITE_AUTH; } int32_t index = 0; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 1a76bd5e61..12d2980038 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -24,7 +24,6 @@ #include "tscSubquery.h" int tsParseInsertSql(SSqlObj *pSql); -int taos_query_imp(STscObj* pObj, SSqlObj* pSql); //////////////////////////////////////////////////////////////////////////////// // functions for normal statement preparation @@ -62,7 +61,7 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ size *= 2; void* tmp = realloc(stmt->parts, sizeof(SNormalStmtPart) * size); if (tmp == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } stmt->sizeParts = size; stmt->parts = (SNormalStmtPart*)tmp; @@ -133,7 +132,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: var->pz = (char*)malloc((*tb->length) + 1); if (var->pz == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } memcpy(var->pz, tb->buffer, (*tb->length)); var->pz[*tb->length] = 0; @@ -142,7 +141,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { default: tscTrace("param %d: type mismatch or invalid", i); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } } @@ -187,7 +186,7 @@ static int normalStmtPrepare(STscStmt* stmt) { if (normal->numParams > 0) { normal->params = calloc(normal->numParams, sizeof(tVariant)); if (normal->params == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -273,7 +272,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { } if (bind->buffer_type != param->type) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } short size = 0; @@ -300,7 +299,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_BINARY: if ((*bind->length) > param->bytes) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } size = (short)*bind->length; STR_WITH_SIZE_TO_VARSTR(data + param->offset, bind->buffer, size); @@ -309,14 +308,14 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { case TSDB_DATA_TYPE_NCHAR: { size_t output = 0; if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } varDataSetLen(data + param->offset, output); return TSDB_CODE_SUCCESS; } default: assert(false); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } memcpy(data + param->offset, bind->buffer, size); @@ -344,7 +343,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { const double factor = 1.5; void* tmp = realloc(pBlock->pData, (uint32_t)(totalDataSize * factor)); if (tmp == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pBlock->pData = (char*)tmp; pBlock->nAllocSize = (uint32_t)(totalDataSize * factor); @@ -416,7 +415,7 @@ static int insertStmtReset(STscStmt* pStmt) { static int insertStmtExecute(STscStmt* stmt) { SSqlCmd* pCmd = &stmt->pSql->cmd; if (pCmd->batchSize == 0) { - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } if ((pCmd->batchSize % 2) == 1) { ++pCmd->batchSize; @@ -470,14 +469,14 @@ static int insertStmtExecute(STscStmt* stmt) { TAOS_STMT* taos_stmt_init(TAOS* taos) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("connection disconnected"); return NULL; } STscStmt* pStmt = calloc(1, sizeof(STscStmt)); if (pStmt == NULL) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; } @@ -486,7 +485,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { free(pStmt); - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; } @@ -494,7 +493,6 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { tsem_init(&pSql->rspSem, 0, 0); pSql->signature = pSql; pSql->pTscObj = pObj; - //pSql->pTscObj->pSql = pSql; pSql->maxRetry = TSDB_MAX_REPLICA_NUM; pStmt->pSql = pSql; @@ -505,8 +503,8 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlObj* pSql = pStmt->pSql; @@ -515,13 +513,13 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { //doAsyncQuery(pObj, pSql, waitForQueryRsp, taos, sqlstr, sqlLen); SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - pSql->param = (void*)pSql; + pSql->param = (void*) pSql; pSql->fp = waitForQueryRsp; pSql->insertType = TSDB_QUERY_TYPE_STMT_INSERT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { tscError("%p failed to malloc payload buffer", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); @@ -529,7 +527,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); free(pCmd->payload); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pRes->qhandle = 0; @@ -545,7 +543,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { pSql->cmd.batchSize = 0; int32_t code = tsParseSql(pSql, true); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore tsem_wait(&pSql->rspSem); return pSql->res.code; @@ -590,7 +588,7 @@ int taos_stmt_add_batch(TAOS_STMT* stmt) { if (pStmt->isInsert) { return insertStmtAddBatch(pStmt); } - return TSDB_CODE_OPS_NOT_SUPPORT; + return TSDB_CODE_COM_OPS_NOT_SUPPORT; } int taos_stmt_reset(TAOS_STMT* stmt) { @@ -609,7 +607,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { } else { char* sql = normalStmtBuildSql(pStmt); if (sql == NULL) { - ret = TSDB_CODE_CLI_OUT_OF_MEMORY; + ret = TSDB_CODE_TSC_OUT_OF_MEMORY; } else { tfree(pStmt->pSql->sqlstr); pStmt->pSql->sqlstr = sql; diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index e6d9aad6e2..79d00bf5dc 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -19,6 +19,7 @@ #include "ttime.h" #include "ttimer.h" #include "tutil.h" +#include "taosmsg.h" void tscSaveSlowQueryFp(void *handle, void *tmrId); void *tscSlowQueryConn = NULL; @@ -96,7 +97,7 @@ void tscSaveSlowQuery(SSqlObj *pSql) { } tscTrace("%p query time:%" PRId64 " sql:%s", pSql, pSql->res.useconds, pSql->sqlstr); - int32_t sqlSize = TSDB_SHOW_SQL_LEN + size; + int32_t sqlSize = TSDB_SLOW_QUERY_SQL_LEN + size; char *sql = malloc(sqlSize); if (sql == NULL) { @@ -106,9 +107,9 @@ void tscSaveSlowQuery(SSqlObj *pSql) { int len = snprintf(sql, size, "insert into %s.slowquery values(now, '%s', %" PRId64 ", %" PRId64 ", '", tsMonitorDbName, pSql->pTscObj->user, pSql->stime, pSql->res.useconds); - int sqlLen = snprintf(sql + len, TSDB_SHOW_SQL_LEN, "%s", pSql->sqlstr); - if (sqlLen > TSDB_SHOW_SQL_LEN - 1) { - sqlLen = len + TSDB_SHOW_SQL_LEN - 1; + int sqlLen = snprintf(sql + len, TSDB_SLOW_QUERY_SQL_LEN, "%s", pSql->sqlstr); + if (sqlLen > TSDB_SLOW_QUERY_SQL_LEN - 1) { + sqlLen = len + TSDB_SLOW_QUERY_SQL_LEN - 1; } else { sqlLen += len; } @@ -205,28 +206,28 @@ void tscKillStream(STscObj *pObj, uint32_t killId) { } pthread_mutex_unlock(&pObj->mutex); - + if (pStream) { tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId); + if (pStream->callback) { + pStream->callback(pStream->param); + } + taos_close_stream(pStream); + } else { + tscError("failed to kill stream, streamId:%d not exist", killId); } - - if (pStream->callback) { - pStream->callback(pStream->param); - } - taos_close_stream(pStream); } -char *tscBuildQueryStreamDesc(char *pMsg, STscObj *pObj) { - char * pMax = pMsg + TSDB_PAYLOAD_SIZE - 256; +int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { + SCMHeartBeatMsg *pHeartbeat = pMsg; + int allocedQueriesNum = pHeartbeat->numOfQueries; + int allocedStreamsNum = pHeartbeat->numOfStreams; - SQqueryList *pQList = (SQqueryList *)pMsg; - pQList->numOfQueries = 0; - - SQueryDesc *pQdesc = (SQueryDesc*)(pMsg + sizeof(SQqueryList)); + pHeartbeat->numOfQueries = 0; + SQueryDesc *pQdesc = (SQueryDesc *)pHeartbeat->pData; // We extract the lock to tscBuildHeartBeatMsg function. - /* pthread_mutex_lock (&pObj->mutex); */ - pMsg += sizeof(SQqueryList); + SSqlObj *pSql = pObj->sqlList; while (pSql) { /* @@ -240,47 +241,46 @@ char *tscBuildQueryStreamDesc(char *pMsg, STscObj *pObj) { strncpy(pQdesc->sql, pSql->sqlstr, TSDB_SHOW_SQL_LEN - 1); pQdesc->sql[TSDB_SHOW_SQL_LEN - 1] = 0; - pQdesc->stime = pSql->stime; - pQdesc->queryId = pSql->queryId; - pQdesc->useconds = pSql->res.useconds; + pQdesc->stime = htobe64(pSql->stime); + pQdesc->queryId = htonl(pSql->queryId); + pQdesc->useconds = htobe64(pSql->res.useconds); - pQList->numOfQueries++; + pHeartbeat->numOfQueries++; pQdesc++; pSql = pSql->next; - pMsg += sizeof(SQueryDesc); - if (pMsg > pMax) break; + if (pHeartbeat->numOfQueries >= allocedQueriesNum) break; } - SStreamList *pSList = (SStreamList *)pMsg; - pSList->numOfStreams = 0; - - SStreamDesc *pSdesc = (SStreamDesc*) (pMsg + sizeof(SStreamList)); + pHeartbeat->numOfStreams = 0; + SStreamDesc *pSdesc = (SStreamDesc *)pQdesc; - pMsg += sizeof(SStreamList); SSqlStream *pStream = pObj->streamList; while (pStream) { strncpy(pSdesc->sql, pStream->pSql->sqlstr, TSDB_SHOW_SQL_LEN - 1); pSdesc->sql[TSDB_SHOW_SQL_LEN - 1] = 0; - pSdesc->streamId = pStream->streamId; - pSdesc->num = pStream->num; + pSdesc->streamId = htonl(pStream->streamId); + pSdesc->num = htobe64(pStream->num); - pSdesc->useconds = pStream->useconds; - pSdesc->stime = pStream->stime - pStream->interval; - pSdesc->ctime = pStream->ctime; + pSdesc->useconds = htobe64(pStream->useconds); + pSdesc->stime = htobe64(pStream->stime - pStream->interval); + pSdesc->ctime = htobe64(pStream->ctime); - pSdesc->slidingTime = pStream->slidingTime; - pSdesc->interval = pStream->interval; + pSdesc->slidingTime = htobe64(pStream->slidingTime); + pSdesc->interval = htobe64(pStream->interval); - pSList->numOfStreams++; + pHeartbeat->numOfStreams++; pSdesc++; pStream = pStream->next; - pMsg += sizeof(SStreamDesc); - if (pMsg > pMax) break; + if (pHeartbeat->numOfStreams >= allocedStreamsNum) break; } - /* pthread_mutex_unlock (&pObj->mutex); */ + int32_t msgLen = pHeartbeat->numOfQueries * sizeof(SQueryDesc) + pHeartbeat->numOfStreams * sizeof(SStreamDesc) + + sizeof(SCMHeartBeatMsg); + pHeartbeat->connId = htonl(pObj->connId); + pHeartbeat->numOfQueries = htonl(pHeartbeat->numOfQueries); + pHeartbeat->numOfStreams = htonl(pHeartbeat->numOfStreams); - return pMsg; + return msgLen; } void tscKillConnection(STscObj *pObj) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 14ab14603f..15706e3235 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -41,7 +41,7 @@ #define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_TBNAME_COLUMN_INDEX)) #define TBNAME_LIST_SEP "," -typedef struct SColumnList { +typedef struct SColumnList { // todo refactor int32_t num; SColumnIndex ids[TSDB_MAX_COLUMNS]; } SColumnList; @@ -93,7 +93,7 @@ static int32_t validateArithmeticSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo static int32_t validateDNodeConfig(tDCLSQL* pOptions); static int32_t validateLocalConfig(tDCLSQL* pOptions); static int32_t validateColumnName(char* name); -static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); +static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType); static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField); static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo); @@ -179,7 +179,7 @@ static int32_t handlePassword(SSqlCmd* pCmd, SSQLToken* pPwd) { // todo handle memory leak in error handle function int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) { - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_TSC_APP_ERROR; } SSqlCmd* pCmd = &(pSql->cmd); @@ -264,7 +264,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { case TSDB_SQL_SHOW: { if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } break; @@ -286,7 +286,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } break; @@ -314,7 +314,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken* pPwd = &pInfo->pDCLInfo->user.passwd; if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pName->n > TSDB_USER_LEN) { @@ -411,12 +411,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pCmd->command == TSDB_SQL_CREATE_USER) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { if (pUser->type == TSDB_ALTER_USER_PASSWD) { if (handlePassword(pCmd, pPwd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { assert(pPwd->type == TSDB_DATA_TYPE_NULL); @@ -531,7 +531,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { case TSDB_SQL_KILL_QUERY: case TSDB_SQL_KILL_STREAM: case TSDB_SQL_KILL_CONNECTION: { - if ((code = setKillInfo(pSql, pInfo)) != TSDB_CODE_SUCCESS) { + if ((code = setKillInfo(pSql, pInfo, pInfo->type)) != TSDB_CODE_SUCCESS) { return code; } @@ -577,7 +577,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { // interval is not null SSQLToken* t = &pQuerySql->interval; if (getTimestampInUsFromStr(t->z, t->n, &pQueryInfo->intervalTime) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // if the unit of time window value is millisecond, change the value from microsecond @@ -596,7 +596,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { // for top/bottom + interval query, we do not add additional timestamp column in the front if (isTopBottomQuery(pQueryInfo)) { if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -635,7 +635,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { } if (tableIndex == COLUMN_INDEX_INITIAL_VAL) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SColumnIndex index = {tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; @@ -651,7 +651,7 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { } if (parseSlidingClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -1040,7 +1040,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) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } memcpy(&fullName[totalLen], pDB->z, pDB->n); @@ -1054,12 +1054,12 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL /* here we only check the table name length limitation */ if (tableName->n > TSDB_TABLE_NAME_LEN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { // pDB == NULL, the db prefix name is specified in tableName /* the length limitation includes tablename + dbname + sep */ if (tableName->n > TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN + tListLen(TS_PATH_DELIMITER)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1075,7 +1075,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL fullName[totalLen] = 0; } - return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_INVALID_SQL; + return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_TSC_INVALID_SQL; } static void extractColumnNameFromString(tSQLExprItem* pItem) { @@ -1122,12 +1122,12 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel // select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2 if (addProjectionExprAndResultField(pQueryInfo, pItem) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else if (pItem->pNode->nSQLOptr >= TK_COUNT && pItem->pNode->nSQLOptr <= TK_TBID) { // sql function in selection clause, append sql function info in pSqlCmd structure sequentially if (addExprAndResultField(pQueryInfo, outputIndex, pItem, true) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else if (pItem->pNode->nSQLOptr >= TK_PLUS && pItem->pNode->nSQLOptr <= TK_REM) { @@ -1154,7 +1154,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel } if (buildArithmeticExprString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // expr string is set as the parameter of function @@ -1230,7 +1230,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel } if (pQueryInfo->fieldsInfo.numOfOutput > TSDB_MAX_COLUMNS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1246,7 +1246,7 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel tscTansformSQLFuncForSTableQuery(pQueryInfo); if (hasUnsupportFunctionsForSTableQuery(pQueryInfo)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1414,7 +1414,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI addProjectQueryCol(pQueryInfo, startPos, &index, pItem); } } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -1483,7 +1483,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t functionID = 0; if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSqlExpr* pExpr = NULL; @@ -1517,12 +1517,14 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); // count tag is equalled to count(tbname) - if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { + bool isTag = false; + if (index.columnIndex >= tscGetNumOfColumns(pTableMetaInfo->pTableMeta) || index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { index.columnIndex = TSDB_TBNAME_COLUMN_INDEX; + isTag = true; } int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize; - pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false); + pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, isTag); } } else { // count(*) is equalled to count(primary_timestamp_key) index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX}; @@ -1543,10 +1545,13 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr tscColumnListInsert(pQueryInfo->colList, &(ids.ids[i])); } } - - SColumnIndex tsCol = {.tableIndex = index.tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; - tscColumnListInsert(pQueryInfo->colList, &tsCol); - + + // the time stamp may be always needed + if (index.tableIndex > 0 && index.tableIndex < tscGetNumOfColumns(pTableMetaInfo->pTableMeta)) { + SColumnIndex tsCol = {.tableIndex = index.tableIndex, .columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX}; + tscColumnListInsert(pQueryInfo->colList, &tsCol); + } + return TSDB_CODE_SUCCESS; } case TK_SUM: @@ -1596,12 +1601,12 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t functionID = 0; if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (getResultDataInfo(pSchema->type, pSchema->bytes, functionID, 0, &resultType, &resultSize, &intermediateResSize, 0, false) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set the first column ts for diff query @@ -1626,14 +1631,14 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr /* set the leastsquares parameters */ char val[8] = {0}; if (tVariantDump(&pParamElem[1].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES, 0); memset(val, 0, tListLen(val)); if (tVariantDump(&pParamElem[2].pNode->val, val, TSDB_DATA_TYPE_DOUBLE, true) < 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0); @@ -1698,7 +1703,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr for (int32_t j = 0; j < tscGetNumOfColumns(pTableMetaInfo->pTableMeta); ++j) { index.columnIndex = j; if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex++, &index) != 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1716,7 +1721,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr } if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i, &index) != 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } @@ -1733,7 +1738,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr SColumnIndex index = {.tableIndex = j, .columnIndex = i}; if (setExprInfoForFunctions(pQueryInfo, pSchema, functionID, pItem->aliasName, colIndex + i + j, &index) != 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -1809,7 +1814,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr */ int16_t functionId = 0; if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pExpr = tscSqlExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, resultSize, false); @@ -1824,7 +1829,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t functionId = 0; if (changeFunctionID(optr, &functionId) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set the first column ts for top/bottom query @@ -1881,22 +1886,38 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr // functions can not be applied to normal columns int32_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta); - if (index.columnIndex < numOfCols) { + if (index.columnIndex < numOfCols && index.columnIndex != TSDB_TBNAME_COLUMN_INDEX) { return invalidSqlErrMsg(pQueryInfo->msg, msg6); } - index.columnIndex -= numOfCols; + if (index.columnIndex > 0) { + index.columnIndex -= numOfCols; + } // 2. valid the column type - int16_t colType = pSchema[index.columnIndex].type; - if (colType == TSDB_DATA_TYPE_BOOL || colType >= TSDB_DATA_TYPE_BINARY) { + int16_t colType = 0; + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + colType = TSDB_DATA_TYPE_BINARY; + } else { + colType = pSchema[index.columnIndex].type; + } + + if (colType == TSDB_DATA_TYPE_BOOL) { return invalidSqlErrMsg(pQueryInfo->msg, msg1); } tscColumnListInsert(pTableMetaInfo->tagColList, &index); SSchema* pTagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); - SSchema s = pTagSchema[index.columnIndex]; - + + SSchema s = {0}; + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + s.bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + s.type = TSDB_DATA_TYPE_BINARY; + s.colId = TSDB_TBNAME_COLUMN_INDEX; + } else { + s = pTagSchema[index.columnIndex]; + } + int16_t bytes = 0; int16_t type = 0; int32_t inter = 0; @@ -1914,7 +1935,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr } default: - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2014,7 +2035,7 @@ int32_t doGetColumnIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColum if (COLUMN_INDEX_VALIDE(*pIndex)) { return TSDB_CODE_SUCCESS; } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2041,7 +2062,7 @@ int32_t getTableIndexImpl(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColum } if (pIndex->tableIndex < 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -2052,7 +2073,7 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn extractTableNameFromToken(pToken, &tableToken); if (getTableIndexImpl(&tableToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -2060,13 +2081,13 @@ int32_t getTableIndexByName(SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIn int32_t getColumnIndexByName(const SSQLToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex) { if (pQueryInfo->pTableMetaInfo == NULL || pQueryInfo->numOfTables == 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSQLToken tmpToken = *pToken; if (getTableIndexByName(&tmpToken, pQueryInfo, pIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return doGetColumnIndexByName(&tmpToken, pQueryInfo, pIndex); @@ -2229,37 +2250,45 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return TSDB_CODE_SUCCESS; } -int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { - const char* msg1 = "invalid ip address"; - const char* msg2 = "invalid port"; +int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) { + const char* msg1 = "invalid connection ID"; + const char* msg2 = "invalid query ID"; + const char* msg3 = "invalid stream ID"; SSqlCmd* pCmd = &pSql->cmd; pCmd->command = pInfo->type; - - SSQLToken* ip = &(pInfo->pDCLInfo->ip); - if (ip->n > TSDB_KILL_MSG_LEN) { - return TSDB_CODE_INVALID_SQL; + + SSQLToken* idStr = &(pInfo->pDCLInfo->ip); + if (idStr->n > TSDB_KILL_MSG_LEN) { + return TSDB_CODE_TSC_INVALID_SQL; } - strncpy(pCmd->payload, ip->z, ip->n); + strncpy(pCmd->payload, idStr->z, idStr->n); const char delim = ':'; + char* connIdStr = strtok(idStr->z, &delim); + char* queryIdStr = strtok(NULL, &delim); - char* ipStr = strtok(ip->z, &delim); - char* portStr = strtok(NULL, &delim); - - if (!validateIpAddress(ipStr, strlen(ipStr))) { + int32_t connId = (int32_t)strtol(connIdStr, NULL, 10); + if (connId <= 0) { memset(pCmd->payload, 0, strlen(pCmd->payload)); - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - uint16_t port = (uint16_t)strtol(portStr, NULL, 10); - if (port <= 0 || port > 65535) { - memset(pCmd->payload, 0, strlen(pCmd->payload)); - return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + if (killType == TSDB_SQL_KILL_CONNECTION) { + return TSDB_CODE_SUCCESS; } + int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10); + if (queryId <= 0) { + memset(pCmd->payload, 0, strlen(pCmd->payload)); + if (killType == TSDB_SQL_KILL_QUERY) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + } else { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); + } + } + return TSDB_CODE_SUCCESS; } @@ -2278,7 +2307,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); if (pTableMetaInfo->pTableMeta == NULL || !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } assert(tscGetNumOfTags(pTableMetaInfo->pTableMeta) >= 0); @@ -2300,7 +2329,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE)) { if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, pExpr->param[0].i64Key, &type, &bytes, &interBytes, 0, true) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tscSqlExprUpdate(pQueryInfo, k, functionId, pExpr->colInfo.colIndex, TSDB_DATA_TYPE_BINARY, bytes); @@ -2724,7 +2753,7 @@ static bool isExprDirectParentOfLeaftNode(tSQLExpr* pExpr) { static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** output) { if (!isExprDirectParentOfLeaftNode(pExpr)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tSQLExpr* pLeft = pExpr->pLeft; @@ -2737,7 +2766,7 @@ static int32_t tSQLExprLeafToString(tSQLExpr* pExpr, bool addParentheses, char** tSQLExprNodeToString(pLeft, output); if (optrToString(pExpr, output) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tSQLExprNodeToString(pRight, output); @@ -2803,7 +2832,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) { break; } default: - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } *exprString += 1; @@ -2814,7 +2843,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) { static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { tSQLExprList* pList = pExpr->pParam; if (pList->nExpr <= 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pList->nExpr > 0) { @@ -2830,7 +2859,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { } if (pSub->val.nLen <= 0 || pSub->val.nLen > TSDB_TABLE_NAME_LEN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -2878,7 +2907,7 @@ static int32_t extractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnIndex* pIn // TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2" pColFilter = addColumnFilterInfo(pColumn); } else { // error; - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pColFilter->filterstr = @@ -2953,7 +2982,7 @@ static int32_t getTablenameCond(SQueryInfo* pQueryInfo, tSQLExpr* pTableCond, SS tSQLExpr* pRight = pTableCond->pRight; if (!isTablenameToken(&pLeft->colInfo)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t ret = TSDB_CODE_SUCCESS; @@ -2986,7 +3015,7 @@ static int32_t getColumnQueryCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr, i } else { // handle leaf node SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return extractColumnFilterInfo(pQueryInfo, &index, pExpr, relOptr); @@ -3010,7 +3039,7 @@ static int32_t getJoinCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) { SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3022,7 +3051,7 @@ static int32_t getJoinCondInfo(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) { index = (SColumnIndex)COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pRight->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3048,7 +3077,7 @@ int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString) { } else { int32_t ret = tSQLExprNodeToString(pLeft, exprString); if (ret != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -3059,7 +3088,7 @@ int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString) { } else { int32_t ret = tSQLExprNodeToString(pRight, exprString); if (ret != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -3073,12 +3102,12 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL if (*type == NON_ARITHMEIC_EXPR) { *type = NORMAL_ARITHMETIC; } else if (*type == AGG_ARIGHTMEIC) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // if column is timestamp, bool, binary, nchar, not support arithmetic, so return invalid sql @@ -3087,17 +3116,17 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL if ((pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) || (pSchema->type == TSDB_DATA_TYPE_BOOL) || (pSchema->type == TSDB_DATA_TYPE_BINARY) || (pSchema->type == TSDB_DATA_TYPE_NCHAR)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pList->ids[pList->num++] = index; } else if (pExpr->nSQLOptr == TK_FLOAT && (isnan(pExpr->val.dKey) || isinf(pExpr->val.dKey))) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) { if (*type == NON_ARITHMEIC_EXPR) { *type = AGG_ARIGHTMEIC; } else if (*type == NORMAL_ARITHMETIC) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t outputIndex = tscSqlExprNumOfExprs(pQueryInfo); @@ -3106,7 +3135,7 @@ static int32_t validateSQLExpr(tSQLExpr* pExpr, SQueryInfo* pQueryInfo, SColumnL // sql function in selection clause, append sql function info in pSqlCmd structure sequentially if (addExprAndResultField(pQueryInfo, outputIndex, &item, false) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -3310,7 +3339,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S if (index.columnIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX) { // query on time range if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set join query condition @@ -3372,7 +3401,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S } else { if (pRight->nSQLOptr == TK_ID) { // join on tag columns for stable query if (!validateJoinExprNode(pQueryInfo, *pExpr, &index)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pCondExpr->pJoinExpr != NULL) { @@ -3417,7 +3446,7 @@ int32_t getQueryCondExpr(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pC tSQLExpr* pRight = (*pExpr)->pRight; if (!isValidExpr(pLeft, pRight, (*pExpr)->nSQLOptr)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t leftType = -1; @@ -3655,7 +3684,7 @@ static int32_t getTimeRangeFromExpr(SQueryInfo* pQueryInfo, tSQLExpr* pExpr) { } else { SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -3883,7 +3912,7 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t * where ts in ('2015-12-12 4:8:12') */ if (pRight->nSQLOptr == TK_SET || optr == TK_IN) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int64_t val = 0; @@ -3896,14 +3925,14 @@ int32_t getTimeRange(STimeWindow* win, tSQLExpr* pRight, int32_t optr, int16_t t if (taosParseTime(pRight->val.pz, &val, pRight->val.nLen, TSDB_TIME_PRECISION_MICRO) == TSDB_CODE_SUCCESS) { parsed = true; } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { SSQLToken token = {.z = pRight->val.pz, .n = pRight->val.nLen, .type = TK_ID}; int32_t len = tSQLGetToken(pRight->val.pz, &token.type); if ((token.type != TK_INTEGER && token.type != TK_FLOAT) || len != pRight->val.nLen) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } else if (pRight->nSQLOptr == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) { @@ -4011,7 +4040,7 @@ int32_t parseFillClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySQL) { if (pQueryInfo->fillVal == NULL) { pQueryInfo->fillVal = calloc(size, sizeof(int64_t)); if (pQueryInfo->fillVal == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -4322,7 +4351,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (!validateOneTags(pCmd, &pFieldList->p[0])) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); @@ -4345,7 +4374,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken name = {.z = pItem->pVar.pz, .n = pItem->pVar.nLen, .type = TK_STRING}; if (getColumnIndexByName(&name, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) { @@ -4362,7 +4391,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } else if (pAlterSQL->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { tVariantList* pVarList = pAlterSQL->varList; if (pVarList->nExpr > 2) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tVariantListItem* pSrcItem = &pAlterSQL->varList->a[0]; @@ -4381,12 +4410,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSQLToken srcToken = {.z = pSrcItem->pVar.pz, .n = pSrcItem->pVar.nLen, .type = TK_STRING}; if (getColumnIndexByName(&srcToken, pQueryInfo, &srcIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSQLToken destToken = {.z = pDstItem->pVar.pz, .n = pDstItem->pVar.nLen, .type = TK_STRING}; if (getColumnIndexByName(&destToken, pQueryInfo, &destIndex) == TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } char name[TSDB_COL_NAME_LEN + 1] = {0}; @@ -4409,7 +4438,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SColumnIndex columnIndex = COLUMN_INDEX_INITIALIZER; SSQLToken name = {.type = TK_STRING, .z = pTagName->pz, .n = pTagName->nLen}; if (getColumnIndexByName(&name, pQueryInfo, &columnIndex) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (columnIndex.columnIndex < tscGetNumOfColumns(pTableMeta)) { @@ -4432,7 +4461,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t size = sizeof(SUpdateTableTagValMsg) + pTagsSchema->bytes + TSDB_EXTRA_PAYLOAD_SIZE; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for alter table msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SUpdateTableTagValMsg* pUpdateMsg = (SUpdateTableTagValMsg*) (pCmd->payload + tsRpcHeadSize); @@ -4466,7 +4495,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (!validateOneColumn(pCmd, &pFieldList->p[0])) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &pFieldList->p[0]); @@ -4555,7 +4584,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SQueryInfo* pQueryInfo) { invalidSqlErrMsg(pQueryInfo->msg, msg1); } - return isProjectionFunction == true ? TSDB_CODE_INVALID_SQL : TSDB_CODE_SUCCESS; + return isProjectionFunction == true ? TSDB_CODE_TSC_INVALID_SQL : TSDB_CODE_SUCCESS; } typedef struct SDNodeDynConfOption { @@ -4565,7 +4594,7 @@ typedef struct SDNodeDynConfOption { int32_t validateDNodeConfig(tDCLSQL* pOptions) { if (pOptions->nTokens < 2 || pOptions->nTokens > 3) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 17; @@ -4591,7 +4620,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { SSQLToken* pValToken = &pOptions->a[2]; int32_t val = strtol(pValToken->z, NULL, 10); if (val != 0 && val != 1) { - return TSDB_CODE_INVALID_SQL; // options value is invalid + return TSDB_CODE_TSC_INVALID_SQL; // options value is invalid } return TSDB_CODE_SUCCESS; } else { @@ -4600,7 +4629,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { int32_t val = strtol(pValToken->z, NULL, 10); if (val < 131 || val > 199) { /* options value is out of valid range */ - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } for (int32_t i = 2; i < DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1; ++i) { @@ -4613,12 +4642,12 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { } } - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t validateLocalConfig(tDCLSQL* pOptions) { if (pOptions->nTokens < 1 || pOptions->nTokens > 2) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12}, @@ -4640,7 +4669,7 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) { int32_t val = strtol(pValToken->z, NULL, 10); if (val < 131 || val > 199) { // options value is out of valid range - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } for (int32_t i = 1; i < tListLen(LOCAL_DYNAMIC_CFG_OPTIONS); ++i) { @@ -4651,20 +4680,20 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) { } } } - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t validateColumnName(char* name) { bool ret = isKeyWord(name, strlen(name)); if (ret) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SSQLToken token = {.z = name}; token.n = tSQLGetToken(name, &token.type); if (token.type != TK_STRING && token.type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (token.type == TK_STRING) { @@ -4673,13 +4702,13 @@ int32_t validateColumnName(char* name) { int32_t k = tSQLGetToken(token.z, &token.type); if (k != token.n) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return validateColumnName(token.z); } else { if (isNumber(&token)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -4877,15 +4906,15 @@ int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { setCreateDBOption(pMsg, pCreateDbSql); if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (setTimePrecision(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; @@ -5316,7 +5345,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } if (checkUpdateTagPrjFunctions(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } /* @@ -5324,7 +5353,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { * divide the subset of final result. */ if (doAddGroupbyColumnsOnDemand(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // projection query on super table does not compatible with "group by" syntax @@ -5371,20 +5400,15 @@ int32_t doLocalQueryProcess(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { switch (index) { case 0: - pQueryInfo->command = TSDB_SQL_CURRENT_DB; - return TSDB_CODE_SUCCESS; + pQueryInfo->command = TSDB_SQL_CURRENT_DB;break; case 1: - pQueryInfo->command = TSDB_SQL_SERV_VERSION; - return TSDB_CODE_SUCCESS; - case 2: - pQueryInfo->command = TSDB_SQL_SERV_STATUS; - return TSDB_CODE_SUCCESS; + pQueryInfo->command = TSDB_SQL_SERV_VERSION;break; + case 2: + pQueryInfo->command = TSDB_SQL_SERV_STATUS;break; case 3: - pQueryInfo->command = TSDB_SQL_CLI_VERSION; - return TSDB_CODE_SUCCESS; + pQueryInfo->command = TSDB_SQL_CLI_VERSION;break; case 4: - pQueryInfo->command = TSDB_SQL_CURRENT_USER; - return TSDB_CODE_SUCCESS; + pQueryInfo->command = TSDB_SQL_CURRENT_USER;break; default: { return invalidSqlErrMsg(pQueryInfo->msg, msg3); } } @@ -5394,6 +5418,8 @@ int32_t doLocalQueryProcess(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) { const char* name = (pExprList->a[0].aliasName != NULL)? pExprList->a[0].aliasName:functionsInfo[index].name; strncpy(pExpr1->aliasName, name, tListLen(pExpr1->aliasName)); + + return TSDB_CODE_SUCCESS; } // can only perform the parameters based on the macro definitation @@ -5519,7 +5545,7 @@ int32_t doCheckForCreateTable(SSqlObj* pSql, int32_t subClauseIndex, SSqlInfo* p if (!validateTableColumnInfo(pFieldList, pCmd) || (pTagList != NULL && !validateTagParams(pTagList, pFieldList, pCmd))) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t col = 0; @@ -5668,22 +5694,22 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo); if (parseSelectClause(&pSql->cmd, 0, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pQuerySql->pWhere != NULL) { // query condition in stream computing if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } // set interval value if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else { if ((pQueryInfo->intervalTime > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } @@ -5697,13 +5723,13 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { } if (tsRewriteFieldNameIfNecessary(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; if (validateSqlFunctionInStreamSql(pQueryInfo) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } /* @@ -5824,26 +5850,26 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { // parse the group by clause in the first place if (parseGroupbyClause(pQueryInfo, pQuerySql->pGroupby, pCmd) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (parseSelectClause(pCmd, index, pQuerySql->pSelection, isSTable) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set interval value if (parseIntervalClause(pQueryInfo, pQuerySql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else { if ((pQueryInfo->intervalTime > 0) && (validateFunctionsInIntervalOrGroupbyQuery(pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } // set order by info if (parseOrderbyClause(pQueryInfo, pQuerySql, tscGetTableSchema(pTableMetaInfo->pTableMeta)) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // set where info @@ -5851,7 +5877,7 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) { if (pQuerySql->pWhere != NULL) { if (parseWhereClause(pQueryInfo, &pQuerySql->pWhere, pSql) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pQuerySql->pWhere = NULL; @@ -6000,7 +6026,7 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* return TSDB_CODE_SUCCESS; } else { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } else { @@ -6019,9 +6045,9 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* if ((*pExpr)->_node.optr == TSDB_BINARY_OP_DIVIDE) { if (pRight->nodeType == TSQL_NODE_VALUE) { if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64Key == 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } else if (pRight->pVal->nType == TSDB_DATA_TYPE_FLOAT && pRight->pVal->dKey == 0) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index ce36a73bfc..59415f842e 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -131,13 +131,6 @@ SSchema* tscGetTableColumnSchema(const STableMeta* pTableMeta, int32_t startCol) assert(pTableMeta != NULL); SSchema* pSchema = (SSchema*) pTableMeta->schema; -#if 0 - if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - assert (pTableMeta->pSTable != NULL); - pSchema = pTableMeta->pSTable->schema; - } -#endif - return &pSchema[startCol]; } diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 5737564877..5114f97f8f 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -161,7 +161,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscError("%p pMemBuffer is NULL", pMemBuffer); - pRes->code = TSDB_CODE_APP_ERROR; + pRes->code = TSDB_CODE_TSC_APP_ERROR; return; } @@ -169,7 +169,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); tscError("%p no local buffer or intermediate result format model", pSql); - pRes->code = TSDB_CODE_APP_ERROR; + pRes->code = TSDB_CODE_TSC_APP_ERROR; return; } @@ -196,7 +196,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pMemBuffer[0]->pageSize); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); - pRes->code = TSDB_CODE_APP_ERROR; + pRes->code = TSDB_CODE_TSC_APP_ERROR; return; } @@ -207,7 +207,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd tscError("%p failed to create local merge structure, out of memory", pSql); tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, numOfBuffer); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -217,7 +217,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pReducer->numOfBuffer = numOfFlush; pReducer->numOfVnode = numOfBuffer; - + pReducer->pDesc = pDesc; tscTrace("%p the number of merged leaves is: %d", pSql, pReducer->numOfBuffer); @@ -229,7 +229,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd SLocalDataSource *ds = (SLocalDataSource *)malloc(sizeof(SLocalDataSource) + pMemBuffer[0]->pageSize); if (ds == NULL) { tscError("%p failed to create merge structure", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -278,6 +278,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); param->groupOrderType = pQueryInfo->groupbyExpr.orderType; + pReducer->orderPrjOnSTable = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0); pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator); if (pReducer->pLoserTree == NULL || pRes->code != 0) { @@ -309,10 +310,10 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16; pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage)); - int32_t finalRowLength = tscGetResRowLength(pQueryInfo->exprList); + pReducer->finalRowSize = tscGetResRowLength(pQueryInfo->exprList); pReducer->resColModel = finalmodel; - pReducer->resColModel->capacity = pReducer->nResultBufSize / finalRowLength; - assert(finalRowLength <= pReducer->rowSize); + pReducer->resColModel->capacity = pReducer->nResultBufSize / pReducer->finalRowSize; + assert(pReducer->finalRowSize <= pReducer->rowSize); pReducer->pFinalRes = calloc(1, pReducer->rowSize * pReducer->resColModel->capacity); // pReducer->pBufForInterpo = calloc(1, pReducer->nResultBufSize); @@ -326,7 +327,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd // tfree(pReducer->pBufForInterpo); tfree(pReducer->prevRowOfInput); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -389,7 +390,7 @@ static int32_t tscFlushTmpBufferImpl(tExtMemBuffer *pMemoryBuf, tOrderDescriptor assert(pPage->num <= pDesc->pColumnModel->capacity); // sort before flush to disk, the data must be consecutively put on tFilePage. - if (pDesc->orderIdx.numOfCols > 0) { + if (pDesc->orderInfo.numOfCols > 0) { tColDataQSort(pDesc, pPage->num, 0, pPage->num - 1, pPage->data, orderType); } @@ -560,7 +561,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm int32_t *orderIdx = (int32_t *)calloc(numOfGroupByCols, sizeof(int32_t)); if (orderIdx == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } if (numOfGroupByCols > 0) { @@ -581,7 +582,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm tfree(orderIdx); if (*pOrderDesc == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } else { return TSDB_CODE_SUCCESS; } @@ -590,12 +591,10 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage *tmpBuffer) { SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); - int16_t functionId = tscSqlExprGet(pQueryInfo, 0)->functionId; - // disable merge procedure for column projection query + int16_t functionId = pReducer->pCtx[0].functionId; assert(functionId != TSDB_FUNC_ARITHM); - - if (tscOrderedProjectionQueryOnSTable(pQueryInfo, 0)) { + if (pReducer->orderPrjOnSTable) { return true; } @@ -604,26 +603,33 @@ bool isSameGroup(SSqlCmd *pCmd, SLocalReducer *pReducer, char *pPrev, tFilePage } tOrderDescriptor *pOrderDesc = pReducer->pDesc; - int32_t numOfCols = pOrderDesc->orderIdx.numOfCols; - + SColumnOrderInfo* orderInfo = &pOrderDesc->orderInfo; + // no group by columns, all data belongs to one group + int32_t numOfCols = orderInfo->numOfCols; if (numOfCols <= 0) { return true; } - if (pOrderDesc->orderIdx.pData[numOfCols - 1] == PRIMARYKEY_TIMESTAMP_COL_INDEX) { //<= 0 - // super table interval query + if (orderInfo->pData[numOfCols - 1] == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + /* + * super table interval query + * if the order columns is the primary timestamp, all result data belongs to one group + */ assert(pQueryInfo->intervalTime > 0); - pOrderDesc->orderIdx.numOfCols -= 1; + if (numOfCols == 1) { + return true; + } } else { // simple group by query assert(pQueryInfo->intervalTime == 0); } // only one row exists - int32_t ret = compare_a(pOrderDesc, 1, 0, pPrev, 1, 0, tmpBuffer->data); - pOrderDesc->orderIdx.numOfCols = numOfCols; - - return (ret == 0); + int32_t index = orderInfo->pData[0]; + int32_t offset = (pOrderDesc->pColumnModel)->pFields[index].offset; + + int32_t ret = memcmp(pPrev + offset, tmpBuffer->data + offset, pOrderDesc->pColumnModel->rowSize - offset); + return ret == 0; } int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOrderDescriptor **pOrderDesc, @@ -641,7 +647,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr (*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pSql->numOfSubs); if (*pMemBuffer == NULL) { tscError("%p failed to allocate memory", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } @@ -650,7 +656,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr pSchema = (SSchema *)calloc(1, sizeof(SSchema) * size); if (pSchema == NULL) { tscError("%p failed to allocate memory", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } @@ -678,7 +684,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr } if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } @@ -873,24 +879,24 @@ static void reversedCopyFromInterpolationToDstBuf(SQueryInfo *pQueryInfo, SSqlRe * Note: pRes->pLocalReducer may be null, due to the fact that "tscDestroyLocalReducer" is called * by "interuptHandler" function in shell */ -static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneOutput) { +static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneOutput) { SSqlCmd * pCmd = &pSql->cmd; SSqlRes * pRes = &pSql->res; tFilePage * pFinalDataPage = pLocalReducer->pResultBuf; SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); - if (pRes->pLocalReducer != pLocalReducer) { - /* - * Release the SSqlObj is called, and it is int destroying function invoked by other thread. - * However, the other thread will WAIT until current process fully completes. - * Since the flag of release struct is set by doLocalReduce function - */ - assert(pRes->pLocalReducer == NULL); - } +// if (pRes->pLocalReducer != pLocalReducer) { +// /* +// * Release the SSqlObj is called, and it is int destroying function invoked by other thread. +// * However, the other thread will WAIT until current process fully completes. +// * Since the flag of release struct is set by doLocalReduce function +// */ +// assert(pRes->pLocalReducer == NULL); +// } + // no interval query, no fill operation if (pQueryInfo->intervalTime == 0 || pQueryInfo->fillType == TSDB_FILL_NONE) { - // no interval query, no fill operation pRes->data = pLocalReducer->pFinalRes; pRes->numOfRows = pFinalDataPage->num; pRes->numOfClauseTotal += pRes->numOfRows; @@ -929,9 +935,7 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo savePrevRecordAndSetupInterpoInfo(pLocalReducer, pQueryInfo, pLocalReducer->pFillInfo); } - int32_t rowSize = tscGetResRowLength(pQueryInfo->exprList); - memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * rowSize); - + memcpy(pRes->data, pFinalDataPage->data, pRes->numOfRows * pLocalReducer->finalRowSize); pFinalDataPage->num = 0; return; } @@ -1037,16 +1041,13 @@ static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, bool needInit) { // the tag columns need to be set before all functions execution SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); + size_t size = tscSqlExprNumOfExprs(pQueryInfo); - for (int32_t j = 0; j < size; ++j) { - SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, j); SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[j]; - tVariantAssign(&pCtx->param[0], &pExpr->param[0]); - // tags/tags_dummy function, the tag field of SQLFunctionCtx is from the input buffer - int32_t functionId = pExpr->functionId; + int32_t functionId = pCtx->functionId; if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS_DUMMY) { tVariantDestroy(&pCtx->tag); char* input = pCtx->aInputElemBuf; @@ -1057,17 +1058,20 @@ static void doExecuteSecondaryMerge(SSqlCmd *pCmd, SLocalReducer *pLocalReducer, } else { tVariantCreateFromBinary(&pCtx->tag, input, pCtx->inputBytes, pCtx->inputType); } + } else if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) { + SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, j); + pCtx->param[0].i64Key = pExpr->param[0].i64Key; } pCtx->currentStage = SECONDARY_STAGE_MERGE; if (needInit) { - aAggs[pExpr->functionId].init(pCtx); + aAggs[pCtx->functionId].init(pCtx); } } for (int32_t j = 0; j < size; ++j) { - int32_t functionId = tscSqlExprGet(pQueryInfo, j)->functionId; + int32_t functionId = pLocalReducer->pCtx[j].functionId; if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { continue; } @@ -1101,8 +1105,7 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx) * ts, tag, tagprj function can not decide the output number of current query * the number of output result is decided by main output */ - SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, j); - int32_t functionId = pExpr->functionId; + int32_t functionId = pCtx[j].functionId; if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ) { continue; } @@ -1136,15 +1139,13 @@ static void fillMultiRowsOfTagsVal(SQueryInfo *pQueryInfo, int32_t numOfRes, SLo char *buf = malloc((size_t)maxBufSize); for (int32_t k = 0; k < size; ++k) { - SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k); - if (pExpr->functionId != TSDB_FUNC_TAG) { + SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k]; + if (pCtx->functionId != TSDB_FUNC_TAG) { continue; } int32_t inc = numOfRes - 1; // tsdb_func_tag function only produce one row of result memset(buf, 0, (size_t)maxBufSize); - - SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k]; memcpy(buf, pCtx->aOutputBuf, (size_t)pCtx->outputBytes); for (int32_t i = 0; i < inc; ++i) { @@ -1160,8 +1161,8 @@ int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) { size_t size = tscSqlExprNumOfExprs(pQueryInfo); for (int32_t k = 0; k < size; ++k) { - SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, k); - aAggs[pExpr->functionId].xFinalize(&pLocalReducer->pCtx[k]); + SQLFunctionCtx* pCtx = &pLocalReducer->pCtx[k]; + aAggs[pCtx->functionId].xFinalize(pCtx); } pLocalReducer->hasPrevRow = false; @@ -1182,13 +1183,13 @@ int32_t finalizeRes(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer) { */ bool needToMerge(SQueryInfo *pQueryInfo, SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) { int32_t ret = 0; // merge all result by default - int16_t functionId = tscSqlExprGet(pQueryInfo, 0)->functionId; - + + int16_t functionId = pLocalReducer->pCtx[0].functionId; if (functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_ARITHM) { // column projection query ret = 1; // disable merge procedure } else { tOrderDescriptor *pDesc = pLocalReducer->pDesc; - if (pDesc->orderIdx.numOfCols > 0) { + if (pDesc->orderInfo.numOfCols > 0) { if (pDesc->tsOrder == TSDB_ORDER_ASC) { // asc // todo refactor comparator ret = compare_a(pLocalReducer->pDesc, 1, 0, pLocalReducer->prevRowOfInput, 1, 0, tmpBuffer->data); @@ -1274,7 +1275,7 @@ bool doGenerateFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool no taosFillCopyInputDataFromOneFilePage(pFillInfo, pResBuf); } - doInterpolateResult(pSql, pLocalReducer, noMoreCurrentGroupRes); + doFillResult(pSql, pLocalReducer, noMoreCurrentGroupRes); return true; } @@ -1341,7 +1342,7 @@ static bool doBuildFilledResultForGroup(SSqlObj *pSql) { // the first column must be the timestamp column int32_t rows = taosGetNumOfResultWithFill(pFillInfo, remain, ekey, pLocalReducer->resColModel->capacity); if (rows > 0) { // do interpo - doInterpolateResult(pSql, pLocalReducer, false); + doFillResult(pSql, pLocalReducer, false); } return true; @@ -1374,7 +1375,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) { pQueryInfo->slidingTimeUnit, tinfo.precision); int32_t rows = taosGetNumOfResultWithFill(pFillInfo, 0, etime, pLocalReducer->resColModel->capacity); if (rows > 0) { // do interpo - doInterpolateResult(pSql, pLocalReducer, true); + doFillResult(pSql, pLocalReducer, true); } } @@ -1408,13 +1409,11 @@ static void doProcessResultInNextWindow(SSqlObj *pSql, int32_t numOfRes) { size_t size = tscSqlExprNumOfExprs(pQueryInfo); for (int32_t k = 0; k < size; ++k) { - SSqlExpr * pExpr = tscSqlExprGet(pQueryInfo, k); SQLFunctionCtx *pCtx = &pLocalReducer->pCtx[k]; - pCtx->aOutputBuf += pCtx->outputBytes * numOfRes; // set the correct output timestamp column position - if (pExpr->functionId == TSDB_FUNC_TOP || pExpr->functionId == TSDB_FUNC_BOTTOM) { + if (pCtx->functionId == TSDB_FUNC_TOP || pCtx->functionId == TSDB_FUNC_BOTTOM) { pCtx->ptsOutputBuf = ((char *)pCtx->ptsOutputBuf + TSDB_KEYSIZE * numOfRes); } } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index defb49c573..2b0f0a4919 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -114,6 +114,8 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { if (pIpList->numOfIps > 0) tscSetMgmtIpList(pIpList); + pSql->pTscObj->connId = htonl(pRsp->connId); + if (pRsp->killConnection) { tscKillConnection(pObj); } else { @@ -177,7 +179,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { char *pMsg = rpcMallocCont(pCmd->payloadLen); if (NULL == pMsg) { tscError("%p msg:%s malloc fail", pSql, taosMsg[pSql->cmd.msgType]); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } if (pSql->cmd.command < TSDB_SQL_MGMT) { @@ -232,11 +234,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { } if (rpcMsg->pCont == NULL) { - rpcMsg->code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; } else { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - if (rpcMsg->code == TSDB_CODE_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_INVALID_VGROUP_ID || - rpcMsg->code == TSDB_CODE_NETWORK_UNAVAIL) { + if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID || + rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { /* * not_active_table: 1. the virtual node may fail to create table, since the procedure of create table is asynchronized, * the virtual node may have not create table till now, so try again by using the new metermeta. @@ -248,11 +250,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { * not_active_session: db has been move to other node, the vnode does not exist on this dnode anymore. */ if (pCmd->command == TSDB_SQL_CONNECT) { - rpcMsg->code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcFreeCont(rpcMsg->pCont); return; } else if (pCmd->command == TSDB_SQL_HB) { - rpcMsg->code = TSDB_CODE_NOT_READY; + rpcMsg->code = TSDB_CODE_RPC_NOT_READY; rpcFreeCont(rpcMsg->pCont); return; } else if (pCmd->command == TSDB_SQL_META) { @@ -279,8 +281,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { pRes->rspLen = 0; - if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { - pRes->code = (rpcMsg->code != TSDB_CODE_SUCCESS) ? rpcMsg->code : TSDB_CODE_NETWORK_UNAVAIL; + if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) { + pRes->code = (rpcMsg->code != TSDB_CODE_SUCCESS) ? rpcMsg->code : TSDB_CODE_RPC_NETWORK_UNAVAIL; } else { tscTrace("%p query is cancelled, code:%d", pSql, tstrerror(pRes->code)); } @@ -290,7 +292,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { pSql->retry = 0; } - if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { + if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) { assert(rpcMsg->msgType == pCmd->msgType + 1); pRes->code = rpcMsg->code; pRes->rspType = rpcMsg->msgType; @@ -299,7 +301,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { if (pRes->rspLen > 0 && rpcMsg->pCont) { char *tmp = (char *)realloc(pRes->pRsp, pRes->rspLen); if (tmp == NULL) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; } else { pRes->pRsp = tmp; memcpy(pRes->pRsp, rpcMsg->pCont, pRes->rspLen); @@ -331,10 +333,10 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); - if (rpcMsg->code != TSDB_CODE_ACTION_IN_PROGRESS) { - rpcMsg->code = pRes->code ? pRes->code : pRes->numOfRows; + + if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? pRes->numOfRows: pRes->code; - tscTrace("%p SQL result:%s res:%p", pSql, tstrerror(pRes->code), pSql); bool shouldFree = tscShouldBeFreed(pSql); (*pSql->fp)(pSql->param, pSql, rpcMsg->code); @@ -400,7 +402,7 @@ int tscProcessSql(SSqlObj *pSql) { tscTrace("%p SQL cmd:%s will be processed, name:%s, type:%d", pSql, sqlCmd[pCmd->command], name, type); if (pCmd->command < TSDB_SQL_MGMT) { // the pTableMetaInfo cannot be NULL if (pTableMetaInfo == NULL) { - pSql->res.code = TSDB_CODE_OTHERS; + pSql->res.code = TSDB_CODE_TSC_APP_ERROR; return pSql->res.code; } } else if (pCmd->command < TSDB_SQL_LOCAL) { @@ -431,7 +433,7 @@ void tscKillSTableQuery(SSqlObj *pSql) { * here, we cannot set the command = TSDB_SQL_KILL_QUERY. Otherwise, it may cause * sub-queries not correctly released and master sql object of metric query reaches an abnormal state. */ - pSql->pSubs[i]->res.code = TSDB_CODE_QUERY_CANCELLED; + pSql->pSubs[i]->res.code = TSDB_CODE_TSC_QUERY_CANCELLED; //taosStopRpcConn(pSql->pSubs[i]->thandle); } @@ -604,7 +606,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for query msg", pSql); - return -1; + return -1; // todo add test for this } SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); @@ -676,7 +678,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex, pColSchema->name); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } pQueryMsg->colList[i].colId = htons(pColSchema->colId); @@ -794,7 +796,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns, pCol->colIndex, pColSchema->name); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } SColumnInfo* pTagCol = (SColumnInfo*) pMsg; @@ -884,7 +886,7 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = sizeof(SCMCreateDnodeMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload; @@ -900,7 +902,7 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = sizeof(SCMCreateAcctMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMCreateAcctMsg *pAlterMsg = (SCMCreateAcctMsg *)pCmd->payload; @@ -946,7 +948,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMCreateUserMsg *pAlterMsg = (SCMCreateUserMsg*)pCmd->payload; @@ -985,7 +987,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload; @@ -1004,7 +1006,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropTableMsg *pDropTableMsg = (SCMDropTableMsg*)pCmd->payload; @@ -1021,7 +1023,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = sizeof(SCMDropDnodeMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload; @@ -1039,7 +1041,7 @@ int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; @@ -1056,7 +1058,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; @@ -1072,7 +1074,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMUseDbMsg *pUseDbMsg = (SCMUseDbMsg*)pCmd->payload; @@ -1091,7 +1093,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMShowMsg *pShowMsg = (SCMShowMsg*)pCmd->payload; @@ -1129,13 +1131,6 @@ int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCMKillQueryMsg); - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { - tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; - } - - SCMKillQueryMsg *pKill = (SCMKillQueryMsg*)pCmd->payload; - strncpy(pKill->queryId, pInfo->pDCLInfo->ip.z, pInfo->pDCLInfo->ip.n); switch (pCmd->command) { case TSDB_SQL_KILL_QUERY: pCmd->msgType = TSDB_MSG_TYPE_CM_KILL_QUERY; @@ -1182,7 +1177,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size = tscEstimateCreateTableMsgLength(pSql, pInfo); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for create table msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1327,7 +1322,7 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); @@ -1397,22 +1392,9 @@ int tscProcessDescribeTableRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, numOfRes); } -int tscProcessTagRetrieveRsp(SSqlObj *pSql) { -// SSqlCmd *pCmd = &pSql->cmd; - -// SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); -// STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - - int32_t numOfRes = 0; -#if 0 - if (tscSqlExprGet(pQueryInfo, 0)->functionId == TSDB_FUNC_TAGPRJ) { - numOfRes = pTableMetaInfo->pMetricMeta->numOfTables; - } else { - numOfRes = 1; // for count function, there is only one output. - } - -#endif - +int tscProcessLocalRetrieveRsp(SSqlObj *pSql) { + int32_t numOfRes = 1; + pSql->res.completed = true; return tscLocalResultCommonBuilder(pSql, numOfRes); } @@ -1450,7 +1432,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("%p failed to malloc for query msg", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } SCMConnectMsg *pConnect = (SCMConnectMsg*)pCmd->payload; @@ -1475,7 +1457,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (len > 0) { tmpData = calloc(1, len); if (NULL == tmpData) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } // STagData is in binary format, strncpy is not available @@ -1743,57 +1725,43 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_SUCCESS; } -int tscEstimateHeartBeatMsgLength(SSqlObj *pSql) { - int size = 0; - STscObj *pObj = pSql->pTscObj; - - size += tsRpcHeadSize; - size += sizeof(SQqueryList); - - SSqlObj *tpSql = pObj->sqlList; - while (tpSql) { - size += sizeof(SQueryDesc); - tpSql = tpSql->next; - } - - size += sizeof(SStreamList); - SSqlStream *pStream = pObj->streamList; - while (pStream) { - size += sizeof(SStreamDesc); - pStream = pStream->next; - } - - return size + TSDB_EXTRA_PAYLOAD_SIZE; -} - int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - char *pMsg, *pStart; - int msgLen = 0; - int size = 0; - SSqlCmd *pCmd = &pSql->cmd; STscObj *pObj = pSql->pTscObj; pthread_mutex_lock(&pObj->mutex); - size = tscEstimateHeartBeatMsgLength(pSql); + int32_t numOfQueries = 2; + SSqlObj *tpSql = pObj->sqlList; + while (tpSql) { + tpSql = tpSql->next; + numOfQueries++; + } + + int32_t numOfStreams = 2; + SSqlStream *pStream = pObj->streamList; + while (pStream) { + pStream = pStream->next; + numOfStreams++; + } + + int size = numOfQueries * sizeof(SQueryDesc) + numOfStreams * sizeof(SStreamDesc) + sizeof(SCMHeartBeatMsg) + 100; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { pthread_mutex_unlock(&pObj->mutex); tscError("%p failed to malloc for heartbeat msg", pSql); return -1; } - pMsg = pCmd->payload; - pStart = pMsg; + SCMHeartBeatMsg *pHeartbeat = (SCMHeartBeatMsg *)pCmd->payload; + pHeartbeat->numOfQueries = numOfQueries; + pHeartbeat->numOfStreams = numOfStreams; + int msgLen = tscBuildQueryStreamDesc(pHeartbeat, pObj); - pMsg = tscBuildQueryStreamDesc(pMsg, pObj); pthread_mutex_unlock(&pObj->mutex); - msgLen = pMsg - pStart; pCmd->payloadLen = msgLen; pCmd->msgType = TSDB_MSG_TYPE_CM_HEARTBEAT; - assert(msgLen + minMsgSize() <= size); return TSDB_CODE_SUCCESS; } @@ -1811,17 +1779,17 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { if (pMetaMsg->sid < 0 || pMetaMsg->vgroup.numOfIps < 0) { tscError("invalid meter vgId:%d, sid%d", pMetaMsg->vgroup.numOfIps, pMetaMsg->sid); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } if (pMetaMsg->numOfTags > TSDB_MAX_TAGS || pMetaMsg->numOfTags < 0) { tscError("invalid numOfTags:%d", pMetaMsg->numOfTags); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } if (pMetaMsg->numOfColumns > TSDB_MAX_COLUMNS || pMetaMsg->numOfColumns <= 0) { tscError("invalid numOfColumns:%d", pMetaMsg->numOfColumns); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_TSC_INVALID_VALUE; } for (int i = 0; i < pMetaMsg->vgroup.numOfIps; ++i) { @@ -1851,7 +1819,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { // todo handle out of memory case if (pTableMetaInfo->pTableMeta == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } tscTrace("%p recv table meta: %"PRId64 ", tid:%d, name:%s", pSql, pTableMeta->uid, pTableMeta->sid, pTableMetaInfo->name); @@ -1872,9 +1840,9 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) { ieType = *rsp; if (ieType != TSDB_IE_TYPE_META) { tscError("invalid ie type:%d", ieType); - pSql->res.code = TSDB_CODE_INVALID_IE; + pSql->res.code = TSDB_CODE_TSC_INVALID_IE; pSql->res.numOfTotal = 0; - return TSDB_CODE_OTHERS; + return TSDB_CODE_TSC_APP_ERROR; } rsp++; @@ -1894,32 +1862,32 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) { if (pMeta->sid <= 0 || pMeta->vgId < 0) { tscError("invalid meter vgId:%d, sid%d", pMeta->vgId, pMeta->sid); - pSql->res.code = TSDB_CODE_INVALID_VALUE; + pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; pSql->res.numOfTotal = i; - return TSDB_CODE_OTHERS; + return TSDB_CODE_TSC_APP_ERROR; } // pMeta->numOfColumns = htons(pMeta->numOfColumns); // // if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) { // tscError("invalid tag value count:%d", pMeta->numOfTags); - // pSql->res.code = TSDB_CODE_INVALID_VALUE; + // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; // pSql->res.numOfTotal = i; - // return TSDB_CODE_OTHERS; + // return TSDB_CODE_TSC_APP_ERROR; // } // // if (pMeta->numOfTags > TSDB_MAX_TAGS || pMeta->numOfTags < 0) { // tscError("invalid numOfTags:%d", pMeta->numOfTags); - // pSql->res.code = TSDB_CODE_INVALID_VALUE; + // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; // pSql->res.numOfTotal = i; - // return TSDB_CODE_OTHERS; + // return TSDB_CODE_TSC_APP_ERROR; // } // // if (pMeta->numOfColumns > TSDB_MAX_COLUMNS || pMeta->numOfColumns < 0) { // tscError("invalid numOfColumns:%d", pMeta->numOfColumns); - // pSql->res.code = TSDB_CODE_INVALID_VALUE; + // pSql->res.code = TSDB_CODE_TSC_INVALID_VALUE; // pSql->res.numOfTotal = i; - // return TSDB_CODE_OTHERS; + // return TSDB_CODE_TSC_APP_ERROR; // } // // for (int j = 0; j < TSDB_REPLICA_MAX_NUM; ++j) { @@ -1984,7 +1952,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { if (metricMetaList == NULL || sizes == NULL) { tfree(metricMetaList); tfree(sizes); - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pSql->res.code; } @@ -2003,7 +1971,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { char *pBuf = calloc(1, size); if (pBuf == NULL) { - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error_clean; } @@ -2063,7 +2031,7 @@ int tscProcessSTableVgroupRsp(SSqlObj *pSql) { // failed to put into cache if (pTableMetaInfo->pMetricMeta == NULL) { - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error_clean; } } @@ -2204,6 +2172,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { strcpy(pObj->sversion, pConnect->serverVersion); pObj->writeAuth = pConnect->writeAuth; pObj->superAuth = pConnect->superAuth; + pObj->connId = htonl(pConnect->connId); taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, pObj, tscTmr, &pObj->pTimer); return 0; @@ -2330,7 +2299,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { } pRes->row = 0; - tscTrace("%p numOfRows:%d, offset:%d", pSql, pRes->numOfRows, pRes->offset); + tscTrace("%p numOfRows:%d, offset:%d, complete:%d", pSql, pRes->numOfRows, pRes->offset, pRes->completed); return 0; } @@ -2356,7 +2325,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); if (NULL == pNew) { tscError("%p malloc failed for new sqlobj to get table meta", pSql); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pNew->pTscObj = pSql->pTscObj; @@ -2373,7 +2342,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf tscError("%p malloc failed for payload to get table meta", pSql); free(pNew); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } STableMetaInfo *pNewMeterMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo); @@ -2389,7 +2358,7 @@ static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInf int32_t code = tscProcessSql(pNew); if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_ACTION_IN_PROGRESS; + code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; } return code; @@ -2486,7 +2455,7 @@ static bool allVgroupInfoRetrieved(SSqlCmd* pCmd, int32_t clauseIndex) { } int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { - int code = TSDB_CODE_NETWORK_UNAVAIL; + int code = TSDB_CODE_RPC_NETWORK_UNAVAIL; SSqlCmd *pCmd = &pSql->cmd; if (allVgroupInfoRetrieved(pCmd, clauseIndex)) { @@ -2523,7 +2492,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { pNew->param = pSql; code = tscProcessSql(pNew); if (code == TSDB_CODE_SUCCESS) { - code = TSDB_CODE_ACTION_IN_PROGRESS; + code = TSDB_CODE_TSC_ACTION_IN_PROGRESS; } return code; @@ -2581,11 +2550,11 @@ void tscInitMsgsFp() { tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; - tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessTagRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessTagRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessTagRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessTagRetrieveRsp; - tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessTagRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessLocalRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessLocalRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessLocalRetrieveRsp; + tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessLocalRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 5ff417f7d5..aab931cf93 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -57,12 +57,12 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con taos_init(); if (!validUserName(user)) { - terrno = TSDB_CODE_INVALID_ACCT; + terrno = TSDB_CODE_TSC_INVALID_USER_LENGTH; return NULL; } if (!validPassword(pass)) { - terrno = TSDB_CODE_INVALID_PASS; + terrno = TSDB_CODE_TSC_INVALID_PASS_LENGTH; return NULL; } @@ -73,13 +73,13 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con void *pDnodeConn = NULL; if (tscInitRpc(user, pass, &pDnodeConn) != 0) { - terrno = TSDB_CODE_NETWORK_UNAVAIL; + terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); return NULL; } @@ -88,13 +88,12 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con strncpy(pObj->user, user, TSDB_USER_LEN); taosEncryptPass((uint8_t *)pass, strlen(pass), pObj->pass); - pObj->mnodePort = port ? port : tsDnodeShellPort; if (db) { int32_t len = strlen(db); /* db name is too long */ if (len > TSDB_DB_NAME_LEN) { - terrno = TSDB_CODE_INVALID_DB; + terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; rpcClose(pDnodeConn); free(pObj); return NULL; @@ -111,7 +110,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (NULL == pSql) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); free(pObj); return NULL; @@ -132,7 +131,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pSql->cmd.command = TSDB_SQL_CONNECT; if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; rpcClose(pDnodeConn); free(pSql); free(pObj); @@ -213,48 +212,6 @@ void taos_close(TAOS *taos) { } } -int taos_query_imp(STscObj *pObj, SSqlObj *pSql) { - SSqlRes *pRes = &pSql->res; - SSqlCmd *pCmd = &pSql->cmd; - - pRes->numOfRows = 1; - pRes->numOfTotal = 0; - pRes->numOfClauseTotal = 0; - - pCmd->curSql = NULL; - if (NULL != pCmd->pTableList) { - taosHashCleanup(pCmd->pTableList); - pCmd->pTableList = NULL; - } - - tscDump("%p pObj:%p, SQL: %s", pSql, pObj, pSql->sqlstr); - - pRes->code = (uint8_t)tsParseSql(pSql, false); - - /* - * set the qhandle to 0 before return in order to erase the qhandle value assigned in the previous successful query. - * If qhandle is NOT set 0, the function of taos_free_result() will send message to server by calling tscProcessSql() - * to free connection, which may cause segment fault, when the parse phrase is not even successfully executed. - */ - pRes->qhandle = 0; - - if (pRes->code == TSDB_CODE_SUCCESS) { - tscDoQuery(pSql); - } - - if (pRes->code == TSDB_CODE_SUCCESS) { - tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj); - } else { - tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj); - } - - if (pRes->code != TSDB_CODE_SUCCESS) { - tscPartiallyFreeSqlObj(pSql); - } - - return pRes->code; -} - void waitForQueryRsp(void *param, TAOS_RES *tres, int code) { assert(tres != NULL); @@ -265,14 +222,14 @@ void waitForQueryRsp(void *param, TAOS_RES *tres, int code) { TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } int32_t sqlLen = strlen(sqlstr); if (sqlLen > tsMaxSQLStringLen) { tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); - terrno = TSDB_CODE_INVALID_SQL; + terrno = TSDB_CODE_TSC_INVALID_SQL; return NULL; } @@ -281,7 +238,7 @@ TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { tscError("failed to malloc sqlObj"); - terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return NULL; } @@ -414,17 +371,13 @@ int taos_fetch_block_impl(TAOS_RES *res, TAOS_ROW *rows) { static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) { SSqlObj* pSql = (SSqlObj*) tres; - - if (numOfRows < 0) { // set the error code - pSql->res.code = -numOfRows; - } sem_post(&pSql->rspSem); } TAOS_ROW taos_fetch_row(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } @@ -445,7 +398,12 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || pCmd->command == TSDB_SQL_SELECT || - pCmd->command == TSDB_SQL_DESCRIBE_TABLE)) { + pCmd->command == TSDB_SQL_DESCRIBE_TABLE || + pCmd->command == TSDB_SQL_SERV_STATUS || + pCmd->command == TSDB_SQL_CURRENT_DB || + pCmd->command == TSDB_SQL_SERV_VERSION || + pCmd->command == TSDB_SQL_CLI_VERSION || + pCmd->command == TSDB_SQL_CURRENT_USER )) { taos_fetch_rows_a(res, waitForRetrieveRsp, pSql->pTscObj); sem_wait(&pSql->rspSem); } @@ -462,7 +420,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int nRows = 0; if (pSql == NULL || pSql->signature != pSql) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; *rows = NULL; return 0; } @@ -505,8 +463,8 @@ int taos_select_db(TAOS *taos, const char *db) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } snprintf(sql, tListLen(sql), "use %s", db); @@ -587,7 +545,7 @@ int taos_errno(TAOS_RES *tres) { * why the sql is invalid */ static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) { - if (code != TSDB_CODE_INVALID_SQL) { + if (code != TSDB_CODE_TSC_INVALID_SQL) { return false; } @@ -649,7 +607,7 @@ void taos_stop_query(TAOS_RES *res) { if (pSql->signature != pSql) return; tscTrace("%p start to cancel query", res); - pSql->res.code = TSDB_CODE_QUERY_CANCELLED; + pSql->res.code = TSDB_CODE_TSC_QUERY_CANCELLED; SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) { @@ -734,8 +692,8 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) int taos_validate_sql(TAOS *taos, const char *sql) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); @@ -752,13 +710,13 @@ int taos_validate_sql(TAOS *taos, const char *sql) { int32_t sqlLen = strlen(sql); if (sqlLen > tsMaxSQLStringLen) { tscError("%p sql too long", pSql); - pRes->code = TSDB_CODE_INVALID_SQL; + pRes->code = TSDB_CODE_TSC_INVALID_SQL; return pRes->code; } pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); if (pSql->sqlstr == NULL) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); return pRes->code; @@ -790,7 +748,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t pCmd->command = TSDB_SQL_MULTI_META; pCmd->count = 0; - int code = TSDB_CODE_INVALID_TABLE_ID; + int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)tblNameList; SQueryInfo *pQueryInfo = NULL; @@ -824,7 +782,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t // Check if the table name available or not if (tscValidateName(&sToken) != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_INVALID_TABLE_ID; + code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "table name is invalid"); return code; } @@ -834,7 +792,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t } if (++pCmd->count > TSDB_MULTI_METERMETA_MAX_NUM) { - code = TSDB_CODE_INVALID_TABLE_ID; + code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; sprintf(pCmd->payload, "tables over the max number"); return code; } @@ -842,7 +800,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) { char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen); if (pNewMem == NULL) { - code = TSDB_CODE_CLI_OUT_OF_MEMORY; + code = TSDB_CODE_TSC_OUT_OF_MEMORY; sprintf(pCmd->payload, "failed to allocate memory"); return code; } @@ -866,8 +824,8 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); @@ -884,13 +842,13 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { int32_t tblListLen = strlen(tableNameList); if (tblListLen > MAX_TABLE_NAME_LENGTH) { tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH); - pRes->code = TSDB_CODE_INVALID_SQL; + pRes->code = TSDB_CODE_TSC_INVALID_SQL; return pRes->code; } char *str = calloc(1, tblListLen + 1); if (str == NULL) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); return pRes->code; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9e1628bb9b..4e92e9dd70 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -77,13 +77,13 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) { int code = tscGetTableMeta(pSql, pTableMetaInfo); pSql->res.code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; if (code == 0 && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscGetSTableVgroupInfo(pSql, 0); pSql->res.code = code; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) return; } tscTansformSQLFuncForSTableQuery(pQueryInfo); @@ -480,7 +480,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); + setErrorInfo(pSql, TSDB_CODE_TSC_OUT_OF_MEMORY, NULL); return NULL; } @@ -497,7 +497,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p pSql->sqlstr = strdup(sqlstr); if (pSql->sqlstr == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); + setErrorInfo(pSql, TSDB_CODE_TSC_OUT_OF_MEMORY, NULL); tfree(pSql); return NULL; @@ -512,7 +512,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE); if (TSDB_CODE_SUCCESS != ret) { setErrorInfo(pSql, ret, NULL); - tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_CLI_OUT_OF_MEMORY); + tscError("%p open stream failed, sql:%s, code:%d", pSql, sqlstr, TSDB_CODE_TSC_OUT_OF_MEMORY); tscFreeSqlObj(pSql); return NULL; } @@ -530,7 +530,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p SSqlStream *pStream = (SSqlStream *)calloc(1, sizeof(SSqlStream)); if (pStream == NULL) { - setErrorInfo(pSql, TSDB_CODE_CLI_OUT_OF_MEMORY, NULL); + setErrorInfo(pSql, TSDB_CODE_TSC_OUT_OF_MEMORY, NULL); tscError("%p open stream failed, sql:%s, reason:%s, code:%d", pSql, sqlstr, pCmd->payload, pRes->code); tscFreeSqlObj(pSql); diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index f6cbe4a42e..9baf49ff21 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -124,7 +124,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* strtolower(pSql->sqlstr, pSql->sqlstr); code = tsParseSql(pSql, false); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore sem_wait(&pSql->rspSem); code = pSql->res.code; @@ -148,7 +148,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* pSub->topic[sizeof(pSub->topic) - 1] = 0; pSub->progress = taosArrayInit(32, sizeof(SSubscriptionProgress)); if (pSub->progress == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } CLEANUP_EXECUTE(); @@ -324,7 +324,7 @@ void tscSaveSubscriptionProgress(void* sub) { TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { - terrno = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("connection disconnected"); return NULL; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 1fdbd43408..84daf63b42 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -348,7 +348,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { //prepare the subqueries object failed, abort if (!success) { - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql, pSql->numOfSubs, pSql->res.code); freeJoinSubqueryObj(pSql); @@ -698,7 +698,7 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) { if (pBuf == NULL) { tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows); - pSupporter->pState->code = TSDB_CODE_APP_ERROR; // todo set the informative code + pSupporter->pState->code = TSDB_CODE_TSC_APP_ERROR; // todo set the informative code quitAllSubquery(pParentSql, pSupporter); return; } @@ -1019,13 +1019,13 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter if (pSql->pSubs == NULL) { pSql->pSubs = calloc(pSupporter->pState->numOfTotal, POINTER_BYTES); if (pSql->pSubs == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } SSqlObj *pNew = createSubqueryObj(pSql, tableIndex, tscJoinQueryCallback, pSupporter, TSDB_SQL_SELECT, NULL); if (pNew == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pSql->pSubs[pSql->numOfSubs++] = pNew; @@ -1163,7 +1163,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { if (pSupporter == NULL) { // failed to create support struct, abort current query tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i); pState->numOfCompleted = pQueryInfo->numOfTables - i - 1; - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pSql->res.code; } @@ -1171,7 +1171,7 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) { int32_t code = tscLaunchJoinSubquery(pSql, i, pSupporter); if (code != TSDB_CODE_SUCCESS) { // failed to create subquery object, quit query tscDestroyJoinSupporter(pSupporter); - pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY; break; } @@ -1209,7 +1209,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; // pRes->code check only serves in launching metric sub-queries - if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { + if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function. return pRes->code; } @@ -1230,7 +1230,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { int32_t ret = tscLocalReducerEnvCreate(pSql, &pMemoryBuf, &pDesc, &pModel, nBufferSize); if (ret != 0) { - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscQueueAsyncRes(pSql); return ret; } @@ -1291,14 +1291,14 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { if (i < pSql->numOfSubs) { tscError("%p failed to prepare subquery structure and launch subqueries", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs); doCleanupSubqueries(pSql, i, pState); return pRes->code; // free all allocated resource } - if (pRes->code == TSDB_CODE_QUERY_CANCELLED) { + if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { tscLocalReducerEnvDestroy(pMemoryBuf, pDesc, pModel, pSql->numOfSubs); doCleanupSubqueries(pSql, i, pState); return pRes->code; @@ -1369,7 +1369,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO /* * kill current sub-query connection, which may retrieve data from vnodes; - * Here we get: pPObj->res.code == TSDB_CODE_QUERY_CANCELLED + * Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED */ pSql->res.numOfRows = 0; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts @@ -1401,7 +1401,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO tscError("%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry", trsupport->pParentSqlObj, pSql); - pState->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; return; } @@ -1475,7 +1475,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) { tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql, tsAvailTmpDirGB, tsMinimalTmpDirGB); - tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_CLI_NO_DISKSPACE); + tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE); return; } @@ -1484,7 +1484,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pQueryInfo->groupbyExpr.orderType); if (ret != 0) { // set no disk space error info, and abort retry - return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_CLI_NO_DISKSPACE); + return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE); } // keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion @@ -1557,13 +1557,13 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR assert(pRes->numOfRows == numOfRows); int64_t num = atomic_add_fetch_64(&pState->numOfRetrievedRows, numOfRows); -// tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%u,vid:%d,orderOfSub:%d", pPObj, pSql, -// pRes->numOfRows, pState->numOfRetrievedRows, pSvd->ip, pSvd->vnode, idx); + tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%s, orderOfSub:%d", pPObj, pSql, + pRes->numOfRows, pState->numOfRetrievedRows, pSql->ipList.fqdn[pSql->ipList.inUse], idx); if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64, pPObj, pSql, tsMaxNumOfOrderedResults, num); - tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_SORTED_RES_TOO_MANY); + tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_SORTED_RES_TOO_MANY); return; } @@ -1578,14 +1578,14 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR if (tsTotalTmpDirGB != 0 && tsAvailTmpDirGB < tsMinimalTmpDirGB) { tscError("%p sub:%p client disk space remain %.3f GB, need at least %.3f GB, stop query", pPObj, pSql, tsAvailTmpDirGB, tsMinimalTmpDirGB); - tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); + tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); return; } int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data, pRes->numOfRows, pQueryInfo->groupbyExpr.orderType); if (ret < 0) { // set no disk space error info, and abort retry - tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_CLI_NO_DISKSPACE); + tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); } else if (pRes->completed) { tscAllDataRetrievedFromDnode(trsupport, pSql); @@ -1672,7 +1672,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { tscError("%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d", trsupport->pParentSqlObj, pSql, pVgroup->vgId, trsupport->subqueryIndex); - pState->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY; trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; } else { SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0); @@ -1713,6 +1713,11 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) { // increase the total inserted rows if (numOfRows > 0) { pParentObj->res.numOfRows += numOfRows; + } else { + SSqlObj* pSql = (SSqlObj*) tres; + assert(pSql != NULL && pSql->res.code == numOfRows); + + pParentObj->res.code = pSql->res.code; } taos_free_result(tres); @@ -1778,7 +1783,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { if (i < pSql->numOfSubs) { tscError("%p failed to prepare subObj structure and launch sub-insertion", pSql); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; // free all allocated resource } @@ -1947,7 +1952,8 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); - for (int i = 0; i < tscNumOfFields(pQueryInfo); ++i) { + size_t size = tscNumOfFields(pQueryInfo); + for (int i = 0; i < size; ++i) { SFieldSupInfo* pSup = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, i); if (pSup->pSqlExpr != NULL) { tscGetResultColumnChr(pRes, &pQueryInfo->fieldsInfo, i); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 4c158ac77a..caf424080d 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -79,8 +79,14 @@ bool tscQueryOnSTable(SSqlCmd* pCmd) { bool tscQueryTags(SQueryInfo* pQueryInfo) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { - int32_t functId = tscSqlExprGet(pQueryInfo, i)->functionId; - + SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); + int32_t functId = pExpr->functionId; + + // "select count(tbname)" query + if (functId == TSDB_FUNC_COUNT && pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { + continue; + } + if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG) { return false; } @@ -183,7 +189,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { /* * In following cases, return false for non ordered project query on super table - * 1. failed to get metermeta from server; 2. not a super table; 3. limitation is 0; + * 1. failed to get tableMeta from server; 2. not a super table; 3. limitation is 0; * 4. show queries, instead of a select query */ size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo); @@ -192,11 +198,6 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { return false; } - // only query on tag, a project query - if (tscQueryTags(pQueryInfo)) { - return true; - } - for (int32_t i = 0; i < numOfExprs; ++i) { int32_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId; if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && @@ -208,6 +209,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { return true; } +// not order by timestamp projection query on super table bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { if (!tscIsProjectionQueryOnSTable(pQueryInfo, tableIndex)) { return false; @@ -299,7 +301,7 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { tfree(pRes->buffer); tfree(pRes->length); - pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY; + pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; } } @@ -404,8 +406,6 @@ void tscPartiallyFreeSqlObj(SSqlObj* pSql) { pSql->numOfSubs = 0; tscResetSqlCmdObj(pCmd); - - tscTrace("%p partially free sqlObj completed", pSql); } void tscFreeSqlObj(SSqlObj* pSql) { @@ -576,7 +576,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks)); if (dataBuf == NULL) { tscError("failed to allocated memory, reason:%s", strerror(errno)); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } dataBuf->nAllocSize = (uint32_t)initialSize; @@ -711,7 +711,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi tscDestroyBlockArrayList(pVnodeDataBlockList); tfree(dataBuf->pData); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -782,12 +782,12 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { assert(pCmd->allocSize == 0); pCmd->payload = (char*)calloc(1, size); - if (pCmd->payload == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; + if (pCmd->payload == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY; pCmd->allocSize = size; } else { if (pCmd->allocSize < size) { char* b = realloc(pCmd->payload, size); - if (b == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; + if (b == NULL) return TSDB_CODE_TSC_OUT_OF_MEMORY; pCmd->payload = b; pCmd->allocSize = size; } @@ -967,7 +967,8 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); pExpr->colInfo.colId = pSchema[pColIndex->columnIndex].colId; strncpy(pExpr->colInfo.name, pSchema[pColIndex->columnIndex].name, TSDB_COL_NAME_LEN); - } else { + } else if (pTableMetaInfo->pTableMeta != NULL) { + // in handling select database/version/server_status(), the pTableMeta is NULL SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pColIndex->columnIndex); pExpr->colInfo.colId = pSchema->colId; strncpy(pExpr->colInfo.name, pSchema->name, TSDB_COL_NAME_LEN); @@ -979,8 +980,11 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol pExpr->colInfo.colIndex = pColIndex->columnIndex; pExpr->resType = type; pExpr->resBytes = size; - pExpr->interBytes = interSize; - pExpr->uid = pTableMetaInfo->pTableMeta->uid; + pExpr->interBytes = interSize; + + if (pTableMetaInfo->pTableMeta) { + pExpr->uid = pTableMetaInfo->pTableMeta->uid; + } return pExpr; } @@ -1149,7 +1153,7 @@ SColumnFilterInfo* tscFilterInfoClone(const SColumnFilterInfo* src, int32_t numO for (int32_t j = 0; j < numOfFilters; ++j) { if (pFilter[j].filterstr) { - size_t len = (size_t) pFilter[j].len + 1; + size_t len = (size_t) pFilter[j].len + 1 * TSDB_NCHAR_SIZE; pFilter[j].pz = (int64_t) calloc(1, len); memcpy((char*)pFilter[j].pz, (char*)src[j].pz, (size_t)len); @@ -1242,14 +1246,14 @@ static int32_t validateQuoteToken(SSQLToken* pToken) { } if (k != pToken->n || pToken->type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return TSDB_CODE_SUCCESS; } int32_t tscValidateName(SSQLToken* pToken) { if (pToken->type != TK_STRING && pToken->type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); @@ -1266,14 +1270,14 @@ int32_t tscValidateName(SSQLToken* pToken) { } else { sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); if (sep == NULL) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } return tscValidateName(pToken); } } else { if (isNumber(pToken)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } } } else { // two part @@ -1286,15 +1290,15 @@ int32_t tscValidateName(SSQLToken* pToken) { pToken->n = tSQLGetToken(pToken->z, &pToken->type); if (pToken->z[pToken->n] != TS_PATH_DELIMITER[0]) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pToken->type != TK_STRING && pToken->type != TK_ID) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } int32_t firstPartLen = pToken->n; @@ -1303,11 +1307,11 @@ int32_t tscValidateName(SSQLToken* pToken) { pToken->n = oldLen - (sep - pStr) - 1; int32_t len = tSQLGetToken(pToken->z, &pToken->type); if (len != pToken->n || (pToken->type != TK_STRING && pToken->type != TK_ID)) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } // re-build the whole name string @@ -1576,7 +1580,7 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { size_t s = pCmd->numOfClause + 1; char* tmp = realloc(pCmd->pQueryInfo, s * POINTER_BYTES); if (tmp == NULL) { - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_TSC_OUT_OF_MEMORY; } pCmd->pQueryInfo = (SQueryInfo**)tmp; @@ -1944,8 +1948,8 @@ int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) { bool tscIsUpdateQuery(SSqlObj* pSql) { if (pSql == NULL || pSql->signature != pSql) { - terrno = TSDB_CODE_DISCONNECTED; - return TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_TSC_DISCONNECTED; + return TSDB_CODE_TSC_DISCONNECTED; } SSqlCmd* pCmd = &pSql->cmd; @@ -1962,7 +1966,7 @@ int32_t tscInvalidSQLErrMsg(char* msg, const char* additionalInfo, const char* s if (sql == NULL) { assert(additionalInfo != NULL); sprintf(msg, msgFormat1, additionalInfo); - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } char buf[64] = {0}; // only extract part of sql string @@ -1974,7 +1978,7 @@ int32_t tscInvalidSQLErrMsg(char* msg, const char* additionalInfo, const char* s sprintf(msg, msgFormat3, buf); // no additional information for invalid sql error } - return TSDB_CODE_INVALID_SQL; + return TSDB_CODE_TSC_INVALID_SQL; } bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) { @@ -2104,7 +2108,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) { } void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) { - SFieldSupInfo* pInfo = tscFieldInfoGetSupp(pFieldInfo, columnIndex); + SFieldSupInfo* pInfo = taosArrayGet(pFieldInfo->pSupportInfo, columnIndex);//tscFieldInfoGetSupp(pFieldInfo, columnIndex); assert(pInfo->pSqlExpr != NULL); int32_t type = pInfo->pSqlExpr->resType; @@ -2143,7 +2147,7 @@ void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t column void* malloc_throw(size_t size) { void* p = malloc(size); if (p == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } return p; } @@ -2151,7 +2155,7 @@ void* malloc_throw(size_t size) { void* calloc_throw(size_t nmemb, size_t size) { void* p = calloc(nmemb, size); if (p == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } return p; } @@ -2159,7 +2163,7 @@ void* calloc_throw(size_t nmemb, size_t size) { char* strdup_throw(const char* str) { char* p = strdup(str); if (p == NULL) { - THROW(TSDB_CODE_CLI_OUT_OF_MEMORY); + THROW(TSDB_CODE_TSC_OUT_OF_MEMORY); } return p; } @@ -2170,7 +2174,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) { if (first && first[0] != 0) { if (strlen(first) >= TSDB_EP_LEN) { - terrno = TSDB_CODE_INVALID_FQDN; + terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } taosGetFqdnPortFromEp(first, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]); @@ -2179,7 +2183,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) { if (second && second[0] != 0) { if (strlen(second) >= TSDB_EP_LEN) { - terrno = TSDB_CODE_INVALID_FQDN; + terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } taosGetFqdnPortFromEp(second, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]); @@ -2187,7 +2191,7 @@ int tscSetMgmtIpListFromCfg(const char *first, const char *second) { } if ( tscMgmtIpSet.numOfIps == 0) { - terrno = TSDB_CODE_INVALID_FQDN; + terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 673ba2a6f5..e010f7fe56 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -112,7 +112,7 @@ int32_t tsMaxShellConns = 5000; char tsDefaultDB[TSDB_DB_NAME_LEN] = {0}; char tsDefaultUser[64] = "root"; char tsDefaultPass[64] = "taosdata"; -int32_t tsMaxConnections = 50; +int32_t tsMaxConnections = 5000; int32_t tsBalanceInterval = 300; // seconds int32_t tsOfflineThreshold = 86400*100; // seconds 10days @@ -234,7 +234,7 @@ bool taosCfgDynamicOptions(char *msg) { int32_t vint = 0; paGetToken(msg, &option, &olen); - if (olen == 0) return TSDB_CODE_INVALID_MSG_CONTENT; + if (olen == 0) return TSDB_CODE_COM_INVALID_CFG_MSG; paGetToken(option + olen + 1, &value, &vlen); if (vlen == 0) @@ -840,7 +840,7 @@ static void doInitGlobalConfig() { cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 1; - cfg.maxValue = 100; + cfg.maxValue = 100000; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); diff --git a/src/connector/python/linux/python2/taos/cinterface.py b/src/connector/python/linux/python2/taos/cinterface.py index 1b17bf72b0..10df10b31f 100644 --- a/src/connector/python/linux/python2/taos/cinterface.py +++ b/src/connector/python/linux/python2/taos/cinterface.py @@ -150,6 +150,7 @@ class CTaosInterface(object): libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None libtaos.taos_errno.restype = ctypes.c_int + libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) def __init__(self, config=None): ''' @@ -412,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/linux/python2/taos/cursor.py b/src/connector/python/linux/python2/taos/cursor.py index 75aa7f69d8..f7c840442e 100644 --- a/src/connector/python/linux/python2/taos/cursor.py +++ b/src/connector/python/linux/python2/taos/cursor.py @@ -93,7 +93,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -109,7 +108,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -202,7 +200,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() return list(map(tuple, zip(*buffer))) @@ -222,6 +219,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None diff --git a/src/connector/python/linux/python3/taos/cinterface.py b/src/connector/python/linux/python3/taos/cinterface.py index 87540bf326..c3c8a4603a 100644 --- a/src/connector/python/linux/python3/taos/cinterface.py +++ b/src/connector/python/linux/python3/taos/cinterface.py @@ -150,6 +150,7 @@ class CTaosInterface(object): libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None libtaos.taos_errno.restype = ctypes.c_int + libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) def __init__(self, config=None): ''' @@ -412,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/linux/python3/taos/cursor.py b/src/connector/python/linux/python3/taos/cursor.py index 3baca89462..5db5365eb3 100644 --- a/src/connector/python/linux/python3/taos/cursor.py +++ b/src/connector/python/linux/python3/taos/cursor.py @@ -95,7 +95,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -111,7 +110,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -204,8 +202,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() - return list(map(tuple, zip(*buffer))) def nextset(self): @@ -224,6 +220,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None @@ -240,3 +238,4 @@ class TDengineCursor(object): (ele['name'], ele['type'], None, None, None, None, False)) return self._result + diff --git a/src/connector/python/windows/python2/taos/cinterface.py b/src/connector/python/windows/python2/taos/cinterface.py index 9fb7d4ec09..06ade4fc35 100644 --- a/src/connector/python/windows/python2/taos/cinterface.py +++ b/src/connector/python/windows/python2/taos/cinterface.py @@ -150,6 +150,7 @@ class CTaosInterface(object): libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None libtaos.taos_errno.restype = ctypes.c_int + libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) def __init__(self, config=None): ''' @@ -412,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/windows/python2/taos/cursor.py b/src/connector/python/windows/python2/taos/cursor.py index 6af82e72de..1da726638a 100644 --- a/src/connector/python/windows/python2/taos/cursor.py +++ b/src/connector/python/windows/python2/taos/cursor.py @@ -86,7 +86,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -102,7 +101,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -149,7 +147,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() return list(map(tuple, zip(*buffer))) @@ -171,6 +168,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None diff --git a/src/connector/python/windows/python3/taos/cinterface.py b/src/connector/python/windows/python3/taos/cinterface.py index 0dbb2ce3a1..c6218fe9d4 100644 --- a/src/connector/python/windows/python3/taos/cinterface.py +++ b/src/connector/python/windows/python3/taos/cinterface.py @@ -150,6 +150,7 @@ class CTaosInterface(object): libtaos.taos_fetch_lengths.restype = ctypes.c_void_p libtaos.taos_free_result.restype = None libtaos.taos_errno.restype = ctypes.c_int + libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p) def __init__(self, config=None): ''' @@ -412,5 +413,5 @@ if __name__ == '__main__': print(data) - cinter.freeresult(result) + cinter.freeResult(result) cinter.close(conn) \ No newline at end of file diff --git a/src/connector/python/windows/python3/taos/cursor.py b/src/connector/python/windows/python3/taos/cursor.py index 0ee8af4ed0..2dcd0aaccb 100644 --- a/src/connector/python/windows/python3/taos/cursor.py +++ b/src/connector/python/windows/python3/taos/cursor.py @@ -86,7 +86,6 @@ class TDengineCursor(object): if self._connection is None: return False - self._connection.clear_result_set() self._reset_result() self._connection = None @@ -102,7 +101,6 @@ class TDengineCursor(object): # TODO : change the exception raised here raise ProgrammingError("Cursor is not connected") - self._connection.clear_result_set() self._reset_result() stmt = operation @@ -149,7 +147,6 @@ class TDengineCursor(object): for i in range(len(self._fields)): buffer[i].extend(block[i]) - self._connection.clear_result_set() return list(map(tuple, zip(*buffer))) @@ -171,6 +168,8 @@ class TDengineCursor(object): """ self._description = None self._rowcount = -1 + if self._result is not None: + CTaosInterface.freeResult(self._result) self._result = None self._fields = None self._block = None diff --git a/src/dnode/src/dnodeMPeer.c b/src/dnode/src/dnodeMPeer.c index e3ba5fcf01..71c2d0e65f 100644 --- a/src/dnode/src/dnodeMPeer.c +++ b/src/dnode/src/dnodeMPeer.c @@ -79,7 +79,7 @@ void dnodeCleanupMnodePeer() { int32_t dnodeAllocateMnodePqueue() { tsMPeerQueue = taosOpenQueue(); - if (tsMPeerQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tsMPeerQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; taosAddIntoQset(tsMPeerQset, tsMPeerQueue, NULL); @@ -125,7 +125,7 @@ static void dnodeFreeMnodePeerMsg(SMnodeMsg *pPeer) { } static void dnodeSendRpcMnodePeerRsp(SMnodeMsg *pPeer, int32_t code) { - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; SRpcMsg rpcRsp = { .handle = pPeer->rpcMsg.handle, diff --git a/src/dnode/src/dnodeMRead.c b/src/dnode/src/dnodeMRead.c index f22346b61c..cb02ffbb1d 100644 --- a/src/dnode/src/dnodeMRead.c +++ b/src/dnode/src/dnodeMRead.c @@ -84,7 +84,7 @@ void dnodeCleanupMnodeRead() { int32_t dnodeAllocateMnodeRqueue() { tsMReadQueue = taosOpenQueue(); - if (tsMReadQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tsMReadQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; taosAddIntoQset(tsMReadQset, tsMReadQueue, NULL); @@ -130,8 +130,8 @@ static void dnodeFreeMnodeReadMsg(SMnodeMsg *pRead) { } static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) { - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) { // may be a auto create req, should put into write queue dnodeReprocessMnodeWriteMsg(pRead); return; diff --git a/src/dnode/src/dnodeMWrite.c b/src/dnode/src/dnodeMWrite.c index 95fa9f0bdd..eb9d8653e5 100644 --- a/src/dnode/src/dnodeMWrite.c +++ b/src/dnode/src/dnodeMWrite.c @@ -81,7 +81,7 @@ void dnodeCleanupMnodeWrite() { int32_t dnodeAllocateMnodeWqueue() { tsMWriteQueue = taosOpenQueue(); - if (tsMWriteQueue == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (tsMWriteQueue == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; taosAddIntoQset(tsMWriteQset, tsMWriteQueue, NULL); @@ -128,8 +128,8 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) { void dnodeSendRpcMnodeWriteRsp(void *pRaw, int32_t code) { SMnodeMsg *pWrite = pRaw; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) { dnodeReprocessMnodeWriteMsg(pWrite); return; } diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 5e81d77489..7683843371 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -46,7 +46,7 @@ typedef struct { void (*cleanup)(); } SDnodeComponent; -static const SDnodeComponent SDnodeComponents[] = { +static const SDnodeComponent tsDnodeComponents[] = { {"storage", dnodeInitStorage, dnodeCleanupStorage}, {"vread", dnodeInitVnodeRead, dnodeCleanupVnodeRead}, {"vwrite", dnodeInitVnodeWrite, dnodeCleanupVnodeWrite}, @@ -72,14 +72,14 @@ static int dnodeCreateDir(const char *dir) { static void dnodeCleanupComponents(int32_t stepId) { for (int32_t i = stepId; i >= 0; i--) { - SDnodeComponents[i].cleanup(); + tsDnodeComponents[i].cleanup(); } } static int32_t dnodeInitComponents() { int32_t code = 0; - for (int32_t i = 0; i < sizeof(SDnodeComponents) / sizeof(SDnodeComponents[0]); i++) { - if (SDnodeComponents[i].init() != 0) { + for (int32_t i = 0; i < sizeof(tsDnodeComponents) / sizeof(tsDnodeComponents[0]); i++) { + if (tsDnodeComponents[i].init() != 0) { dnodeCleanupComponents(i); code = -1; break; @@ -133,7 +133,7 @@ int32_t dnodeInitSystem() { void dnodeCleanUpSystem() { if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_STOPPED) { dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_STOPPED); - dnodeCleanupComponents(sizeof(SDnodeComponents) / sizeof(SDnodeComponents[0]) - 1); + dnodeCleanupComponents(sizeof(tsDnodeComponents) / sizeof(tsDnodeComponents[0]) - 1); taos_cleanup(); taosCloseLog(); } diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 7c457defca..69e91fd4ee 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -180,7 +180,7 @@ void dnodeDispatchToMgmtQueue(SRpcMsg *pMsg) { SRpcMsg rsp; rsp.handle = pMsg->handle; rsp.pCont = NULL; - rsp.code = TSDB_CODE_SERV_OUT_OF_MEMORY; + rsp.code = TSDB_CODE_DND_OUT_OF_MEMORY; rpcSendResponse(&rsp); rpcFreeCont(pMsg->pCont); } @@ -202,7 +202,7 @@ static void *dnodeProcessMgmtQueue(void *param) { if (dnodeProcessMgmtMsgFp[pMsg->msgType]) { rsp.code = (*dnodeProcessMgmtMsgFp[pMsg->msgType])(pMsg); } else { - rsp.code = TSDB_CODE_MSG_NOT_PROCESSED; + rsp.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; } rsp.handle = pMsg->handle; @@ -219,7 +219,7 @@ static void *dnodeProcessMgmtQueue(void *param) { static int32_t dnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) { DIR *dir = opendir(tsVnodeDir); if (dir == NULL) { - return TSDB_CODE_NO_WRITE_ACCESS; + return TSDB_CODE_DND_NO_WRITE_ACCESS; } *numOfVnodes = 0; diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index ea3af08d71..eb017c335e 100644 --- a/src/dnode/src/dnodePeer.c +++ b/src/dnode/src/dnodePeer.c @@ -89,7 +89,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { rspMsg.contLen = 0; if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { - rspMsg.code = TSDB_CODE_NOT_READY; + rspMsg.code = TSDB_CODE_RPC_NOT_READY; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); dTrace("RPC %p, msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); @@ -97,7 +97,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { } if (pMsg->pCont == NULL) { - rspMsg.code = TSDB_CODE_INVALID_MSG_LEN; + rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN; rpcSendResponse(&rspMsg); return; } @@ -106,13 +106,14 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { (*dnodeProcessReqMsgFp[pMsg->msgType])(pMsg); } else { dTrace("RPC %p, message:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); - rspMsg.code = TSDB_CODE_MSG_NOT_PROCESSED; + rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); } } int32_t dnodeInitClient() { + char secret[TSDB_KEY_LEN] = "secret"; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.label = "DND-C"; @@ -123,7 +124,7 @@ int32_t dnodeInitClient() { rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.user = "t"; rpcInit.ckey = "key"; - rpcInit.secret = "secret"; + rpcInit.secret = secret; tsDnodeClientRpc = rpcOpen(&rpcInit); if (tsDnodeClientRpc == NULL) { diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 074f21f972..8eba1f3775 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -115,7 +115,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { if (dnodeGetRunStatus() != TSDB_DNODE_RUN_STATUS_RUNING) { dError("RPC %p, shell msg:%s is ignored since dnode not running", pMsg->handle, taosMsg[pMsg->msgType]); - rpcMsg.code = TSDB_CODE_NOT_READY; + rpcMsg.code = TSDB_CODE_RPC_NOT_READY; rpcSendResponse(&rpcMsg); rpcFreeCont(pMsg->pCont); return; @@ -131,7 +131,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { (*dnodeProcessShellMsgFp[pMsg->msgType])(pMsg); } else { dError("RPC %p, shell msg:%s is not processed", pMsg->handle, taosMsg[pMsg->msgType]); - rpcMsg.code = TSDB_CODE_MSG_NOT_PROCESSED; + rpcMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; rpcSendResponse(&rpcMsg); rpcFreeCont(pMsg->pCont); return; @@ -140,7 +140,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcIpSet *pIpSet) { static int dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) { int code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey); - if (code != TSDB_CODE_NOT_READY) return code; + if (code != TSDB_CODE_RPC_NOT_READY) return code; SDMAuthMsg *pMsg = rpcMallocCont(sizeof(SDMAuthMsg)); strcpy(pMsg->user, user); diff --git a/src/dnode/src/dnodeVRead.c b/src/dnode/src/dnodeVRead.c index 72882b679b..7f1a5b2580 100644 --- a/src/dnode/src/dnodeVRead.c +++ b/src/dnode/src/dnodeVRead.c @@ -134,7 +134,7 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) { .handle = pMsg->handle, .pCont = NULL, .contLen = 0, - .code = TSDB_CODE_INVALID_VGROUP_ID, + .code = TSDB_CODE_VND_INVALID_VGROUP_ID, .msgType = 0 }; rpcSendResponse(&rpcRsp); @@ -189,8 +189,8 @@ static void dnodeContinueExecuteQuery(void* pVnode, void* qhandle, SReadMsg *pMs } void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) { - if (code == TSDB_CODE_ACTION_IN_PROGRESS) return; - if (code == TSDB_CODE_ACTION_NEED_REPROCESSED) { + if (code == TSDB_CODE_VND_ACTION_IN_PROGRESS) return; + if (code == TSDB_CODE_VND_ACTION_NEED_REPROCESSED) { dnodeContinueExecuteQuery(pVnode, pRead->rspRet.qhandle, pRead); } diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index 4b26c05649..53533b8183 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -115,7 +115,7 @@ void dnodeDispatchToVnodeWriteQueue(SRpcMsg *pMsg) { .handle = pMsg->handle, .pCont = NULL, .contLen = 0, - .code = TSDB_CODE_INVALID_VGROUP_ID, + .code = TSDB_CODE_VND_INVALID_VGROUP_ID, .msgType = 0 }; rpcSendResponse(&rpcRsp); diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 7d1b3046d9..c75fc70d75 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -221,6 +221,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_COUNTRY_LEN 20 #define TSDB_LOCALE_LEN 64 #define TSDB_TIMEZONE_LEN 64 +#define TSDB_LABEL_LEN 8 #define TSDB_FQDN_LEN 128 #define TSDB_EP_LEN (TSDB_FQDN_LEN+6) @@ -231,7 +232,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_SHELL_VNODE_BITS 24 #define TSDB_SHELL_SID_MASK 0xFF #define TSDB_HTTP_TOKEN_LEN 20 -#define TSDB_SHOW_SQL_LEN 512 +#define TSDB_SHOW_SQL_LEN 64 +#define TSDB_SLOW_QUERY_SQL_LEN 512 #define TSDB_METER_STATE_OFFLINE 0 #define TSDB_METER_STATE_ONLLINE 1 diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index f11a2cf750..6012efa359 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -46,134 +46,173 @@ static STaosError errors[] = { #endif // rpc -TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_IN_PROGRESS, 0, 0x0001, "action in progress") -TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_NEED_REPROCESSED, 0, 0x0003, "action need to be reprocessed") -TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, 0, 0x0004, "message not processed") -TAOS_DEFINE_ERROR(TSDB_CODE_ALREADY_PROCESSED, 0, 0x0005, "message already processed") -TAOS_DEFINE_ERROR(TSDB_CODE_REDIRECT, 0, 0x0006, "redirect") -TAOS_DEFINE_ERROR(TSDB_CODE_LAST_SESSION_NOT_FINISHED, 0, 0x0007, "last session not finished") -TAOS_DEFINE_ERROR(TSDB_CODE_MAX_SESSIONS, 0, 0x0008, "max sessions") // too many sessions -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SESSION_ID, 0, 0x0009, "invalid session id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TRAN_ID, 0, 0x000A, "invalid transaction id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_TYPE, 0, 0x000B, "invalid message type") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_LEN, 0, 0x000C, "invalid message length") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_CONTENT, 0, 0x000D, "invalid message content") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG_VERSION, 0, 0x000E, "invalid message version") -TAOS_DEFINE_ERROR(TSDB_CODE_UNEXPECTED_RESPONSE, 0, 0x000F, "unexpected response") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_RESPONSE_TYPE, 0, 0x0010, "invalid response type") -TAOS_DEFINE_ERROR(TSDB_CODE_MISMATCHED_METER_ID, 0, 0x0011, "mismatched meter id") -TAOS_DEFINE_ERROR(TSDB_CODE_DISCONNECTED, 0, 0x0012, "disconnected") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_READY, 0, 0x0013, "not ready") // peer is not ready to process data -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_SLOW, 0, 0x0014, "too slow") -TAOS_DEFINE_ERROR(TSDB_CODE_OTHERS, 0, 0x0015, "others") -TAOS_DEFINE_ERROR(TSDB_CODE_APP_ERROR, 0, 0x0016, "app error") -TAOS_DEFINE_ERROR(TSDB_CODE_ALREADY_THERE, 0, 0x0017, "already there") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_RESOURCE, 0, 0x0018, "no resource") -TAOS_DEFINE_ERROR(TSDB_CODE_OPS_NOT_SUPPORT, 0, 0x0019, "operations not support") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_OPTION, 0, 0x001A, "invalid option") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_CONFIGURED, 0, 0x001B, "not configured") -TAOS_DEFINE_ERROR(TSDB_CODE_NETWORK_UNAVAIL, 0, 0x001C, "network unavailable") -TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_REQUIRED, 0, 0x001D, "auth required") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ACTION_IN_PROGRESS, 0, 0x0001, "action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_REQUIRED, 0, 0x0002, "auth required") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_FAILURE, 0, 0x0003, "auth failure") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_REDIRECT, 0, 0x0004, "redirect") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NOT_READY, 0, 0x0005, "not ready") // peer is not ready to process data +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_ALREADY_PROCESSED, 0, 0x0006, "message already processed") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED,0, 0x0007, "last session not finished") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MISMATCHED_LINK_ID, 0, 0x0008, "mismatched meter id") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TOO_SLOW, 0, 0x0009, "too slow") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_MAX_SESSIONS, 0, 0x000A, "max sessions") // too many sessions +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_NETWORK_UNAVAIL, 0, 0x000B, "network unavailable") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_APP_ERROR, 0, 0x000C, "rpc app error") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_UNEXPECTED_RESPONSE, 0, 0x000D, "unexpected response") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_VALUE, 0, 0x000E, "invalid value") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TRAN_ID, 0, 0x000F, "invalid transaction id") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_SESSION_ID, 0, 0x0010, "invalid session id") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_MSG_TYPE, 0, 0x0011, "invalid message type") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_RESPONSE_TYPE, 0, 0x0012, "invalid response type") +TAOS_DEFINE_ERROR(TSDB_CODE_RPC_INVALID_TIME_STAMP, 0, 0x0013, "invalid timestamp") -// db -TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 0x0100, "db not selected") -TAOS_DEFINE_ERROR(TSDB_CODE_DB_ALREADY_EXIST, 0, 0x0101, "database aleady exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_DB, 0, 0x0102, "invalid database") -TAOS_DEFINE_ERROR(TSDB_CODE_MONITOR_DB_FORBIDDEN, 0, 0x0103, "monitor db forbidden") +//common & util +TAOS_DEFINE_ERROR(TSDB_CODE_COM_OPS_NOT_SUPPORT, 0, 0x0100, "operations not support") +TAOS_DEFINE_ERROR(TSDB_CODE_COM_MEMORY_CORRUPTED, 0, 0x0101, "memory corrupted") +TAOS_DEFINE_ERROR(TSDB_CODE_COM_OUT_OF_MEMORY, 0, 0x0102, "out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_COM_INVALID_CFG_MSG, 0, 0x0103, "invalid config message") -// user -TAOS_DEFINE_ERROR(TSDB_CODE_USER_ALREADY_EXIST, 0, 0x0180, "user already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER, 0, 0x0181, "invalid user") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS, 0, 0x0182, "invalid password") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER_FORMAT, 0, 0x0183, "invalid user format") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS_FORMAT, 0, 0x0184, "invalid password format") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_USER_FROM_CONN, 0, 0x0185, "can not get user from conn") +//client +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_SQL, 0, 0x0200, "invalid sql") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_QHANDLE, 0, 0x0201, "client invalid qhandle") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TIME_STAMP, 0, 0x0202, "client time/server time can not be mixed up") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_VALUE, 0, 0x0203, "clientinvalid value") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_VERSION, 0, 0x0204, "client invalid version") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_IE, 0, 0x0205, "client invalid ie") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_FQDN, 0, 0x0206, "client invalid fqdn") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_USER_LENGTH, 0, 0x0207, "client invalid username length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_PASS_LENGTH, 0, 0x0208, "client invalid password length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_DB_LENGTH, 0, 0x0209, "client invalid database length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH, 0, 0x020A, "client invalid table length") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_CONNECTION, 0, 0x020B, "client invalid connection") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_OUT_OF_MEMORY, 0, 0x020C, "client out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_DISKSPACE, 0, 0x020D, "client no disk space") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CACHE_ERASED, 0, 0x020E, "client query cache erased") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CANCELLED, 0, 0x020F, "client query cancelled") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SORTED_RES_TOO_MANY, 0, 0x0210, "client sorted res too many") // too many result for ordered super table projection query +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_APP_ERROR, 0, 0x0211, "client app error") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_ACTION_IN_PROGRESS, 0, 0x0212, "client action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DISCONNECTED, 0, 0x0213, "client disconnected") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_WRITE_AUTH, 0, 0x0214, "client no write auth") -// table -TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ALREADY_EXIST, 0, 0x0200, "table already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE_ID, 0, 0x0201, "invalid table id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TABLE_TYPE, 0, 0x0202, "invalid table type") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUPER_TABLE, 0, 0x0203, "no super table") // operation only available for super table -TAOS_DEFINE_ERROR(TSDB_CODE_TAG_ALREAY_EXIST, 0, 0x0204, "tag already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_TAG_NOT_EXIST, 0, 0x0205, "tag not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_ALREAY_EXIST, 0, 0x0206, "field already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_FIELD_NOT_EXIST, 0, 0x0207, "field not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_COL_NAME_TOO_LONG, 0, 0x0208, "column name too long") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TAGS, 0, 0x0209, "too many tags") +// mnode +TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, 0, 0x0300, "mnode message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_IN_PROGRESS, 0, 0x0301, "mnode action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, 0, 0x0302, "mnode action need to be reprocessed") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, 0, 0x0303, "mnode no rights") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, 0, 0x0304, "mnode app error") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONNECTION, 0, 0x0305, "mnode invalid message connection") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_VERSION, 0, 0x0306, "mnode invalid message version") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_LEN, 0, 0x0307, "mnode invalid message length") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_TYPE, 0, 0x0308, "mnode invalid message type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_SHELL_CONNS, 0, 0x0309, "mnode too many shell conns") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_OUT_OF_MEMORY, 0, 0x030A, "mnode out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SHOWOBJ, 0, 0x030B, "mnode invalid show handle") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_QUERY_ID, 0, 0x030C, "mnode invalid query id") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STREAM_ID, 0, 0x030D, "mnode invalid stream id") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONN_ID, 0, 0x030E, "mnode invalid connection") -// dnode & mnode -TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 0x0280, "no enough dnodes") -TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 0x0281, "dnode already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 0x0282, "dnode not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 0x0283, "no master") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 0x0284, "no remove master") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 0x0285, "invalid query id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 0x0286, "invalid stream id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 0x0287, "invalid connection") -TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 0x0288, "sdb error") -TAOS_DEFINE_ERROR(TSDB_CODE_TIMESTAMP_OUT_OF_RANGE, 0, 0x0289, "timestamp is out of range") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "mnode object already there") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "mnode sdb error") -// acct -TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 0x0300, "accounts already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 0x0301, "invalid account") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 0x0302, "invalid account parameter") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 0x0303, "too many accounts") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 0x0304, "too many users") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 0x0305, "too many tables") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 0x0306, "too many databases") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 0x0307, "not enough time series") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "mnode dnode already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnode not exist") +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_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_PARA, 0, 0x0342, "mnode invalid account parameter") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT_OPTION, 0, 0x0343, "mnode invalid acct option") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_ACCTS, 0, 0x0344, "mnode too many accounts") + +TAOS_DEFINE_ERROR(TSDB_CODE_MND_USER_ALREADY_EXIST, 0, 0x0350, "mnode user already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER, 0, 0x0351, "mnode invalid user") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_USER_FORMAT, 0, 0x0352, "mnode invalid user format") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_PASS_FORMAT, 0, 0x0353, "mnode invalid password format") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, 0, 0x0354, "mnode can not get user from conn") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, 0, 0x0355, "mnode too many users") + +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TABLE_ALREADY_EXIST, 0, 0x0360, "mnode table already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, 0, 0x0361, "mnode invalid table id") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, 0, 0x0362, "mnode invalid table type") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, 0, 0x0363, "mnode too many tags") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TABLES, 0, 0x0364, "mnode too many tables") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, 0, 0x0365, "mnode not enough time series") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, 0, 0x0366, "mnode no super table") // operation only available for super table +TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, 0, 0x0367, "mnode column name too long") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, 0, 0x0368, "mnode tag already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, 0, 0x0369, "mnode tag not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, 0, 0x036A, "mnode field already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, 0, 0x036B, "mnode field not exist") + +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_SELECTED, 0, 0x0380, "mnode db not selected") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, 0, 0x0381, "mnode database aleady exist") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION, 0, 0x0382, "mnode invalid db option") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB, 0, 0x0383, "mnode invalid database") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_MONITOR_DB_FORBIDDEN, 0, 0x0384, "mnode monitor db forbidden") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DATABASES, 0, 0x0385, "mnode too many databases") + +// dnode +TAOS_DEFINE_ERROR(TSDB_CODE_DND_MSG_NOT_PROCESSED, 0, 0x0400, "dnode message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_OUT_OF_MEMORY, 0, 0x0401, "dnode out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_NO_WRITE_ACCESS, 0, 0x0402, "dnode no disk write access") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, 0, 0x0403, "dnode invalid message length") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_FILE_FORMAT, 0, 0x0404, "dnode invalid file format") + +// vnode +TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_IN_PROGRESS, 0, 0x0500, "vnode action in progress") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_MSG_NOT_PROCESSED, 0, 0x0501, "vnode message not processed") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_NEED_REPROCESSED, 0, 0x0502, "vnode action need to be reprocessed") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, 0, 0x0503, "vnode invalid vgroup id") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_INIT_FAILED, 0, 0x0504, "vnode init failed") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISKSPACE, 0, 0x0505, "vnode no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "vnode no disk permissions") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error") + +// tsdb +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_TYPE, 0, 0x0601, "tsdb invalid table schema version") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_SCHEMA_VERSION, 0, 0x0602, "tsdb invalid table schema version") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_ALREADY_EXIST, 0, 0x0603, "tsdb table already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CONFIG, 0, 0x0604, "tsdb invalid configuration") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INIT_FAILED, 0, 0x0605, "tsdb init failed") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISKSPACE, 0, 0x0606, "tsdb no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISK_PERMISSIONS, 0, 0x0607, "tsdb no disk permissions") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_CORRUPTED, 0, 0x0608, "tsdb file corrupted") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_OUT_OF_MEMORY, 0, 0x0609, "tsdb out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE, 0, 0x060A, "tsdb tag version is out of date") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE, 0, 0x060B, "tsdb timestamp is out of range") + +// query +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, 0, 0x0700, "query invalid handle") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_MSG, 0, 0x0701, "query invalid message") // failed to validate the sql expression msg by vnode +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NO_DISKSPACE, 0, 0x0702, "query no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_OUT_OF_MEMORY, 0, 0x0703, "query out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_APP_ERROR, 0, 0x0704, "query app error") // grant -TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 0x0380, "auth failure") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 0x0381, "no rights") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 0x0382, "no write access") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 0x0383, "no read access") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0384, "grant expired") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0385, "grant dnode limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0386, "grant account limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 0x0387, "grant timeseries limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 0x0388, "grant db limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 0x0389, "grant user limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 0x038A, "grant conn limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 0x038B, "grant stream limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 0x038C, "grant speed limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x038D, "grant storage limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x038E, "grant query time limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x038F, "grant cpu limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "grant expired") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 0x0801, "grant dnode limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 0x0802, "grant account limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 0x0803, "grant timeseries limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 0x0804, "grant db limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 0x0805, "grant user limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 0x0806, "grant conn limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 0x0807, "grant stream limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 0x0808, "grant speed limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 0x0809, "grant storage limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 0x080A, "grant query time limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x080B, "grant cpu limited") -// server -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 0x0400, "invalid vgroup id") -TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 0x0402, "vgroup init failed") -TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 0x0403, "server no diskspace") -TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 0x0404, "server out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 0x0405, "no disk permissions") -TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 0x0406, "file corrupted") -TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 0x0407, "memory corrupted") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_SUCH_FILE_OR_DIR, 0, 0x0408, "no such file or directory") - -// client -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 0x0481, "invalid client version") -TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 0x0482, "client out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 0x0483, "client no disk space") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 0x0484, "invalid timestamp") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 0x0485, "invalid sql") -TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 0x0486, "query cache erased") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 0x0487, "invalid query message") // failed to validate the sql expression msg by vnode -TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 0x0488, "sorted res too many") // too many result for ordered super table projection query -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 0x0489, "invalid handle") -TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 0x048A, "query cancelled") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 0x048B, "invalid ie") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 0x048C, "invalid value") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FQDN, 0, 0x048D, "invalid FQDN") - -// others -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 0x0500, "invalid file format") - -// TSDB -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONFIG, 0, 0x0580, "invalid TSDB configuration") -TAOS_DEFINE_ERROR(TSDB_CODE_TAG_VER_OUT_OF_DATE, 0, 0x0581, "tag version is out of date") -TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_SCHEMA_VERSION, 0, 0x0582, "invalid table schema version from client") +// sync +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x0900, "sync invalid configuration") +// wal +TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "wal app error") #ifdef TAOS_ERROR_C }; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 2cf0567f5a..88c6f9cf26 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -137,6 +137,7 @@ enum _mgmt_table { TSDB_MGMT_TABLE_SCORES, TSDB_MGMT_TABLE_GRANTS, TSDB_MGMT_TABLE_VNODES, + TSDB_MGMT_TABLE_STREAMTABLES, TSDB_MGMT_TABLE_MAX, }; @@ -299,6 +300,9 @@ typedef struct { char serverVersion[TSDB_VERSION_LEN]; int8_t writeAuth; int8_t superAuth; + int8_t reserved1; + int8_t reserved2; + int32_t connId; SRpcIpSet ipList; } SCMConnectRsp; @@ -716,16 +720,10 @@ typedef struct { } SStreamDesc; typedef struct { - int32_t numOfQueries; -} SQqueryList; - -typedef struct { - int32_t numOfStreams; -} SStreamList; - -typedef struct { - SQqueryList qlist; - SStreamList slist; + uint32_t connId; + int32_t numOfQueries; + int32_t numOfStreams; + char pData[]; } SCMHeartBeatMsg; typedef struct { @@ -733,6 +731,7 @@ typedef struct { uint32_t streamId; uint32_t totalDnodes; uint32_t onlineDnodes; + uint32_t connId; int8_t killConnection; SRpcIpSet ipList; } SCMHeartBeatRsp; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 79b0adb957..2dc9b977b4 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -188,9 +188,10 @@ typedef void *TsdbPosT; * @param tsdb tsdb handle * @param pCond query condition, including time window, result set order, and basic required columns for each block * @param groupInfo tableId list in the form of set, seperated into different groups according to group by condition + * @param qinfo query info handle from query processor * @return */ -TsdbQueryHandleT *tsdbQueryTables(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo); +TsdbQueryHandleT *tsdbQueryTables(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo, void* qinfo); /** * Get the last row of the given query time window for all the tables in STableGroupInfo object. @@ -202,11 +203,11 @@ TsdbQueryHandleT *tsdbQueryTables(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STable * @param groupInfo tableId list. * @return */ -TsdbQueryHandleT tsdbQueryLastRow(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo); +TsdbQueryHandleT tsdbQueryLastRow(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupInfo, void* qinfo); SArray* tsdbGetQueriedTableIdList(TsdbQueryHandleT *pHandle); -TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TsdbRepoT *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList); +TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TsdbRepoT *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo); /** * move to next block if exists diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index effaafc4e7..d388bc9dbe 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -148,8 +148,8 @@ #define TK_SET 130 #define TK_KILL 131 #define TK_CONNECTION 132 -#define TK_COLON 133 -#define TK_STREAM 134 +#define TK_STREAM 133 +#define TK_COLON 134 #define TK_ABORT 135 #define TK_AFTER 136 #define TK_ATTACH 137 diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index a01decc6c6..954f2cb8a3 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -858,11 +858,11 @@ void shellGetGrantInfo(void *con) { char sql[] = "show grants"; - TAOS_RES* pSql = taos_query(con, sql); - int code = taos_errno(pSql); - + result = taos_query(con, sql); + + int code = taos_errno(result); if (code != TSDB_CODE_SUCCESS) { - if (code == TSDB_CODE_OPS_NOT_SUPPORT) { + if (code == TSDB_CODE_COM_OPS_NOT_SUPPORT) { fprintf(stdout, "Server is Community Edition, version is %s\n\n", taos_get_server_info(con)); } else { fprintf(stderr, "Failed to check Server Edition, Reason:%d:%s\n\n", taos_errno(con), taos_errstr(con)); diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 1fbe04208c..92474bdd03 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -16,21 +16,19 @@ #include "os.h" #include "shell.h" #include "tsclient.h" -#include "tutil.h" -TAOS_RES* con; pthread_t pid; // TODO: IMPLEMENT INTERRUPT HANDLER. void interruptHandler(int signum) { #ifdef LINUX - taos_stop_query(con); - if (con != NULL) { + taos_stop_query(result); + if (result != NULL) { /* * we need to free result in async model, in order to avoid free * results while the master thread is waiting for server response. */ - tscQueueAsyncFreeResult(con); + tscQueueAsyncFreeResult(result); } result = NULL; @@ -88,7 +86,7 @@ int main(int argc, char* argv[]) { shellParseArgument(argc, argv, &args); /* Initialize the shell */ - con = shellInit(&args); + TAOS* con = shellInit(&args); if (con == NULL) { exit(EXIT_FAILURE); } @@ -109,5 +107,4 @@ int main(int argc, char* argv[]) { pthread_create(&pid, NULL, shellLoopQuery, con); pthread_join(pid, NULL); } - return 0; } diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 594fd3fd50..cf9058b9cf 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -182,8 +182,6 @@ typedef struct SUserObj { int8_t updateEnd[1]; int32_t refCount; struct SAcctObj * pAcct; - SQqueryList * pQList; // query list - SStreamList * pSList; // stream list } SUserObj; typedef struct { diff --git a/src/mnode/inc/mnodeProfile.h b/src/mnode/inc/mnodeProfile.h index 0311983a38..30745db035 100644 --- a/src/mnode/inc/mnodeProfile.h +++ b/src/mnode/inc/mnodeProfile.h @@ -21,9 +21,30 @@ extern "C" { #endif #include "mnodeDef.h" +typedef struct { + char user[TSDB_USER_LEN + 1]; + int8_t killed; + uint16_t port; + uint32_t ip; + uint32_t connId; + uint64_t stime; + uint64_t lastAccess; + uint32_t queryId; + uint32_t streamId; + int32_t numOfQueries; + int32_t numOfStreams; + SStreamDesc *pStreams; + SQueryDesc * pQueries; +} SConnObj; + int32_t mnodeInitProfile(); void mnodeCleanupProfile(); +SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port); +SConnObj *mnodeAccquireConn(uint32_t connId, char *user, uint32_t ip, uint16_t port); +void mnodeReleaseConn(SConnObj *pConn); +int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg); + #ifdef __cplusplus } #endif diff --git a/src/mnode/inc/mnodeShow.h b/src/mnode/inc/mnodeShow.h index d571eabfd8..da66e71678 100644 --- a/src/mnode/inc/mnodeShow.h +++ b/src/mnode/inc/mnodeShow.h @@ -28,6 +28,7 @@ typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pCon typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn); void mnodeAddShowMetaHandle(uint8_t showType, SShowMetaFp fp); void mnodeAddShowRetrieveHandle(uint8_t showType, SShowRetrieveFp fp); +void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow); #ifdef __cplusplus } diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 3836bcea52..9634d2c645 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -70,7 +70,7 @@ static int32_t mnodeActionActionEncode(SSdbOper *pOper) { static int32_t mnodeAcctActionDecode(SSdbOper *pOper) { SAcctObj *pAcct = (SAcctObj *) calloc(1, sizeof(SAcctObj)); - if (pAcct == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pAcct == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pAcct, pOper->rowData, tsAcctUpdateSize); pOper->pObj = pAcct; diff --git a/src/mnode/src/mnodeBalance.c b/src/mnode/src/mnodeBalance.c index 64d3c6d7c7..14acffdb62 100644 --- a/src/mnode/src/mnodeBalance.c +++ b/src/mnode/src/mnodeBalance.c @@ -56,7 +56,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { if (pSelDnode == NULL) { mError("failed to alloc vnode to vgroup"); - return TSDB_CODE_NO_ENOUGH_DNODES; + return TSDB_CODE_MND_NO_ENOUGH_DNODES; } pVgroup->vnodeGid[0].dnodeId = pSelDnode->dnodeId; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 23e903dd25..90569b4a95 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -71,7 +71,7 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { } else { mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct); - return TSDB_CODE_INVALID_ACCT; + return TSDB_CODE_MND_INVALID_ACCT; } return TSDB_CODE_SUCCESS; @@ -111,7 +111,7 @@ static int32_t mnodeDbActionEncode(SSdbOper *pOper) { static int32_t mnodeDbActionDecode(SSdbOper *pOper) { SDbObj *pDb = (SDbObj *) calloc(1, sizeof(SDbObj)); - if (pDb == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pDb == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pDb, pOper->rowData, tsDbUpdateSize); pOper->pObj = pDb; @@ -189,102 +189,102 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) { if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { mError("invalid db option cacheBlockSize:%d valid range: [%d, %d]", pCfg->cacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) { mError("invalid db option totalBlocks:%d valid range: [%d, %d]", pCfg->totalBlocks, TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->maxTables < TSDB_MIN_TABLES || pCfg->maxTables > TSDB_MAX_TABLES) { mError("invalid db option maxTables:%d valid range: [%d, %d]", pCfg->maxTables, TSDB_MIN_TABLES, TSDB_MAX_TABLES); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) { mError("invalid db option daysPerFile:%d valid range: [%d, %d]", pCfg->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) { mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, TSDB_MAX_KEEP); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep < pCfg->daysPerFile) { mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > pCfg->daysToKeep) { mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, pCfg->daysToKeep); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) { mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, TSDB_MIN_KEEP, pCfg->daysToKeep2); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) { mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock, TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) { mError("invalid db option minRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->minRowsPerFileBlock, TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) { mError("invalid db option minRowsPerFileBlock:%d should smaller than maxRowsPerFileBlock:%d", pCfg->minRowsPerFileBlock, pCfg->maxRowsPerFileBlock); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) { mError("invalid db option commitTime:%d valid range: [%d, %d]", pCfg->commitTime, TSDB_MIN_COMMIT_TIME, TSDB_MAX_COMMIT_TIME); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) { mError("invalid db option timePrecision:%d valid value: [%d, %d]", pCfg->precision, TSDB_MIN_PRECISION, TSDB_MAX_PRECISION); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) { mError("invalid db option compression:%d valid range: [%d, %d]", pCfg->compression, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) { mError("invalid db option walLevel:%d, valid range: [%d, %d]", pCfg->walLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->replications < TSDB_MIN_REPLICA_NUM || pCfg->replications > TSDB_MAX_REPLICA_NUM) { mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_REPLICA_NUM, TSDB_MAX_REPLICA_NUM); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL) { mError("invalid db option walLevel:%d must be greater than 0", pCfg->walLevel); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } #ifndef _SYNC if (pCfg->replications != 1) { mError("invalid db option replications:%d can only be 1 in this version", pCfg->replications); - return TSDB_CODE_INVALID_OPTION; + return TSDB_CODE_MND_INVALID_DB_OPTION; } #endif @@ -320,7 +320,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { return TSDB_CODE_SUCCESS; } else { mError("db:%s, is already exist, ignore exist not set", pCreate->db); - return TSDB_CODE_DB_ALREADY_EXIST; + return TSDB_CODE_MND_DB_ALREADY_EXIST; } } @@ -366,7 +366,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pDb); - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -743,7 +743,7 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } return code; @@ -766,7 +766,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { if (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS) { code = TSDB_CODE_GRANT_EXPIRED; } else if (!pMsg->pUser->writeAuth) { - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } else { code = mnodeCreateDb(pMsg->pUser->pAcct, pCreate); if (code == TSDB_CODE_SUCCESS) { @@ -800,7 +800,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) { mError("db:%s, can't alter cache option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (totalBlocks > 0 && totalBlocks != pDb->cfg.totalBlocks) { @@ -813,13 +813,13 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { newCfg.maxTables = maxTables; if (newCfg.maxTables < pDb->cfg.maxTables) { mError("db:%s, tables:%d should larger than origin:%d", pDb->name, newCfg.maxTables, pDb->cfg.maxTables); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } } if (daysPerFile > 0 && daysPerFile != pDb->cfg.daysPerFile) { mError("db:%s, can't alter days option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) { @@ -839,22 +839,22 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (minRows > 0 && minRows != pDb->cfg.minRowsPerFileBlock) { mError("db:%s, can't alter minRows option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (maxRows > 0 && maxRows != pDb->cfg.maxRowsPerFileBlock) { mError("db:%s, can't alter maxRows option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (commitTime > 0 && commitTime != pDb->cfg.commitTime) { mError("db:%s, can't alter commitTime option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (precision > 0 && precision != pDb->cfg.precision) { mError("db:%s, can't alter precision option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (compression >= 0 && compression != pDb->cfg.compression) { @@ -864,7 +864,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (walLevel > 0 && walLevel != pDb->cfg.walLevel) { mError("db:%s, can't alter walLevel option", pDb->name); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (replications > 0 && replications != pDb->cfg.replications) { @@ -873,17 +873,17 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (pDb->cfg.walLevel < TSDB_MIN_WAL_LEVEL) { mError("db:%s, walLevel:%d must be greater than 0", pDb->name, pDb->cfg.walLevel); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } if (replications > mnodeGetDnodesNum()) { mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications); - terrno = TSDB_CODE_NO_ENOUGH_DNODES; + terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES; } if (pDb->cfg.replications - replications >= 2) { mError("db:%s, replica number can't change from 3 to 1", pDb->name, replications); - terrno = TSDB_CODE_INVALID_OPTION; + terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } } @@ -914,7 +914,7 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } } @@ -942,7 +942,7 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pAlter->db); if (pMsg->pDb == NULL) { mError("db:%s, failed to alter, invalid db", pAlter->db); - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } int32_t code = mnodeAlterDb(pMsg->pDb, pAlter); @@ -966,7 +966,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { }; int32_t code = sdbDeleteRow(&oper); if (code != 0) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -983,13 +983,13 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("db:%s, failed to drop, invalid db", pDrop->db); - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } } if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { mError("db:%s, can't drop monitor database", pDrop->db); - return TSDB_CODE_MONITOR_DB_FORBIDDEN; + return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; } int32_t code = mnodeSetDbDropping(pMsg->pDb); diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 506511ece9..6fd565b5e6 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -107,7 +107,7 @@ static int32_t mnodeDnodeActionEncode(SSdbOper *pOper) { static int32_t mnodeDnodeActionDecode(SSdbOper *pOper) { SDnodeObj *pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); - if (pDnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pDnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pDnode, pOper->rowData, tsDnodeUpdateSize); pOper->pObj = pDnode; @@ -249,7 +249,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { } if (strcmp(pMsg->pUser->user, "root") != 0) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep); @@ -286,7 +286,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { uint32_t version = htonl(pStatus->version); if (version != tsVersion) { mError("status msg version:%d not equal with mnode:%d", version, tsVersion); - return TSDB_CODE_INVALID_MSG_VERSION; + return TSDB_CODE_MND_INVALID_MSG_VERSION; } SDnodeObj *pDnode = NULL; @@ -294,13 +294,13 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { pDnode = mnodeGetDnodeByEp(pStatus->dnodeEp); if (pDnode == NULL) { mTrace("dnode %s not created", pStatus->dnodeEp); - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } } else { pDnode = mnodeGetDnode(pStatus->dnodeId); if (pDnode == NULL) { mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp); - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } } @@ -347,7 +347,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess); SDMStatusRsp *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } mnodeGetMnodeInfos(&pRsp->mnodes); @@ -376,7 +376,7 @@ static int32_t mnodeCreateDnode(char *ep) { if (pDnode != NULL) { mnodeDecDnodeRef(pDnode); mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort); - return TSDB_CODE_DNODE_ALREADY_EXIST; + return TSDB_CODE_MND_DNODE_ALREADY_EXIST; } pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); @@ -398,7 +398,7 @@ static int32_t mnodeCreateDnode(char *ep) { int dnodeId = pDnode->dnodeId; tfree(pDnode); mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code)); - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code)); @@ -414,7 +414,7 @@ int32_t mnodeDropDnode(SDnodeObj *pDnode) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); @@ -425,13 +425,13 @@ static int32_t mnodeDropDnodeByEp(char *ep) { SDnodeObj *pDnode = mnodeGetDnodeByEp(ep); if (pDnode == NULL) { mError("dnode:%s, is not exist", ep); - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } mnodeDecDnodeRef(pDnode); if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) { mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep); - return TSDB_CODE_NO_REMOVE_MASTER; + return TSDB_CODE_MND_NO_REMOVE_MASTER; } mPrint("dnode:%d, start to drop it", pDnode->dnodeId); @@ -446,7 +446,7 @@ static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) { SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont; if (strcmp(pMsg->pUser->user, "root") != 0) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } else { int32_t code = mnodeCreateDnode(pCreate->ep); @@ -466,7 +466,7 @@ static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) { SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont; if (strcmp(pMsg->pUser->user, "root") != 0) { - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } else { int32_t code = mnodeDropDnodeByEp(pDrop->ep); @@ -486,7 +486,7 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC if (strcmp(pUser->pAcct->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } int32_t cols = 0; @@ -615,7 +615,7 @@ static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p if (strcmp(pUser->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SSchema *pSchema = pMeta->schema; @@ -725,7 +725,7 @@ static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p if (strcmp(pUser->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SSchema *pSchema = pMeta->schema; @@ -812,7 +812,7 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC if (strcmp(pUser->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } SSchema *pSchema = pMeta->schema; diff --git a/src/mnode/src/mnodeInt.c b/src/mnode/src/mnodeInt.c index 1cb421bef7..c2dd46d981 100644 --- a/src/mnode/src/mnodeInt.c +++ b/src/mnode/src/mnodeInt.c @@ -41,7 +41,7 @@ void mnodeCreateMsg(SMnodeMsg *pMsg, SRpcMsg *rpcMsg) { int32_t mnodeInitMsg(SMnodeMsg *pMsg) { pMsg->pUser = mnodeGetUserFromConn(pMsg->rpcMsg.handle); if (pMsg->pUser == NULL) { - return TSDB_CODE_INVALID_USER; + return TSDB_CODE_MND_INVALID_USER; } return TSDB_CODE_SUCCESS; diff --git a/src/mnode/src/mnodeMain.c b/src/mnode/src/mnodeMain.c index baecfac077..298d10993b 100644 --- a/src/mnode/src/mnodeMain.c +++ b/src/mnode/src/mnodeMain.c @@ -33,14 +33,54 @@ #include "mnodeUser.h" #include "mnodeTable.h" #include "mnodeShow.h" +#include "mnodeProfile.h" + +typedef struct { + const char *const name; + int (*init)(); + void (*cleanup)(); +} SMnodeComponent; void *tsMnodeTmr; static bool tsMgmtIsRunning = false; +static const SMnodeComponent tsMnodeComponents[] = { + {"profile", mnodeInitProfile, mnodeCleanupProfile}, + {"accts", mnodeInitAccts, mnodeCleanupAccts}, + {"users", mnodeInitUsers, mnodeCleanupUsers}, + {"dnodes", mnodeInitDnodes, mnodeCleanupDnodes}, + {"dbs", mnodeInitDbs, mnodeCleanupDbs}, + {"vgroups", mnodeInitVgroups, mnodeCleanupVgroups}, + {"tables", mnodeInitTables, mnodeCleanupTables}, + {"mnodes", mnodeInitMnodes, mnodeCleanupMnodes}, + {"sdb", sdbInit, sdbCleanUp}, + {"balance", balanceInit, balanceCleanUp}, + {"grant", grantInit, grantCleanUp}, + {"show", mnodeInitShow, mnodeCleanUpShow} +}; + static void mnodeInitTimer(); static void mnodeCleanupTimer(); static bool mnodeNeedStart() ; +static void mnodeCleanupComponents(int32_t stepId) { + for (int32_t i = stepId; i >= 0; i--) { + tsMnodeComponents[i].cleanup(); + } +} + +static int32_t mnodeInitComponents() { + int32_t code = 0; + for (int32_t i = 0; i < sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]); i++) { + if (tsMnodeComponents[i].init() != 0) { + mnodeCleanupComponents(i); + code = -1; + break; + } + } + return code; +} + int32_t mnodeStartSystem() { if (tsMgmtIsRunning) { mPrint("mnode module already started..."); @@ -57,57 +97,7 @@ int32_t mnodeStartSystem() { dnodeAllocateMnodeRqueue(); dnodeAllocateMnodePqueue(); - if (mnodeInitAccts() < 0) { - mError("failed to init accts"); - return -1; - } - - if (mnodeInitUsers() < 0) { - mError("failed to init users"); - return -1; - } - - if (mnodeInitDnodes() < 0) { - mError("failed to init dnodes"); - return -1; - } - - if (mnodeInitDbs() < 0) { - mError("failed to init dbs"); - return -1; - } - - if (mnodeInitVgroups() < 0) { - mError("failed to init vgroups"); - return -1; - } - - if (mnodeInitTables() < 0) { - mError("failed to init tables"); - return -1; - } - - if (mnodeInitMnodes() < 0) { - mError("failed to init mnodes"); - return -1; - } - - if (sdbInit() < 0) { - mError("failed to init sdb"); - return -1; - } - - if (balanceInit() < 0) { - mError("failed to init balance") - } - - if (grantInit() < 0) { - mError("failed to init grant"); - return -1; - } - - if (mnodeInitShow() < 0) { - mError("failed to init show"); + if (mnodeInitComponents() != 0) { return -1; } @@ -115,7 +105,6 @@ int32_t mnodeStartSystem() { tsMgmtIsRunning = true; mPrint("mnode is initialized successfully"); - return 0; } @@ -133,17 +122,8 @@ void mnodeCleanupSystem() { dnodeFreeMnodeRqueue(); dnodeFreeMnodePqueue(); mnodeCleanupTimer(); - mnodeCleanUpShow(); - grantCleanUp(); - balanceCleanUp(); - sdbCleanUp(); - mnodeCleanupMnodes(); - mnodeCleanupTables(); - mnodeCleanupVgroups(); - mnodeCleanupDbs(); - mnodeCleanupDnodes(); - mnodeCleanupUsers(); - mnodeCleanupAccts(); + mnodeCleanupComponents(sizeof(tsMnodeComponents) / sizeof(tsMnodeComponents[0]) - 1); + mPrint("mnode is cleaned up"); } diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index de1826a174..43ee45f3b1 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -63,7 +63,7 @@ static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) { static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) { SMnodeObj *pMnode = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); - if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; + if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; pDnode->isMgmt = true; mnodeDecDnodeRef(pDnode); @@ -75,7 +75,7 @@ static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) { SMnodeObj *pMnode = pOper->pObj; SDnodeObj *pDnode = mnodeGetDnode(pMnode->mnodeId); - if (pDnode == NULL) return TSDB_CODE_DNODE_NOT_EXIST; + if (pDnode == NULL) return TSDB_CODE_MND_DNODE_NOT_EXIST; pDnode->isMgmt = false; mnodeDecDnodeRef(pDnode); @@ -103,7 +103,7 @@ static int32_t mnodeMnodeActionEncode(SSdbOper *pOper) { static int32_t mnodeMnodeActionDecode(SSdbOper *pOper) { SMnodeObj *pMnode = calloc(1, sizeof(SMnodeObj)); - if (pMnode == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pMnode == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pMnode, pOper->rowData, tsMnodeUpdateSize); pOper->pObj = pMnode; @@ -285,7 +285,7 @@ int32_t mnodeAddMnode(int32_t dnodeId) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pMnode); - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } mnodeUpdateMnodeIpSet(); @@ -307,7 +307,7 @@ void mnodeDropMnodeLocal(int32_t dnodeId) { int32_t mnodeDropMnode(int32_t dnodeId) { SMnodeObj *pMnode = mnodeGetMnode(dnodeId); if (pMnode == NULL) { - return TSDB_CODE_DNODE_NOT_EXIST; + return TSDB_CODE_MND_DNODE_NOT_EXIST; } SSdbOper oper = { @@ -318,7 +318,7 @@ int32_t mnodeDropMnode(int32_t dnodeId) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } sdbDecRef(tsMnodeSdb, pMnode); @@ -335,7 +335,7 @@ static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC if (strcmp(pUser->pAcct->user, "root") != 0) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } int32_t cols = 0; diff --git a/src/mnode/src/mnodePeer.c b/src/mnode/src/mnodePeer.c index d3699948f2..9aefc73b77 100644 --- a/src/mnode/src/mnodePeer.c +++ b/src/mnode/src/mnodePeer.c @@ -48,7 +48,7 @@ void mnodeAddPeerRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)) { int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) { if (pMsg->rpcMsg.pCont == NULL) { mError("%p, msg:%s in mpeer queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_INVALID_MSG_LEN; + return TSDB_CODE_MND_INVALID_MSG_LEN; } if (!sdbIsMaster()) { @@ -63,12 +63,12 @@ int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) { mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); } - return TSDB_CODE_REDIRECT; + return TSDB_CODE_RPC_REDIRECT; } if (tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType] == NULL) { mError("%p, msg:%s in mpeer queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_MND_MSG_NOT_PROCESSED; } return (*tsMnodeProcessPeerMsgFp[pMsg->rpcMsg.msgType])(pMsg); diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index a37f5436c6..541fc9cbd8 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -18,6 +18,10 @@ #include "taosmsg.h" #include "taoserror.h" #include "tutil.h" +#include "ttime.h" +#include "tcache.h" +#include "tglobal.h" +#include "tdataformat.h" #include "mnode.h" #include "mnodeDef.h" #include "mnodeInt.h" @@ -32,468 +36,156 @@ #include "mnodeVgroup.h" #include "mnodeWrite.h" -int32_t mnodeSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg); +#define CONN_KEEP_TIME (tsShellActivityTimer * 3) +#define CONN_CHECK_TIME (tsShellActivityTimer * 2) +#define QUERY_ID_SIZE 20 -int32_t mnodeKillQuery(char *qidstr, void *pConn); -int32_t mnodeKillStream(char *qidstr, void *pConn); -int32_t mnodeKillConnection(char *qidstr, void *pConn); +extern void *tsMnodeTmr; +static SCacheObj *tsMnodeConnCache = NULL; +static uint32_t tsConnIndex = 0; -typedef struct { - char user[TSDB_TABLE_ID_LEN + 1]; - uint64_t stime; - uint32_t ip; - uint16_t port; -} SConnInfo; +static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static void mnodeFreeConn(void *data); +static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg); +static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg); +static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg); -typedef struct { - int numOfConns; - int index; - SConnInfo connInfo[]; -} SConnShow; +int32_t mnodeInitProfile() { + mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_QUERIES, mnodeGetQueryMeta); + mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_QUERIES, mnodeRetrieveQueries); + mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONNS, mnodeGetConnsMeta); + mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONNS, mnodeRetrieveConns); + mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMS, mnodeGetStreamMeta); + mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMS, mnodeRetrieveStreams); -typedef struct { - uint32_t ip; - uint16_t port; - char user[TSDB_TABLE_ID_LEN+ 1]; -} SCDesc; - -typedef struct { - int32_t index; - int32_t numOfQueries; - SCDesc * connInfo; - SCDesc **cdesc; - SQueryDesc qdesc[]; -} SQueryShow; - -typedef struct { - int32_t index; - int32_t numOfStreams; - SCDesc * connInfo; - SCDesc **cdesc; - SStreamDesc sdesc[]; -} SStreamShow; - -int32_t mgmtSaveQueryStreamList(SCMHeartBeatMsg *pHBMsg) { -// SAcctObj *pAcct = pConn->pAcct; -// -// if (contLen <= 0 || pAcct == NULL) { -// return 0; -// } -// -// pthread_mutex_lock(&pAcct->mutex); -// -// if (pConn->pQList) { -// pAcct->acctInfo.numOfQueries -= pConn->pQList->numOfQueries; -// pAcct->acctInfo.numOfStreams -= pConn->pSList->numOfStreams; -// } -// -// pConn->pQList = realloc(pConn->pQList, contLen); -// memcpy(pConn->pQList, cont, contLen); -// -// pConn->pSList = (SStreamList *)(((char *)pConn->pQList) + pConn->pQList->numOfQueries * sizeof(SQueryDesc) + sizeof(SQqueryList)); -// -// pAcct->acctInfo.numOfQueries += pConn->pQList->numOfQueries; -// pAcct->acctInfo.numOfStreams += pConn->pSList->numOfStreams; -// -// pthread_mutex_unlock(&pAcct->mutex); - - return TSDB_CODE_SUCCESS; -} - -int32_t mnodeGetQueries(SShowObj *pShow, void *pConn) { -// SAcctObj * pAcct = pConn->pAcct; -// SQueryShow *pQueryShow; -// -// pthread_mutex_lock(&pAcct->mutex); -// -// pQueryShow = malloc(sizeof(SQueryDesc) * pAcct->acctInfo.numOfQueries + sizeof(SQueryShow)); -// pQueryShow->numOfQueries = 0; -// pQueryShow->index = 0; -// pQueryShow->connInfo = NULL; -// pQueryShow->cdesc = NULL; -// -// if (pAcct->acctInfo.numOfQueries > 0) { -// pQueryShow->connInfo = (SCDesc *)malloc(pAcct->acctInfo.numOfConns * sizeof(SCDesc)); -// pQueryShow->cdesc = (SCDesc **)malloc(pAcct->acctInfo.numOfQueries * sizeof(SCDesc *)); -// -// pConn = pAcct->pConn; -// SQueryDesc * pQdesc = pQueryShow->qdesc; -// SCDesc * pCDesc = pQueryShow->connInfo; -// SCDesc **ppCDesc = pQueryShow->cdesc; -// -// while (pConn) { -// if (pConn->pQList && pConn->pQList->numOfQueries > 0) { -// pCDesc->ip = pConn->ip; -// pCDesc->port = pConn->port; -// strcpy(pCDesc->user, pConn->pUser->user); -// -// memcpy(pQdesc, pConn->pQList->qdesc, sizeof(SQueryDesc) * pConn->pQList->numOfQueries); -// pQdesc += pConn->pQList->numOfQueries; -// pQueryShow->numOfQueries += pConn->pQList->numOfQueries; -// for (int32_t i = 0; i < pConn->pQList->numOfQueries; ++i, ++ppCDesc) *ppCDesc = pCDesc; -// -// pCDesc++; -// } -// pConn = pConn->next; -// } -// } -// -// pthread_mutex_unlock(&pAcct->mutex); -// -// // sorting based on useconds -// -// pShow->pIter = pQueryShow; + mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_QUERY, mnodeProcessKillQueryMsg); + mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_STREAM, mnodeProcessKillStreamMsg); + mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_CONN, mnodeProcessKillConnectionMsg); + tsMnodeConnCache = taosCacheInitWithCb(tsMnodeTmr, CONN_CHECK_TIME, mnodeFreeConn); return 0; } -int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { - int32_t cols = 0; +void mnodeCleanupProfile() { + if (tsMnodeConnCache != NULL) { + mPrint("conn cache is cleanup"); + taosCacheCleanup(tsMnodeConnCache); + tsMnodeConnCache = NULL; + } +} +SConnObj *mnodeCreateConn(char *user, uint32_t ip, uint16_t port) { + int32_t connSize = taosHashGetSize(tsMnodeConnCache->pHashTable); + if (connSize > tsMaxShellConns) { + mError("failed to create conn for user:%s ip:%s:%u, conns:%d larger than maxShellConns:%d, ", user, taosIpStr(ip), + port, connSize, tsMaxShellConns); + terrno = TSDB_CODE_MND_TOO_MANY_SHELL_CONNS; + return NULL; + } + + uint32_t connId = atomic_add_fetch_32(&tsConnIndex, 1); + if (connId == 0) atomic_add_fetch_32(&tsConnIndex, 1); + + SConnObj connObj = { + .ip = ip, + .port = port, + .connId = connId, + .stime = taosGetTimestampMs() + }; + strcpy(connObj.user, user); + + char key[10]; + sprintf(key, "%u", connId); + SConnObj *pConn = taosCachePut(tsMnodeConnCache, key, &connObj, sizeof(connObj), CONN_KEEP_TIME); + + mTrace("connId:%d, is created, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port); + return pConn; +} + +void mnodeReleaseConn(SConnObj *pConn) { + if(pConn == NULL) return; + taosCacheRelease(tsMnodeConnCache, (void**)&pConn, false); +} + +SConnObj *mnodeAccquireConn(uint32_t connId, char *user, uint32_t ip, uint16_t port) { + char key[10]; + sprintf(key, "%u", connId); + uint64_t expireTime = CONN_KEEP_TIME * 1000 + (uint64_t)taosGetTimestampMs(); + + SConnObj *pConn = taosCacheUpdateExpireTimeByName(tsMnodeConnCache, key, expireTime); + if (pConn == NULL) { + mError("connId:%d, is already destroyed, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port); + return NULL; + } + + if (pConn->ip != ip || pConn->port != port /* || strcmp(pConn->user, user) != 0 */) { + mError("connId:%d, incoming conn user:%s ip:%s:%u, not match exist conn user:%s ip:%s:%u", connId, user, + taosIpStr(ip), port, pConn->user, taosIpStr(pConn->ip), pConn->port); + taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false); + return NULL; + } + + // mTrace("connId:%d, is incoming, user:%s ip:%s:%u", connId, pConn->user, taosIpStr(pConn->ip), pConn->port); + pConn->lastAccess = expireTime; + return pConn; +} + +static void mnodeFreeConn(void *data) { + SConnObj *pConn = data; + tfree(pConn->pQueries); + tfree(pConn->pQueries); + + mTrace("connId:%d, is destroyed", pConn->connId); +} + +static void *mnodeGetNextConn(SHashMutableIterator *pIter, SConnObj **pConn) { + *pConn = NULL; + + if (pIter == NULL) { + pIter = taosHashCreateIter(tsMnodeConnCache->pHashTable); + } + + if (!taosHashIterNext(pIter)) { + taosHashDestroyIter(pIter); + return NULL; + } + + SCacheDataNode **pNode = taosHashIterGet(pIter); + if (pNode == NULL || *pNode == NULL) { + taosHashDestroyIter(pIter); + return NULL; + } + + *pConn = (SConnObj*)((*pNode)->data); + return pIter; +} + +static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + SUserObj *pUser = mnodeGetUserFromConn(pConn); + if (pUser == NULL) return 0; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + + int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = TSDB_USER_LEN; + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "connId"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "user"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 14; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ip:port:id"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "created_time"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; - strcpy(pSchema[cols].name, "time(us)"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pMeta->numOfColumns = htons(cols); - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - - pShow->numOfRows = 1000000; - pShow->pIter = NULL; - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - - mnodeGetQueries(pShow, pConn); - return 0; -} - -int32_t mnodeKillQuery(char *qidstr, void *pConn) { -// char *temp, *chr, idstr[64]; -// strcpy(idstr, qidstr); -// -// temp = idstr; -// chr = strchr(temp, ':'); -// if (chr == NULL) goto _error; -// *chr = 0; -// uint32_t ip = inet_addr(temp); -// -// temp = chr + 1; -// chr = strchr(temp, ':'); -// if (chr == NULL) goto _error; -// *chr = 0; -// uint16_t port = htons(atoi(temp)); -// -// temp = chr + 1; -// uint32_t queryId = atoi(temp); -// -// SAcctObj *pAcct = pConn->pAcct; -// -// pthread_mutex_lock(&pAcct->mutex); -// -// pConn = pAcct->pConn; -// while (pConn) { -// if (pConn->ip == ip && pConn->port == port && pConn->pQList) { -// int32_t i; -// SQueryDesc *pQDesc = pConn->pQList->qdesc; -// for (i = 0; i < pConn->pQList->numOfQueries; ++i, ++pQDesc) { -// if (pQDesc->queryId == queryId) break; -// } -// -// if (i < pConn->pQList->numOfQueries) break; -// } -// -// pConn = pConn->next; -// } -// -// if (pConn) pConn->queryId = queryId; -// -// pthread_mutex_unlock(&pAcct->mutex); -// -// if (pConn == NULL || pConn->pQList == NULL || pConn->pQList->numOfQueries == 0) goto _error; -// -// mTrace("query:%s is there, kill it", qidstr); -// return 0; -// -//_error: -// mTrace("query:%s is not there", qidstr); - - return TSDB_CODE_INVALID_QUERY_ID; -} - -int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn) { - int32_t numOfRows = 0; - char *pWrite; - int32_t cols = 0; - - SQueryShow *pQueryShow = (SQueryShow *)pShow->pIter; - - if (rows > pQueryShow->numOfQueries - pQueryShow->index) rows = pQueryShow->numOfQueries - pQueryShow->index; - - while (numOfRows < rows) { - SQueryDesc *pNode = pQueryShow->qdesc + pQueryShow->index; - SCDesc *pCDesc = pQueryShow->cdesc[pQueryShow->index]; - cols = 0; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, pCDesc->user); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - uint32_t ip = pCDesc->ip; - sprintf(pWrite, "%d.%d.%d.%d:%hu:%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24, htons(pCDesc->port), - pNode->queryId); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pNode->stime; - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pNode->useconds; - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, pNode->sql); - cols++; - - numOfRows++; - pQueryShow->index++; - } - - if (numOfRows == 0) { - tfree(pQueryShow->cdesc); - tfree(pQueryShow->connInfo); - tfree(pQueryShow); - } - - pShow->numOfReads += numOfRows; - return numOfRows; -} - -int32_t mnodeGetStreams(SShowObj *pShow, void *pConn) { -// SAcctObj * pAcct = pConn->pAcct; -// SStreamShow *pStreamShow; -// -// pthread_mutex_lock(&pAcct->mutex); -// -// pStreamShow = malloc(sizeof(SStreamDesc) * pAcct->acctInfo.numOfStreams + sizeof(SQueryShow)); -// pStreamShow->numOfStreams = 0; -// pStreamShow->index = 0; -// pStreamShow->connInfo = NULL; -// pStreamShow->cdesc = NULL; -// -// if (pAcct->acctInfo.numOfStreams > 0) { -// pStreamShow->connInfo = (SCDesc *)malloc(pAcct->acctInfo.numOfConns * sizeof(SCDesc)); -// pStreamShow->cdesc = (SCDesc **)malloc(pAcct->acctInfo.numOfStreams * sizeof(SCDesc *)); -// -// pConn = pAcct->pConn; -// SStreamDesc * pSdesc = pStreamShow->sdesc; -// SCDesc * pCDesc = pStreamShow->connInfo; -// SCDesc **ppCDesc = pStreamShow->cdesc; -// -// while (pConn) { -// if (pConn->pSList && pConn->pSList->numOfStreams > 0) { -// pCDesc->ip = pConn->ip; -// pCDesc->port = pConn->port; -// strcpy(pCDesc->user, pConn->pUser->user); -// -// memcpy(pSdesc, pConn->pSList->sdesc, sizeof(SStreamDesc) * pConn->pSList->numOfStreams); -// pSdesc += pConn->pSList->numOfStreams; -// pStreamShow->numOfStreams += pConn->pSList->numOfStreams; -// for (int32_t i = 0; i < pConn->pSList->numOfStreams; ++i, ++ppCDesc) *ppCDesc = pCDesc; -// -// pCDesc++; -// } -// pConn = pConn->next; -// } -// } -// -// pthread_mutex_unlock(&pAcct->mutex); -// -// // sorting based on useconds -// -// pShow->pIter = pStreamShow; - - return 0; -} - - -int32_t mnodeKillStream(char *qidstr, void *pConn) { -// char *temp, *chr, idstr[64]; -// strcpy(idstr, qidstr); -// -// temp = idstr; -// chr = strchr(temp, ':'); -// if (chr == NULL) goto _error; -// *chr = 0; -// uint32_t ip = inet_addr(temp); -// -// temp = chr + 1; -// chr = strchr(temp, ':'); -// if (chr == NULL) goto _error; -// *chr = 0; -// uint16_t port = htons(atoi(temp)); -// -// temp = chr + 1; -// uint32_t streamId = atoi(temp); -// -// SAcctObj *pAcct = pConn->pAcct; -// -// pthread_mutex_lock(&pAcct->mutex); -// -// pConn = pAcct->pConn; -// while (pConn) { -// if (pConn->ip == ip && pConn->port == port && pConn->pSList) { -// int32_t i; -// SStreamDesc *pSDesc = pConn->pSList->sdesc; -// for (i = 0; i < pConn->pSList->numOfStreams; ++i, ++pSDesc) { -// if (pSDesc->streamId == streamId) break; -// } -// -// if (i < pConn->pSList->numOfStreams) break; -// } -// -// pConn = pConn->next; -// } -// -// if (pConn) pConn->streamId = streamId; -// -// pthread_mutex_unlock(&pAcct->mutex); -// -// if (pConn == NULL || pConn->pSList == NULL || pConn->pSList->numOfStreams == 0) goto _error; -// -// mTrace("stream:%s is there, kill it", qidstr); -// return 0; -// -//_error: -// mTrace("stream:%s is not there", qidstr); - - return TSDB_CODE_INVALID_STREAM_ID; -} - -int32_t mnodeKillConnection(char *qidstr, void *pConn) { -// void *pConn1 = NULL; -// char * temp, *chr, idstr[64]; -// strcpy(idstr, qidstr); -// -// temp = idstr; -// chr = strchr(temp, ':'); -// if (chr == NULL) goto _error; -// *chr = 0; -// uint32_t ip = inet_addr(temp); -// -// temp = chr + 1; -// uint16_t port = htons(atoi(temp)); -// SAcctObj *pAcct = pConn->pAcct; -// -// pthread_mutex_lock(&pAcct->mutex); -// -// pConn = pAcct->pConn; -// while (pConn) { -// if (pConn->ip == ip && pConn->port == port) { -// // there maybe two connections from a shell -// if (pConn1 == NULL) -// pConn1 = pConn; -// else -// break; -// } -// -// pConn = pConn->next; -// } -// -// if (pConn1) pConn1->killConnection = 1; -// if (pConn) pConn->killConnection = 1; -// -// pthread_mutex_unlock(&pAcct->mutex); -// -// if (pConn1 == NULL) goto _error; -// -// mTrace("connection:%s is there, kill it", qidstr); -// return 0; -// -//_error: -// mTrace("connection:%s is not there", qidstr); - - return TSDB_CODE_INVALID_CONNECTION; -} - - -int mnodeGetConns(SShowObj *pShow, void *pConn) { - // SAcctObj * pAcct = pConn->pAcct; - // SConnShow *pConnShow; - // - // pthread_mutex_lock(&pAcct->mutex); - // - // pConnShow = malloc(sizeof(SConnInfo) * pAcct->acctInfo.numOfConns + sizeof(SConnShow)); - // pConnShow->index = 0; - // pConnShow->numOfConns = 0; - // - // if (pAcct->acctInfo.numOfConns > 0) { - // pConn = pAcct->pConn; - // SConnInfo *pConnInfo = pConnShow->connInfo; - // - // while (pConn && pConn->pUser) { - // strcpy(pConnInfo->user, pConn->pUser->user); - // pConnInfo->ip = pConn->ip; - // pConnInfo->port = pConn->port; - // pConnInfo->stime = pConn->stime; - // - // pConnShow->numOfConns++; - // pConnInfo++; - // pConn = pConn->next; - // } - // } - // - // pthread_mutex_unlock(&pAcct->mutex); - // - // // sorting based on useconds - // - // pShow->pIter = pConnShow; - - return 0; -} - -int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { - int32_t cols = 0; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN; - SSchema *pSchema = pMeta->schema; - - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "user"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6; + pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "ip:port"); pSchema[cols].bytes = htons(pShow->bytes[cols]); @@ -505,144 +197,399 @@ int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "last access"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pMeta->numOfColumns = htons(cols); pShow->numOfColumns = cols; pShow->offset[0] = 0; - for (int i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } - pShow->numOfRows = 1000000; - pShow->pIter = NULL; + pShow->numOfRows = taosHashGetSize(tsMnodeConnCache->pHashTable); pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - mnodeGetConns(pShow, pConn); return 0; } -int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn) { +static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t numOfRows = 0; - char *pWrite; + SConnObj *pConnObj = NULL; int32_t cols = 0; - - SConnShow *pConnShow = (SConnShow *)pShow->pIter; - - if (rows > pConnShow->numOfConns - pConnShow->index) rows = pConnShow->numOfConns - pConnShow->index; + char * pWrite; + char ipStr[TSDB_IPv4ADDR_LEN + 7]; while (numOfRows < rows) { - SConnInfo *pNode = pConnShow->connInfo + pConnShow->index; + pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj); + if (pConnObj == NULL) break; + cols = 0; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, pNode->user); + *(int32_t *) pWrite = pConnObj->connId; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - uint32_t ip = pNode->ip; - sprintf(pWrite, "%d.%d.%d.%d:%hu", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24, htons(pNode->port)); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, TSDB_USER_LEN); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pNode->stime; + snprintf(ipStr, TSDB_IPv4ADDR_LEN + 6, "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, TSDB_IPv4ADDR_LEN + 6); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pConnObj->stime; + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pConnObj->lastAccess; cols++; numOfRows++; - pConnShow->index++; - } - - if (numOfRows == 0) { - tfree(pConnShow); } pShow->numOfReads += numOfRows; + const int32_t NUM_OF_COLUMNS = 5; + mnodeVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow); + return numOfRows; } -int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { - // SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; - - // SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle); - // if (pUser == NULL) { - // rpcRsp.code = TSDB_CODE_INVALID_USER; - // rpcSendResponse(&rpcRsp); - // return; - // } +// not thread safe, need optimized +int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) { + pConn->numOfQueries = htonl(pHBMsg->numOfQueries); + if (pConn->numOfQueries > 0) { + pConn->pQueries = calloc(sizeof(SQueryDesc), pConn->numOfQueries); + memcpy(pConn->pQueries, pHBMsg->pData, pConn->numOfQueries * sizeof(SQueryDesc)); + } - // SCMKillQueryMsg *pKill = pMsg->pCont; - // int32_t code; + pConn->numOfStreams = htonl(pHBMsg->numOfStreams); + if (pConn->numOfStreams > 0) { + pConn->pStreams = calloc(sizeof(SStreamDesc), pConn->numOfStreams); + memcpy(pConn->pStreams, pHBMsg->pData + pConn->numOfQueries * sizeof(SQueryDesc), + pConn->numOfStreams * sizeof(SStreamDesc)); + } - // if (!pUser->writeAuth) { - // code = TSDB_CODE_NO_RIGHTS; - // } else { - // code = mgmtKillQuery(pKill->queryId, pMsg->thandle); - // } - - // rpcRsp.code = code; - // rpcSendResponse(&rpcRsp); - // mnodeDecUserRef(pUser); return TSDB_CODE_SUCCESS; } -int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { - // SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; - - // SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle); - // if (pUser == NULL) { - // rpcRsp.code = TSDB_CODE_INVALID_USER; - // rpcSendResponse(&rpcRsp); - // return; - // } +static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + SUserObj *pUser = mnodeGetUserFromConn(pConn); + if (pUser == NULL) return 0; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; - // SCMKillStreamMsg *pKill = pMsg->pCont; - // int32_t code; + int32_t cols = 0; + SSchema *pSchema = pMeta->schema; - // if (!pUser->writeAuth) { - // code = TSDB_CODE_NO_RIGHTS; - // } else { - // code = mgmtKillStream(pKill->queryId, pMsg->thandle); - // } + pShow->bytes[cols] = QUERY_ID_SIZE + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "queryId"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; - // rpcRsp.code = code; - // rpcSendResponse(&rpcRsp); - // mnodeDecUserRef(pUser); - return TSDB_CODE_SUCCESS; -} + pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "user"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; -int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) { - // SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; - - // SUserObj *pUser = mnodeGetUserFromConn(pMsg->thandle); - // if (pUser == NULL) { - // rpcRsp.code = TSDB_CODE_INVALID_USER; - // rpcSendResponse(&rpcRsp); - // return; - // } + pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "ip:port"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; - // SCMKillConnMsg *pKill = pMsg->pCont; - // int32_t code; + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "created time"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; - // if (!pUser->writeAuth) { - // code = TSDB_CODE_NO_RIGHTS; - // } else { - // code = mgmtKillConnection(pKill->queryId, pMsg->thandle); - // } + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; + strcpy(pSchema[cols].name, "time(us)"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; - // rpcRsp.code = code; - // rpcSendResponse(&rpcRsp); - // mnodeDecUserRef(pUser); - return TSDB_CODE_SUCCESS; -} + pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sql"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; -int32_t mnodeInitProfile() { - // mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_QUERIES, mnodeGetQueryMeta); - // mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_QUERIES, mnodeRetrieveQueries); - // mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONNS, mnodeGetConnsMeta); - // mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONNS, mnodeRetrieveConns); + pMeta->numOfColumns = htons(cols); + pShow->numOfColumns = cols; - // mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_QUERY, mnodeProcessKillQueryMsg); - // mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_STREAM, mnodeProcessKillStreamMsg); - // mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_CONN, mnodeProcessKillConnectionMsg); + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = 1000000; + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; return 0; } -void mnodeCleanupProfile() {} +static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + SConnObj *pConnObj = NULL; + int32_t cols = 0; + char * pWrite; + char ipStr[TSDB_IPv4ADDR_LEN + 7]; + + while (numOfRows < rows) { + pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj); + if (pConnObj == NULL) break; + + for (int32_t i = 0; i < pConnObj->numOfQueries; ++i) { + SQueryDesc *pDesc = pConnObj->pQueries + i; + cols = 0; + + 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); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, TSDB_USER_LEN); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + snprintf(ipStr, TSDB_IPv4ADDR_LEN + 6, "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, TSDB_IPv4ADDR_LEN + 6); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->stime); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->useconds); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, TSDB_SHOW_SQL_LEN); + cols++; + + numOfRows++; + } + } + + pShow->numOfReads += numOfRows; + const int32_t NUM_OF_COLUMNS = 6; + mnodeVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow); + return numOfRows; +} + +static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { + SUserObj *pUser = mnodeGetUserFromConn(pConn); + if (pUser == NULL) return 0; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + + int32_t cols = 0; + SSchema *pSchema = pMeta->schema; + + pShow->bytes[cols] = QUERY_ID_SIZE + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "streamId"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "user"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "ip:port"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "created time"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "exec time"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; + strcpy(pSchema[cols].name, "time(us)"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sql"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "cycles"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pMeta->numOfColumns = htons(cols); + pShow->numOfColumns = cols; + + pShow->offset[0] = 0; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; + } + + pShow->numOfRows = 1000000; + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + + return 0; +} + +static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn) { + int32_t numOfRows = 0; + SConnObj *pConnObj = NULL; + int32_t cols = 0; + char * pWrite; + char ipStr[TSDB_IPv4ADDR_LEN + 7]; + + while (numOfRows < rows) { + pShow->pIter = mnodeGetNextConn(pShow->pIter, &pConnObj); + if (pConnObj == NULL) break; + + for (int32_t i = 0; i < pConnObj->numOfStreams; ++i) { + SStreamDesc *pDesc = pConnObj->pStreams + i; + cols = 0; + + 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); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConnObj->user, TSDB_USER_LEN); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + snprintf(ipStr, TSDB_IPv4ADDR_LEN + 6, "%s:%u", taosIpStr(pConnObj->ip), pConnObj->port); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, TSDB_IPv4ADDR_LEN + 6); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->ctime); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->stime); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->useconds); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, TSDB_SHOW_SQL_LEN); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = (int32_t)htobe64(pDesc->num); + cols++; + + numOfRows++; + } + } + + pShow->numOfReads += numOfRows; + const int32_t NUM_OF_COLUMNS = 8; + mnodeVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow); + return numOfRows; +} + +static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { + SUserObj *pUser = pMsg->pUser; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + + SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; + mPrint("kill query msg is received, queryId:%s", pKill->queryId); + + const char delim = ':'; + char* connIdStr = strtok(pKill->queryId, &delim); + char* queryIdStr = strtok(NULL, &delim); + + if (queryIdStr == NULL || connIdStr == NULL) { + mPrint("failed to kill query, queryId:%s", pKill->queryId); + return TSDB_CODE_MND_INVALID_QUERY_ID; + } + + int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10); + + SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr); + if (pConn == NULL) { + mError("connId:%s, failed to kill queryId:%d, conn not exist", connIdStr, queryId); + return TSDB_CODE_MND_INVALID_CONN_ID; + } else { + mPrint("connId:%s, queryId:%d is killed by user:%s", connIdStr, queryId, pUser->user); + pConn->queryId = queryId; + taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false); + return TSDB_CODE_SUCCESS; + } +} + +static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { + SUserObj *pUser = pMsg->pUser; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + + SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; + mPrint("kill stream msg is received, streamId:%s", pKill->queryId); + + const char delim = ':'; + char* connIdStr = strtok(pKill->queryId, &delim); + char* streamIdStr = strtok(NULL, &delim); + + if (streamIdStr == NULL || connIdStr == NULL) { + mPrint("failed to kill stream, streamId:%s", pKill->queryId); + return TSDB_CODE_MND_INVALID_STREAM_ID; + } + + int32_t streamId = (int32_t)strtol(streamIdStr, NULL, 10); + + SConnObj *pConn = taosCacheAcquireByName(tsMnodeConnCache, connIdStr); + if (pConn == NULL) { + mError("connId:%s, failed to kill streamId:%d, conn not exist", connIdStr, streamId); + return TSDB_CODE_MND_INVALID_CONN_ID; + } else { + mPrint("connId:%s, streamId:%d is killed by user:%s", connIdStr, streamId, pUser->user); + pConn->streamId = streamId; + taosCacheRelease(tsMnodeConnCache, (void **)&pConn, false); + return TSDB_CODE_SUCCESS; + } +} + +static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) { + SUserObj *pUser = pMsg->pUser; + if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + + SCMKillConnMsg *pKill = pMsg->rpcMsg.pCont; + SConnObj * pConn = taosCacheAcquireByName(tsMnodeConnCache, pKill->queryId); + if (pConn == NULL) { + mError("connId:%s, failed to kill, conn not exist", pKill->queryId); + return TSDB_CODE_MND_INVALID_CONN_ID; + } else { + mPrint("connId:%s, is killed by user:%s", pKill->queryId, pUser->user); + pConn->killed = 1; + taosCacheRelease(tsMnodeConnCache, (void**)&pConn, false); + return TSDB_CODE_SUCCESS; + } +} diff --git a/src/mnode/src/mnodeRead.c b/src/mnode/src/mnodeRead.c index 0ee917f2d1..2c1f204277 100644 --- a/src/mnode/src/mnodeRead.c +++ b/src/mnode/src/mnodeRead.c @@ -44,7 +44,7 @@ void mnodeAddReadMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *pMsg)) { int32_t mnodeProcessRead(SMnodeMsg *pMsg) { if (pMsg->rpcMsg.pCont == NULL) { mError("%p, msg:%s in mread queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_INVALID_MSG_LEN; + return TSDB_CODE_MND_INVALID_MSG_LEN; } if (!sdbIsMaster()) { @@ -59,12 +59,12 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) { mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); } - return TSDB_CODE_REDIRECT; + return TSDB_CODE_RPC_REDIRECT; } if (tsMnodeProcessReadMsgFp[pMsg->rpcMsg.msgType] == NULL) { mError("%p, msg:%s in mread queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_MND_MSG_NOT_PROCESSED; } int32_t code = mnodeInitMsg(pMsg); diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 51b5fb0d2d..b9033cdf3c 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -518,7 +518,7 @@ static int sdbWrite(void *param, void *data, int type) { sdbError("table:%s, failed to restore %s record:%s from wal, version:%" PRId64 " too large, sdb version:%" PRId64, pTable->tableName, sdbGetActionStr(action), sdbGetKeyStr(pTable, pHead->cont), pHead->version, tsSdbObj.version); - return TSDB_CODE_OTHERS; + return TSDB_CODE_MND_APP_ERROR; } else { tsSdbObj.version = pHead->version; } @@ -561,7 +561,7 @@ static int sdbWrite(void *param, void *data, int type) { SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; code = (*pTable->decodeFp)(&oper); return sdbUpdateHash(pTable, &oper); - } else { return TSDB_CODE_INVALID_MSG_TYPE; } + } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; } } int32_t sdbInsertRow(SSdbOper *pOper) { @@ -571,7 +571,7 @@ int32_t sdbInsertRow(SSdbOper *pOper) { if (sdbGetRowFromObj(pTable, pOper->pObj)) { sdbError("table:%s, failed to insert record:%s, already exist", pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj)); sdbDecRef(pTable, pOper->pObj); - return TSDB_CODE_ALREADY_THERE; + return TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE; } if (pTable->keyType == SDB_KEY_AUTO) { diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index dd6de9d351..36e7d13a86 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -110,12 +110,12 @@ static char *mnodeGetShowType(int32_t showType) { static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { SCMShowMsg *pShowMsg = pMsg->rpcMsg.pCont; if (pShowMsg->type >= TSDB_MGMT_TABLE_MAX) { - return TSDB_CODE_INVALID_MSG_TYPE; + return TSDB_CODE_MND_INVALID_MSG_TYPE; } if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) { mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type)); - return TSDB_CODE_OPS_NOT_SUPPORT; + return TSDB_CODE_COM_OPS_NOT_SUPPORT; } int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen); @@ -127,14 +127,14 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { pShow = mnodePutShowObj(pShow, showObjSize); if (pShow == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } int32_t size = sizeof(SCMShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE; SCMShowRsp *pShowRsp = rpcMallocCont(size); if (pShowRsp == NULL) { mnodeReleaseShowObj(pShow, true); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pShowRsp->qhandle = htobe64((uint64_t) pShow); @@ -169,7 +169,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { */ if (!mnodeAccquireShowObj(pShow)) { mError("%p, show is invalid", pShow); - return TSDB_CODE_INVALID_QHANDLE; + return TSDB_CODE_MND_INVALID_SHOWOBJ; } if (mnodeCheckShowFinished(pShow)) { @@ -202,7 +202,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { rpcFreeCont(pRsp); mnodeReleaseShowObj(pShow, false); assert(false); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } pRsp->numOfRows = htonl(rowsRead); @@ -224,24 +224,50 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { SCMHeartBeatRsp *pHBRsp = (SCMHeartBeatRsp *) rpcMallocCont(sizeof(SCMHeartBeatRsp)); if (pHBRsp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; + } + + SCMHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont; + SRpcConnInfo connInfo; + rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo); + + int32_t connId = htonl(pHBMsg->connId); + SConnObj *pConn = mnodeAccquireConn(connId, connInfo.user, connInfo.clientIp, connInfo.clientPort); + if (pConn == NULL) { + pConn = mnodeCreateConn(connInfo.user, connInfo.clientIp, connInfo.clientPort); + } + + if (pConn == NULL) { + // do not close existing links, otherwise + // mError("failed to create connId, close connect"); + // pHBRsp->killConnection = 1; + } else { + pHBRsp->connId = htonl(pConn->connId); + mnodeSaveQueryStreamList(pConn, pHBMsg); + + if (pConn->killed != 0) { + pHBRsp->killConnection = 1; + } + + if (pConn->streamId != 0) { + pHBRsp->streamId = htonl(pConn->streamId); + pConn->streamId = 0; + } + + if (pConn->queryId != 0) { + pHBRsp->queryId = htonl(pConn->queryId); + pConn->queryId = 0; + } } pHBRsp->onlineDnodes = htonl(mnodeGetOnlinDnodesNum()); pHBRsp->totalDnodes = htonl(mnodeGetDnodesNum()); mnodeGetMnodeIpSetForShell(&pHBRsp->ipList); - - /* - * TODO - * Dispose kill stream or kill query message - */ - pHBRsp->queryId = 0; - pHBRsp->streamId = 0; - pHBRsp->killConnection = 0; pMsg->rpcRsp.rsp = pHBRsp; pMsg->rpcRsp.len = sizeof(SCMHeartBeatRsp); + mnodeReleaseConn(pConn); return TSDB_CODE_SUCCESS; } @@ -252,7 +278,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { SRpcConnInfo connInfo; if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) != 0) { mError("thandle:%p is already released while process connect msg", pMsg->rpcMsg.handle); - code = TSDB_CODE_INVALID_MSG_CONTENT; + code = TSDB_CODE_MND_INVALID_CONNECTION; goto connect_over; } @@ -269,7 +295,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { sprintf(dbName, "%x%s%s", pAcct->acctId, TS_PATH_DELIMITER, pConnectMsg->db); SDbObj *pDb = mnodeGetDb(dbName); if (pDb == NULL) { - code = TSDB_CODE_INVALID_DB; + code = TSDB_CODE_MND_INVALID_DB; goto connect_over; } mnodeDecDbRef(pDb); @@ -277,15 +303,23 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); if (pConnectRsp == NULL) { - code = TSDB_CODE_SERV_OUT_OF_MEMORY; + code = TSDB_CODE_MND_OUT_OF_MEMORY; goto connect_over; } + SConnObj *pConn = mnodeCreateConn(connInfo.user, connInfo.clientIp, connInfo.clientPort); + if (pConn == NULL) { + code = terrno; + } else { + pConnectRsp->connId = htonl(pConn->connId); + mnodeReleaseConn(pConn); + } + sprintf(pConnectRsp->acctId, "%x", pAcct->acctId); strcpy(pConnectRsp->serverVersion, version); pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->superAuth = pUser->superAuth; - + mnodeGetMnodeIpSetForShell(&pConnectRsp->ipList); connect_over: @@ -306,7 +340,7 @@ static int32_t mnodeProcessUseMsg(SMnodeMsg *pMsg) { int32_t code = TSDB_CODE_SUCCESS; if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pUseDbMsg->db); if (pMsg->pDb == NULL) { - code = TSDB_CODE_INVALID_DB; + code = TSDB_CODE_MND_INVALID_DB; } return code; @@ -358,3 +392,11 @@ static void mnodeReleaseShowObj(void *pShow, bool forceRemove) { mTrace("%p, show is released, force:%s", pShow, forceRemove ? "true" : "false"); taosCacheRelease(tsMnodeShowCache, &pShow, forceRemove); } + +void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) { + if (rows < capacity) { + for (int32_t i = 0; i < numOfCols; ++i) { + memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows); + } + } +} \ No newline at end of file diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 196056b474..2077d6f43e 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -61,8 +61,8 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); -static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); -static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn); +static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); +static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *mnodeMsg); static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg); @@ -107,21 +107,21 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) { SVgObj *pVgroup = mnodeGetVgroup(pTable->vgId); if (pVgroup == NULL) { mError("ctable:%s, not in vgId:%d", pTable->info.tableId, pTable->vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } mnodeDecVgroupRef(pVgroup); SDbObj *pDb = mnodeGetDb(pVgroup->dbName); if (pDb == NULL) { mError("ctable:%s, vgId:%d not in db:%s", pTable->info.tableId, pVgroup->vgId, pVgroup->dbName); - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } mnodeDecDbRef(pDb); SAcctObj *pAcct = mnodeGetAcct(pDb->acct); if (pAcct == NULL) { mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); - return TSDB_CODE_INVALID_ACCT; + return TSDB_CODE_MND_INVALID_ACCT; } mnodeDecAcctRef(pAcct); @@ -145,7 +145,7 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) { static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) { SChildTableObj *pTable = pOper->pObj; if (pTable->vgId == 0) { - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } SVgObj *pVgroup = NULL; @@ -201,7 +201,7 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { assert(pTable != NULL && pOper->rowData != NULL); int32_t len = strlen(pTable->info.tableId); - if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_INVALID_TABLE_ID; + if (len > TSDB_TABLE_ID_LEN) return TSDB_CODE_MND_INVALID_TABLE_ID; memcpy(pOper->rowData, pTable->info.tableId, len); memset(pOper->rowData + len, 0, 1); @@ -229,12 +229,12 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) { static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { assert(pOper->rowData != NULL); SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); - if (pTable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pTable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; int32_t len = strlen(pOper->rowData); if (len > TSDB_TABLE_ID_LEN) { free(pTable); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } pTable->info.tableId = strdup(pOper->rowData); len++; @@ -247,7 +247,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { pTable->schema = (SSchema *)malloc(schemaSize); if (pTable->schema == NULL) { mnodeDestroyChildTable(pTable); - return TSDB_CODE_INVALID_TABLE_TYPE; + return TSDB_CODE_MND_INVALID_TABLE_TYPE; } memcpy(pTable->schema, pOper->rowData + len, schemaSize); len += schemaSize; @@ -256,7 +256,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) { pTable->sql = malloc(pTable->sqlLen); if (pTable->sql == NULL) { mnodeDestroyChildTable(pTable); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } memcpy(pTable->sql, pOper->rowData + len, pTable->sqlLen); } @@ -453,7 +453,7 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { assert(pOper->pObj != NULL && pOper->rowData != NULL); int32_t len = strlen(pStable->info.tableId); - if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_INVALID_TABLE_ID; + if (len > TSDB_TABLE_ID_LEN) len = TSDB_CODE_MND_INVALID_TABLE_ID; memcpy(pOper->rowData, pStable->info.tableId, len); memset(pOper->rowData + len, 0, 1); @@ -474,12 +474,12 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) { static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { assert(pOper->rowData != NULL); SSuperTableObj *pStable = (SSuperTableObj *) calloc(1, sizeof(SSuperTableObj)); - if (pStable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pStable == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; int32_t len = strlen(pOper->rowData); if (len > TSDB_TABLE_ID_LEN){ free(pStable); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } pStable->info.tableId = strdup(pOper->rowData); len++; @@ -491,7 +491,7 @@ static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) { pStable->schema = malloc(schemaSize); if (pStable->schema == NULL) { mnodeDestroySuperTable(pStable); - return TSDB_CODE_NOT_SUPER_TABLE; + return TSDB_CODE_MND_NOT_SUPER_TABLE; } memcpy(pStable->schema, pOper->rowData + len, schemaSize); @@ -568,8 +568,8 @@ int32_t mnodeInitTables() { mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_TABLE, mnodeRetrieveShowTables); mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_METRIC, mnodeGetShowSuperTableMeta); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_METRIC, mnodeRetrieveShowSuperTables); - mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMS, mnodeGetStreamMeta); - mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMS, mnodeRetrieveStreams); + mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMTABLES, mnodeGetStreamTableMeta); + mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMTABLES, mnodeRetrieveStreamTables); return TSDB_CODE_SUCCESS; } @@ -668,7 +668,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDb(pCreate->db); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to create, db not selected", pCreate->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId); @@ -681,7 +681,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("table:%s, failed to create, table already exist", pCreate->tableId); - return TSDB_CODE_TABLE_ALREADY_EXIST; + return TSDB_CODE_MND_TABLE_ALREADY_EXIST; } } @@ -699,12 +699,12 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pDrop->tableId); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to drop table, db not selected", pDrop->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { mError("table:%s, failed to drop table, in monitor database", pDrop->tableId); - return TSDB_CODE_MONITOR_DB_FORBIDDEN; + return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pDrop->tableId); @@ -714,7 +714,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } else { mError("table:%s, failed to drop table, table not exist", pDrop->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } } @@ -735,14 +735,14 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pInfo->tableId); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to get table meta, db not selected", pInfo->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pInfo->tableId); if (pMsg->pTable == NULL) { if (!pInfo->createFlag) { mError("table:%s, failed to get table meta, table not exist", pInfo->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } else { mTrace("table:%s, failed to get table meta, start auto create table ", pInfo->tableId); return mnodeAutoCreateChildTable(pMsg); @@ -761,7 +761,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { SSuperTableObj *pStable = calloc(1, sizeof(SSuperTableObj)); if (pStable == NULL) { mError("table:%s, failed to create, no enough memory", pCreate->tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pStable->info.tableId = strdup(pCreate->tableId); @@ -779,7 +779,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (pStable->schema == NULL) { free(pStable); mError("table:%s, failed to create, no schema input", pCreate->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } memcpy(pStable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); @@ -804,7 +804,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (code != TSDB_CODE_SUCCESS) { mnodeDestroySuperTable(pStable); mError("table:%s, failed to create, sdb error", pCreate->tableId); - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } else { mLPrint("table:%s, is created, tags:%d fields:%d", pStable->info.tableId, pStable->numOfTags, pStable->numOfColumns); return TSDB_CODE_SUCCESS; @@ -862,18 +862,18 @@ static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char * static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t ntags) { if (pStable->numOfTags + ntags > TSDB_MAX_TAGS) { mError("stable:%s, add tag, too many tags", pStable->info.tableId); - return TSDB_CODE_TOO_MANY_TAGS; + return TSDB_CODE_MND_TOO_MANY_TAGS; } for (int32_t i = 0; i < ntags; i++) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add tag, column:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_TAG_ALREAY_EXIST; + return TSDB_CODE_MND_TAG_ALREAY_EXIST; } if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add tag, tag:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_FIELD_ALREAY_EXIST; + return TSDB_CODE_MND_FIELD_ALREAY_EXIST; } } @@ -898,7 +898,7 @@ static int32_t mnodeAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to add tag %s", pStable->info.tableId, schema[0].name); @@ -909,7 +909,7 @@ static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) { int32_t col = mnodeFindSuperTableTagIndex(pStable, tagName); if (col < 0) { mError("stable:%s, drop tag, tag:%s not exist", pStable->info.tableId, tagName); - return TSDB_CODE_TAG_NOT_EXIST; + return TSDB_CODE_MND_TAG_NOT_EXIST; } memmove(pStable->schema + pStable->numOfColumns + col, pStable->schema + pStable->numOfColumns + col + 1, @@ -925,7 +925,7 @@ static int32_t mnodeDropSuperTableTag(SSuperTableObj *pStable, char *tagName) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to drop tag %s", pStable->info.tableId, tagName); @@ -936,17 +936,17 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa int32_t col = mnodeFindSuperTableTagIndex(pStable, oldTagName); if (col < 0) { mError("stable:%s, failed to modify table tag, oldName: %s, newName: %s", pStable->info.tableId, oldTagName, newTagName); - return TSDB_CODE_TAG_NOT_EXIST; + return TSDB_CODE_MND_TAG_NOT_EXIST; } // int32_t rowSize = 0; uint32_t len = strlen(newTagName); if (len >= TSDB_COL_NAME_LEN) { - return TSDB_CODE_COL_NAME_TOO_LONG; + return TSDB_CODE_MND_COL_NAME_TOO_LONG; } if (mnodeFindSuperTableTagIndex(pStable, newTagName) >= 0) { - return TSDB_CODE_TAG_ALREAY_EXIST; + return TSDB_CODE_MND_TAG_ALREAY_EXIST; } // update @@ -961,7 +961,7 @@ static int32_t mnodeModifySuperTableTagName(SSuperTableObj *pStable, char *oldTa int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to modify tag %s to %s", pStable->info.tableId, oldTagName, newTagName); @@ -982,18 +982,18 @@ static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *col static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSchema schema[], int32_t ncols) { if (ncols <= 0) { mError("stable:%s, add column, ncols:%d <= 0", pStable->info.tableId); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_MND_APP_ERROR; } for (int32_t i = 0; i < ncols; i++) { if (mnodeFindSuperTableColumnIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add column, column:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_FIELD_ALREAY_EXIST; + return TSDB_CODE_MND_FIELD_ALREAY_EXIST; } if (mnodeFindSuperTableTagIndex(pStable, schema[i].name) > 0) { mError("stable:%s, add column, tag:%s already exist", pStable->info.tableId, schema[i].name); - return TSDB_CODE_TAG_ALREAY_EXIST; + return TSDB_CODE_MND_TAG_ALREAY_EXIST; } } @@ -1026,7 +1026,7 @@ static int32_t mnodeAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SS int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to add column", pStable->info.tableId); @@ -1037,7 +1037,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c int32_t col = mnodeFindSuperTableColumnIndex(pStable, colName); if (col <= 0) { mError("stable:%s, drop column, column:%s not exist", pStable->info.tableId, colName); - return TSDB_CODE_FIELD_NOT_EXIST; + return TSDB_CODE_MND_FIELD_NOT_EXIST; } memmove(pStable->schema + col, pStable->schema + col + 1, @@ -1063,7 +1063,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("stable %s, succeed to delete column", pStable->info.tableId); @@ -1073,7 +1073,7 @@ static int32_t mnodeDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, c // show super tables static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); - if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; + if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -1277,14 +1277,14 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { SCMSTableVgroupRspMsg *pRsp = rpcMallocCont(contLen); if (pRsp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pRsp->numOfTables = 0; char *msg = (char *)pRsp + sizeof(SCMSTableVgroupRspMsg); for (int32_t i = 0; i < numOfTable; ++i) { - char *stableName = (char*)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_ID_LEN) * i; + char * stableName = (char *)pInfo + sizeof(SCMSTableVgroupMsg) + (TSDB_TABLE_ID_LEN)*i; SSuperTableObj *pTable = mnodeGetSuperTable(stableName); if (pTable == NULL) { mError("stable:%s, not exist while get stable vgroup info", stableName); @@ -1294,46 +1294,53 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { if (pTable->vgHash == NULL) { mError("stable:%s, not vgroup exist while get stable vgroup info", stableName); mnodeDecTableRef(pTable); - continue; - } - SVgroupsInfo *pVgroupInfo = (SVgroupsInfo *)msg; + // even this super table has no corresponding table, still return + pRsp->numOfTables++; - SHashMutableIterator *pIter = taosHashCreateIter(pTable->vgHash); - int32_t vgSize = 0; - while (taosHashIterNext(pIter)) { - int32_t *pVgId = taosHashIterGet(pIter); - SVgObj * pVgroup = mnodeGetVgroup(*pVgId); - if (pVgroup == NULL) continue; + SVgroupsInfo *pVgroupInfo = (SVgroupsInfo *)msg; + pVgroupInfo->numOfVgroups = 0; + + msg += sizeof(SVgroupsInfo); + } else { + SVgroupsInfo *pVgroupInfo = (SVgroupsInfo *)msg; - pVgroupInfo->vgroups[vgSize].vgId = htonl(pVgroup->vgId); - for (int32_t vn = 0; vn < pVgroup->numOfVnodes; ++vn) { - SDnodeObj *pDnode = pVgroup->vnodeGid[vn].pDnode; - if (pDnode == NULL) break; + SHashMutableIterator *pIter = taosHashCreateIter(pTable->vgHash); + int32_t vgSize = 0; + while (taosHashIterNext(pIter)) { + int32_t *pVgId = taosHashIterGet(pIter); + SVgObj * pVgroup = mnodeGetVgroup(*pVgId); + if (pVgroup == NULL) continue; - strncpy(pVgroupInfo->vgroups[vgSize].ipAddr[vn].fqdn, pDnode->dnodeFqdn, tListLen(pDnode->dnodeFqdn)); - pVgroupInfo->vgroups[vgSize].ipAddr[vn].port = htons(pDnode->dnodePort); + pVgroupInfo->vgroups[vgSize].vgId = htonl(pVgroup->vgId); + for (int32_t vn = 0; vn < pVgroup->numOfVnodes; ++vn) { + SDnodeObj *pDnode = pVgroup->vnodeGid[vn].pDnode; + if (pDnode == NULL) break; - pVgroupInfo->vgroups[vgSize].numOfIps++; + strncpy(pVgroupInfo->vgroups[vgSize].ipAddr[vn].fqdn, pDnode->dnodeFqdn, tListLen(pDnode->dnodeFqdn)); + pVgroupInfo->vgroups[vgSize].ipAddr[vn].port = htons(pDnode->dnodePort); + + pVgroupInfo->vgroups[vgSize].numOfIps++; + } + + vgSize++; + mnodeDecVgroupRef(pVgroup); } - vgSize++; - mnodeDecVgroupRef(pVgroup); + taosHashDestroyIter(pIter); + mnodeDecTableRef(pTable); + + pVgroupInfo->numOfVgroups = htonl(vgSize); + + // one table is done, try the next table + msg += sizeof(SVgroupsInfo) + vgSize * sizeof(SCMVgroupInfo); + pRsp->numOfTables++; } - - taosHashDestroyIter(pIter); - mnodeDecTableRef(pTable); - - pVgroupInfo->numOfVgroups = htonl(vgSize); - - // one table is done, try the next table - msg += sizeof(SVgroupsInfo) + vgSize * sizeof(SCMVgroupInfo); - pRsp->numOfTables++; } if (pRsp->numOfTables != numOfTable) { rpcFreeCont(pRsp); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } else { pRsp->numOfTables = htonl(pRsp->numOfTables); pMsg->rpcRsp.rsp = pRsp; @@ -1367,7 +1374,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO SMDCreateTableMsg *pCreate = rpcMallocCont(contLen); if (pCreate == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } @@ -1424,7 +1431,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb SChildTableObj *pTable = calloc(1, sizeof(SChildTableObj)); if (pTable == NULL) { mError("table:%s, failed to alloc memory", pCreate->tableId); - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } @@ -1445,7 +1452,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb if (pSuperTable == NULL) { mError("table:%s, corresponding super table:%s does not exist", pCreate->tableId, pTagData->name); mnodeDestroyChildTable(pTable); - terrno = TSDB_CODE_INVALID_TABLE_ID; + terrno = TSDB_CODE_MND_INVALID_TABLE_ID; return NULL; } mnodeDecTableRef(pSuperTable); @@ -1465,7 +1472,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb pTable->schema = (SSchema *) calloc(1, schemaSize); if (pTable->schema == NULL) { free(pTable); - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema)); @@ -1482,7 +1489,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb pTable->sql = calloc(1, pTable->sqlLen); if (pTable->sql == NULL) { free(pTable); - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_MND_OUT_OF_MEMORY; return NULL; } memcpy(pTable->sql, (char *) (pCreate->schema) + numOfCols * sizeof(SSchema), pTable->sqlLen); @@ -1499,7 +1506,7 @@ static SChildTableObj* mnodeDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgOb if (sdbInsertRow(&desc) != TSDB_CODE_SUCCESS) { free(pTable); mError("table:%s, update sdb error", pCreate->tableId); - terrno = TSDB_CODE_SDB_ERROR; + terrno = TSDB_CODE_MND_SDB_ERROR; return NULL; } @@ -1560,7 +1567,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { dnodeSendMsgToDnode(&ipSet, &rpcMsg); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { @@ -1568,13 +1575,13 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) { mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId); - return TSDB_CODE_OTHERS; + return TSDB_CODE_MND_APP_ERROR; } SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg)); if (pDrop == NULL) { mError("table:%s, failed to drop ctable, no enough memory", pTable->info.tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } strcpy(pDrop->tableId, pTable->info.tableId); @@ -1596,11 +1603,11 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { dnodeSendMsgToDnode(&ipSet, &rpcMsg); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } static int32_t mnodeModifyChildTableTagValue(SChildTableObj *pTable, char *tagName, char *nContent) { - return TSDB_CODE_OPS_NOT_SUPPORT; + return TSDB_CODE_COM_OPS_NOT_SUPPORT; } static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) { @@ -1617,13 +1624,13 @@ static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *col static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSchema schema[], int32_t ncols) { if (ncols <= 0) { mError("table:%s, add column, ncols:%d <= 0", pTable->info.tableId); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_MND_APP_ERROR; } for (int32_t i = 0; i < ncols; i++) { if (mnodeFindNormalTableColumnIndex(pTable, schema[i].name) > 0) { mError("table:%s, add column, column:%s already exist", pTable->info.tableId, schema[i].name); - return TSDB_CODE_FIELD_ALREAY_EXIST; + return TSDB_CODE_MND_FIELD_ALREAY_EXIST; } } @@ -1654,7 +1661,7 @@ static int32_t mnodeAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SS int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("table %s, succeed to add column", pTable->info.tableId); @@ -1665,7 +1672,7 @@ static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, c int32_t col = mnodeFindNormalTableColumnIndex(pTable, colName); if (col <= 0) { mError("table:%s, drop column, column:%s not exist", pTable->info.tableId, colName); - return TSDB_CODE_FIELD_NOT_EXIST; + return TSDB_CODE_MND_FIELD_NOT_EXIST; } memmove(pTable->schema + col, pTable->schema + col + 1, sizeof(SSchema) * (pTable->numOfColumns - col - 1)); @@ -1686,7 +1693,7 @@ static int32_t mnodeDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, c int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("table %s, succeed to drop column %s", pTable->info.tableId, colName); @@ -1732,8 +1739,8 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) { - mError("table:%s, failed to get table meta, db not selected", pTable->info.tableId); - return TSDB_CODE_INVALID_VGROUP_ID; + mError("table:%s, failed to get table meta, vgroup not exist", pTable->info.tableId); + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } for (int32_t i = 0; i < pMsg->pVgroup->numOfVnodes; ++i) { @@ -1759,7 +1766,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) { SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen); if (pCreateMsg == NULL) { mError("table:%s, failed to create table while get meta info, no enough memory", pInfo->tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } strncpy(pCreateMsg->tableId, pInfo->tableId, tListLen(pInfo->tableId)); @@ -1776,14 +1783,14 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) { pMsg->rpcMsg.pCont = pCreateMsg; pMsg->rpcMsg.contLen = contLen; - return TSDB_CODE_ACTION_NEED_REPROCESSED; + return TSDB_CODE_MND_ACTION_NEED_REPROCESSED; } static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg) { STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16)); if (pMeta == NULL) { mError("table:%s, failed to get table meta, no enough memory", pMsg->pTable->tableId); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } mnodeDoGetChildTableMeta(pMsg, pMeta); @@ -1902,7 +1909,7 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) { SChildTableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid); if (pTable == NULL) { mError("dnode:%d, vgId:%d sid:%d, table not found", pCfg->dnodeId, pCfg->vgId, pCfg->sid); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } SMDCreateTableMsg *pCreate = NULL; @@ -1936,7 +1943,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) { if (mnodeMsg->pVgroup == NULL) mnodeMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (mnodeMsg->pVgroup == NULL) { mError("table:%s, failed to get vgroup", pTable->info.tableId); - dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_INVALID_VGROUP_ID); + dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_VGROUP_NOT_EXIST); return; } @@ -1949,7 +1956,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { mError("table:%s, update ctables sdb error", pTable->info.tableId); - dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_SDB_ERROR); + dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_SDB_ERROR); return; } @@ -2018,7 +2025,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { int32_t totalMallocLen = 4 * 1024 * 1024; // first malloc 4 MB, subsequent reallocation as twice SMultiTableMeta *pMultiMeta = rpcMallocCont(totalMallocLen); if (pMultiMeta == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } pMultiMeta->contLen = sizeof(SMultiTableMeta); @@ -2041,7 +2048,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { pMultiMeta = rpcReallocCont(pMultiMeta, totalMallocLen); if (pMultiMeta == NULL) { mnodeDecTableRef(pTable); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_MND_OUT_OF_MEMORY; } else { t--; mnodeDecTableRef(pTable); @@ -2067,7 +2074,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); - if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; + if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -2111,14 +2118,6 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void return 0; } -static void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) { - if (rows < capacity) { - for (int32_t i = 0; i < numOfCols; ++i) { - memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows); - } - } -} - static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); if (pDb == NULL) return 0; @@ -2202,18 +2201,18 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { if (pMsg->pDb == NULL) pMsg->pDb = mnodeGetDbByTableId(pAlter->tableId); if (pMsg->pDb == NULL || pMsg->pDb->status != TSDB_DB_STATUS_READY) { mError("table:%s, failed to alter table, db not selected", pAlter->tableId); - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } if (mnodeCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) { mError("table:%s, failed to alter table, its log db", pAlter->tableId); - return TSDB_CODE_MONITOR_DB_FORBIDDEN; + return TSDB_CODE_MND_MONITOR_DB_FORBIDDEN; } if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId); if (pMsg->pTable == NULL) { mError("table:%s, failed to alter table, table not exist", pMsg->pTable->tableId); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } pAlter->type = htons(pAlter->type); @@ -2222,14 +2221,14 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { if (pAlter->numOfCols > 2) { mError("table:%s, error numOfCols:%d in alter table", pAlter->tableId, pAlter->numOfCols); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_MND_APP_ERROR; } for (int32_t i = 0; i < pAlter->numOfCols; ++i) { pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes); } - int32_t code = TSDB_CODE_OPS_NOT_SUPPORT; + int32_t code = TSDB_CODE_COM_OPS_NOT_SUPPORT; if (pMsg->pTable->type == TSDB_SUPER_TABLE) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; mTrace("table:%s, start to alter stable", pAlter->tableId); @@ -2262,9 +2261,9 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { return code; } -static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { +static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); - if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED; + if (pDb == NULL) return TSDB_CODE_MND_DB_NOT_SELECTED; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -2308,7 +2307,7 @@ static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p return 0; } -static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn) { +static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t rows, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); if (pDb == NULL) return 0; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 209b439275..aab0847a6b 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -56,7 +56,7 @@ static int32_t mnodeUserActionInsert(SSdbOper *pOper) { mnodeDecAcctRef(pAcct); } else { mError("user:%s, acct:%s info not exist in sdb", pUser->user, pUser->acct); - return TSDB_CODE_INVALID_ACCT; + return TSDB_CODE_MND_INVALID_ACCT; } return TSDB_CODE_SUCCESS; @@ -94,7 +94,7 @@ static int32_t mnodeUserActionEncode(SSdbOper *pOper) { static int32_t mnodeUserActionDecode(SSdbOper *pOper) { SUserObj *pUser = (SUserObj *)calloc(1, sizeof(SUserObj)); - if (pUser == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pUser == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pUser, pOper->rowData, tsUserUpdateSize); pOper->pObj = pUser; @@ -179,7 +179,7 @@ static int32_t mnodeUpdateUser(SUserObj *pUser) { int32_t code = sdbUpdateRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -192,18 +192,18 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) { } if (name[0] == 0) { - return TSDB_CODE_INVALID_USER_FORMAT; + return TSDB_CODE_MND_INVALID_USER_FORMAT; } if (pass[0] == 0) { - return TSDB_CODE_INVALID_PASS_FORMAT; + return TSDB_CODE_MND_INVALID_PASS_FORMAT; } SUserObj *pUser = mnodeGetUser(name); if (pUser != NULL) { mTrace("user:%s, is already there", name); mnodeDecUserRef(pUser); - return TSDB_CODE_USER_ALREADY_EXIST; + return TSDB_CODE_MND_USER_ALREADY_EXIST; } code = grantCheck(TSDB_GRANT_USER); @@ -232,7 +232,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) { code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pUser); - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -247,7 +247,7 @@ static int32_t mnodeDropUser(SUserObj *pUser) { int32_t code = sdbDeleteRow(&oper); if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } return code; @@ -256,7 +256,7 @@ static int32_t mnodeDropUser(SUserObj *pUser) { static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) { - return TSDB_CODE_NO_USER_FROM_CONN; + return TSDB_CODE_MND_NO_USER_FROM_CONN; } int32_t cols = 0; @@ -369,7 +369,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) { } } else { mError("user:%s, no rights to create user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } return code; @@ -382,12 +382,12 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { SCMAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; SUserObj *pUser = mnodeGetUser(pAlter->user); if (pUser == NULL) { - return TSDB_CODE_INVALID_USER; + return TSDB_CODE_MND_INVALID_USER; } if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { @@ -413,7 +413,7 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { mLPrint("user:%s, password is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); } else { mError("user:%s, no rights to alter user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } } else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { bool hasRight = false; @@ -454,11 +454,11 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { mLPrint("user:%s, privilege is altered by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); } else { mError("user:%s, no rights to alter user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } } else { mError("user:%s, no rights to alter user", pOperUser->user); - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } mnodeDecUserRef(pUser); @@ -472,13 +472,13 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) { SCMDropUserMsg *pDrop = pMsg->rpcMsg.pCont; SUserObj *pUser = mnodeGetUser(pDrop->user); if (pUser == NULL) { - return TSDB_CODE_INVALID_USER; + return TSDB_CODE_MND_INVALID_USER; } if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { mnodeDecUserRef(pUser); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } bool hasRight = false; @@ -502,7 +502,7 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) { mLPrint("user:%s, is dropped by %s, result:%s", pUser->user, pOperUser->user, tstrerror(code)); } } else { - code = TSDB_CODE_NO_RIGHTS; + code = TSDB_CODE_MND_NO_RIGHTS; } mnodeDecUserRef(pUser); @@ -540,15 +540,15 @@ void mnodeDropAllUsers(SAcctObj *pAcct) { int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) { if (!sdbIsMaster()) { *secret = 0; - mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_NOT_READY)); - return TSDB_CODE_NOT_READY; + mTrace("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_RPC_NOT_READY)); + return TSDB_CODE_RPC_NOT_READY; } SUserObj *pUser = mnodeGetUser(user); if (pUser == NULL) { *secret = 0; - mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_INVALID_USER)); - return TSDB_CODE_INVALID_USER; + mError("user:%s, failed to auth user, reason:%s", user, tstrerror(TSDB_CODE_MND_INVALID_USER)); + return TSDB_CODE_MND_INVALID_USER; } else { *spi = 1; *encrypt = 0; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 920d8503b2..7274c879c6 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -68,7 +68,7 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) { // refer to db SDbObj *pDb = mnodeGetDb(pVgroup->dbName); if (pDb == NULL) { - return TSDB_CODE_INVALID_DB; + return TSDB_CODE_MND_INVALID_DB; } pVgroup->pDb = pDb; @@ -185,7 +185,7 @@ static int32_t mnodeVgroupActionEncode(SSdbOper *pOper) { static int32_t mnodeVgroupActionDecode(SSdbOper *pOper) { SVgObj *pVgroup = (SVgObj *) calloc(1, sizeof(SVgObj)); - if (pVgroup == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pVgroup == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY; memcpy(pVgroup, pOper->rowData, tsVgUpdateSize); pOper->pObj = pVgroup; @@ -307,7 +307,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { if (balanceAllocVnodes(pVgroup) != 0) { mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes); free(pVgroup); - return TSDB_CODE_NO_ENOUGH_DNODES; + return TSDB_CODE_MND_NO_ENOUGH_DNODES; } SSdbOper oper = { @@ -320,7 +320,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pVgroup); - return TSDB_CODE_SDB_ERROR; + return TSDB_CODE_MND_SDB_ERROR; } mPrint("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); @@ -333,7 +333,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { pMsg->expected = pVgroup->numOfVnodes; mnodeSendCreateVgroupMsg(pVgroup, pMsg); - return TSDB_CODE_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) { @@ -358,7 +358,7 @@ void mnodeCleanupVgroups() { int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SDbObj *pDb = mnodeGetDb(pShow->db); if (pDb == NULL) { - return TSDB_CODE_DB_NOT_SELECTED; + return TSDB_CODE_MND_DB_NOT_SELECTED; } int32_t cols = 0; @@ -383,11 +383,11 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { pTable = mnodeGetTable(pShow->payload); if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { mnodeDecTableRef(pTable); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_MND_INVALID_TABLE_ID; } mnodeDecTableRef(pTable); pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId); - if (NULL == pVgroup) return TSDB_CODE_INVALID_TABLE_ID; + if (NULL == pVgroup) return TSDB_CODE_MND_INVALID_TABLE_ID; mnodeDecVgroupRef(pVgroup); maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; } else { @@ -643,7 +643,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { }; int32_t code = sdbDeleteRow(&oper); if (code != 0) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } dnodeSendRpcMnodeWriteRsp(mnodeMsg, code); @@ -704,7 +704,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) { }; int32_t code = sdbDeleteRow(&oper); if (code != 0) { - code = TSDB_CODE_SDB_ERROR; + code = TSDB_CODE_MND_SDB_ERROR; } dnodeReprocessMnodeWriteMsg(mnodeMsg); @@ -718,14 +718,14 @@ static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) { SDnodeObj *pDnode = mnodeGetDnode(pCfg->dnodeId); if (pDnode == NULL) { mTrace("dnode:%s, invalid dnode", taosIpStr(pCfg->dnodeId), pCfg->vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } mnodeDecDnodeRef(pDnode); SVgObj *pVgroup = mnodeGetVgroup(pCfg->vgId); if (pVgroup == NULL) { mTrace("dnode:%s, vgId:%d, no vgroup info", taosIpStr(pCfg->dnodeId), pCfg->vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_MND_VGROUP_NOT_EXIST; } mnodeDecVgroupRef(pVgroup); diff --git a/src/mnode/src/mnodeWrite.c b/src/mnode/src/mnodeWrite.c index 8b3d82d32a..29b2e6c82b 100644 --- a/src/mnode/src/mnodeWrite.c +++ b/src/mnode/src/mnodeWrite.c @@ -44,7 +44,7 @@ void mnodeAddWriteMsgHandle(uint8_t msgType, int32_t (*fp)(SMnodeMsg *mnodeMsg)) int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { if (pMsg->rpcMsg.pCont == NULL) { mError("%p, msg:%s in mwrite queue, content is null", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_INVALID_MSG_LEN; + return TSDB_CODE_MND_INVALID_MSG_LEN; } if (!sdbIsMaster()) { @@ -59,12 +59,12 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { mTrace("mnode index:%d ip:%s:%d", i, ipSet->fqdn[i], htons(ipSet->port[i])); } - return TSDB_CODE_REDIRECT; + return TSDB_CODE_RPC_REDIRECT; } if (tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType] == NULL) { mError("%p, msg:%s in mwrite queue, not processed", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_MND_MSG_NOT_PROCESSED; } int32_t code = mnodeInitMsg(pMsg); @@ -75,7 +75,7 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { if (!pMsg->pUser->writeAuth) { mError("%p, msg:%s in mwrite queue, not processed, no write auth", pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - return TSDB_CODE_NO_RIGHTS; + return TSDB_CODE_MND_NO_RIGHTS; } return (*tsMnodeProcessWriteMsgFp[pMsg->rpcMsg.msgType])(pMsg); diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index 74e3c409a1..950258533f 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -443,9 +443,9 @@ void httpJsonPairStatus(JsonBuf* buf, int code) { httpJsonPairIntVal(buf, "code", 4, code); if (code >= 0) { httpJsonItemToken(buf); - if (code == TSDB_CODE_DB_NOT_SELECTED) { + if (code == TSDB_CODE_MND_DB_NOT_SELECTED) { httpJsonPair(buf, "desc", 4, "failed to create database", 23); - } else if (code == TSDB_CODE_INVALID_TABLE_ID) { + } else if (code == TSDB_CODE_MND_INVALID_TABLE_ID) { httpJsonPair(buf, "desc", 4, "failed to create table", 22); } else httpJsonPair(buf, "desc", 4, (char*)tstrerror(code), (int)strlen(tstrerror(code))); diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index c82a235eba..af9ad8e38a 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -80,7 +80,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos; char * sql = httpGetCmdsString(pContext, singleCmd->sql); - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%s:inprogress, sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql); return; @@ -234,7 +234,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { HttpEncodeMethod *encode = pContext->encodeMethod; - if (code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s:inprogress, sqlObj:%p", pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), (SSqlObj *)result); return; @@ -242,7 +242,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { if (code < 0) { SSqlObj *pObj = (SSqlObj *)result; - if (code == TSDB_CODE_INVALID_SQL) { + if (code == TSDB_CODE_TSC_INVALID_SQL) { httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p, error:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj, pObj->cmd.payload); httpSendTaosdInvalidSqlErrorResp(pContext, pObj->cmd.payload); diff --git a/src/plugins/http/src/tgJson.c b/src/plugins/http/src/tgJson.c index 27059010b8..6c0b3c8663 100644 --- a/src/plugins/http/src/tgJson.c +++ b/src/plugins/http/src/tgJson.c @@ -103,7 +103,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) { if (cmd->cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { - if (code == TSDB_CODE_DB_NOT_SELECTED || code == TSDB_CODE_INVALID_DB) { + if (code == TSDB_CODE_MND_DB_NOT_SELECTED || code == TSDB_CODE_MND_INVALID_DB) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; if (multiCmds->cmds[0].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { multiCmds->pos = (int16_t)-1; @@ -111,7 +111,7 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { pContext->ipstr); return false; } - } else if (code == TSDB_CODE_INVALID_TABLE_ID) { + } else if (code == TSDB_CODE_MND_INVALID_TABLE_ID) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; if (multiCmds->cmds[multiCmds->pos - 1].cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { multiCmds->pos = (int16_t)(multiCmds->pos - 2); diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 0c27233289..01e276da64 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -183,7 +183,7 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.slowquery(ts timestamp, username " "binary(%d), created_time timestamp, time bigint, sql binary(%d))", - tsMonitorDbName, TSDB_TABLE_ID_LEN, TSDB_SHOW_SQL_LEN); + tsMonitorDbName, TSDB_TABLE_ID_LEN, TSDB_SLOW_QUERY_SQL_LEN); } else if (cmd == MONITOR_CMD_CREATE_TB_LOG) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.log(ts timestamp, level tinyint, " @@ -207,7 +207,7 @@ static void monitorInitDatabase() { } static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { - if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) { + if (-code == TSDB_CODE_MND_TABLE_ALREADY_EXIST || -code == TSDB_CODE_MND_DB_ALREADY_EXIST || code >= 0) { monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { monitorPrint("dnode:%s is started", tsLocalEp); diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index 7ea272b8e8..c964772496 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -172,10 +172,11 @@ typedef struct SQueryRuntimeEnv { STSBuf* pTSBuf; STSCursor cur; SQueryCostInfo summary; - bool stableQuery; // super table query or not + bool stableQuery; // super table query or not void* pQueryHandle; void* pSecQueryHandle; // another thread for SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file + bool topBotQuery; // false; } SQueryRuntimeEnv; typedef struct SQInfo { diff --git a/src/query/inc/qUtil.h b/src/query/inc/qUtil.h index e21504b908..1ecca102ba 100644 --- a/src/query/inc/qUtil.h +++ b/src/query/inc/qUtil.h @@ -31,7 +31,8 @@ void closeTimeWindow(SWindowResInfo* pWindowResInfo, int32_t slot); void closeAllTimeWindow(SWindowResInfo* pWindowResInfo); void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_t order); SWindowResult *getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot); -int32_t curTimeWindow(SWindowResInfo *pWindowResInfo); + +#define curTimeWindow(_winres) ((_winres)->curIndex) bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot); void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo); diff --git a/src/query/inc/qextbuffer.h b/src/query/inc/qextbuffer.h index 9721687110..23b67083e5 100644 --- a/src/query/inc/qextbuffer.h +++ b/src/query/inc/qextbuffer.h @@ -28,7 +28,7 @@ extern "C" { #include "tdataformat.h" #include "talgo.h" -#define DEFAULT_PAGE_SIZE (1024L*56) // 16k larger than the SHistoInfo +#define DEFAULT_PAGE_SIZE (1024L*64) // 16k larger than the SHistoInfo #define MAX_TMPFILE_PATH_LENGTH PATH_MAX #define INITIAL_ALLOCATION_BUFFER_SIZE 64 @@ -96,7 +96,7 @@ typedef struct SColumnOrderInfo { typedef struct tOrderDescriptor { SColumnModel * pColumnModel; int32_t tsOrder; // timestamp order type if exists - SColumnOrderInfo orderIdx; + SColumnOrderInfo orderInfo; } tOrderDescriptor; typedef struct tExtMemBuffer { diff --git a/src/query/inc/qresultBuf.h b/src/query/inc/qresultBuf.h index 1375594210..ad01555c28 100644 --- a/src/query/inc/qresultBuf.h +++ b/src/query/inc/qresultBuf.h @@ -85,7 +85,7 @@ SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId); * @param id * @return */ -tFilePage* getResultBufferPageById(SDiskbasedResultBuf* pResultBuf, int32_t id); +#define GET_RES_BUF_PAGE_BY_ID(buf, id) ((tFilePage*)((buf)->pBuf + DEFAULT_INTERN_BUF_PAGE_SIZE*(id))) /** * get the total buffer size in the format of disk file diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index dd104ba2d2..4a20502e4e 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -647,9 +647,9 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). { } ////////////////////////////////////////kill statement/////////////////////////////////////// -cmd ::= KILL CONNECTION IPTOKEN(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &X);} -cmd ::= KILL STREAM IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &X);} -cmd ::= KILL QUERY IPTOKEN(X) COLON(Z) INTEGER(Y) COLON(K) INTEGER(F). {X.n += (Z.n + Y.n + K.n + F.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &X);} +cmd ::= KILL CONNECTION INTEGER(Y). {setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &Y);} +cmd ::= KILL STREAM INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &X);} +cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &X);} %fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD diff --git a/src/query/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h index 22d126f7a2..aa8e83da38 100644 --- a/src/query/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -272,9 +272,18 @@ bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *mi bool stableQueryFunctChanged(int32_t funcId); void resetResultInfo(SResultInfo *pResInfo); -void initResultInfo(SResultInfo *pResInfo); void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable); +static FORCE_INLINE void initResultInfo(SResultInfo *pResInfo) { + pResInfo->initialized = true; // the this struct has been initialized flag + + pResInfo->complete = false; + pResInfo->hasResult = false; + pResInfo->numOfRes = 0; + + memset(pResInfo->interResultBuf, 0, (size_t)pResInfo->bufLen); +} + #ifdef __cplusplus } #endif diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6824d305c3..5dff47121b 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -98,6 +98,7 @@ static bool isIntervalQuery(SQuery *pQuery) { return pQuery->intervalTime > 0; } static int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *group); static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult); +static void setWindowResOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult); static void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx, SResultInfo *pResultInfo); static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t functionId); static void getNextTimeWindow(SQuery *pQuery, STimeWindow *pTimeWindow); @@ -441,7 +442,7 @@ static int32_t addNewWindowResultBuf(SWindowResult *pWindowRes, SDiskbasedResult pData = getNewDataBuf(pResultBuf, sid, &pageId); } else { pageId = getLastPageId(&list); - pData = getResultBufferPageById(pResultBuf, pageId); + pData = GET_RES_BUF_PAGE_BY_ID(pResultBuf, pageId); if (pData->num >= numOfRowsPerPage) { pData = getNewDataBuf(pResultBuf, sid, &pageId); @@ -484,10 +485,8 @@ static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowRes // set time window for current result pWindowRes->window = *win; - - setWindowResOutputBuf(pRuntimeEnv, pWindowRes); - initCtxOutputBuf(pRuntimeEnv); - + + setWindowResOutputBufInitCtx(pRuntimeEnv, pWindowRes); return TSDB_CODE_SUCCESS; } @@ -651,7 +650,7 @@ static void doBlockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SWindowStat pCtx[k].startOffset = (QUERY_IS_ASC_QUERY(pQuery)) ? offset : offset - (forwardStep - 1); if ((aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) != 0) { - pCtx[k].ptsList = tsBuf; + pCtx[k].ptsList = &tsBuf[offset]; } // not a whole block involved in query processing, statistics data can not be used @@ -687,47 +686,52 @@ static int32_t getNextQualifiedWindow(SQueryRuntimeEnv *pRuntimeEnv, STimeWindow SDataBlockInfo *pDataBlockInfo, TSKEY *primaryKeys, __block_search_fn_t searchFn) { SQuery *pQuery = pRuntimeEnv->pQuery; - - while (1) { - if ((pNextWin->ekey > pQuery->window.ekey && QUERY_IS_ASC_QUERY(pQuery)) || - (pNextWin->skey < pQuery->window.ekey && !QUERY_IS_ASC_QUERY(pQuery))) { - return -1; - } - - getNextTimeWindow(pQuery, pNextWin); - - // next time window is not in current block - if ((pNextWin->skey > pDataBlockInfo->window.ekey && QUERY_IS_ASC_QUERY(pQuery)) || - (pNextWin->ekey < pDataBlockInfo->window.skey && !QUERY_IS_ASC_QUERY(pQuery))) { - return -1; - } - - TSKEY startKey = -1; - if (QUERY_IS_ASC_QUERY(pQuery)) { - startKey = pNextWin->skey; - if (startKey < pQuery->window.skey) { - startKey = pQuery->window.skey; - } - } else { - startKey = pNextWin->ekey; - if (startKey > pQuery->window.skey) { - startKey = pQuery->window.skey; - } - } - - int32_t startPos = searchFn((char *)primaryKeys, pDataBlockInfo->rows, startKey, pQuery->order.order); - - /* - * This time window does not cover any data, try next time window, - * this case may happen when the time window is too small - */ - if ((primaryKeys[startPos] > pNextWin->ekey && QUERY_IS_ASC_QUERY(pQuery)) || - (primaryKeys[startPos] < pNextWin->skey && !QUERY_IS_ASC_QUERY(pQuery))) { - continue; - } - - return startPos; + + // tumbling time window query, a special case of sliding time window query + if (pQuery->slidingTime == pQuery->intervalTime) { + // todo opt } + + getNextTimeWindow(pQuery, pNextWin); + + // next time window is not in current block + if ((pNextWin->skey > pDataBlockInfo->window.ekey && QUERY_IS_ASC_QUERY(pQuery)) || + (pNextWin->ekey < pDataBlockInfo->window.skey && !QUERY_IS_ASC_QUERY(pQuery))) { + return -1; + } + + TSKEY startKey = -1; + if (QUERY_IS_ASC_QUERY(pQuery)) { + startKey = pNextWin->skey; + if (startKey < pQuery->window.skey) { + startKey = pQuery->window.skey; + } + } else { + startKey = pNextWin->ekey; + if (startKey > pQuery->window.skey) { + startKey = pQuery->window.skey; + } + } + + int32_t startPos = searchFn((char *)primaryKeys, pDataBlockInfo->rows, startKey, pQuery->order.order); + + /* + * This time window does not cover any data, try next time window, + * this case may happen when the time window is too small + */ + if (QUERY_IS_ASC_QUERY(pQuery) && primaryKeys[startPos] > pNextWin->ekey) { + TSKEY next = primaryKeys[startPos]; + + pNextWin->ekey += ((next - pNextWin->ekey + pQuery->slidingTime - 1)/pQuery->slidingTime) * pQuery->slidingTime; + pNextWin->skey = pNextWin->ekey - pQuery->intervalTime + 1; + } else if ((!QUERY_IS_ASC_QUERY(pQuery)) && primaryKeys[startPos] < pNextWin->skey) { + TSKEY next = primaryKeys[startPos]; + + pNextWin->skey -= ((pNextWin->skey - next + pQuery->slidingTime - 1) / pQuery->slidingTime) * pQuery->slidingTime; + pNextWin->ekey = pNextWin->skey + pQuery->intervalTime - 1; + } + + return startPos; } static TSKEY reviseWindowEkey(SQuery *pQuery, STimeWindow *pWindow) { @@ -785,11 +789,10 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas sas->data = calloc(pQuery->numOfCols, POINTER_BYTES); // here the pQuery->colList and sas->colList are identical + int32_t numOfCols = taosArrayGetSize(pDataBlock); for (int32_t i = 0; i < pQuery->numOfCols; ++i) { SColumnInfo *pColMsg = &pQuery->colList[i]; - int32_t numOfCols = taosArrayGetSize(pDataBlock); - dataBlock = NULL; for (int32_t k = 0; k < numOfCols; ++k) { //todo refactor SColumnInfoData *p = taosArrayGet(pDataBlock, k); @@ -1027,7 +1030,7 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx } // in the supplementary scan, only the following functions need to be executed - if (IS_REVERSE_SCAN(pRuntimeEnv)) {// && (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS)) { + if (IS_REVERSE_SCAN(pRuntimeEnv)) { return false; } @@ -1183,7 +1186,6 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl STableQueryInfo* pTableQInfo = pQuery->current; SWindowResInfo* pWindowResInfo = &pRuntimeEnv->windowResInfo; - pQuery->pos = QUERY_IS_ASC_QUERY(pQuery)? 0 : pDataBlockInfo->rows - 1; if (pQuery->numOfFilterCols > 0 || pRuntimeEnv->pTSBuf != NULL || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { rowwiseApplyFunctions(pRuntimeEnv, pStatis, pDataBlockInfo, pWindowResInfo, pDataBlock); @@ -1434,7 +1436,7 @@ _clean: tfree(pRuntimeEnv->resultInfo); tfree(pRuntimeEnv->pCtx); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { @@ -1475,7 +1477,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { } static bool isQueryKilled(SQInfo *pQInfo) { - return (pQInfo->code == TSDB_CODE_QUERY_CANCELLED); + return (pQInfo->code == TSDB_CODE_TSC_QUERY_CANCELLED); #if 0 /* * check if the queried meter is going to be deleted. @@ -1491,7 +1493,7 @@ static bool isQueryKilled(SQInfo *pQInfo) { #endif } -static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_QUERY_CANCELLED; } +static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; } static bool isFixedOutputQuery(SQuery *pQuery) { if (pQuery->intervalTime != 0) { @@ -1587,8 +1589,11 @@ static bool needReverseScan(SQuery *pQuery) { static bool onlyQueryTags(SQuery* pQuery) { for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { - int32_t functionId = pQuery->pSelectExpr[i].base.functionId; - if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG) { + SExprInfo* pExprInfo = &pQuery->pSelectExpr[i]; + + int32_t functionId = pExprInfo->base.functionId; + if (functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TID_TAG && + (!(functionId == TSDB_FUNC_COUNT && pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX))) { return false; } } @@ -1598,8 +1603,7 @@ static bool onlyQueryTags(SQuery* pQuery) { ///////////////////////////////////////////////////////////////////////////////////////////// -void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int64_t keyLast, int64_t *realSkey, - int64_t *realEkey, STimeWindow *win) { +void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow *realWin, STimeWindow *win) { assert(key >= keyFirst && key <= keyLast && pQuery->slidingTime <= pQuery->intervalTime); win->skey = taosGetIntervalStartTimestamp(key, pQuery->slidingTime, pQuery->slidingTimeUnit, pQuery->precision); @@ -1611,8 +1615,8 @@ void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int6 */ assert(keyLast - keyFirst < pQuery->intervalTime); - *realSkey = keyFirst; - *realEkey = keyLast; + realWin->skey = keyFirst; + realWin->ekey = keyLast; win->ekey = INT64_MAX; return; @@ -1620,17 +1624,8 @@ void getAlignQueryTimeWindow(SQuery *pQuery, int64_t key, int64_t keyFirst, int6 win->ekey = win->skey + pQuery->intervalTime - 1; - if (win->skey < keyFirst) { - *realSkey = keyFirst; - } else { - *realSkey = win->skey; - } - - if (win->ekey < keyLast) { - *realEkey = win->ekey; - } else { - *realEkey = keyLast; - } + realWin->skey = (win->skey < keyFirst)? keyFirst : win->skey; + realWin->ekey = (win->ekey < keyLast) ? win->ekey : keyLast; } static void setScanLimitationByResultBuffer(SQuery *pQuery) { @@ -1847,31 +1842,21 @@ static int32_t getInitialPageNum(SQInfo *pQInfo) { return num; } -static int32_t getRowParamForMultiRowsOutput(SQuery *pQuery, bool isSTableQuery) { - int32_t rowparam = 1; +#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pSelectExpr[1].base.arg->argValue.i64:1) - if (isTopBottomQuery(pQuery) && (!isSTableQuery)) { - rowparam = pQuery->pSelectExpr[1].base.arg->argValue.i64; - } - - return rowparam; -} - -static int32_t getNumOfRowsInResultPage(SQuery *pQuery, bool isSTableQuery) { - int32_t rowSize = pQuery->rowSize * getRowParamForMultiRowsOutput(pQuery, isSTableQuery); +static FORCE_INLINE int32_t getNumOfRowsInResultPage(SQuery *pQuery, bool topBotQuery, bool isSTableQuery) { + int32_t rowSize = pQuery->rowSize * GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, topBotQuery, isSTableQuery); return (DEFAULT_INTERN_BUF_PAGE_SIZE - sizeof(tFilePage)) / rowSize; } char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult) { assert(pResult != NULL && pRuntimeEnv != NULL); - SQuery * pQuery = pRuntimeEnv->pQuery; - tFilePage *page = getResultBufferPageById(pRuntimeEnv->pResultBuf, pResult->pos.pageId); + SQuery *pQuery = pRuntimeEnv->pQuery; + tFilePage *page = GET_RES_BUF_PAGE_BY_ID(pRuntimeEnv->pResultBuf, pResult->pos.pageId); + int32_t realRowId = pResult->pos.rowId * GET_ROW_PARAM_FOR_MULTIOUTPUT(pQuery, pRuntimeEnv->topBotQuery, pRuntimeEnv->stableQuery); - int32_t numOfRows = getNumOfRowsInResultPage(pQuery, pRuntimeEnv->stableQuery); - int32_t realRowId = pResult->pos.rowId * getRowParamForMultiRowsOutput(pQuery, pRuntimeEnv->stableQuery); - - return ((char *)page->data) + pRuntimeEnv->offset[columnIndex] * numOfRows + + return ((char *)page->data) + pRuntimeEnv->offset[columnIndex] * pRuntimeEnv->numOfRowsPerPage + pQuery->pSelectExpr[columnIndex].bytes * realRowId; } @@ -2034,6 +2019,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle, } pRuntimeEnv->summary.totalCheckedRows += pBlockInfo->rows; + pRuntimeEnv->summary.loadBlocks += 1; pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); } @@ -2115,7 +2101,8 @@ static void ensureOutputBuffer(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pB for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { int32_t bytes = pQuery->pSelectExpr[i].bytes; - + assert(bytes > 0 && newSize > 0); + char *tmp = realloc(pQuery->sdata[i], bytes * newSize + sizeof(tFilePage)); if (tmp == NULL) { // todo handle the oom assert(0); @@ -2143,6 +2130,7 @@ static void ensureOutputBuffer(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pB static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; STableQueryInfo* pTableQueryInfo = pQuery->current; + SQueryCostInfo* summary = &pRuntimeEnv->summary; qTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", lastkey:%" PRId64 ", order:%d", GET_QINFO_ADDR(pRuntimeEnv), pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, pTableQueryInfo->lastKey, @@ -2150,7 +2138,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { TsdbQueryHandleT pQueryHandle = IS_MASTER_SCAN(pRuntimeEnv)? pRuntimeEnv->pQueryHandle : pRuntimeEnv->pSecQueryHandle; while (tsdbNextDataBlock(pQueryHandle)) { - pRuntimeEnv->summary.totalBlocks += 1; + summary->totalBlocks += 1; if (isQueryKilled(GET_QINFO_ADDR(pRuntimeEnv))) { return 0; } @@ -2159,19 +2147,16 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { // todo extract methods if (isIntervalQuery(pQuery) && pRuntimeEnv->windowResInfo.prevSKey == TSKEY_INITIAL_VAL) { - TSKEY skey1, ekey1; - STimeWindow w = TSWINDOW_INITIALIZER; + STimeWindow realWin = TSWINDOW_INITIALIZER, w = TSWINDOW_INITIALIZER; SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo; if (QUERY_IS_ASC_QUERY(pQuery)) { - getAlignQueryTimeWindow(pQuery, blockInfo.window.skey, blockInfo.window.skey, pQuery->window.ekey, &skey1, - &ekey1, &w); + getAlignQueryTimeWindow(pQuery, blockInfo.window.skey, blockInfo.window.skey, pQuery->window.ekey, &realWin, &w); pWindowResInfo->startTime = w.skey; pWindowResInfo->prevSKey = w.skey; } else { // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp - getAlignQueryTimeWindow(pQuery, blockInfo.window.ekey, pQuery->window.ekey, blockInfo.window.ekey, &skey1, - &ekey1, &w); + getAlignQueryTimeWindow(pQuery, blockInfo.window.ekey, pQuery->window.ekey, blockInfo.window.ekey, &realWin, &w); pWindowResInfo->startTime = pQuery->window.skey; pWindowResInfo->prevSKey = w.skey; @@ -2187,9 +2172,12 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { SDataStatis *pStatis = NULL; SArray *pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis); + + // query start position can not move into tableApplyFunctionsOnBlock due to limit/offset condition + pQuery->pos = QUERY_IS_ASC_QUERY(pQuery)? 0 : blockInfo.rows - 1; int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, pStatis, binarySearchForKey, pDataBlock); - pRuntimeEnv->summary.totalRows += blockInfo.rows; + summary->totalRows += blockInfo.rows; qTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", numOfRows:%d, numOfRes:%d, lastKey:%"PRId64, GET_QINFO_ADDR(pRuntimeEnv), blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, numOfRes, pQuery->current->lastKey); @@ -2531,7 +2519,7 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) { int32_t total = 0; for (int32_t i = 0; i < list.size; ++i) { - tFilePage *pData = getResultBufferPageById(pResultBuf, list.pData[i]); + tFilePage *pData = GET_RES_BUF_PAGE_BY_ID(pResultBuf, list.pData[i]); total += pData->num; } @@ -2539,7 +2527,7 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) { int32_t offset = 0; for (int32_t num = 0; num < list.size; ++num) { - tFilePage *pData = getResultBufferPageById(pResultBuf, list.pData[num]); + tFilePage *pData = GET_RES_BUF_PAGE_BY_ID(pResultBuf, list.pData[num]); for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { int32_t bytes = pRuntimeEnv->pCtx[i].outputBytes; @@ -2558,10 +2546,8 @@ void copyResToQueryResultBuf(SQInfo *pQInfo, SQuery *pQuery) { pQInfo->offset += 1; } -int64_t getNumOfResultWindowRes(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindowRes) { - SQuery *pQuery = pRuntimeEnv->pQuery; - - int64_t maxOutput = 0; +int64_t getNumOfResultWindowRes(SQuery *pQuery, SWindowResult *pWindowRes) { +// int64_t maxOutput = 0; for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { int32_t functionId = pQuery->pSelectExpr[j].base.functionId; @@ -2574,12 +2560,23 @@ int64_t getNumOfResultWindowRes(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pW } SResultInfo *pResultInfo = &pWindowRes->resultInfo[j]; - if (pResultInfo != NULL && maxOutput < pResultInfo->numOfRes) { - maxOutput = pResultInfo->numOfRes; + assert(pResultInfo != NULL); + + if (pResultInfo->numOfRes > 0) { + return pResultInfo->numOfRes; } +// if (pResultInfo != NULL && maxOutput < pResultInfo->numOfRes) { +// maxOutput = pResultInfo->numOfRes; +// +// if (maxOutput > 0) { +// break; +// } +// } +// +// assert(pResultInfo != NULL); } - return maxOutput; + return 0; } int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { @@ -2612,6 +2609,8 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { assert(pQInfo->numOfGroupResultPages == 0); return 0; + } else if (numOfTables == 1) { // no need to merge results since only one table in each group + } SCompSupporter cs = {pTableList, posList, pQInfo}; @@ -2636,7 +2635,7 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { TSKEY ts = GET_INT64_VAL(b); assert(ts == pWindowRes->window.skey); - int64_t num = getNumOfResultWindowRes(pRuntimeEnv, pWindowRes); + int64_t num = getNumOfResultWindowRes(pQuery, pWindowRes); if (num <= 0) { cs.position[pos] += 1; @@ -2699,10 +2698,11 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { displayInterResult(pQuery->sdata, pRuntimeEnv, pQuery->sdata[0]->num); #endif - qTrace("QInfo:%p result merge completed, elapsed time:%" PRId64 " ms", GET_QINFO_ADDR(pQuery), endt - startt); - tfree(pTree); + qTrace("QInfo:%p result merge completed for group:%d, elapsed time:%" PRId64 " ms", pQInfo, pQInfo->groupIndex, endt - startt); + tfree(pTableList); tfree(posList); + tfree(pTree); pQInfo->offset = 0; for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { @@ -2928,8 +2928,13 @@ void initCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) { for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { int32_t functionId = pQuery->pSelectExpr[j].base.functionId; - pRuntimeEnv->pCtx[j].currentStage = 0; + + SResultInfo* pResInfo = GET_RES_INFO(&pRuntimeEnv->pCtx[j]); + if (pResInfo->initialized) { + continue; + } + aAggs[functionId].init(&pRuntimeEnv->pCtx[j]); } } @@ -3078,7 +3083,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); } - pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo); + pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo, pQInfo); setQueryStatus(pQuery, QUERY_NOT_COMPLETED); switchCtxOrder(pRuntimeEnv); @@ -3150,7 +3155,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) { tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); } - pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo); + pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo, pQInfo); pRuntimeEnv->windowResInfo.curIndex = qstatus.windowIndex; setQueryStatus(pQuery, QUERY_NOT_COMPLETED); @@ -3295,13 +3300,14 @@ void setExecutionContext(SQInfo *pQInfo, STableId* pTableId, int32_t groupIndex, setAdditionalInfo(pQInfo, pTableId, pTableQueryInfo); } -static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) { +void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) { SQuery *pQuery = pRuntimeEnv->pQuery; // Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { SQLFunctionCtx *pCtx = &pRuntimeEnv->pCtx[i]; pCtx->aOutputBuf = getPosInResultPage(pRuntimeEnv, i, pResult); + int32_t functionId = pQuery->pSelectExpr[i].base.functionId; if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { pCtx->ptsOutputBuf = pRuntimeEnv->pCtx[0].aOutputBuf; @@ -3319,6 +3325,38 @@ static void setWindowResOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult * } } +void setWindowResOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pResult) { + SQuery *pQuery = pRuntimeEnv->pQuery; + + // Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group + for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { + SQLFunctionCtx *pCtx = &pRuntimeEnv->pCtx[i]; + + pCtx->resultInfo = &pResult->resultInfo[i]; + if (pCtx->resultInfo->complete) { + continue; + } + + pCtx->aOutputBuf = getPosInResultPage(pRuntimeEnv, i, pResult); + pCtx->currentStage = 0; + + int32_t functionId = pCtx->functionId; + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + pCtx->ptsOutputBuf = pRuntimeEnv->pCtx[0].aOutputBuf; + } + + /* + * set the output buffer information and intermediate buffer + * not all queries require the interResultBuf, such as COUNT + */ + pCtx->resultInfo->superTableQ = pRuntimeEnv->stableQuery; // set super table query flag + + if (!pCtx->resultInfo->initialized) { + aAggs[functionId].init(pCtx); + } + } +} + int32_t setAdditionalInfo(SQInfo *pQInfo, STableId* pTableId, STableQueryInfo *pTableQueryInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; assert(pTableQueryInfo->lastKey >= TSKEY_INITIAL_VAL); @@ -3374,13 +3412,12 @@ void setIntervalQueryRange(SQInfo *pQInfo, TSKEY key) { * In ascending query, key is the first qualified timestamp. However, in the descending order query, additional * operations involve. */ - TSKEY skey1, ekey1; - STimeWindow w = {0}; + STimeWindow w = TSWINDOW_INITIALIZER, realWin = TSWINDOW_INITIALIZER; SWindowResInfo *pWindowResInfo = &pTableQueryInfo->windowResInfo; TSKEY sk = MIN(win.skey, win.ekey); TSKEY ek = MAX(win.skey, win.ekey); - getAlignQueryTimeWindow(pQuery, win.skey, sk, ek, &skey1, &ekey1, &w); + getAlignQueryTimeWindow(pQuery, win.skey, sk, ek, &realWin, &w); pWindowResInfo->startTime = pTableQueryInfo->win.skey; // windowSKey may be 0 in case of 1970 timestamp if (pWindowResInfo->prevSKey == TSKEY_INITIAL_VAL) { @@ -3738,7 +3775,7 @@ static void updateOffsetVal(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBloc SColumnInfoData *pColInfoData = taosArrayGet(pDataBlock, 0); // update the pQuery->limit.offset value, and pQuery->pos value - TSKEY *keys = (TSKEY *)pColInfoData->pData; + TSKEY *keys = (TSKEY *) pColInfoData->pData; // update the offset value pTableQueryInfo->lastKey = keys[pQuery->pos]; @@ -3800,8 +3837,7 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) { */ assert(pRuntimeEnv->windowResInfo.prevSKey == TSKEY_INITIAL_VAL); - TSKEY skey1, ekey1; - STimeWindow w = TSWINDOW_INITIALIZER; + STimeWindow w = TSWINDOW_INITIALIZER, realWin = TSWINDOW_INITIALIZER; SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo; STableQueryInfo *pTableQueryInfo = pQuery->current; @@ -3811,14 +3847,12 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) { if (QUERY_IS_ASC_QUERY(pQuery)) { if (pWindowResInfo->prevSKey == TSKEY_INITIAL_VAL) { - getAlignQueryTimeWindow(pQuery, blockInfo.window.skey, blockInfo.window.skey, pQuery->window.ekey, &skey1, - &ekey1, &w); + getAlignQueryTimeWindow(pQuery, blockInfo.window.skey, blockInfo.window.skey, pQuery->window.ekey, &realWin, &w); pWindowResInfo->startTime = w.skey; pWindowResInfo->prevSKey = w.skey; } } else { - getAlignQueryTimeWindow(pQuery, blockInfo.window.ekey, pQuery->window.ekey, blockInfo.window.ekey, &skey1, &ekey1, - &w); + getAlignQueryTimeWindow(pQuery, blockInfo.window.ekey, pQuery->window.ekey, blockInfo.window.ekey, &realWin, &w); pWindowResInfo->startTime = pQuery->window.skey; pWindowResInfo->prevSKey = w.skey; @@ -3939,11 +3973,11 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) { } if (isFirstLastRowQuery(pQuery)) { - pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableIdGroupInfo); + pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableIdGroupInfo, pQInfo); } else if (isPointInterpoQuery(pQuery)) { - pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(tsdb, &cond, &pQInfo->tableIdGroupInfo); + pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(tsdb, &cond, &pQInfo->tableIdGroupInfo, pQInfo); } else { - pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo); + pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo, pQInfo); } } @@ -3999,7 +4033,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool return code; } - pRuntimeEnv->numOfRowsPerPage = getNumOfRowsInResultPage(pQuery, isSTableQuery); + pRuntimeEnv->numOfRowsPerPage = getNumOfRowsInResultPage(pQuery, pRuntimeEnv->topBotQuery, isSTableQuery); if (isSTableQuery) { int32_t rows = getInitialPageNum(pQInfo); @@ -4057,6 +4091,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool pQuery->slidingTime, pQuery->fillType, pColInfo); } + pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery); return TSDB_CODE_SUCCESS; } @@ -4086,10 +4121,10 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { } } -static int64_t queryOnDataBlocks(SQInfo *pQInfo) { +static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; - SQuery * pQuery = pRuntimeEnv->pQuery; - SQueryCostInfo* summary = &pRuntimeEnv->summary; + SQuery* pQuery = pRuntimeEnv->pQuery; + SQueryCostInfo* summary = &pRuntimeEnv->summary; int64_t st = taosGetTimestampMs(); @@ -4144,8 +4179,9 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { summary->totalRows += blockInfo.rows; stableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, pStatis, pDataBlock, binarySearchForKey); - qTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", numOfRows:%d, lastKey:%"PRId64, GET_QINFO_ADDR(pRuntimeEnv), - blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, pQuery->current->lastKey); + qTrace("QInfo:%p check data block, uid:%"PRId64", tid:%d, brange:%" PRId64 "-%" PRId64 ", numOfRows:%d, lastKey:%" PRId64, + GET_QINFO_ADDR(pRuntimeEnv), blockInfo.uid, blockInfo.tid, blockInfo.window.skey, blockInfo.window.ekey, + blockInfo.rows, pQuery->current->lastKey); } int64_t et = taosGetTimestampMs(); @@ -4186,7 +4222,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { pRuntimeEnv->pQueryHandle = NULL; } - pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp); + pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo); taosArrayDestroy(tx); taosArrayDestroy(g1); @@ -4252,9 +4288,9 @@ static void sequentialTableProcess(SQInfo *pQInfo) { } if (isFirstLastRowQuery(pQuery)) { - pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(pQInfo->tsdb, &cond, &gp); + pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(pQInfo->tsdb, &cond, &gp, pQInfo); } else { - pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(pQInfo->tsdb, &cond, &gp); + pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(pQInfo->tsdb, &cond, &gp, pQInfo); } initCtxOutputBuf(pRuntimeEnv); @@ -4448,7 +4484,7 @@ static void doSaveContext(SQInfo *pQInfo) { tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); } - pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo); + pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableIdGroupInfo, pQInfo); setQueryStatus(pQuery, QUERY_NOT_COMPLETED); switchCtxOrder(pRuntimeEnv); @@ -4515,7 +4551,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { pQuery->window.skey, pQuery->window.ekey, pQuery->order.order); // do check all qualified data blocks - int64_t el = queryOnDataBlocks(pQInfo); + int64_t el = scanMultiTableDataBlocks(pQInfo); qTrace("QInfo:%p master scan completed, elapsed time: %lldms, reverse scan start", pQInfo, el); // query error occurred or query is killed, abort current execution @@ -4530,7 +4566,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { if (needReverseScan(pQuery)) { doSaveContext(pQInfo); - el = queryOnDataBlocks(pQInfo); + el = scanMultiTableDataBlocks(pQInfo); qTrace("QInfo:%p reversed scan completed, elapsed time: %lldms", pQInfo, el); doRestoreContext(pQInfo); @@ -4817,7 +4853,7 @@ static void tableQueryImpl(SQInfo *pQInfo) { /* check if query is killed or not */ if (isQueryKilled(pQInfo)) { qTrace("QInfo:%p query is killed", pQInfo); - } else {// todo set the table uid and tid in log + } else { qTrace("QInfo:%p query paused, %" PRId64 " rows returned, numOfTotal:%" PRId64 " rows", pQInfo, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows); } @@ -4852,6 +4888,10 @@ static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pE int32_t j = 0; if (TSDB_COL_IS_TAG(pExprMsg->colInfo.flag)) { + if (pExprMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { + return -1; + } + while(j < pQueryMsg->numOfTags) { if (pExprMsg->colInfo.colId == pTagCols[j].colId) { return j; @@ -4909,9 +4949,15 @@ static bool validateQuerySourceCols(SQueryTableMsg *pQueryMsg, SSqlFuncMsg** pEx return false; } else if (numOfTotal == 0) { for(int32_t i = 0; i < pQueryMsg->numOfOutput; ++i) { - if (pExprMsg[i]->functionId != TSDB_FUNC_TAGPRJ) { - return false; + SSqlFuncMsg* pFuncMsg = pExprMsg[i]; + + if ((pFuncMsg->functionId == TSDB_FUNC_TAGPRJ) || + (pFuncMsg->functionId == TSDB_FUNC_TID_TAG && pFuncMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) || + (pFuncMsg->functionId == TSDB_FUNC_COUNT && pFuncMsg->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX)) { + continue; } + + return false; } } @@ -4973,7 +5019,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, // query msg safety check if (!validateQueryMsg(pQueryMsg)) { - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } char *pMsg = (char *)(pQueryMsg->colList) + sizeof(SColumnInfo) * pQueryMsg->numOfCols; @@ -5043,14 +5089,14 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, } } - if (pExprMsg->functionId == TSDB_FUNC_TAG || pExprMsg->functionId == TSDB_FUNC_TAGPRJ || - pExprMsg->functionId == TSDB_FUNC_TAG_DUMMY) { + int16_t functionId = pExprMsg->functionId; + if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_TAG_DUMMY) { if (pExprMsg->colInfo.flag != TSDB_COL_TAG) { // ignore the column index check for arithmetic expression. - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } } else { // if (!validateExprColumnInfo(pQueryMsg, pExprMsg)) { -// return TSDB_CODE_INVALID_QUERY_MSG; +// return TSDB_CODE_QRY_INVALID_MSG; // } } @@ -5060,7 +5106,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, if (!validateQuerySourceCols(pQueryMsg, *pExpr)) { tfree(*pExpr); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } pMsg = createTableIdList(pQueryMsg, pMsg, pTableIdList); @@ -5149,21 +5195,21 @@ static int32_t buildAirthmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable if (pExprNode == NULL) { qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz); - return TSDB_CODE_APP_ERROR; + return TSDB_CODE_QRY_APP_ERROR; } pArithExprInfo->pExpr = pExprNode; return TSDB_CODE_SUCCESS; } -static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, +static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg, SColumnInfo* pTagCols) { *pExprInfo = NULL; int32_t code = TSDB_CODE_SUCCESS; - SExprInfo *pExprs = (SExprInfo *)calloc(1, sizeof(SExprInfo) * pQueryMsg->numOfOutput); + SExprInfo *pExprs = (SExprInfo *)calloc(pQueryMsg->numOfOutput, sizeof(SExprInfo)); if (pExprs == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } bool isSuperTable = QUERY_IS_STABLE_QUERY(pQueryMsg->queryType); @@ -5187,23 +5233,29 @@ static int32_t createSqlFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo type = TSDB_DATA_TYPE_DOUBLE; bytes = tDataTypeDesc[type].nSize; - } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { // parse the normal column + } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX && pExprs[i].base.functionId == TSDB_FUNC_TAGPRJ) { // parse the normal column type = TSDB_DATA_TYPE_BINARY; bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - } else{ + } else { int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); - assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags); + assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX); + + if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX) { + SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; + type = pCol->type; + bytes = pCol->bytes; + } else { + type = TSDB_DATA_TYPE_BINARY; + bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; + } - SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; - type = pCol->type; - bytes = pCol->bytes; } int32_t param = pExprs[i].base.arg[0].argValue.i64; if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].type, &pExprs[i].bytes, &pExprs[i].interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { tfree(pExprs); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } if (pExprs[i].base.functionId == TSDB_FUNC_TAG_DUMMY || pExprs[i].base.functionId == TSDB_FUNC_TS_DUMMY) { @@ -5244,7 +5296,7 @@ static SSqlGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SCol // using group by tag columns SSqlGroupbyExpr *pGroupbyExpr = (SSqlGroupbyExpr *)calloc(1, sizeof(SSqlGroupbyExpr)); if (pGroupbyExpr == NULL) { - *code = TSDB_CODE_SERV_OUT_OF_MEMORY; + *code = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } @@ -5292,7 +5344,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (lower == TSDB_RELATION_INVALID && upper == TSDB_RELATION_INVALID) { qError("QInfo:%p invalid filter info", pQInfo); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } int16_t type = pQuery->colList[i].type; @@ -5304,7 +5356,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (rangeFilterArray == NULL && filterArray == NULL) { qError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } if ((lower == TSDB_RELATION_GREATER_EQUAL || lower == TSDB_RELATION_GREATER) && @@ -5328,7 +5380,7 @@ static int32_t createFilterInfo(void *pQInfo, SQuery *pQuery) { if (upper != TSDB_RELATION_INVALID) { qError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type); - return TSDB_CODE_INVALID_QUERY_MSG; + return TSDB_CODE_QRY_INVALID_MSG; } } else { pSingleColFilter->fp = filterArray[upper]; @@ -5777,18 +5829,18 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi if (pQueryMsg->numOfTables <= 0) { qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables); - code = TSDB_CODE_INVALID_QUERY_MSG; + code = TSDB_CODE_QRY_INVALID_MSG; goto _over; } if (pTableIdList == NULL || taosArrayGetSize(pTableIdList) == 0) { qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg); - code = TSDB_CODE_INVALID_QUERY_MSG; + code = TSDB_CODE_QRY_INVALID_MSG; goto _over; } SExprInfo *pExprs = NULL; - if ((code = createSqlFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { + if ((code = createQFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { goto _over; } @@ -5846,7 +5898,7 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi (*pQInfo) = createQInfoImpl(pQueryMsg, pTableIdList, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo); if ((*pQInfo) == NULL) { - code = TSDB_CODE_SERV_OUT_OF_MEMORY; + code = TSDB_CODE_QRY_OUT_OF_MEMORY; goto _over; } @@ -5890,6 +5942,7 @@ void qTableQuery(qinfo_t qinfo) { qTrace("QInfo:%p query task is launched", pQInfo); if (onlyQueryTags(pQInfo->runtimeEnv.pQuery)) { + assert(pQInfo->runtimeEnv.pQueryHandle == NULL); buildTagQueryResult(pQInfo); // todo support the limit/offset } else if (pQInfo->runtimeEnv.stableQuery) { stableQueryImpl(pQInfo); @@ -5905,7 +5958,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo) { SQInfo *pQInfo = (SQInfo *)qinfo; if (pQInfo == NULL || !isValidQInfo(pQInfo)) { - return TSDB_CODE_INVALID_QHANDLE; + return TSDB_CODE_QRY_INVALID_QHANDLE; } SQuery *pQuery = pQInfo->runtimeEnv.pQuery; @@ -5944,7 +5997,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co SQInfo *pQInfo = (SQInfo *)qinfo; if (pQInfo == NULL || !isValidQInfo(pQInfo)) { - return TSDB_CODE_INVALID_QHANDLE; + return TSDB_CODE_QRY_INVALID_QHANDLE; } SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; @@ -5980,94 +6033,106 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co } return code; - - // if (numOfRows == 0 && (pRetrieve->qhandle == (uint64_t)pObj->qhandle) && (code != TSDB_CODE_ACTION_IN_PROGRESS)) { - // qTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code); - // vnodeDecRefCount(pObj->qhandle); - // pObj->qhandle = NULL; - // } } static void buildTagQueryResult(SQInfo* pQInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQuery * pQuery = pRuntimeEnv->pQuery; - size_t num = taosArrayGetSize(pQInfo->groupInfo.pGroupList); - assert(num == 0 || num == 1); - if (num == 0) { + size_t numOfGroup = taosArrayGetSize(pQInfo->groupInfo.pGroupList); + assert(numOfGroup == 0 || numOfGroup == 1); + + if (numOfGroup == 0) { return; } SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); - num = taosArrayGetSize(pa); - + + size_t num = taosArrayGetSize(pa); assert(num == pQInfo->groupInfo.numOfTables); -// int16_t type, bytes; - + + int32_t count = 0; int32_t functionId = pQuery->pSelectExpr[0].base.functionId; if (functionId == TSDB_FUNC_TID_TAG) { // return the tags & table Id assert(pQuery->numOfOutput == 1); + SExprInfo* pExprInfo = &pQuery->pSelectExpr[0]; - int32_t rsize = pExprInfo->bytes; + count = 0; + + while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) { + int32_t i = pQInfo->tableIndex++; + SGroupItem *item = taosArrayGet(pa, i); - for(int32_t i = 0; i < num; ++i) { - SGroupItem* item = taosArrayGet(pa, i); - - char* output = pQuery->sdata[0]->data + i * rsize; + char *output = pQuery->sdata[0]->data + i * rsize; varDataSetLen(output, rsize - VARSTR_HEADER_SIZE); - + output = varDataVal(output); - *(int64_t*) output = item->id.uid; // memory align problem, todo serialize + *(int64_t *)output = item->id.uid; // memory align problem, todo serialize output += sizeof(item->id.uid); - *(int32_t*) output = item->id.tid; + *(int32_t *)output = item->id.tid; output += sizeof(item->id.tid); - *(int32_t*) output = pQInfo->vgId; + *(int32_t *)output = pQInfo->vgId; output += sizeof(pQInfo->vgId); int16_t bytes = pExprInfo->bytes; int16_t type = pExprInfo->type; - - char* val = tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo->base.colInfo.colId, type, bytes); - - // todo refactor - if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { - if (val == NULL) { - setVardataNull(output, type); - } else { - memcpy(output, val, varDataTLen(val)); - } + + if (pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { + char *data = tsdbGetTableName(pQInfo->tsdb, &item->id); + memcpy(output, data, varDataTLen(data)); } else { - if (val == NULL) { - setNull(output, type, bytes); + char *val = tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo->base.colInfo.colId, type, bytes); + + // todo refactor + if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + if (val == NULL) { + setVardataNull(output, type); + } else { + memcpy(output, val, varDataTLen(val)); + } } else { - memcpy(output, val, bytes); + if (val == NULL) { + setNull(output, type, bytes); + } else { + memcpy(output, val, bytes); + } } } + + count += 1; } + + qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, count); + + } else if (functionId == TSDB_FUNC_COUNT) {// handle the "count(tbname)" query + *(int64_t*) pQuery->sdata[0]->data = num; - qTrace("QInfo:%p create (tableId, tag) info completed, rows:%d", pQInfo, num); + count = 1; + pQInfo->tableIndex = num; //set query completed + qTrace("QInfo:%p create count(tbname) query, res:%d rows:1", pQInfo, count); } else { // return only the tags|table name etc. - for(int32_t i = 0; i < num; ++i) { + count = 0; + while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) { + int32_t i = pQInfo->tableIndex++; + SExprInfo* pExprInfo = pQuery->pSelectExpr; SGroupItem* item = taosArrayGet(pa, i); for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { - // todo check the return value, refactor codes if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { char* data = tsdbGetTableName(pQInfo->tsdb, &item->id); - - char* dst = pQuery->sdata[j]->data + i * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); + char* dst = pQuery->sdata[j]->data + count * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); memcpy(dst, data, varDataTLen(data)); } else {// todo refactor int16_t type = pExprInfo[j].type; int16_t bytes = pExprInfo[j].bytes; char* data = tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo[j].base.colInfo.colId, type, bytes); + char* dst = pQuery->sdata[j]->data + count * pExprInfo[j].bytes; - char* dst = pQuery->sdata[j]->data + i * pExprInfo[j].bytes; if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { if (data == NULL) { setVardataNull(dst, type); @@ -6083,13 +6148,13 @@ static void buildTagQueryResult(SQInfo* pQInfo) { } } } + count += 1; } - - pQInfo->tableIndex = pQInfo->groupInfo.numOfTables; - qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, num); + + qTrace("QInfo:%p create tag values results completed, rows:%d", pQInfo, count); } - pQuery->rec.rows = num; + pQuery->rec.rows = count; setQueryStatus(pQuery, QUERY_COMPLETED); } diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index a85cdc274d..143d86d5db 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -206,11 +206,6 @@ bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot) { return (getWindowResult(pWindowResInfo, slot)->status.closed == true); } -int32_t curTimeWindow(SWindowResInfo *pWindowResInfo) { - assert(pWindowResInfo->curIndex >= 0 && pWindowResInfo->curIndex < pWindowResInfo->size); - return pWindowResInfo->curIndex; -} - void closeTimeWindow(SWindowResInfo *pWindowResInfo, int32_t slot) { getWindowResult(pWindowResInfo, slot)->status.closed = true; } diff --git a/src/query/src/qast.c b/src/query/src/qast.c index f35f4d0184..0a0fe56ebd 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -1035,7 +1035,7 @@ void exprTreeToBinary(SBufferWriter* bw, tExprNode* expr) { static void* exception_calloc(size_t nmemb, size_t size) { void* p = calloc(nmemb, size); if (p == NULL) { - THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); + THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } return p; } @@ -1043,7 +1043,7 @@ static void* exception_calloc(size_t nmemb, size_t size) { static void* exception_malloc(size_t size) { void* p = malloc(size); if (p == NULL) { - THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); + THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } return p; } @@ -1051,7 +1051,7 @@ static void* exception_malloc(size_t size) { static UNUSED_FUNC char* exception_strdup(const char* str) { char* p = strdup(str); if (p == NULL) { - THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); + THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); } return p; } diff --git a/src/query/src/qextbuffer.c b/src/query/src/qextbuffer.c index 98d830c26f..6351b850d8 100644 --- a/src/query/src/qextbuffer.c +++ b/src/query/src/qextbuffer.c @@ -356,17 +356,15 @@ static FORCE_INLINE int32_t primaryKeyComparator(int64_t f1, int64_t f2, int32_t static FORCE_INLINE int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t bytes) { switch (type) { case TSDB_DATA_TYPE_INT: { - int32_t first = *(int32_t *)f1; - int32_t second = *(int32_t *)f2; + int32_t first = *(int32_t *) f1; + int32_t second = *(int32_t *) f2; if (first == second) { return 0; } return (first < second) ? -1 : 1; }; case TSDB_DATA_TYPE_DOUBLE: { - //double first = *(double *)f1; - double first = GET_DOUBLE_VAL(f1); - //double second = *(double *)f2; + double first = GET_DOUBLE_VAL(f1); double second = GET_DOUBLE_VAL(f2); if (first == second) { return 0; @@ -374,9 +372,7 @@ static FORCE_INLINE int32_t columnValueAscendingComparator(char *f1, char *f2, i return (first < second) ? -1 : 1; }; case TSDB_DATA_TYPE_FLOAT: { - //float first = *(float *)f1; - //float second = *(float *)f2; - float first = GET_FLOAT_VAL(f1); + float first = GET_FLOAT_VAL(f1); float second = GET_FLOAT_VAL(f2); if (first == second) { return 0; @@ -439,9 +435,9 @@ int32_t compare_a(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1, int32_t s2, char *data2) { assert(numOfRows1 == numOfRows2); - int32_t cmpCnt = pDescriptor->orderIdx.numOfCols; + int32_t cmpCnt = pDescriptor->orderInfo.numOfCols; for (int32_t i = 0; i < cmpCnt; ++i) { - int32_t colIdx = pDescriptor->orderIdx.pData[i]; + int32_t colIdx = pDescriptor->orderInfo.pData[i]; char *f1 = COLMODEL_GET_VAL(data1, pDescriptor->pColumnModel, numOfRows1, s1, colIdx); char *f2 = COLMODEL_GET_VAL(data2, pDescriptor->pColumnModel, numOfRows2, s2, colIdx); @@ -471,9 +467,9 @@ int32_t compare_d(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1, int32_t s2, char *data2) { assert(numOfRows1 == numOfRows2); - int32_t cmpCnt = pDescriptor->orderIdx.numOfCols; + int32_t cmpCnt = pDescriptor->orderInfo.numOfCols; for (int32_t i = 0; i < cmpCnt; ++i) { - int32_t colIdx = pDescriptor->orderIdx.pData[i]; + int32_t colIdx = pDescriptor->orderInfo.pData[i]; char *f1 = COLMODEL_GET_VAL(data1, pDescriptor->pColumnModel, numOfRows1, s1, colIdx); char *f2 = COLMODEL_GET_VAL(data2, pDescriptor->pColumnModel, numOfRows2, s2, colIdx); @@ -563,13 +559,13 @@ static void median(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta int32_t midIdx = ((end - start) >> 1) + start; #if defined(_DEBUG_VIEW) - int32_t f = pDescriptor->orderIdx.pData[0]; + int32_t f = pDescriptor->orderInfo.pData[0]; char *midx = COLMODEL_GET_VAL(data, pDescriptor->pColumnModel, numOfRows, midIdx, f); char *startx = COLMODEL_GET_VAL(data, pDescriptor->pColumnModel, numOfRows, start, f); char *endx = COLMODEL_GET_VAL(data, pDescriptor->pColumnModel, numOfRows, end, f); - int32_t colIdx = pDescriptor->orderIdx.pData[0]; + int32_t colIdx = pDescriptor->orderInfo.pData[0]; tSortDataPrint(pDescriptor->pColumnModel->pFields[colIdx].field.type, "before", startx, midx, endx); #endif @@ -596,7 +592,7 @@ static void median(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta } static UNUSED_FUNC void tRowModelDisplay(tOrderDescriptor *pDescriptor, int32_t numOfRows, char *d, int32_t len) { - int32_t colIdx = pDescriptor->orderIdx.pData[0]; + int32_t colIdx = pDescriptor->orderInfo.pData[0]; for (int32_t i = 0; i < len; ++i) { char *startx = COLMODEL_GET_VAL(d, pDescriptor->pColumnModel, numOfRows, i, colIdx); @@ -1062,9 +1058,9 @@ tOrderDescriptor *tOrderDesCreate(const int32_t *orderColIdx, int32_t numOfOrder desc->pColumnModel = pModel; desc->tsOrder = tsOrderType; - desc->orderIdx.numOfCols = numOfOrderCols; + desc->orderInfo.numOfCols = numOfOrderCols; for (int32_t i = 0; i < numOfOrderCols; ++i) { - desc->orderIdx.pData[i] = orderColIdx[i]; + desc->orderInfo.pData[i] = orderColIdx[i]; } return desc; diff --git a/src/query/src/qresultBuf.c b/src/query/src/qresultBuf.c index 8910d84830..55ec57b763 100644 --- a/src/query/src/qresultBuf.c +++ b/src/query/src/qresultBuf.c @@ -28,19 +28,19 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si if (!FD_VALID(pResBuf->fd)) { qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); - return TSDB_CODE_CLI_NO_DISKSPACE; + return TSDB_CODE_QRY_NO_DISKSPACE; } int32_t ret = ftruncate(pResBuf->fd, pResBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE); if (ret != TSDB_CODE_SUCCESS) { qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); - return TSDB_CODE_CLI_NO_DISKSPACE; + return TSDB_CODE_QRY_NO_DISKSPACE; } pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0); if (pResBuf->pBuf == MAP_FAILED) { qError("QInfo:%p failed to map temp file: %s. %s", handle, pResBuf->path, strerror(errno)); - return TSDB_CODE_CLI_OUT_OF_MEMORY; // todo change error code + return TSDB_CODE_QRY_OUT_OF_MEMORY; // todo change error code } qTrace("QInfo:%p create tmp file for output result, %s, %" PRId64 "bytes", handle, pResBuf->path, @@ -50,12 +50,6 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si return TSDB_CODE_SUCCESS; } -tFilePage* getResultBufferPageById(SDiskbasedResultBuf* pResultBuf, int32_t id) { - assert(id < pResultBuf->numOfPages && id >= 0); - - return (tFilePage*)(pResultBuf->pBuf + DEFAULT_INTERN_BUF_PAGE_SIZE * id); -} - int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf) { return taosHashGetSize(pResultBuf->idsTable); } int32_t getResBufSize(SDiskbasedResultBuf* pResultBuf) { return pResultBuf->totalBufSize; } @@ -74,7 +68,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf if (ret != 0) { // dError("QInfo:%p failed to create intermediate result output file:%s. %s", pQInfo, pSupporter->extBufFile, // strerror(errno)); - return -TSDB_CODE_SERV_NO_DISKSPACE; + return -TSDB_CODE_QRY_NO_DISKSPACE; } pResultBuf->totalBufSize = pResultBuf->numOfPages * DEFAULT_INTERN_BUF_PAGE_SIZE; @@ -82,7 +76,7 @@ static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOf if (pResultBuf->pBuf == MAP_FAILED) { // dError("QInfo:%p failed to map temp file: %s. %s", pQInfo, pSupporter->extBufFile, strerror(errno)); - return -TSDB_CODE_SERV_OUT_OF_MEMORY; + return -TSDB_CODE_QRY_OUT_OF_MEMORY; } return TSDB_CODE_SUCCESS; @@ -169,7 +163,7 @@ tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32 *pageId = (pResultBuf->allocateId++); registerPageId(pResultBuf, groupId, *pageId); - tFilePage* page = getResultBufferPageById(pResultBuf, *pageId); + tFilePage* page = GET_RES_BUF_PAGE_BY_ID(pResultBuf, *pageId); // clear memory for the new page memset(page, 0, DEFAULT_INTERN_BUF_PAGE_SIZE); diff --git a/src/query/src/qsyntaxtreefunction.c b/src/query/src/qsyntaxtreefunction.c index 41e84b5ab0..5719bb0188 100644 --- a/src/query/src/qsyntaxtreefunction.c +++ b/src/query/src/qsyntaxtreefunction.c @@ -311,7 +311,7 @@ void calc_fn_i32_i32_sub(void *left, void *right, int32_t numLeft, int32_t numRi if (numLeft == numRight) { for (; i >= 0 && i < numRight; i += step, pOutput += 1) { if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) { - setNull((char *)&(pOutput[i]), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize); + setNull((char *)(pOutput), TSDB_DATA_TYPE_DOUBLE, tDataTypeDesc[TSDB_DATA_TYPE_DOUBLE].nSize); continue; } *pOutput = (double)pLeft[i] - pRight[i]; diff --git a/src/query/src/sql.c b/src/query/src/sql.c index d079e5a24e..545cef4082 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -126,17 +126,17 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 247 +#define YYNSTATE 241 #define YYNRULE 220 #define YYNTOKEN 205 -#define YY_MAX_SHIFT 246 -#define YY_MIN_SHIFTREDUCE 403 -#define YY_MAX_SHIFTREDUCE 622 -#define YY_ERROR_ACTION 623 -#define YY_ACCEPT_ACTION 624 -#define YY_NO_ACTION 625 -#define YY_MIN_REDUCE 626 -#define YY_MAX_REDUCE 845 +#define YY_MAX_SHIFT 240 +#define YY_MIN_SHIFTREDUCE 397 +#define YY_MAX_SHIFTREDUCE 616 +#define YY_ERROR_ACTION 617 +#define YY_ACCEPT_ACTION 618 +#define YY_NO_ACTION 619 +#define YY_MIN_REDUCE 620 +#define YY_MAX_REDUCE 839 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -202,63 +202,63 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (547) +#define YY_ACTTAB_COUNT (541) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 724, 444, 723, 11, 722, 134, 624, 246, 725, 445, - /* 10 */ 727, 726, 764, 41, 43, 21, 35, 36, 153, 244, - /* 20 */ 135, 29, 135, 444, 203, 39, 37, 40, 38, 158, - /* 30 */ 833, 445, 832, 34, 33, 139, 135, 32, 31, 30, - /* 40 */ 41, 43, 753, 35, 36, 157, 833, 166, 29, 739, - /* 50 */ 103, 203, 39, 37, 40, 38, 188, 21, 103, 99, - /* 60 */ 34, 33, 761, 155, 32, 31, 30, 404, 405, 406, - /* 70 */ 407, 408, 409, 410, 411, 412, 413, 414, 415, 245, - /* 80 */ 444, 742, 41, 43, 103, 35, 36, 103, 445, 168, - /* 90 */ 29, 738, 21, 203, 39, 37, 40, 38, 32, 31, - /* 100 */ 30, 56, 34, 33, 753, 787, 32, 31, 30, 43, - /* 110 */ 191, 35, 36, 788, 829, 198, 29, 21, 154, 203, - /* 120 */ 39, 37, 40, 38, 167, 578, 739, 8, 34, 33, - /* 130 */ 61, 113, 32, 31, 30, 665, 35, 36, 126, 59, - /* 140 */ 200, 29, 58, 17, 203, 39, 37, 40, 38, 221, - /* 150 */ 26, 739, 169, 34, 33, 220, 219, 32, 31, 30, - /* 160 */ 16, 239, 214, 238, 213, 212, 211, 237, 210, 236, - /* 170 */ 235, 209, 720, 828, 709, 710, 711, 712, 713, 714, - /* 180 */ 715, 716, 717, 718, 719, 162, 591, 234, 76, 582, - /* 190 */ 165, 585, 240, 588, 234, 162, 591, 98, 827, 582, - /* 200 */ 225, 585, 60, 588, 26, 162, 591, 12, 742, 582, - /* 210 */ 742, 585, 674, 588, 27, 126, 21, 159, 160, 34, - /* 220 */ 33, 202, 842, 32, 31, 30, 148, 159, 160, 740, - /* 230 */ 536, 539, 88, 87, 142, 18, 666, 159, 160, 126, - /* 240 */ 147, 559, 560, 39, 37, 40, 38, 50, 226, 550, - /* 250 */ 739, 34, 33, 46, 507, 32, 31, 30, 523, 531, - /* 260 */ 17, 520, 151, 521, 51, 522, 190, 26, 16, 239, - /* 270 */ 152, 238, 243, 242, 95, 237, 551, 236, 235, 177, - /* 280 */ 14, 42, 223, 222, 580, 741, 185, 187, 182, 170, - /* 290 */ 171, 42, 590, 584, 150, 587, 74, 78, 83, 86, - /* 300 */ 77, 42, 590, 161, 608, 592, 80, 589, 13, 13, - /* 310 */ 140, 583, 590, 586, 513, 47, 141, 589, 46, 798, - /* 320 */ 581, 116, 117, 68, 64, 67, 143, 589, 130, 128, - /* 330 */ 91, 90, 89, 512, 48, 207, 527, 22, 528, 22, - /* 340 */ 144, 3, 73, 72, 10, 9, 145, 525, 146, 526, - /* 350 */ 85, 84, 137, 797, 133, 138, 136, 163, 794, 524, - /* 360 */ 793, 164, 763, 733, 224, 100, 755, 780, 779, 114, - /* 370 */ 26, 115, 112, 676, 208, 131, 24, 217, 673, 218, - /* 380 */ 841, 70, 840, 838, 118, 694, 25, 93, 23, 132, - /* 390 */ 663, 79, 189, 546, 661, 192, 81, 82, 659, 658, - /* 400 */ 172, 127, 656, 196, 655, 654, 653, 652, 644, 129, - /* 410 */ 650, 648, 646, 52, 752, 767, 49, 44, 768, 781, - /* 420 */ 201, 199, 197, 195, 193, 28, 216, 75, 227, 228, - /* 430 */ 229, 230, 205, 232, 231, 53, 233, 241, 622, 149, - /* 440 */ 173, 62, 65, 174, 176, 175, 621, 178, 179, 180, - /* 450 */ 181, 657, 121, 120, 695, 125, 119, 122, 123, 92, - /* 460 */ 124, 651, 1, 106, 104, 737, 94, 105, 620, 109, - /* 470 */ 107, 108, 110, 111, 2, 184, 613, 183, 186, 190, - /* 480 */ 533, 55, 547, 156, 101, 57, 552, 194, 102, 5, - /* 490 */ 6, 63, 484, 593, 4, 19, 20, 15, 204, 7, - /* 500 */ 206, 481, 479, 478, 477, 475, 448, 215, 66, 45, - /* 510 */ 22, 509, 508, 69, 506, 54, 469, 467, 459, 465, - /* 520 */ 461, 463, 457, 455, 71, 483, 482, 480, 476, 474, - /* 530 */ 46, 446, 419, 417, 626, 625, 625, 625, 625, 625, - /* 540 */ 96, 625, 625, 625, 625, 625, 97, + /* 0 */ 718, 438, 717, 11, 716, 134, 618, 240, 719, 439, + /* 10 */ 721, 720, 758, 41, 43, 21, 35, 36, 153, 238, + /* 20 */ 135, 29, 135, 438, 197, 39, 37, 40, 38, 158, + /* 30 */ 827, 439, 826, 34, 33, 139, 135, 32, 31, 30, + /* 40 */ 41, 43, 747, 35, 36, 157, 827, 166, 29, 733, + /* 50 */ 103, 197, 39, 37, 40, 38, 182, 21, 103, 99, + /* 60 */ 34, 33, 755, 155, 32, 31, 30, 398, 399, 400, + /* 70 */ 401, 402, 403, 404, 405, 406, 407, 408, 409, 239, + /* 80 */ 438, 736, 41, 43, 103, 35, 36, 103, 439, 168, + /* 90 */ 29, 732, 21, 197, 39, 37, 40, 38, 32, 31, + /* 100 */ 30, 56, 34, 33, 747, 781, 32, 31, 30, 43, + /* 110 */ 185, 35, 36, 782, 823, 192, 29, 21, 154, 197, + /* 120 */ 39, 37, 40, 38, 167, 572, 733, 8, 34, 33, + /* 130 */ 61, 113, 32, 31, 30, 659, 35, 36, 126, 59, + /* 140 */ 194, 29, 58, 17, 197, 39, 37, 40, 38, 215, + /* 150 */ 26, 733, 169, 34, 33, 214, 213, 32, 31, 30, + /* 160 */ 16, 233, 208, 232, 207, 206, 205, 231, 204, 230, + /* 170 */ 229, 203, 714, 219, 703, 704, 705, 706, 707, 708, + /* 180 */ 709, 710, 711, 712, 713, 162, 585, 50, 60, 576, + /* 190 */ 175, 579, 165, 582, 234, 162, 585, 179, 178, 576, + /* 200 */ 27, 579, 734, 582, 51, 162, 585, 12, 98, 576, + /* 210 */ 736, 579, 736, 582, 228, 26, 21, 159, 160, 34, + /* 220 */ 33, 196, 836, 32, 31, 30, 148, 159, 160, 76, + /* 230 */ 822, 533, 88, 87, 142, 228, 668, 159, 160, 126, + /* 240 */ 147, 553, 554, 39, 37, 40, 38, 821, 220, 544, + /* 250 */ 733, 34, 33, 46, 501, 32, 31, 30, 517, 525, + /* 260 */ 17, 514, 151, 515, 152, 516, 184, 26, 16, 233, + /* 270 */ 140, 232, 237, 236, 95, 231, 660, 230, 229, 126, + /* 280 */ 530, 42, 217, 216, 578, 18, 581, 181, 161, 170, + /* 290 */ 171, 42, 584, 577, 150, 580, 74, 78, 83, 86, + /* 300 */ 77, 42, 584, 574, 545, 602, 80, 583, 14, 13, + /* 310 */ 141, 586, 584, 143, 507, 13, 47, 583, 46, 73, + /* 320 */ 72, 116, 117, 68, 64, 67, 3, 583, 130, 128, + /* 330 */ 91, 90, 89, 506, 201, 48, 144, 22, 22, 575, + /* 340 */ 521, 519, 522, 520, 10, 9, 85, 84, 145, 146, + /* 350 */ 137, 133, 138, 735, 136, 792, 791, 163, 788, 518, + /* 360 */ 787, 164, 757, 727, 218, 100, 749, 774, 773, 114, + /* 370 */ 26, 115, 112, 670, 202, 131, 24, 211, 667, 212, + /* 380 */ 835, 70, 834, 832, 118, 688, 25, 183, 23, 132, + /* 390 */ 657, 79, 93, 540, 655, 186, 81, 82, 653, 652, + /* 400 */ 172, 190, 127, 746, 650, 649, 648, 647, 646, 638, + /* 410 */ 129, 644, 642, 52, 640, 44, 49, 195, 761, 762, + /* 420 */ 775, 191, 193, 189, 187, 28, 210, 75, 221, 222, + /* 430 */ 223, 224, 225, 199, 226, 227, 235, 53, 616, 174, + /* 440 */ 615, 149, 62, 173, 65, 176, 177, 614, 180, 651, + /* 450 */ 607, 184, 92, 527, 645, 541, 120, 689, 121, 122, + /* 460 */ 119, 123, 125, 124, 94, 104, 1, 731, 105, 111, + /* 470 */ 108, 106, 107, 109, 110, 2, 55, 57, 101, 156, + /* 480 */ 188, 5, 546, 102, 19, 6, 587, 20, 4, 15, + /* 490 */ 63, 7, 198, 478, 200, 475, 473, 472, 471, 469, + /* 500 */ 442, 209, 66, 45, 69, 71, 22, 503, 502, 500, + /* 510 */ 54, 463, 461, 453, 459, 455, 457, 451, 449, 477, + /* 520 */ 476, 474, 470, 468, 46, 440, 96, 413, 411, 620, + /* 530 */ 619, 619, 619, 619, 619, 619, 619, 619, 619, 619, + /* 540 */ 97, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 225, 1, 227, 258, 229, 258, 206, 207, 233, 9, @@ -278,44 +278,44 @@ static const YYCODETYPE yy_lookahead[] = { /* 140 */ 262, 21, 264, 97, 24, 25, 26, 27, 28, 241, /* 150 */ 104, 243, 126, 33, 34, 129, 130, 37, 38, 39, /* 160 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - /* 170 */ 95, 96, 225, 258, 227, 228, 229, 230, 231, 232, - /* 180 */ 233, 234, 235, 236, 237, 1, 2, 78, 72, 5, - /* 190 */ 226, 7, 226, 9, 78, 1, 2, 97, 258, 5, - /* 200 */ 209, 7, 245, 9, 104, 1, 2, 44, 244, 5, - /* 210 */ 244, 7, 213, 9, 257, 216, 209, 33, 34, 33, - /* 220 */ 34, 37, 244, 37, 38, 39, 63, 33, 34, 238, - /* 230 */ 102, 37, 69, 70, 71, 107, 213, 33, 34, 216, - /* 240 */ 77, 114, 115, 25, 26, 27, 28, 102, 241, 98, + /* 170 */ 95, 96, 225, 209, 227, 228, 229, 230, 231, 232, + /* 180 */ 233, 234, 235, 236, 237, 1, 2, 102, 245, 5, + /* 190 */ 125, 7, 226, 9, 226, 1, 2, 132, 133, 5, + /* 200 */ 257, 7, 238, 9, 119, 1, 2, 44, 97, 5, + /* 210 */ 244, 7, 244, 9, 78, 104, 209, 33, 34, 33, + /* 220 */ 34, 37, 244, 37, 38, 39, 63, 33, 34, 72, + /* 230 */ 258, 37, 69, 70, 71, 78, 213, 33, 34, 216, + /* 240 */ 77, 114, 115, 25, 26, 27, 28, 258, 241, 98, /* 250 */ 243, 33, 34, 102, 5, 37, 38, 39, 2, 98, - /* 260 */ 97, 5, 258, 7, 119, 9, 105, 104, 85, 86, - /* 270 */ 258, 88, 60, 61, 62, 92, 98, 94, 95, 125, - /* 280 */ 102, 97, 33, 34, 1, 244, 132, 124, 134, 33, + /* 260 */ 97, 5, 258, 7, 258, 9, 105, 104, 85, 86, + /* 270 */ 258, 88, 60, 61, 62, 92, 213, 94, 95, 216, + /* 280 */ 102, 97, 33, 34, 5, 107, 7, 124, 59, 33, /* 290 */ 34, 97, 108, 5, 131, 7, 64, 65, 66, 67, - /* 300 */ 68, 97, 108, 59, 98, 98, 74, 123, 102, 102, - /* 310 */ 258, 5, 108, 7, 98, 102, 258, 123, 102, 239, - /* 320 */ 37, 64, 65, 66, 67, 68, 258, 123, 64, 65, - /* 330 */ 66, 67, 68, 98, 121, 98, 5, 102, 7, 102, - /* 340 */ 258, 97, 127, 128, 127, 128, 258, 5, 258, 7, - /* 350 */ 72, 73, 258, 239, 258, 258, 258, 239, 239, 103, + /* 300 */ 68, 97, 108, 1, 98, 98, 74, 123, 102, 102, + /* 310 */ 258, 98, 108, 258, 98, 102, 102, 123, 102, 127, + /* 320 */ 128, 64, 65, 66, 67, 68, 97, 123, 64, 65, + /* 330 */ 66, 67, 68, 98, 98, 121, 258, 102, 102, 37, + /* 340 */ 5, 5, 7, 7, 127, 128, 72, 73, 258, 258, + /* 350 */ 258, 258, 258, 244, 258, 239, 239, 239, 239, 103, /* 360 */ 239, 239, 209, 240, 239, 209, 242, 265, 265, 209, /* 370 */ 104, 209, 246, 209, 209, 209, 209, 209, 209, 209, - /* 380 */ 209, 209, 209, 209, 209, 209, 209, 59, 209, 209, - /* 390 */ 209, 209, 242, 108, 209, 261, 209, 209, 209, 209, - /* 400 */ 209, 209, 209, 261, 209, 209, 209, 209, 209, 209, - /* 410 */ 209, 209, 209, 118, 255, 210, 120, 117, 210, 210, - /* 420 */ 112, 116, 111, 110, 109, 122, 75, 84, 83, 49, - /* 430 */ 80, 82, 210, 81, 53, 210, 79, 75, 5, 210, - /* 440 */ 133, 214, 214, 5, 58, 133, 5, 133, 5, 133, - /* 450 */ 58, 210, 218, 222, 224, 217, 223, 221, 219, 211, - /* 460 */ 220, 210, 215, 252, 254, 242, 211, 253, 5, 249, - /* 470 */ 251, 250, 248, 247, 212, 58, 87, 133, 125, 105, - /* 480 */ 98, 106, 98, 1, 97, 102, 98, 97, 97, 113, - /* 490 */ 113, 72, 9, 98, 97, 102, 102, 97, 99, 97, - /* 500 */ 99, 5, 5, 5, 5, 5, 76, 15, 72, 16, - /* 510 */ 102, 5, 5, 128, 98, 97, 5, 5, 5, 5, - /* 520 */ 5, 5, 5, 5, 128, 5, 5, 5, 5, 5, - /* 530 */ 102, 76, 59, 58, 0, 269, 269, 269, 269, 269, - /* 540 */ 21, 269, 269, 269, 269, 269, 21, 269, 269, 269, + /* 380 */ 209, 209, 209, 209, 209, 209, 209, 242, 209, 209, + /* 390 */ 209, 209, 59, 108, 209, 261, 209, 209, 209, 209, + /* 400 */ 209, 261, 209, 255, 209, 209, 209, 209, 209, 209, + /* 410 */ 209, 209, 209, 118, 209, 117, 120, 112, 210, 210, + /* 420 */ 210, 111, 116, 110, 109, 122, 75, 84, 83, 49, + /* 430 */ 80, 82, 53, 210, 81, 79, 75, 210, 5, 5, + /* 440 */ 5, 210, 214, 134, 214, 134, 5, 5, 125, 210, + /* 450 */ 87, 105, 211, 98, 210, 98, 222, 224, 218, 221, + /* 460 */ 223, 219, 217, 220, 211, 254, 215, 242, 253, 247, + /* 470 */ 250, 252, 251, 249, 248, 212, 106, 102, 97, 1, + /* 480 */ 97, 113, 98, 97, 102, 113, 98, 102, 97, 97, + /* 490 */ 72, 97, 99, 9, 99, 5, 5, 5, 5, 5, + /* 500 */ 76, 15, 72, 16, 128, 128, 102, 5, 5, 98, + /* 510 */ 97, 5, 5, 5, 5, 5, 5, 5, 5, 5, + /* 520 */ 5, 5, 5, 5, 102, 76, 21, 59, 58, 0, + /* 530 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, + /* 540 */ 21, 269, 269, 269, 269, 269, 269, 269, 269, 269, /* 550 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, /* 560 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, /* 570 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, @@ -335,84 +335,83 @@ static const YYCODETYPE yy_lookahead[] = { /* 710 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, /* 720 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, /* 730 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 740 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 750 */ 269, 269, + /* 740 */ 269, 269, 269, 269, 269, 269, }; -#define YY_SHIFT_COUNT (246) +#define YY_SHIFT_COUNT (240) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (534) +#define YY_SHIFT_MAX (529) static const unsigned short int yy_shift_ofst[] = { /* 0 */ 163, 75, 183, 184, 204, 79, 79, 79, 79, 79, /* 10 */ 79, 0, 22, 204, 256, 256, 256, 46, 79, 79, - /* 20 */ 79, 79, 79, 116, 109, 109, 547, 194, 204, 204, + /* 20 */ 79, 79, 79, 157, 136, 136, 541, 194, 204, 204, /* 30 */ 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, /* 40 */ 204, 204, 204, 204, 204, 256, 256, 249, 249, 249, - /* 50 */ 249, 249, 249, 30, 249, 100, 79, 79, 127, 127, - /* 60 */ 128, 79, 79, 79, 79, 79, 79, 79, 79, 79, + /* 50 */ 249, 249, 249, 30, 249, 111, 79, 79, 127, 127, + /* 60 */ 178, 79, 79, 79, 79, 79, 79, 79, 79, 79, /* 70 */ 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, /* 80 */ 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - /* 90 */ 79, 79, 79, 79, 79, 79, 79, 79, 266, 328, - /* 100 */ 328, 285, 285, 328, 295, 296, 300, 308, 305, 311, - /* 110 */ 313, 315, 303, 266, 328, 328, 351, 351, 328, 343, - /* 120 */ 345, 380, 350, 349, 381, 352, 357, 328, 362, 328, - /* 130 */ 362, 547, 547, 27, 69, 69, 69, 95, 120, 218, + /* 90 */ 79, 79, 79, 79, 79, 79, 79, 79, 266, 333, + /* 100 */ 333, 285, 285, 333, 295, 296, 298, 305, 306, 310, + /* 110 */ 313, 315, 303, 266, 333, 333, 351, 351, 333, 343, + /* 120 */ 345, 380, 350, 349, 379, 353, 356, 333, 361, 333, + /* 130 */ 361, 541, 541, 27, 69, 69, 69, 95, 120, 218, /* 140 */ 218, 218, 232, 186, 186, 186, 186, 257, 264, 26, - /* 150 */ 154, 61, 61, 212, 161, 151, 178, 206, 207, 288, - /* 160 */ 306, 283, 244, 213, 145, 216, 235, 237, 215, 217, - /* 170 */ 331, 342, 278, 433, 307, 438, 312, 386, 441, 314, - /* 180 */ 443, 316, 392, 463, 344, 417, 389, 353, 374, 382, - /* 190 */ 375, 383, 384, 387, 482, 390, 388, 391, 393, 376, - /* 200 */ 394, 377, 395, 397, 400, 399, 402, 401, 419, 483, - /* 210 */ 496, 497, 498, 499, 500, 430, 492, 436, 493, 385, - /* 220 */ 396, 408, 506, 507, 416, 418, 408, 511, 512, 513, - /* 230 */ 514, 515, 516, 517, 518, 520, 521, 522, 523, 524, - /* 240 */ 428, 455, 519, 525, 473, 475, 534, + /* 150 */ 65, 61, 61, 212, 161, 151, 206, 207, 213, 279, + /* 160 */ 288, 302, 229, 214, 85, 216, 235, 236, 192, 217, + /* 170 */ 335, 336, 274, 433, 309, 434, 435, 311, 441, 442, + /* 180 */ 363, 323, 346, 355, 370, 375, 357, 381, 478, 383, + /* 190 */ 384, 386, 382, 368, 385, 372, 388, 391, 392, 393, + /* 200 */ 394, 395, 418, 484, 490, 491, 492, 493, 494, 424, + /* 210 */ 486, 430, 487, 376, 377, 404, 502, 503, 411, 413, + /* 220 */ 404, 506, 507, 508, 509, 510, 511, 512, 513, 514, + /* 230 */ 515, 516, 517, 518, 422, 449, 505, 519, 468, 470, + /* 240 */ 529, }; #define YY_REDUCE_COUNT (132) #define YY_REDUCE_MIN (-255) -#define YY_REDUCE_MAX (262) +#define YY_REDUCE_MAX (263) static const short yy_reduce_ofst[] = { /* 0 */ -200, -53, -225, -238, -222, -151, -122, -194, -117, -92, - /* 10 */ 7, -197, -190, -236, -163, -36, -34, -138, -150, -159, - /* 20 */ -125, -9, -152, -78, -1, 23, -43, -255, -253, -223, - /* 30 */ -144, -85, -60, 4, 12, 52, 58, 68, 82, 88, - /* 40 */ 90, 94, 96, 97, 98, -22, 41, 80, 114, 118, + /* 10 */ 7, -197, -190, -236, -163, -34, -32, -138, -150, -159, + /* 20 */ -125, -36, -152, -78, 23, 63, -57, -255, -253, -223, + /* 30 */ -144, -28, -11, 4, 6, 12, 52, 55, 78, 90, + /* 40 */ 91, 92, 93, 94, 96, -22, 109, 116, 117, 118, /* 50 */ 119, 121, 122, 123, 125, 124, 153, 156, 102, 103, /* 60 */ 126, 160, 162, 164, 165, 166, 167, 168, 169, 170, /* 70 */ 171, 172, 173, 174, 175, 176, 177, 179, 180, 181, - /* 80 */ 182, 185, 187, 188, 189, 190, 191, 192, 193, 195, - /* 90 */ 196, 197, 198, 199, 200, 201, 202, 203, 150, 205, - /* 100 */ 208, 134, 142, 209, 159, 210, 214, 211, 219, 221, - /* 110 */ 220, 224, 226, 223, 222, 225, 227, 228, 229, 230, - /* 120 */ 233, 231, 234, 236, 239, 240, 238, 241, 248, 251, - /* 130 */ 255, 247, 262, + /* 80 */ 182, 185, 187, 188, 189, 190, 191, 193, 195, 196, + /* 90 */ 197, 198, 199, 200, 201, 202, 203, 205, 145, 208, + /* 100 */ 209, 134, 140, 210, 148, 211, 215, 219, 221, 220, + /* 110 */ 224, 226, 222, 225, 223, 227, 228, 230, 231, 233, + /* 120 */ 237, 234, 240, 238, 242, 243, 245, 239, 241, 244, + /* 130 */ 253, 251, 263, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 623, 675, 664, 835, 835, 623, 623, 623, 623, 623, - /* 10 */ 623, 765, 641, 835, 623, 623, 623, 623, 623, 623, - /* 20 */ 623, 623, 623, 677, 677, 677, 760, 623, 623, 623, - /* 30 */ 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, - /* 40 */ 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, - /* 50 */ 623, 623, 623, 623, 623, 623, 623, 623, 784, 784, - /* 60 */ 758, 623, 623, 623, 623, 623, 623, 623, 623, 623, - /* 70 */ 623, 623, 623, 623, 623, 623, 623, 623, 623, 662, - /* 80 */ 623, 660, 623, 623, 623, 623, 623, 623, 623, 623, - /* 90 */ 623, 623, 623, 623, 623, 649, 623, 623, 623, 643, - /* 100 */ 643, 623, 623, 643, 791, 795, 789, 777, 785, 776, - /* 110 */ 772, 771, 799, 623, 643, 643, 672, 672, 643, 693, - /* 120 */ 691, 689, 681, 687, 683, 685, 679, 643, 670, 643, - /* 130 */ 670, 708, 721, 623, 800, 834, 790, 818, 817, 830, - /* 140 */ 824, 823, 623, 822, 821, 820, 819, 623, 623, 623, - /* 150 */ 623, 826, 825, 623, 623, 623, 623, 623, 623, 623, - /* 160 */ 623, 623, 802, 796, 792, 623, 623, 623, 623, 623, - /* 170 */ 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, - /* 180 */ 623, 623, 623, 623, 623, 623, 623, 623, 757, 623, - /* 190 */ 623, 766, 623, 623, 623, 623, 623, 623, 786, 623, - /* 200 */ 778, 623, 623, 623, 623, 623, 623, 734, 623, 623, - /* 210 */ 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, - /* 220 */ 623, 839, 623, 623, 623, 728, 837, 623, 623, 623, - /* 230 */ 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, - /* 240 */ 696, 623, 647, 645, 623, 639, 623, + /* 0 */ 617, 669, 658, 829, 829, 617, 617, 617, 617, 617, + /* 10 */ 617, 759, 635, 829, 617, 617, 617, 617, 617, 617, + /* 20 */ 617, 617, 617, 671, 671, 671, 754, 617, 617, 617, + /* 30 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 617, + /* 40 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 617, + /* 50 */ 617, 617, 617, 617, 617, 617, 617, 617, 778, 778, + /* 60 */ 752, 617, 617, 617, 617, 617, 617, 617, 617, 617, + /* 70 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 656, + /* 80 */ 617, 654, 617, 617, 617, 617, 617, 617, 617, 617, + /* 90 */ 617, 617, 617, 617, 617, 643, 617, 617, 617, 637, + /* 100 */ 637, 617, 617, 637, 785, 789, 783, 771, 779, 770, + /* 110 */ 766, 765, 793, 617, 637, 637, 666, 666, 637, 687, + /* 120 */ 685, 683, 675, 681, 677, 679, 673, 637, 664, 637, + /* 130 */ 664, 702, 715, 617, 794, 828, 784, 812, 811, 824, + /* 140 */ 818, 817, 617, 816, 815, 814, 813, 617, 617, 617, + /* 150 */ 617, 820, 819, 617, 617, 617, 617, 617, 617, 617, + /* 160 */ 617, 617, 796, 790, 786, 617, 617, 617, 617, 617, + /* 170 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 617, + /* 180 */ 617, 617, 751, 617, 617, 760, 617, 617, 617, 617, + /* 190 */ 617, 617, 780, 617, 772, 617, 617, 617, 617, 617, + /* 200 */ 617, 728, 617, 617, 617, 617, 617, 617, 617, 617, + /* 210 */ 617, 617, 617, 617, 617, 833, 617, 617, 617, 722, + /* 220 */ 831, 617, 617, 617, 617, 617, 617, 617, 617, 617, + /* 230 */ 617, 617, 617, 617, 690, 617, 641, 639, 617, 633, + /* 240 */ 617, }; /********** End of lemon-generated parsing tables *****************************/ @@ -565,8 +564,8 @@ static const YYCODETYPE yyFallback[] = { 0, /* SET => nothing */ 0, /* KILL => nothing */ 0, /* CONNECTION => nothing */ - 0, /* COLON => nothing */ 0, /* STREAM => nothing */ + 0, /* COLON => nothing */ 1, /* ABORT => ID */ 1, /* AFTER => ID */ 1, /* ATTACH => ID */ @@ -856,8 +855,8 @@ static const char *const yyTokenName[] = { /* 130 */ "SET", /* 131 */ "KILL", /* 132 */ "CONNECTION", - /* 133 */ "COLON", - /* 134 */ "STREAM", + /* 133 */ "STREAM", + /* 134 */ "COLON", /* 135 */ "ABORT", /* 136 */ "AFTER", /* 137 */ "ATTACH", @@ -1216,9 +1215,9 @@ static const char *const yyRuleName[] = { /* 214 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", /* 215 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", /* 216 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 217 */ "cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER", - /* 218 */ "cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER", - /* 219 */ "cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER", + /* 217 */ "cmd ::= KILL CONNECTION INTEGER", + /* 218 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 219 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1893,9 +1892,9 @@ static const struct { { 207, -7 }, /* (214) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { 207, -8 }, /* (215) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { 207, -9 }, /* (216) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 207, -5 }, /* (217) cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ - { 207, -7 }, /* (218) cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ - { 207, -7 }, /* (219) cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ + { 207, -3 }, /* (217) cmd ::= KILL CONNECTION INTEGER */ + { 207, -5 }, /* (218) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 207, -5 }, /* (219) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2734,14 +2733,14 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 217: /* cmd ::= KILL CONNECTION IPTOKEN COLON INTEGER */ -{yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[-2].minor.yy0);} + case 217: /* cmd ::= KILL CONNECTION INTEGER */ +{setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 218: /* cmd ::= KILL STREAM IPTOKEN COLON INTEGER COLON INTEGER */ -{yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-4].minor.yy0);} + case 218: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ +{yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 219: /* cmd ::= KILL QUERY IPTOKEN COLON INTEGER COLON INTEGER */ -{yymsp[-4].minor.yy0.n += (yymsp[-3].minor.yy0.n + yymsp[-2].minor.yy0.n + yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-4].minor.yy0);} + case 219: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ +{yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: break; diff --git a/src/query/src/tlosertree.c b/src/query/src/tlosertree.c index 0d81f4604b..5d471bb927 100644 --- a/src/query/src/tlosertree.c +++ b/src/query/src/tlosertree.c @@ -46,7 +46,7 @@ uint32_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* pa *pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries); if ((*pTree) == NULL) { qError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); - return TSDB_CODE_CLI_OUT_OF_MEMORY; + return TSDB_CODE_QRY_OUT_OF_MEMORY; } (*pTree)->pNode = (SLoserTreeNode*)(((char*)(*pTree)) + sizeof(SLoserTreeInfo)); diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index df28a3e4d1..c33ebeb58b 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -99,47 +99,47 @@ TEST(testCase, db_table_name) { EXPECT_EQ(testValidateName(t4), TSDB_CODE_SUCCESS); char t5[] = "table.'def'"; - EXPECT_EQ(testValidateName(t5), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t5), TSDB_CODE_TSC_INVALID_SQL); char t6[] = "'table'.'def'"; - EXPECT_EQ(testValidateName(t6), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t6), TSDB_CODE_TSC_INVALID_SQL); char t7[] = "'_ab1234'.'def'"; EXPECT_EQ(testValidateName(t7), TSDB_CODE_SUCCESS); printf("%s\n", t7); char t8[] = "'_ab&^%1234'.'def'"; - EXPECT_EQ(testValidateName(t8), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t8), TSDB_CODE_TSC_INVALID_SQL); char t9[] = "'_123'.'gtest中文'"; - EXPECT_EQ(testValidateName(t9), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t9), TSDB_CODE_TSC_INVALID_SQL); char t10[] = "abc.'gtest中文'"; - EXPECT_EQ(testValidateName(t10), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t10), TSDB_CODE_TSC_INVALID_SQL); char t10_1[] = "abc.'中文gtest'"; - EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t10_1), TSDB_CODE_TSC_INVALID_SQL); char t11[] = "'192.168.0.1'.abc"; - EXPECT_EQ(testValidateName(t11), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t11), TSDB_CODE_TSC_INVALID_SQL); char t12[] = "192.168.0.1.abc"; - EXPECT_EQ(testValidateName(t12), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t12), TSDB_CODE_TSC_INVALID_SQL); char t13[] = "abc."; - EXPECT_EQ(testValidateName(t13), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t13), TSDB_CODE_TSC_INVALID_SQL); char t14[] = ".abc"; - EXPECT_EQ(testValidateName(t14), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t14), TSDB_CODE_TSC_INVALID_SQL); char t15[] = ".'abc'"; - EXPECT_EQ(testValidateName(t15), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t15), TSDB_CODE_TSC_INVALID_SQL); char t16[] = ".abc'"; - EXPECT_EQ(testValidateName(t16), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t16), TSDB_CODE_TSC_INVALID_SQL); char t17[] = "123a.\"abc\""; - EXPECT_EQ(testValidateName(t17), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t17), TSDB_CODE_TSC_INVALID_SQL); printf("%s\n", t17); char t18[] = "a.\"abc\""; @@ -147,13 +147,13 @@ TEST(testCase, db_table_name) { printf("%s\n", t18); char t19[] = "'_ab1234'.'def'.'ab123'"; - EXPECT_EQ(testValidateName(t19), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t19), TSDB_CODE_TSC_INVALID_SQL); char t20[] = "'_ab1234*&^'"; - EXPECT_EQ(testValidateName(t20), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t20), TSDB_CODE_TSC_INVALID_SQL); char t21[] = "'1234_abc'"; - EXPECT_EQ(testValidateName(t21), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t21), TSDB_CODE_TSC_INVALID_SQL); // =======Containing capital letters================= @@ -167,10 +167,10 @@ TEST(testCase, db_table_name) { EXPECT_EQ(testValidateName(t32), TSDB_CODE_SUCCESS); char t33[] = "'ABC.def"; - EXPECT_EQ(testValidateName(t33), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t33), TSDB_CODE_TSC_INVALID_SQL); char t33_0[] = "abc.DEF'"; - EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t33_0), TSDB_CODE_TSC_INVALID_SQL); char t34[] = "'ABC.def'"; //int32_t tmp0 = testValidateName(t34); @@ -193,38 +193,38 @@ TEST(testCase, db_table_name) { // do not use key words char t39[] = "table.'DEF'"; - EXPECT_EQ(testValidateName(t39), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t39), TSDB_CODE_TSC_INVALID_SQL); char t40[] = "'table'.'DEF'"; - EXPECT_EQ(testValidateName(t40), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t40), TSDB_CODE_TSC_INVALID_SQL); char t41[] = "'_abXYZ1234'.'deFF'"; EXPECT_EQ(testValidateName(t41), TSDB_CODE_SUCCESS); char t42[] = "'_abDEF&^%1234'.'DIef'"; - EXPECT_EQ(testValidateName(t42), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t42), TSDB_CODE_TSC_INVALID_SQL); char t43[] = "'_123'.'Gtest中文'"; - EXPECT_EQ(testValidateName(t43), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t43), TSDB_CODE_TSC_INVALID_SQL); char t44[] = "'aABC'.'Gtest中文'"; - EXPECT_EQ(testValidateName(t44), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t44), TSDB_CODE_TSC_INVALID_SQL); char t45[] = "'ABC'."; - EXPECT_EQ(testValidateName(t45), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t45), TSDB_CODE_TSC_INVALID_SQL); char t46[] = ".'ABC'"; - EXPECT_EQ(testValidateName(t46), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t46), TSDB_CODE_TSC_INVALID_SQL); char t47[] = "a.\"aTWc\""; EXPECT_EQ(testValidateName(t47), TSDB_CODE_SUCCESS); // ================has space ================= char t60[] = " ABC "; - EXPECT_EQ(testValidateName(t60), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t60), TSDB_CODE_TSC_INVALID_SQL); char t60_1[] = " ABC "; - EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t60_1), TSDB_CODE_TSC_INVALID_SQL); char t61[] = "' ABC '"; EXPECT_EQ(testValidateName(t61), TSDB_CODE_SUCCESS); @@ -233,96 +233,96 @@ TEST(testCase, db_table_name) { EXPECT_EQ(testValidateName(t61_1), TSDB_CODE_SUCCESS); char t62[] = " ABC . def "; - EXPECT_EQ(testValidateName(t62), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t62), TSDB_CODE_TSC_INVALID_SQL); char t63[] = "' ABC . def "; - EXPECT_EQ(testValidateName(t63), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t63), TSDB_CODE_TSC_INVALID_SQL); char t63_0[] = " abc . DEF ' "; - EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t63_0), TSDB_CODE_TSC_INVALID_SQL); char t64[] = " ' ABC . def ' "; //int32_t tmp1 = testValidateName(t64); - EXPECT_EQ(testValidateName(t64), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t64), TSDB_CODE_TSC_INVALID_SQL); char t65[] = " ' ABC '. def "; - EXPECT_EQ(testValidateName(t65), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t65), TSDB_CODE_TSC_INVALID_SQL); char t66[] = "' ABC '.' DEF '"; EXPECT_EQ(testValidateName(t66), TSDB_CODE_SUCCESS); char t67[] = "abc . ' DEF '"; - EXPECT_EQ(testValidateName(t67), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t67), TSDB_CODE_TSC_INVALID_SQL); char t68[] = "' abc '.' DEF '"; EXPECT_EQ(testValidateName(t68), TSDB_CODE_SUCCESS); // do not use key words char t69[] = "table.'DEF'"; - EXPECT_EQ(testValidateName(t69), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t69), TSDB_CODE_TSC_INVALID_SQL); char t70[] = "'table'.'DEF'"; - EXPECT_EQ(testValidateName(t70), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t70), TSDB_CODE_TSC_INVALID_SQL); char t71[] = "'_abXYZ1234 '.' deFF '"; EXPECT_EQ(testValidateName(t71), TSDB_CODE_SUCCESS); char t72[] = "'_abDEF&^%1234'.' DIef'"; - EXPECT_EQ(testValidateName(t72), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t72), TSDB_CODE_TSC_INVALID_SQL); char t73[] = "'_123'.' Gtest中文'"; - EXPECT_EQ(testValidateName(t73), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t73), TSDB_CODE_TSC_INVALID_SQL); char t74[] = "' aABC'.'Gtest中文'"; - EXPECT_EQ(testValidateName(t74), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t74), TSDB_CODE_TSC_INVALID_SQL); char t75[] = "' ABC '."; - EXPECT_EQ(testValidateName(t75), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t75), TSDB_CODE_TSC_INVALID_SQL); char t76[] = ".' ABC'"; - EXPECT_EQ(testValidateName(t76), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t76), TSDB_CODE_TSC_INVALID_SQL); char t77[] = " a . \"aTWc\" "; - EXPECT_EQ(testValidateName(t77), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t77), TSDB_CODE_TSC_INVALID_SQL); char t78[] = " a.\"aTWc \""; - EXPECT_EQ(testValidateName(t78), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t78), TSDB_CODE_TSC_INVALID_SQL); // ===============muti string by space =================== // There's no such case. //char t160[] = "A BC"; - //EXPECT_EQ(testValidateName(t160), TSDB_CODE_INVALID_SQL); + //EXPECT_EQ(testValidateName(t160), TSDB_CODE_TSC_INVALID_SQL); //printf("end:%s\n", t160); // There's no such case. //char t161[] = "' A BC '"; - //EXPECT_EQ(testValidateName(t161), TSDB_CODE_INVALID_SQL); + //EXPECT_EQ(testValidateName(t161), TSDB_CODE_TSC_INVALID_SQL); char t162[] = " AB C . de f "; - EXPECT_EQ(testValidateName(t162), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t162), TSDB_CODE_TSC_INVALID_SQL); char t163[] = "' AB C . de f "; - EXPECT_EQ(testValidateName(t163), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t163), TSDB_CODE_TSC_INVALID_SQL); char t163_0[] = " ab c . DE F ' "; - EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t163_0), TSDB_CODE_TSC_INVALID_SQL); char t164[] = " ' AB C . de f ' "; //int32_t tmp2 = testValidateName(t164); - EXPECT_EQ(testValidateName(t164), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t164), TSDB_CODE_TSC_INVALID_SQL); char t165[] = " ' A BC '. de f "; - EXPECT_EQ(testValidateName(t165), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t165), TSDB_CODE_TSC_INVALID_SQL); char t166[] = "' AB C '.' DE F '"; - EXPECT_EQ(testValidateName(t166), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t166), TSDB_CODE_TSC_INVALID_SQL); char t167[] = "ab c . ' D EF '"; - EXPECT_EQ(testValidateName(t167), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t167), TSDB_CODE_TSC_INVALID_SQL); char t168[] = "' a bc '.' DE F '"; - EXPECT_EQ(testValidateName(t168), TSDB_CODE_INVALID_SQL); + EXPECT_EQ(testValidateName(t168), TSDB_CODE_TSC_INVALID_SQL); } diff --git a/src/rpc/src/rpcCache.c b/src/rpc/src/rpcCache.c index 7a96571ab9..6f89969305 100644 --- a/src/rpc/src/rpcCache.c +++ b/src/rpc/src/rpcCache.c @@ -127,7 +127,7 @@ void rpcAddConnIntoCache(void *handle, void *data, char *fqdn, uint16_t port, in hash = rpcHashConn(pCache, fqdn, port, connType); pNode = (SConnHash *)taosMemPoolMalloc(pCache->connHashMemPool); - strcpy(pNode->fqdn, fqdn); + tstrncpy(pNode->fqdn, fqdn, sizeof(pNode->fqdn)); pNode->port = port; pNode->connType = connType; pNode->data = data; diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index e7861201d3..b0a5a0bfc0 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -47,7 +47,7 @@ typedef struct { uint16_t localPort; int8_t connType; int index; // for UDP server only, round robin for multiple threads - char label[12]; + char label[TSDB_LABEL_LEN]; char user[TSDB_UNI_LEN]; // meter ID char spi; // security parameter index @@ -58,9 +58,10 @@ typedef struct { void (*cfp)(SRpcMsg *, SRpcIpSet *); int (*afp)(char *user, char *spi, char *encrypt, char *secret, char *ckey); + int refCount; void *idPool; // handle to ID pool void *tmrCtrl; // handle to timer - void *hash; // handle returned by hash utility + SHashObj *hash; // handle returned by hash utility void *tcphandle;// returned handle from TCP initialization void *udphandle;// returned handle from UDP initialization void *pCache; // connection cache @@ -87,7 +88,7 @@ typedef struct { } SRpcReqContext; typedef struct SRpcConn { - char info[50];// debug info: label + pConn + ahandle + char info[48];// debug info: label + pConn + ahandle int sid; // session ID uint32_t ownId; // own link ID uint32_t peerId; // peer link ID @@ -199,6 +200,8 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen); static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen); static void rpcLockConn(SRpcConn *pConn); static void rpcUnlockConn(SRpcConn *pConn); +static void rpcAddRef(SRpcInfo *pRpc); +static void rpcDecRef(SRpcInfo *pRpc); void *rpcOpen(const SRpcInit *pInit) { SRpcInfo *pRpc; @@ -211,7 +214,7 @@ void *rpcOpen(const SRpcInit *pInit) { pRpc = (SRpcInfo *)calloc(1, sizeof(SRpcInfo)); if (pRpc == NULL) return NULL; - if(pInit->label) strcpy(pRpc->label, pInit->label); + if(pInit->label) tstrncpy(pRpc->label, pInit->label, sizeof(pRpc->label)); pRpc->connType = pInit->connType; pRpc->idleTime = pInit->idleTime; pRpc->numOfThreads = pInit->numOfThreads>TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS:pInit->numOfThreads; @@ -224,11 +227,12 @@ void *rpcOpen(const SRpcInit *pInit) { pRpc->spi = pInit->spi; pRpc->cfp = pInit->cfp; pRpc->afp = pInit->afp; + pRpc->refCount = 1; size_t size = sizeof(SRpcConn) * pRpc->sessions; pRpc->connList = (SRpcConn *)calloc(1, size); if (pRpc->connList == NULL) { - tError("%s failed to allocate memory for taos connections, size:%d", pRpc->label, size); + tError("%s failed to allocate memory for taos connections, size:%ld", pRpc->label, size); rpcClose(pRpc); return NULL; } @@ -293,15 +297,8 @@ void rpcClose(void *param) { (*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle); (*taosCleanUpConn[pRpc->connType])(pRpc->udphandle); - taosHashCleanup(pRpc->hash); - taosTmrCleanUp(pRpc->tmrCtrl); - taosIdPoolCleanUp(pRpc->idPool); - rpcCloseConnCache(pRpc->pCache); - - tfree(pRpc->connList); - pthread_mutex_destroy(&pRpc->mutex); tTrace("%s rpc is closed", pRpc->label); - tfree(pRpc); + rpcDecRef(pRpc); } void *rpcMallocCont(int contLen) { @@ -378,6 +375,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcMsg rpcMsg = *pRsp; SRpcMsg *pMsg = &rpcMsg; + SRpcInfo *pRpc = pConn->pRpc; if ( pMsg->pCont == NULL ) { pMsg->pCont = rpcMallocCont(0); @@ -395,6 +393,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { if ( pConn->inType == 0 || pConn->user[0] == 0 ) { tTrace("%s, connection is already released, rsp wont be sent", pConn->info); rpcUnlockConn(pConn); + rpcDecRef(pRpc); return; } @@ -418,9 +417,8 @@ void rpcSendResponse(const SRpcMsg *pRsp) { rpcFreeMsg(pConn->pRspMsg); pConn->pRspMsg = msg; pConn->rspMsgLen = msgLen; - if (pMsg->code == TSDB_CODE_ACTION_IN_PROGRESS) pConn->inTranId--; + if (pMsg->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) pConn->inTranId--; - SRpcInfo *pRpc = pConn->pRpc; taosTmrStopA(&pConn->pTimer); // set the idle timer to monitor the activity @@ -429,6 +427,7 @@ void rpcSendResponse(const SRpcMsg *pRsp) { pConn->secured = 1; // connection shall be secured rpcUnlockConn(pConn); + rpcDecRef(pRpc); // decrease the referene count return; } @@ -443,7 +442,7 @@ void rpcSendRedirectRsp(void *thandle, const SRpcIpSet *pIpSet) { memcpy(rpcMsg.pCont, pIpSet, sizeof(SRpcIpSet)); - rpcMsg.code = TSDB_CODE_REDIRECT; + rpcMsg.code = TSDB_CODE_RPC_REDIRECT; rpcMsg.handle = thandle; rpcSendResponse(&rpcMsg); @@ -459,7 +458,7 @@ int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo) { pInfo->clientPort = pConn->peerPort; // pInfo->serverIp = pConn->destIp; - strcpy(pInfo->user, pConn->user); + strncpy(pInfo->user, pConn->user, sizeof(pInfo->user)); return 0; } @@ -496,24 +495,24 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, uint32_t peerIp = taosGetIpFromFqdn(peerFqdn); if (peerIp == -1) { tError("%s, failed to resolve FQDN:%s", pRpc->label, peerFqdn); - terrno = TSDB_CODE_APP_ERROR; + terrno = TSDB_CODE_RPC_APP_ERROR; return NULL; } pConn = rpcAllocateClientConn(pRpc); if (pConn) { - strcpy(pConn->peerFqdn, peerFqdn); + tstrncpy(pConn->peerFqdn, peerFqdn, sizeof(pConn->peerFqdn)); pConn->peerIp = peerIp; pConn->peerPort = peerPort; - strcpy(pConn->user, pRpc->user); + tstrncpy(pConn->user, pRpc->user, sizeof(pConn->user)); pConn->connType = connType; if (taosOpenConn[connType]) { void *shandle = (connType & RPC_CONN_TCP)? pRpc->tcphandle:pRpc->udphandle; pConn->chandle = (*taosOpenConn[connType])(shandle, pConn, pConn->peerIp, pConn->peerPort); if (pConn->chandle == NULL) { - terrno = TSDB_CODE_NETWORK_UNAVAIL; + terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcCloseConn(pConn); pConn = NULL; } @@ -570,7 +569,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { int sid = taosAllocateId(pRpc->idPool); if (sid <= 0) { tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions); - terrno = TSDB_CODE_MAX_SESSIONS; + terrno = TSDB_CODE_RPC_MAX_SESSIONS; } else { pConn = pRpc->connList + sid; memset(pConn, 0, sizeof(SRpcConn)); @@ -606,7 +605,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) { int sid = taosAllocateId(pRpc->idPool); if (sid <= 0) { tError("%s maximum number of sessions:%d is reached", pRpc->label, pRpc->sessions); - terrno = TSDB_CODE_MAX_SESSIONS; + terrno = TSDB_CODE_RPC_MAX_SESSIONS; } else { pConn = pRpc->connList + sid; memset(pConn, 0, sizeof(SRpcConn)); @@ -618,7 +617,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) { pConn->linkUid = pHead->linkUid; if (pRpc->afp) { if (pConn->user[0] == 0) { - terrno = TSDB_CODE_AUTH_REQUIRED; + terrno = TSDB_CODE_RPC_AUTH_REQUIRED; } else { terrno = (*pRpc->afp)(pConn->user, &pConn->spi, &pConn->encrypt, pConn->secret, pConn->ckey); } @@ -656,13 +655,13 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, SRecvInfo *pRecv) { if (pRpc->connType == TAOS_CONN_SERVER) { pConn = rpcAllocateServerConn(pRpc, pRecv); } else { - terrno = TSDB_CODE_UNEXPECTED_RESPONSE; + terrno = TSDB_CODE_RPC_UNEXPECTED_RESPONSE; } } if (pConn) { if (pConn->linkUid != pHead->linkUid) { - terrno = TSDB_CODE_MISMATCHED_METER_ID; + terrno = TSDB_CODE_RPC_MISMATCHED_LINK_ID; pConn = NULL; } } @@ -700,7 +699,7 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { if (pConn->peerId != pHead->sourceId) { tTrace("%s, source Id is changed, old:0x%08x new:0x%08x", pConn->info, pConn->peerId, pHead->sourceId); - return TSDB_CODE_INVALID_VALUE; + return TSDB_CODE_RPC_INVALID_VALUE; } } @@ -708,7 +707,7 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { if (pConn->inType == pHead->msgType) { if (pHead->code == 0) { tTrace("%s, %s is retransmitted", pConn->info, taosMsg[pHead->msgType]); - rpcSendQuickRsp(pConn, TSDB_CODE_ACTION_IN_PROGRESS); + rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS); } else { // do nothing, it is heart beat from client } @@ -720,13 +719,13 @@ static int rpcProcessReqHead(SRpcConn *pConn, SRpcHead *pHead) { } // do not reply any message - return TSDB_CODE_ALREADY_PROCESSED; + return TSDB_CODE_RPC_ALREADY_PROCESSED; } if (pConn->inType != 0) { tTrace("%s, last session is not finished, inTranId:%d tranId:%d", pConn->info, pConn->inTranId, pHead->tranId); - return TSDB_CODE_LAST_SESSION_NOT_FINISHED; + return TSDB_CODE_RPC_LAST_SESSION_NOT_FINISHED; } pConn->inTranId = pHead->tranId; @@ -740,39 +739,39 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) { pConn->peerId = pHead->sourceId; if (pConn->outType == 0 || pConn->pContext == NULL) { - return TSDB_CODE_UNEXPECTED_RESPONSE; + return TSDB_CODE_RPC_UNEXPECTED_RESPONSE; } if (pHead->tranId != pConn->outTranId) { - return TSDB_CODE_INVALID_TRAN_ID; + return TSDB_CODE_RPC_INVALID_TRAN_ID; } if (pHead->msgType != pConn->outType + 1) { - return TSDB_CODE_INVALID_RESPONSE_TYPE; + return TSDB_CODE_RPC_INVALID_RESPONSE_TYPE; } taosTmrStopA(&pConn->pTimer); pConn->retry = 0; - if (pHead->code == TSDB_CODE_AUTH_REQUIRED && pRpc->spi) { + if (pHead->code == TSDB_CODE_RPC_AUTH_REQUIRED && pRpc->spi) { tTrace("%s, authentication shall be restarted", pConn->info); pConn->secured = 0; rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); - return TSDB_CODE_ALREADY_PROCESSED; + return TSDB_CODE_RPC_ALREADY_PROCESSED; } - if (pHead->code == TSDB_CODE_ACTION_IN_PROGRESS) { + if (pHead->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) { if (pConn->tretry <= tsRpcMaxRetry) { tTrace("%s, peer is still processing the transaction, retry:%d", pConn->info, pConn->tretry); pConn->tretry++; rpcSendReqHead(pConn); pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl); - return TSDB_CODE_ALREADY_PROCESSED; + return TSDB_CODE_RPC_ALREADY_PROCESSED; } else { // peer still in processing, give up tTrace("%s, server processing takes too long time, give up", pConn->info); - pHead->code = TSDB_CODE_TOO_SLOW; + pHead->code = TSDB_CODE_RPC_TOO_SLOW; } } @@ -793,29 +792,29 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) { if (pHead->msgType >= TSDB_MSG_TYPE_MAX || pHead->msgType <= 0) { tTrace("%s sid:%d, invalid message type:%d", pRpc->label, sid, pHead->msgType); - terrno = TSDB_CODE_INVALID_MSG_TYPE; return NULL; + terrno = TSDB_CODE_RPC_INVALID_MSG_TYPE; return NULL; } if (sid < 0 || sid >= pRpc->sessions) { tTrace("%s sid:%d, sid is out of range, max sid:%d, %s discarded", pRpc->label, sid, pRpc->sessions, taosMsg[pHead->msgType]); - terrno = TSDB_CODE_INVALID_SESSION_ID; return NULL; + terrno = TSDB_CODE_RPC_INVALID_SESSION_ID; return NULL; } pConn = rpcGetConnObj(pRpc, sid, pRecv); if (pConn == NULL) { - tTrace("%s %p, failed to get connection obj(%s)", pRpc->label, pHead->ahandle, tstrerror(terrno)); + tTrace("%s %p, failed to get connection obj(%s)", pRpc->label, (void *)pHead->ahandle, tstrerror(terrno)); return NULL; - } else { - if (rpcIsReq(pHead->msgType)) { - pConn->ahandle = (void *)pHead->ahandle; - sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle); - } - } + } rpcLockConn(pConn); - sid = pConn->sid; + if (rpcIsReq(pHead->msgType)) { + pConn->ahandle = (void *)pHead->ahandle; + sprintf(pConn->info, "%s %p %p", pRpc->label, pConn, pConn->ahandle); + } + + sid = pConn->sid; pConn->chandle = pRecv->chandle; pConn->peerIp = pRecv->ip; pConn->peerPort = pRecv->port; @@ -848,14 +847,15 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) { } static void rpcProcessBrokenLink(SRpcConn *pConn) { + if (pConn == NULL) return; SRpcInfo *pRpc = pConn->pRpc; - tTrace("%s, link is broken", pConn->info); - // pConn->chandle = NULL; + + rpcLockConn(pConn); if (pConn->outType) { SRpcReqContext *pContext = pConn->pContext; - pContext->code = TSDB_CODE_NETWORK_UNAVAIL; + pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; taosTmrStart(rpcProcessConnError, 0, pContext, pRpc->tmrCtrl); } @@ -868,11 +868,12 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) { rpcMsg.contLen = 0; rpcMsg.handle = pConn; rpcMsg.msgType = pConn->inType; - rpcMsg.code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; (*(pRpc->cfp))(&rpcMsg); */ } - + + rpcUnlockConn(pConn); rpcCloseConn(pConn); } @@ -886,7 +887,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 && pConn) { + if (pRecv->ip == 0) { rpcProcessBrokenLink(pConn); return NULL; } @@ -901,7 +902,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { } int32_t code = terrno; - if (code != TSDB_CODE_ALREADY_PROCESSED) { + if (code != TSDB_CODE_RPC_ALREADY_PROCESSED) { if (code != 0) { // parsing error if (rpcIsReq(pHead->msgType)) { rpcSendErrorMsgToPeer(pRecv, code); @@ -951,6 +952,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { if ( rpcIsReq(pHead->msgType) ) { rpcMsg.handle = pConn; + rpcAddRef(pRpc); // add the refCount for requests pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); (*(pRpc->cfp))(&rpcMsg, NULL); } else { @@ -960,28 +962,28 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { pConn->pContext = NULL; // for UDP, port may be changed by server, the port in ipSet shall be used for cache - if (pHead->code != TSDB_CODE_TOO_SLOW) { + if (pHead->code != TSDB_CODE_RPC_TOO_SLOW) { rpcAddConnIntoCache(pRpc->pCache, pConn, pConn->peerFqdn, pContext->ipSet.port[pContext->ipSet.inUse], pConn->connType); } else { rpcCloseConn(pConn); } - if (pHead->code == TSDB_CODE_REDIRECT) { + if (pHead->code == TSDB_CODE_RPC_REDIRECT) { pContext->redirect++; if (pContext->redirect > TSDB_MAX_REPLICA) { - pHead->code = TSDB_CODE_NETWORK_UNAVAIL; + pHead->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; tWarn("%s, too many redirects, quit", pConn->info); } } - if (pHead->code == TSDB_CODE_REDIRECT) { + if (pHead->code == TSDB_CODE_RPC_REDIRECT) { pContext->numOfTry = 0; memcpy(&pContext->ipSet, pHead->content, sizeof(pContext->ipSet)); tTrace("%s, redirect is received, numOfIps:%d", pConn->info, pContext->ipSet.numOfIps); for (int i=0; iipSet.numOfIps; ++i) pContext->ipSet.port[i] = htons(pContext->ipSet.port[i]); rpcSendReqToServer(pRpc, pContext); - } else if (pHead->code == TSDB_CODE_NOT_READY) { + } else if (pHead->code == TSDB_CODE_RPC_NOT_READY) { pContext->code = pHead->code; rpcProcessConnError(pContext, NULL); } else { @@ -1058,7 +1060,7 @@ static void rpcSendErrorMsgToPeer(SRecvInfo *pRecv, int32_t code) { pReplyHead->code = htonl(code); msgLen = sizeof(SRpcHead); - if (code == TSDB_CODE_INVALID_TIME_STAMP) { + if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP) { // include a time stamp if client's time is not synchronized well uint8_t *pContent = pReplyHead->content; timeStamp = htonl(taosGetTimestampSec()); @@ -1200,7 +1202,7 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) { rpcUnlockConn(pConn); if (reportDisc && pConn->pContext) { - pConn->pContext->code = TSDB_CODE_NETWORK_UNAVAIL; + pConn->pContext->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcProcessConnError(pConn->pContext, NULL); rpcCloseConn(pConn); } @@ -1221,7 +1223,7 @@ static void rpcProcessIdleTimer(void *param, void *tmrId) { rpcMsg.contLen = 0; rpcMsg.handle = pConn; rpcMsg.msgType = pConn->inType; - rpcMsg.code = TSDB_CODE_NETWORK_UNAVAIL; + rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; (*(pRpc->cfp))(&rpcMsg); */ } @@ -1239,7 +1241,7 @@ static void rpcProcessProgressTimer(void *param, void *tmrId) { if (pConn->inType && pConn->user[0]) { tTrace("%s, progress timer expired, send progress", pConn->info); - rpcSendQuickRsp(pConn, TSDB_CODE_ACTION_IN_PROGRESS); + rpcSendQuickRsp(pConn, TSDB_CODE_RPC_ACTION_IN_PROGRESS); pConn->pTimer = taosTmrStart(rpcProcessProgressTimer, tsProgressTimer, pConn, pRpc->tmrCtrl); } else { tTrace("%s, progress timer:%p not processed", pConn->info, tmrId); @@ -1379,12 +1381,12 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { if ( !rpcIsReq(pHead->msgType) ) { // for response, if code is auth failure, it shall bypass the auth process code = htonl(pHead->code); - if (code==TSDB_CODE_INVALID_TIME_STAMP || code==TSDB_CODE_AUTH_FAILURE || code == TSDB_CODE_AUTH_REQUIRED || - code==TSDB_CODE_INVALID_USER || code == TSDB_CODE_NOT_READY) { + if (code == TSDB_CODE_RPC_INVALID_TIME_STAMP || code == TSDB_CODE_RPC_AUTH_FAILURE || + code == TSDB_CODE_RPC_AUTH_REQUIRED || code == TSDB_CODE_MND_INVALID_USER || code == TSDB_CODE_RPC_NOT_READY) { pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen); // tTrace("%s, dont check authentication since code is:0x%x", pConn->info, code); return 0; - } + } } code = 0; @@ -1397,11 +1399,11 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { delta -= (int32_t)taosGetTimestampSec(); if (abs(delta) > 900) { tWarn("%s, time diff:%d is too big, msg discarded", pConn->info, delta); - code = TSDB_CODE_INVALID_TIME_STAMP; + code = TSDB_CODE_RPC_INVALID_TIME_STAMP; } else { if (rpcAuthenticateMsg(pHead, msgLen-TSDB_AUTH_LEN, pDigest->auth, pConn->secret) < 0) { tTrace("%s, authentication failed, msg discarded", pConn->info); - code = TSDB_CODE_AUTH_FAILURE; + code = TSDB_CODE_RPC_AUTH_FAILURE; } else { pHead->msgLen = (int32_t)htonl((uint32_t)pHead->msgLen) - sizeof(SRpcDigest); if ( !rpcIsReq(pHead->msgType) ) pConn->secured = 1; // link is secured for client @@ -1410,7 +1412,7 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) { } } else { tTrace("%s, auth spi:%d not matched with received:%d", pConn->info, pConn->spi, pHead->spi); - code = pHead->spi ? TSDB_CODE_AUTH_FAILURE : TSDB_CODE_AUTH_REQUIRED; + code = pHead->spi ? TSDB_CODE_RPC_AUTH_FAILURE : TSDB_CODE_RPC_AUTH_REQUIRED; } return code; @@ -1433,3 +1435,23 @@ static void rpcUnlockConn(SRpcConn *pConn) { } } +static void rpcAddRef(SRpcInfo *pRpc) +{ + atomic_add_fetch_8(&pRpc->refCount, 1); +} + +static void rpcDecRef(SRpcInfo *pRpc) +{ + if (atomic_sub_fetch_8(&pRpc->refCount, 1) == 0) { + taosHashCleanup(pRpc->hash); + taosTmrCleanUp(pRpc->tmrCtrl); + taosIdPoolCleanUp(pRpc->idPool); + rpcCloseConnCache(pRpc->pCache); + + tfree(pRpc->connList); + pthread_mutex_destroy(&pRpc->mutex); + tTrace("%s rpc resources are released", pRpc->label); + tfree(pRpc); + } +} + diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 42940e80c1..04a269502e 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -16,6 +16,8 @@ #include "os.h" #include "tsocket.h" #include "tutil.h" +#include "taosdef.h" +#include "taoserror.h" #include "rpcLog.h" #include "rpcHead.h" #include "rpcTcp.h" @@ -26,8 +28,9 @@ typedef struct SFdObj { void *signature; - int fd; // TCP socket FD - void *thandle; // handle from upper layer, like TAOS + int fd; // TCP socket FD + int closedByApp; // 1: already closed by App + void *thandle; // handle from upper layer, like TAOS uint32_t ip; uint16_t port; struct SThreadObj *pThreadObj; @@ -44,7 +47,7 @@ typedef struct SThreadObj { int pollFd; int numOfFds; int threadId; - char label[12]; + char label[TSDB_LABEL_LEN]; void *shandle; // handle passed by upper layer during server initialization void *(*processData)(SRecvInfo *pPacket); } SThreadObj; @@ -53,7 +56,7 @@ typedef struct { int fd; uint32_t ip; uint16_t port; - char label[12]; + char label[TSDB_LABEL_LEN]; int numOfThreads; void * shandle; SThreadObj *pThreadObj; @@ -71,45 +74,58 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread SThreadObj *pThreadObj; pServerObj = (SServerObj *)calloc(sizeof(SServerObj), 1); + if (pServerObj == NULL) { + tError("TCP:%s no enough memory", label); + terrno = TAOS_SYSTEM_ERROR(errno); + return NULL; + } + + pServerObj->thread = 0; pServerObj->ip = ip; pServerObj->port = port; - strcpy(pServerObj->label, label); + tstrncpy(pServerObj->label, label, sizeof(pServerObj->label)); pServerObj->numOfThreads = numOfThreads; pServerObj->pThreadObj = (SThreadObj *)calloc(sizeof(SThreadObj), numOfThreads); if (pServerObj->pThreadObj == NULL) { tError("TCP:%s no enough memory", label); + terrno = TAOS_SYSTEM_ERROR(errno); free(pServerObj); return NULL; } int code = 0; + pthread_attr_t thattr; + pthread_attr_init(&thattr); + pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); + pThreadObj = pServerObj->pThreadObj; for (int i = 0; i < numOfThreads; ++i) { + pThreadObj->pollFd = -1; + pThreadObj->thread = 0; pThreadObj->processData = fp; - strcpy(pThreadObj->label, label); + tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); pThreadObj->shandle = shandle; code = pthread_mutex_init(&(pThreadObj->mutex), NULL); if (code < 0) { tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); break;; } pThreadObj->pollFd = epoll_create(10); // size does not matter if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP epoll", label); + terrno = TAOS_SYSTEM_ERROR(errno); code = -1; break; } - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); - pthread_attr_destroy(&thattr); if (code != 0) { tError("%s failed to create TCP process data thread(%s)", label, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); break; } @@ -118,47 +134,47 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread } if (code == 0) { - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); code = pthread_create(&(pServerObj->thread), &thattr, (void *)taosAcceptTcpConnection, (void *)(pServerObj)); - pthread_attr_destroy(&thattr); if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP accept thread(%s)", label, strerror(errno)); } } if (code != 0) { - free(pServerObj->pThreadObj); - free(pServerObj); + taosCleanUpTcpServer(pServerObj); pServerObj = NULL; } else { tTrace("%s TCP server is initialized, ip:0x%x port:%hu numOfThreads:%d", label, ip, port, numOfThreads); } + pthread_attr_destroy(&thattr); return (void *)pServerObj; } static void taosStopTcpThread(SThreadObj* pThreadObj) { pThreadObj->stop = true; + eventfd_t fd = -1; - // signal the thread to stop, try graceful method first, - // and use pthread_cancel when failed - struct epoll_event event = { .events = EPOLLIN }; - eventfd_t fd = eventfd(1, 0); - if (fd == -1) { - tError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); - pthread_cancel(pThreadObj->thread); - } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { - tError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThreadObj->label, strerror(errno)); - pthread_cancel(pThreadObj->thread); + if (pThreadObj->thread && pThreadObj->pollFd >=0) { + // signal the thread to stop, try graceful method first, + // and use pthread_cancel when failed + struct epoll_event event = { .events = EPOLLIN }; + fd = eventfd(1, 0); + if (fd == -1) { + // failed to create eventfd, call pthread_cancel instead, which may result in data corruption: + tError("%s, failed to create eventfd(%s)", pThreadObj->label, strerror(errno)); + pthread_cancel(pThreadObj->thread); + } else if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { + // failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption: + tError("%s, failed to call epoll_ctl(%s)", pThreadObj->label, strerror(errno)); + pthread_cancel(pThreadObj->thread); + } } - pthread_join(pThreadObj->thread, NULL); - close(pThreadObj->pollFd); - if (fd != -1) { - close(fd); - } + if (pThreadObj->thread) pthread_join(pThreadObj->thread, NULL); + if (pThreadObj->pollFd >=0) close(pThreadObj->pollFd); + if (fd != -1) close(fd); while (pThreadObj->pHead) { SFdObj *pFdObj = pThreadObj->pHead; @@ -173,9 +189,8 @@ void taosCleanUpTcpServer(void *handle) { SThreadObj *pThreadObj; if (pServerObj == NULL) return; - - shutdown(pServerObj->fd, SHUT_RD); - pthread_join(pServerObj->thread, NULL); + if(pServerObj->fd >=0) shutdown(pServerObj->fd, SHUT_RD); + if(pServerObj->thread) pthread_join(pServerObj->thread, NULL); for (int i = 0; i < pServerObj->numOfThreads; ++i) { pThreadObj = pServerObj->pThreadObj + i; @@ -211,6 +226,7 @@ static void* taosAcceptTcpConnection(void *arg) { tTrace("%s TCP server socket was shutdown, exiting...", pServerObj->label); break; } + tError("%s TCP accept failure(%s)", pServerObj->label, strerror(errno)); continue; } @@ -247,13 +263,14 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * pThreadObj = (SThreadObj *)malloc(sizeof(SThreadObj)); memset(pThreadObj, 0, sizeof(SThreadObj)); - strcpy(pThreadObj->label, label); + tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); pThreadObj->ip = ip; pThreadObj->shandle = shandle; if (pthread_mutex_init(&(pThreadObj->mutex), NULL) < 0) { tError("%s failed to init TCP client mutex(%s)", label, strerror(errno)); free(pThreadObj); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -261,6 +278,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * if (pThreadObj->pollFd < 0) { tError("%s failed to create TCP client epoll", label); free(pThreadObj); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -273,6 +291,7 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * if (code != 0) { close(pThreadObj->pollFd); free(pThreadObj); + terrno = TAOS_SYSTEM_ERROR(errno); tError("%s failed to create TCP read data thread(%s)", label, strerror(errno)); return NULL; } @@ -287,7 +306,7 @@ void taosCleanUpTcpClient(void *chandle) { if (pThreadObj == NULL) return; taosStopTcpThread(pThreadObj); - tTrace (":%s, all connections are cleaned up", pThreadObj->label); + tTrace ("%s, all connections are cleaned up", pThreadObj->label); tfree(pThreadObj); } @@ -318,7 +337,9 @@ void taosCloseTcpConnection(void *chandle) { SFdObj *pFdObj = chandle; if (pFdObj == NULL) return; - taosFreeFdObj(pFdObj); + pFdObj->thandle = NULL; + pFdObj->closedByApp = 1; + shutdown(pFdObj->fd, SHUT_WR); } int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle) { @@ -334,7 +355,9 @@ static void taosReportBrokenLink(SFdObj *pFdObj) { SThreadObj *pThreadObj = pFdObj->pThreadObj; // notify the upper layer, so it will clean the associated context - if (pFdObj->thandle) { + if (pFdObj->closedByApp == 0) { + shutdown(pFdObj->fd, SHUT_WR); + SRecvInfo recvInfo; recvInfo.msg = NULL; recvInfo.msgLen = 0; @@ -345,9 +368,59 @@ static void taosReportBrokenLink(SFdObj *pFdObj) { recvInfo.chandle = NULL; recvInfo.connType = RPC_CONN_TCP; (*(pThreadObj->processData))(&recvInfo); - } else { - taosFreeFdObj(pFdObj); + } + + taosFreeFdObj(pFdObj); +} + +static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) { + SRpcHead rpcHead; + int32_t msgLen, leftLen, retLen, headLen; + char *buffer, *msg; + + SThreadObj *pThreadObj = pFdObj->pThreadObj; + + headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead)); + if (headLen != sizeof(SRpcHead)) { + tTrace("%s %p, read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen); + return -1; } + + msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen); + buffer = malloc(msgLen + tsRpcOverhead); + if ( NULL == buffer) { + tError("%s %p, TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); + return -1; + } + + msg = buffer + tsRpcOverhead; + leftLen = msgLen - headLen; + retLen = taosReadMsg(pFdObj->fd, msg + headLen, leftLen); + + if (leftLen != retLen) { + tError("%s %p, read error, leftLen:%d retLen:%d", + pThreadObj->label, pFdObj->thandle, leftLen, retLen); + free(buffer); + return -1; + } + + memcpy(msg, &rpcHead, sizeof(SRpcHead)); + + pInfo->msg = msg; + pInfo->msgLen = msgLen; + pInfo->ip = pFdObj->ip; + pInfo->port = pFdObj->port; + pInfo->shandle = pThreadObj->shandle; + pInfo->thandle = pFdObj->thandle;; + pInfo->chandle = pFdObj; + pInfo->connType = RPC_CONN_TCP; + + if (pFdObj->closedByApp) { + free(buffer); + return -1; + } + + return 0; } #define maxEvents 10 @@ -357,7 +430,6 @@ static void *taosProcessTcpData(void *param) { SFdObj *pFdObj; struct epoll_event events[maxEvents]; SRecvInfo recvInfo; - SRpcHead rpcHead; while (1) { int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, -1); @@ -376,51 +448,23 @@ static void *taosProcessTcpData(void *param) { continue; } + if (events[i].events & EPOLLRDHUP) { + tTrace("%s %p, FD RD hang up", pThreadObj->label, pFdObj->thandle); + taosReportBrokenLink(pFdObj); + continue; + } + if (events[i].events & EPOLLHUP) { tTrace("%s %p, FD hang up", pThreadObj->label, pFdObj->thandle); taosReportBrokenLink(pFdObj); continue; } - int32_t headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead)); - if (headLen != sizeof(SRpcHead)) { - tTrace("%s %p, read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen); - taosReportBrokenLink(pFdObj); + if (taosReadTcpData(pFdObj, &recvInfo) < 0) { + shutdown(pFdObj->fd, SHUT_WR); continue; } - int32_t msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen); - char *buffer = malloc(msgLen + tsRpcOverhead); - if ( NULL == buffer) { - tError("%s %p, TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); - taosReportBrokenLink(pFdObj); - continue; - } - - char *msg = buffer + tsRpcOverhead; - int32_t leftLen = msgLen - headLen; - int32_t retLen = taosReadMsg(pFdObj->fd, msg + headLen, leftLen); - - if (leftLen != retLen) { - tError("%s %p, read error, leftLen:%d retLen:%d", - pThreadObj->label, pFdObj->thandle, leftLen, retLen); - taosReportBrokenLink(pFdObj); - tfree(buffer); - continue; - } - - // tTrace("%s TCP data is received, ip:0x%x:%u len:%d", pThreadObj->label, pFdObj->ip, pFdObj->port, msgLen); - - memcpy(msg, &rpcHead, sizeof(SRpcHead)); - recvInfo.msg = msg; - recvInfo.msgLen = msgLen; - recvInfo.ip = pFdObj->ip; - recvInfo.port = pFdObj->port; - recvInfo.shandle = pThreadObj->shandle; - recvInfo.thandle = pFdObj->thandle;; - recvInfo.chandle = pFdObj; - recvInfo.connType = RPC_CONN_TCP; - pFdObj->thandle = (*(pThreadObj->processData))(&recvInfo); if (pFdObj->thandle == NULL) taosFreeFdObj(pFdObj); } @@ -433,16 +477,20 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd) { struct epoll_event event; SFdObj *pFdObj = (SFdObj *)calloc(sizeof(SFdObj), 1); - if (pFdObj == NULL) return NULL; + if (pFdObj == NULL) { + return NULL; + } + pFdObj->closedByApp = 0; pFdObj->fd = fd; pFdObj->pThreadObj = pThreadObj; pFdObj->signature = pFdObj; - event.events = EPOLLIN | EPOLLPRI | EPOLLWAKEUP; + event.events = EPOLLIN | EPOLLRDHUP; event.data.ptr = pFdObj; if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { tfree(pFdObj); + terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -475,13 +523,10 @@ static void taosFreeFdObj(SFdObj *pFdObj) { taosCloseSocket(pFdObj->fd); pThreadObj->numOfFds--; - if (pThreadObj->numOfFds < 0) tError("%s %p, TCP thread:%d, number of FDs is negative!!!", pThreadObj->label, pFdObj->thandle, pThreadObj->threadId); - // remove from the FdObject list - if (pFdObj->prev) { (pFdObj->prev)->next = pFdObj->next; } else { diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 9723080cda..7e2fe0db61 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -18,6 +18,7 @@ #include "tsystem.h" #include "ttimer.h" #include "tutil.h" +#include "taosdef.h" #include "rpcLog.h" #include "rpcUdp.h" #include "rpcHead.h" @@ -33,7 +34,7 @@ typedef struct { int fd; uint16_t port; // peer port uint16_t localPort; // local port - char label[12]; // copy from udpConnSet; + char label[TSDB_LABEL_LEN]; // copy from udpConnSet; pthread_t thread; void *hash; void *shandle; // handle passed by upper layer during server initialization @@ -49,7 +50,7 @@ typedef struct { uint16_t port; // local Port void *shandle; // handle passed by upper layer during server initialization int threads; - char label[12]; + char label[TSDB_LABEL_LEN]; void *(*fp)(SRecvInfo *pPacket); SUdpConn udpConn[]; } SUdpConnSet; @@ -72,7 +73,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads pSet->port = port; pSet->shandle = shandle; pSet->fp = fp; - strcpy(pSet->label, label); + tstrncpy(pSet->label, label, sizeof(pSet->label)); uint16_t ownPort; for (int i = 0; i < threads; ++i) { @@ -93,13 +94,13 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads } struct sockaddr_in sin; - unsigned int addrlen = sizeof(sin); + unsigned int addrlen = sizeof(sin); if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 && sin.sin_family == AF_INET && addrlen == sizeof(sin)) { pConn->localPort = (uint16_t)ntohs(sin.sin_port); } - strcpy(pConn->label, label); + tstrncpy(pConn->label, label, sizeof(pConn->label)); pConn->shandle = shandle; pConn->processData = fp; pConn->index = i; diff --git a/src/rpc/test/rclient.c b/src/rpc/test/rclient.c index 857b39dd82..d4e67fb1ec 100644 --- a/src/rpc/test/rclient.c +++ b/src/rpc/test/rclient.c @@ -76,6 +76,7 @@ int main(int argc, char *argv[]) { int numOfReqs = 0; int appThreads = 1; char serverIp[40] = "127.0.0.1"; + char secret[TSDB_KEY_LEN] = "mypassword"; struct timeval systemTime; int64_t startTime, endTime; pthread_attr_t thattr; @@ -97,7 +98,7 @@ int main(int argc, char *argv[]) { rpcInit.sessions = 100; rpcInit.idleTime = tsShellActivityTimer*1000; rpcInit.user = "michael"; - rpcInit.secret = "mypassword"; + rpcInit.secret = secret; rpcInit.ckey = "key"; rpcInit.spi = 1; rpcInit.connType = TAOS_CONN_CLIENT; @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) { if (strcmp(argv[i], "-p")==0 && i < argc-1) { ipSet.port[0] = atoi(argv[++i]); } else if (strcmp(argv[i], "-i") ==0 && i < argc-1) { - tstrncpy(ipSet.fqdn[0], argv[++i], sizeof(ipSet.fqdn)); + tstrncpy(ipSet.fqdn[0], argv[++i], sizeof(ipSet.fqdn[0])); } else if (strcmp(argv[i], "-t")==0 && i < argc-1) { rpcInit.numOfThreads = atoi(argv[++i]); } else if (strcmp(argv[i], "-m")==0 && i < argc-1) { diff --git a/src/rpc/test/rsclient.c b/src/rpc/test/rsclient.c index 659a79216f..01c7a353c5 100644 --- a/src/rpc/test/rsclient.c +++ b/src/rpc/test/rsclient.c @@ -77,6 +77,7 @@ int main(int argc, char *argv[]) { int numOfReqs = 0; int appThreads = 1; char serverIp[40] = "127.0.0.1"; + char secret[TSDB_KEY_LEN] = "mypassword"; struct timeval systemTime; int64_t startTime, endTime; pthread_attr_t thattr; @@ -98,7 +99,7 @@ int main(int argc, char *argv[]) { rpcInit.sessions = 100; rpcInit.idleTime = tsShellActivityTimer*1000; rpcInit.user = "michael"; - rpcInit.secret = "mypassword"; + rpcInit.secret = secret; rpcInit.ckey = "key"; rpcInit.spi = 1; rpcInit.connType = TAOS_CONN_CLIENT; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 0efb477e73..8f102795b5 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -92,16 +92,15 @@ STsdbCfg *tsdbGetCfg(const TsdbRepoT *repo) { * @return a TSDB repository handle on success, NULL for failure */ int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter /* TODO */) { - if (mkdir(rootDir, 0755) != 0) { tsdbError("vgId:%d, failed to create rootDir! rootDir:%s, reason:%s", pCfg->tsdbId, rootDir, strerror(errno)); if (errno == EACCES) { - return TSDB_CODE_NO_DISK_PERMISSIONS; + return TSDB_CODE_TDB_NO_DISK_PERMISSIONS; } else if (errno == ENOSPC) { - return TSDB_CODE_SERV_NO_DISKSPACE; + return TSDB_CODE_TDB_NO_DISKSPACE; } else if (errno == EEXIST) { } else { - return TSDB_CODE_VG_INIT_FAILED; + return TSDB_CODE_TDB_INIT_FAILED; } } @@ -315,7 +314,7 @@ int32_t tsdbConfigRepo(TsdbRepoT *repo, STsdbCfg *pCfg) { STsdbRepo *pRepo = (STsdbRepo *)repo; STsdbCfg * pRCfg = &pRepo->config; - if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return TSDB_CODE_INVALID_CONFIG; + if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return TSDB_CODE_TDB_INVALID_CONFIG; ASSERT(pRCfg->tsdbId == pCfg->tsdbId); ASSERT(pRCfg->cacheBlockSize == pCfg->cacheBlockSize); @@ -416,13 +415,13 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) { int16_t tversion = htons(pMsg->tversion); STable *pTable = tsdbGetTableByUid(pMeta, htobe64(pMsg->uid)); - if (pTable == NULL) return TSDB_CODE_INVALID_TABLE_ID; - if (pTable->tableId.tid != htonl(pMsg->tid)) return TSDB_CODE_INVALID_TABLE_ID; + if (pTable == NULL) return TSDB_CODE_TDB_INVALID_TABLE_ID; + if (pTable->tableId.tid != htonl(pMsg->tid)) return TSDB_CODE_TDB_INVALID_TABLE_ID; if (pTable->type != TSDB_CHILD_TABLE) { tsdbError("vgId:%d failed to update tag value of table %s since its type is %d", pRepo->config.tsdbId, varDataVal(pTable->name), pTable->type); - return TSDB_CODE_INVALID_TABLE_TYPE; + return TSDB_CODE_TDB_INVALID_TABLE_TYPE; } if (schemaVersion(tsdbGetTableTagSchema(pMeta, pTable)) < tversion) { @@ -452,7 +451,7 @@ int tsdbUpdateTagValue(TsdbRepoT *repo, SUpdateTableTagValMsg *pMsg) { "vgId:%d failed to update tag value of table %s since version out of date, client tag version:%d server tag " "version:%d", pRepo->config.tsdbId, varDataVal(pTable->name), tversion, schemaVersion(pTable->tagSchema)); - return TSDB_CODE_TAG_VER_OUT_OF_DATE; + return TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE; } if (schemaColAt(pTagSchema, DEFAULT_TAG_INDEX_COLUMN)->colId == htons(pMsg->colId)) { tsdbRemoveTableFromIndex(pMeta, pTable); @@ -948,7 +947,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY if (pTable == NULL) { tsdbError("vgId:%d, failed to get table for insert, uid:" PRIu64 ", tid:%d", pRepo->config.tsdbId, pBlock->uid, pBlock->tid); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_TDB_INVALID_TABLE_ID; } // Check schema version @@ -980,7 +979,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY if (tsdbGetTableSchemaByVersion(pMeta, pTable, tversion) == NULL) { tsdbError("vgId:%d table:%s tid:%d invalid schema version %d from client", pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, tversion); - return TSDB_CODE_TABLE_SCHEMA_VERSION; + return TSDB_CODE_TDB_TABLE_SCHEMA_VERSION; } } @@ -996,7 +995,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock, TSKEY tsdbError("vgId:%d, table:%s, tid:%d, talbe uid:%ld timestamp is out of range. now:" PRId64 ", maxKey:" PRId64 ", minKey:" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, pTable->tableId.uid, now, minKey, maxKey); - return TSDB_CODE_TIMESTAMP_OUT_OF_RANGE; + return TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE; } if (tdInsertRowToTable(pRepo, row, pTable) < 0) { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 9f1e507d54..34d3c27893 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -323,7 +323,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { pTable = (STable *)calloc(1, sizeof(STable)); if (pTable == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } @@ -343,7 +343,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); if (pTable->name == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->sname, tsize); @@ -352,7 +352,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, pColSchema->type, pColSchema->bytes, 1, 0, 0, getTagIndexKey); // Allow duplicate key, no lock if (pTable->pIndex == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } } else { @@ -364,7 +364,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { tsize = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN); pTable->name = calloc(1, tsize + VARSTR_HEADER_SIZE + 1); if (pTable->name == NULL) { - terrno = TSDB_CODE_SERV_OUT_OF_MEMORY; + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } STR_WITH_SIZE_TO_VARSTR(pTable->name, pCfg->name, tsize); @@ -399,7 +399,7 @@ static int tsdbUpdateTableTagSchema(STable *pTable, STSchema *newSchema) { ASSERT(schemaVersion(pTable->tagSchema) < schemaVersion(newSchema)); STSchema *pOldSchema = pTable->tagSchema; STSchema *pNewSchema = tdDupSchema(newSchema); - if (pNewSchema == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; + if (pNewSchema == NULL) return TSDB_CODE_TDB_OUT_OF_MEMORY; pTable->tagSchema = pNewSchema; tdFreeSchema(pOldSchema); @@ -454,7 +454,7 @@ int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg) { if (pTable != NULL) { tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, pRepo->config.tsdbId, varDataVal(pTable->name), pTable->tableId.tid, pTable->tableId.uid); - return TSDB_CODE_TABLE_ALREADY_EXIST; + return TSDB_CODE_TDB_TABLE_ALREADY_EXIST; } STable *super = NULL; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 4a48bcefe7..86ce44ad7b 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -17,6 +17,7 @@ #include "tulog.h" #include "talgo.h" #include "tutil.h" +#include "ttime.h" #include "tcompare.h" #include "exception.h" @@ -71,6 +72,8 @@ typedef struct STableCheckInfo { int32_t compSize; int32_t numOfBlocks; // number of qualified data blocks not the original blocks SDataCols* pDataCols; + + int32_t chosen; // indicate which iterator should move forward bool initBuf; // whether to initialize the in-memory skip list iterator or not SSkipListIterator* iter; // mem buffer skip list iterator SSkipListIterator* iiter; // imem buffer skip list iterator @@ -79,8 +82,6 @@ typedef struct STableCheckInfo { typedef struct STableBlockInfo { SCompBlock* compBlock; STableCheckInfo* pTableCheckInfo; -// int32_t blockIndex; -// int32_t groupIdx; /* number of group is less than the total number of tables */ } STableBlockInfo; typedef struct SBlockOrderSupporter { @@ -120,7 +121,7 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle); static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SCompBlock* pBlock, SArray* sa); static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); -static int tsdbReadRowsFromCache(SSkipListIterator* pIter, STable* pTable, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey, +static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey, STsdbQueryHandle* pQueryHandle); static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { @@ -134,7 +135,7 @@ static void tsdbInitCompBlockLoadInfo(SLoadCompBlockInfo* pCompBlockLoadInfo) { pCompBlockLoadInfo->fileId = -1; } -TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList) { +TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, void* qinfo) { // todo 1. filter not exist table // todo 2. add the reference count for each table that is involved in query @@ -147,6 +148,7 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable pQueryHandle->cur.win = TSWINDOW_INITIALIZER; pQueryHandle->checkFiles = true;//ASCENDING_TRAVERSE(pQueryHandle->order); pQueryHandle->activeIndex = 0; // current active table index + pQueryHandle->qinfo = qinfo; pQueryHandle->outputCapacity = ((STsdbRepo*)tsdb)->config.maxRowsPerFileBlock; tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb); @@ -201,8 +203,8 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable return (TsdbQueryHandleT) pQueryHandle; } -TsdbQueryHandleT tsdbQueryLastRow(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList) { - STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList); +TsdbQueryHandleT tsdbQueryLastRow(TsdbRepoT *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo) { + STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo); pQueryHandle->type = TSDB_QUERY_TYPE_LAST; pQueryHandle->order = TSDB_ORDER_DESC; @@ -227,8 +229,8 @@ SArray* tsdbGetQueriedTableIdList(TsdbQueryHandleT *pHandle) { return res; } -TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TsdbRepoT *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList) { - STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList); +TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TsdbRepoT *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo) { + STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo); pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL; // pQueryHandle->outputCapacity = 2; // only allowed two rows to be loaded @@ -303,6 +305,83 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh return true; } +SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo) { + SDataRow rmem = NULL, rimem = NULL; + if (pCheckInfo->iter) { + SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); + if (node != NULL) { + rmem = SL_GET_NODE_DATA(node); + } + } + + if (pCheckInfo->iiter) { + SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter); + if (node != NULL) { + rimem = SL_GET_NODE_DATA(node); + } + } + + if (rmem != NULL && rimem != NULL) { + if (dataRowKey(rmem) < dataRowKey(rimem)) { + pCheckInfo->chosen = 0; + return rmem; + } else if (dataRowKey(rmem) == dataRowKey(rimem)) { + // data ts are duplicated, ignore the data in mem + tSkipListIterNext(pCheckInfo->iter); + pCheckInfo->chosen = 1; + return rimem; + } else { + pCheckInfo->chosen = 1; + return rimem; + } + } + + if (rmem != NULL) { + pCheckInfo->chosen = 0; + return rmem; + } + + if (rimem != NULL) { + pCheckInfo->chosen = 1; + return rimem; + } + + return NULL; +} + +bool moveToNextRow(STableCheckInfo* pCheckInfo) { + bool hasNext = false; + if (pCheckInfo->chosen == 0) { + if (pCheckInfo->iter != NULL) { + hasNext = tSkipListIterNext(pCheckInfo->iter); + } + + if (hasNext) { + return hasNext; + } + + if (pCheckInfo->iiter != NULL) { + return tSkipListIterGet(pCheckInfo->iiter) != NULL; + } + } else { + if (pCheckInfo->chosen == 1) { + if (pCheckInfo->iiter != NULL) { + hasNext = tSkipListIterNext(pCheckInfo->iiter); + } + + if (hasNext) { + return hasNext; + } + + if (pCheckInfo->iter != NULL) { + return tSkipListIterGet(pCheckInfo->iter) != NULL; + } + } + } + + return hasNext; +} + static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1); @@ -312,31 +391,13 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { STable* pTable = pCheckInfo->pTableObj; assert(pTable != NULL); - - // no data in cache, abort - if (pTable->mem == NULL && pTable->imem == NULL) { + + initTableMemIterator(pHandle, pCheckInfo); + SDataRow row = getSDataRowInTableMem(pCheckInfo); + if (row == NULL) { return false; } - if (pCheckInfo->iter == NULL && pTable->mem) { - pCheckInfo->iter = tSkipListCreateIterFromVal(pTable->mem->pData, (const char*) &pCheckInfo->lastKey, - TSDB_DATA_TYPE_TIMESTAMP, pHandle->order); - - if (pCheckInfo->iter == NULL) { - return false; - } - - if (!tSkipListIterNext(pCheckInfo->iter)) { // buffer is empty - return false; - } - } - - SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter); - if (node == NULL) { - return false; - } - - SDataRow row = SL_GET_NODE_DATA(node); pCheckInfo->lastKey = dataRowKey(row); // first timestamp in buffer tsdbTrace("%p uid:%" PRId64", tid:%d check data in buffer from skey:%" PRId64 ", order:%d, %p", pHandle, pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, pCheckInfo->lastKey, pHandle->order, pHandle->qinfo); @@ -349,7 +410,7 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1; STimeWindow* win = &pHandle->cur.win; - pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo->iter, pCheckInfo->pTableObj, pHandle->window.ekey, + pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey, pHandle->outputCapacity, &win->skey, &win->ekey, pHandle); // todo refactor API // update the last key value @@ -382,7 +443,7 @@ static int32_t getFileIdFromKey(TSKEY key, int32_t daysPerFile, int32_t precisio return fid; } -static int32_t binarySearchForBlockImpl(SCompBlock* pBlock, int32_t numOfBlocks, TSKEY skey, int32_t order) { +static int32_t binarySearchForBlock(SCompBlock* pBlock, int32_t numOfBlocks, TSKEY skey, int32_t order) { int32_t firstSlot = 0; int32_t lastSlot = numOfBlocks - 1; @@ -448,7 +509,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo TSKEY e = MAX(pCheckInfo->lastKey, pQueryHandle->window.ekey); // discard the unqualified data block based on the query time window - int32_t start = binarySearchForBlockImpl(pCompInfo->blocks, compIndex->numOfBlocks, s, TSDB_ORDER_ASC); + int32_t start = binarySearchForBlock(pCompInfo->blocks, compIndex->numOfBlocks, s, TSDB_ORDER_ASC); int32_t end = start; if (s > pCompInfo->blocks[start].keyLast) { @@ -522,7 +583,9 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo bool blockLoaded = false; SArray* sa = getDefaultLoadColumns(pQueryHandle, true); - + + int64_t st = taosGetTimestampUs(); + if (pCheckInfo->pDataCols == NULL) { STsdbMeta* pMeta = tsdbGetMeta(pRepo); pCheckInfo->pDataCols = tdNewDataCols(pMeta->maxRowBytes, pMeta->maxCols, pRepo->config.maxRowsPerFileBlock); @@ -540,9 +603,15 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo blockLoaded = true; } + SDataCols* pCols = pQueryHandle->rhelper.pDataCols[0]; + assert(pCols->numOfRows != 0); + taosArrayDestroy(sa); tfree(data); - + + int64_t et = taosGetTimestampUs() - st; + tsdbTrace("%p load file block into buffer, elapsed time:%"PRId64 " us", pQueryHandle, et); + return blockLoaded; } @@ -600,7 +669,7 @@ static void handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SCompBlock* // do not load file block into buffer int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order) ? 1 : -1; - cur->rows = tsdbReadRowsFromCache(pCheckInfo->iter, pCheckInfo->pTableObj, binfo.window.skey - step, + cur->rows = tsdbReadRowsFromCache(pCheckInfo, binfo.window.skey - step, pQueryHandle->outputCapacity, &cur->win.skey, &cur->win.ekey, pQueryHandle); pQueryHandle->realNumOfRows = cur->rows; @@ -649,7 +718,7 @@ static bool loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock if (!doLoadFileDataBlock(pQueryHandle, pBlock, pCheckInfo)) { return false; } - + SDataCols* pTSCol = pQueryHandle->rhelper.pDataCols[0]; assert(pTSCol->cols->type == TSDB_DATA_TYPE_TIMESTAMP && pTSCol->numOfRows == pBlock->numOfRows); @@ -1147,7 +1216,7 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numOfBlocks, int32_t* numOfAllocBlocks) { char* tmp = realloc(pQueryHandle->pDataBlockInfo, sizeof(STableBlockInfo) * numOfBlocks); if (tmp == NULL) { - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } pQueryHandle->pDataBlockInfo = (STableBlockInfo*) tmp; @@ -1155,7 +1224,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO *numOfAllocBlocks = numOfBlocks; int32_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); - + SBlockOrderSupporter sup = {0}; sup.numOfTables = numOfTables; sup.numOfBlocksPerTable = calloc(1, sizeof(int32_t) * numOfTables); @@ -1164,7 +1233,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO if (sup.numOfBlocksPerTable == NULL || sup.blockIndexArray == NULL || sup.pDataBlockInfo == NULL) { cleanBlockOrderSupporter(&sup, 0); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } int32_t cnt = 0; @@ -1182,7 +1251,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO char* buf = calloc(1, sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); if (buf == NULL) { cleanBlockOrderSupporter(&sup, numOfQualTables); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } sup.pDataBlockInfo[numOfQualTables] = (STableBlockInfo*)buf; @@ -1192,15 +1261,26 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO pBlockInfo->compBlock = &pBlock[k]; pBlockInfo->pTableCheckInfo = pTableCheck; - // pBlockInfo->groupIdx = pTableCheckInfo[j]->groupIdx; // set the group index - // pBlockInfo->blockIndex = pTableCheckInfo[j]->start + k; // set the block index in original table cnt++; } numOfQualTables++; } - tsdbTrace("%p create data blocks info struct completed, %d blocks in %d tables", pQueryHandle, cnt, numOfQualTables); + assert(numOfBlocks == cnt); + + // since there is only one table qualified, blocks are not sorted + if (numOfQualTables == 1) { + memcpy(pQueryHandle->pDataBlockInfo, sup.pDataBlockInfo[0], sizeof(STableBlockInfo) * numOfBlocks); + cleanBlockOrderSupporter(&sup, numOfQualTables); + + tsdbTrace("%p create data blocks info struct completed for 1 table, %d blocks not sorted %p ", pQueryHandle, cnt, + pQueryHandle->qinfo); + return TSDB_CODE_SUCCESS; + } + + tsdbTrace("%p create data blocks info struct completed, %d blocks in %d tables %p", pQueryHandle, cnt, + numOfQualTables, pQueryHandle->qinfo); assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pTableQueryInfo[j]->numOfBlocks may be 0 sup.numOfTables = numOfQualTables; @@ -1209,7 +1289,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO uint8_t ret = tLoserTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); if (ret != TSDB_CODE_SUCCESS) { cleanBlockOrderSupporter(&sup, numOfTables); - return TSDB_CODE_SERV_OUT_OF_MEMORY; + return TSDB_CODE_TDB_OUT_OF_MEMORY; } int32_t numOfTotal = 0; @@ -1257,8 +1337,8 @@ static bool getDataBlocksInFilesImpl(STsdbQueryHandle* pQueryHandle) { break; } - tsdbTrace("%p %d blocks found in file for %d table(s), fid:%d", pQueryHandle, numOfBlocks, - numOfTables, pQueryHandle->pFileGroup->fileId); + tsdbTrace("%p %d blocks found in file for %d table(s), fid:%d, %p", pQueryHandle, numOfBlocks, + numOfTables, pQueryHandle->pFileGroup->fileId, pQueryHandle->qinfo); assert(numOfBlocks >= 0); if (numOfBlocks == 0) { @@ -1565,19 +1645,22 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle) { pQueryHandle->window = (STimeWindow) {info.lastKey, TSKEY_INITIAL_VAL}; } -static int tsdbReadRowsFromCache(SSkipListIterator* pIter, STable* pTable, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey, +static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey, STsdbQueryHandle* pQueryHandle) { int numOfRows = 0; int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns); *skey = TSKEY_INITIAL_VAL; + int64_t st = taosGetTimestampUs(); + STSchema* pSchema = tsdbGetTableSchema(tsdbGetMeta(pQueryHandle->pTsdb), pCheckInfo->pTableObj); + int32_t numOfTableCols = schemaNCols(pSchema); + do { - SSkipListNode* node = tSkipListIterGet(pIter); - if (node == NULL) { + SDataRow row = getSDataRowInTableMem(pCheckInfo); + if (row == NULL) { break; } - SDataRow row = SL_GET_NODE_DATA(node); TSKEY key = dataRowKey(row); if ((key > maxKey && ASCENDING_TRAVERSE(pQueryHandle->order)) || @@ -1590,49 +1673,69 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, STable* pTable, TSKEY } if (*skey == INT64_MIN) { - *skey = dataRowKey(row); + *skey = key; } - *ekey = dataRowKey(row); - - int32_t offset = -1; + *ekey = key; char* pData = NULL; - - STSchema* pSchema = tsdbGetTableSchema(tsdbGetMeta(pQueryHandle->pTsdb), pTable); - int32_t numOfTableCols = schemaNCols(pSchema); - for (int32_t i = 0; i < numOfCols; ++i) { + int32_t i = 0, j = 0; + while(i < numOfCols && j < numOfTableCols) { SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); - + if (pSchema->columns[j].colId < pColInfo->info.colId) { + j++; + continue; + } + if (ASCENDING_TRAVERSE(pQueryHandle->order)) { pData = pColInfo->pData + numOfRows * pColInfo->info.bytes; } else { pData = pColInfo->pData + (maxRowsToRead - numOfRows - 1) * pColInfo->info.bytes; } - for(int32_t j = 0; j < numOfTableCols; ++j) { - if (pColInfo->info.colId == pSchema->columns[j].colId) { - offset = pSchema->columns[j].offset; - break; + if (pSchema->columns[j].colId == pColInfo->info.colId) { + void* value = tdGetRowDataOfCol(row, pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[j].offset); + if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { + memcpy(pData, value, varDataTLen(value)); + } else { + memcpy(pData, value, pColInfo->info.bytes); } - } - - assert(offset != -1); // todo handle error - void *value = tdGetRowDataOfCol(row, pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + offset); - - if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { - memcpy(pData, value, varDataTLen(value)); - } else { - memcpy(pData, value, pColInfo->info.bytes); + + j++; + i++; + } else { // pColInfo->info.colId < pSchema->columns[j].colId, it is a NULL data + if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { + setVardataNull(pData, pColInfo->info.type); + } else { + setNull(pData, pColInfo->info.type, pColInfo->info.bytes); + } + i++; } } - + + while (i < numOfCols) { // the remain columns are all null data + SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); + if (ASCENDING_TRAVERSE(pQueryHandle->order)) { + pData = pColInfo->pData + numOfRows * pColInfo->info.bytes; + } else { + pData = pColInfo->pData + (maxRowsToRead - numOfRows - 1) * pColInfo->info.bytes; + } + + if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { + setVardataNull(pData, pColInfo->info.type); + } else { + setNull(pData, pColInfo->info.type, pColInfo->info.bytes); + } + + i++; + } + if (++numOfRows >= maxRowsToRead) { - tSkipListIterNext(pIter); + moveToNextRow(pCheckInfo); break; } - } while(tSkipListIterNext(pIter)); + } while(moveToNextRow(pCheckInfo)); assert(numOfRows <= maxRowsToRead); @@ -1646,6 +1749,10 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, STable* pTable, TSKEY } } + int64_t elapsedTime = taosGetTimestampUs() - st; + tsdbTrace("%p build data block from cache completed, elapsed time:%"PRId64" us, numOfRows:%d, numOfCols:%d", pQueryHandle, + elapsedTime, numOfRows, numOfCols); + return numOfRows; } @@ -2070,14 +2177,14 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); if (pTable == NULL) { tsdbError("%p failed to get stable, uid:%" PRIu64, tsdb, uid); - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_TDB_INVALID_TABLE_ID; } if (pTable->type != TSDB_SUPER_TABLE) { tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", tid:%d, name:%s", tsdb, uid, pTable->tableId.tid, pTable->name); - return TSDB_CODE_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client + return TSDB_CODE_COM_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client } SArray* res = taosArrayInit(8, sizeof(STableId)); @@ -2114,7 +2221,7 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag tExprNode* tbnameExpr = expr; expr = calloc(1, sizeof(tExprNode)); if (expr == NULL) { - THROW( TSDB_CODE_SERV_OUT_OF_MEMORY ); + THROW( TSDB_CODE_TDB_OUT_OF_MEMORY ); } expr->nodeType = TSQL_NODE_EXPR; expr->_node.optr = tagNameRelType; @@ -2141,7 +2248,7 @@ int32_t tsdbQuerySTableByTagCond(TsdbRepoT* tsdb, uint64_t uid, const char* pTag int32_t tsdbGetOneTableGroup(TsdbRepoT* tsdb, uint64_t uid, STableGroupInfo* pGroupInfo) { STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); if (pTable == NULL) { - return TSDB_CODE_INVALID_TABLE_ID; + return TSDB_CODE_TDB_INVALID_TABLE_ID; } //todo assert table type, add the table ref count diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index 6a22bdea6a..2369f63f16 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -111,6 +111,15 @@ void *taosCachePut(SCacheObj *pCacheObj, const char *key, const void *pData, siz */ void *taosCacheAcquireByName(SCacheObj *pCacheObj, const char *key); +/** + * update the expire time of data in cache + * @param pCacheObj cache object + * @param key key + * @param expireTime new expire time of data + * @return + */ +void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, const char *key, uint64_t expireTime); + /** * Add one reference count for the exist data, and assign this data for a new owner. * The new owner needs to invoke the taosCacheRelease when it does not need this data anymore. diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 4fc382a09b..d38f983718 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -153,6 +153,8 @@ bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes); +void taosRandStr(char* str, int32_t size); + int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); bool taosValidateEncodec(const char *encodec); diff --git a/src/util/src/tarray.c b/src/util/src/tarray.c index 8908dc2e65..b99e722262 100755 --- a/src/util/src/tarray.c +++ b/src/util/src/tarray.c @@ -92,12 +92,14 @@ void* taosArrayGet(const SArray* pArray, size_t index) { } void* taosArrayGetP(const SArray* pArray, size_t index) { - void* ret = taosArrayGet(pArray, index); - if (ret == NULL) { + assert(index < pArray->size); + + void* d = TARRAY_GET_ELEM(pArray, index); + if (d == NULL) { return NULL; } - return *(void**)ret; + return *(void**)d; } size_t taosArrayGetSize(const SArray* pArray) { return pArray->size; } diff --git a/src/util/src/tbuffer.c b/src/util/src/tbuffer.c index 3b4cc74cc3..4b37cbd2d5 100644 --- a/src/util/src/tbuffer.c +++ b/src/util/src/tbuffer.c @@ -26,7 +26,7 @@ size_t tbufSkip(SBufferReader* buf, size_t size) { if( (buf->pos + size) > buf->size ) { - THROW( TSDB_CODE_MEMORY_CORRUPTED ); + THROW( TSDB_CODE_COM_MEMORY_CORRUPTED ); } size_t old = buf->pos; buf->pos += size; @@ -58,7 +58,7 @@ const char* tbufReadString( SBufferReader* buf, size_t* len ) { const char* ret = buf->data + buf->pos; tbufSkip( buf, l + 1 ); if( ret[l] != 0 ) { - THROW( TSDB_CODE_MEMORY_CORRUPTED ); + THROW( TSDB_CODE_COM_MEMORY_CORRUPTED ); } if( len != NULL ) { *len = l; @@ -204,7 +204,7 @@ void tbufEnsureCapacity( SBufferWriter* buf, size_t size ) { char* data = (*buf->allocator)( buf->data, nsize ); // TODO: the exception should be thrown by the allocator function if( data == NULL ) { - THROW( TSDB_CODE_SERV_OUT_OF_MEMORY ); + THROW( TSDB_CODE_COM_OUT_OF_MEMORY ); } buf->data = data; buf->size = nsize; diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 82873f9906..b0291b5cc0 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -488,6 +488,35 @@ void *taosCacheAcquireByName(SCacheObj *pCacheObj, const char *key) { return (ptNode != NULL) ? (*ptNode)->data : NULL; } +void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, const char *key, uint64_t expireTime) { + if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) { + return NULL; + } + + uint32_t keyLen = (uint32_t)strlen(key); + + __cache_rd_lock(pCacheObj); + + SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen); + if (ptNode != NULL) { + T_REF_INC(*ptNode); + (*ptNode)->expiredTime = expireTime; + } + + __cache_unlock(pCacheObj); + + if (ptNode != NULL) { + atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1); + uTrace("key:%s expireTime is updated in cache, %p refcnt:%d", key, (*ptNode), T_REF_VAL_GET(*ptNode)); + } else { + atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); + uTrace("key:%s not in cache, retrieved failed", key); + } + + atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1); + return (ptNode != NULL) ? (*ptNode)->data : NULL; +} + void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) { if (pCacheObj == NULL || data == NULL) return NULL; diff --git a/src/util/src/tqueue.c b/src/util/src/tqueue.c index 4cf7eb3164..7e9392f410 100644 --- a/src/util/src/tqueue.c +++ b/src/util/src/tqueue.c @@ -55,7 +55,7 @@ taos_queue taosOpenQueue() { STaosQueue *queue = (STaosQueue *) calloc(sizeof(STaosQueue), 1); if (queue == NULL) { - terrno = TSDB_CODE_NO_RESOURCE; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; } @@ -216,7 +216,7 @@ taos_qset taosOpenQset() { STaosQset *qset = (STaosQset *) calloc(sizeof(STaosQset), 1); if (qset == NULL) { - terrno = TSDB_CODE_NO_RESOURCE; + terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; } diff --git a/src/util/src/tsched.c b/src/util/src/tsched.c index 25893969e4..898ab70876 100644 --- a/src/util/src/tsched.c +++ b/src/util/src/tsched.c @@ -14,6 +14,7 @@ */ #include "os.h" +#include "taosdef.h" #include "tulog.h" #include "tsched.h" #include "ttimer.h" @@ -21,7 +22,7 @@ #define DUMP_SCHEDULER_TIME_WINDOW 30000 //every 30sec, take a snap shot of task queue. typedef struct { - char label[16]; + char label[TSDB_LABEL_LEN]; tsem_t emptySem; tsem_t fullSem; pthread_mutex_t queueMutex; diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index d92228a089..00c8bba94e 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -19,27 +19,42 @@ #include "tutil.h" int taosGetFqdn(char *fqdn) { + int code = 0; char hostname[1024]; hostname[1023] = '\0'; gethostname(hostname, 1023); - struct hostent* h; - h = gethostbyname(hostname); - if (h != NULL) { - strcpy(fqdn, h->h_name); - return 0; + struct addrinfo hints = {0}; + struct addrinfo *result = NULL; + + hints.ai_flags = AI_CANONNAME; + + getaddrinfo(hostname, NULL, &hints, &result); + if (result) { + strcpy(fqdn, result->ai_canonname); + freeaddrinfo(result); } else { - uError("failed to get host name"); - return -1; + code = -1; } - free(h); + return code; } uint32_t taosGetIpFromFqdn(const char *fqdn) { - struct hostent * record = gethostbyname(fqdn); - if(record == NULL) return -1; - return ((struct in_addr *)record->h_addr)->s_addr; + struct addrinfo hints = {0}; + struct addrinfo *result = NULL; + + getaddrinfo(fqdn, NULL, &hints, &result); + if (result) { + struct sockaddr *sa = result->ai_addr; + struct sockaddr_in *si = (struct sockaddr_in*)sa; + struct in_addr ia = si->sin_addr; + uint32_t ip = ia.s_addr; + freeaddrinfo(result); + return ip; + } else { + return -1; + } } // Function converting an IP address string to an unsigned int. @@ -47,7 +62,7 @@ uint32_t ip2uint(const char *const ip_addr) { char ip_addr_cpy[20]; char ip[5]; - strcpy(ip_addr_cpy, ip_addr); + tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy)); char *s_start, *s_end; s_start = ip_addr_cpy; @@ -206,7 +221,7 @@ int taosOpenUdpSocket(uint32_t ip, uint16_t port) { int reuse, nocheck; int bufSize = 8192000; - uTrace("open udp socket:%s:%hu", ip, port); + uTrace("open udp socket:0x%x:%hu", ip, port); memset((char *)&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; @@ -257,7 +272,7 @@ int taosOpenUdpSocket(uint32_t ip, uint16_t port) { /* bind socket to local address */ if (bind(sockFd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) { - uError("failed to bind udp socket: %d (%s), %s:%hu", errno, strerror(errno), ip, port); + uError("failed to bind udp socket: %d (%s), 0x%x:%hu", errno, strerror(errno), ip, port); taosCloseSocket(sockFd); return -1; } @@ -363,7 +378,7 @@ int taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { int sockFd; int reuse; - uTrace("open tcp server socket:%s:%hu", ip, port); + uTrace("open tcp server socket:0x%x:%hu", ip, port); bzero((char *)&serverAdd, sizeof(serverAdd)); serverAdd.sin_family = AF_INET; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 6a5c8b6799..c524a61591 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -27,8 +27,6 @@ #include "tulog.h" #include "taoserror.h" -int32_t tmpFileSerialNum = 0; - int32_t strdequote(char *z) { if (z == NULL) { return 0; @@ -433,12 +431,24 @@ void getTmpfilePath(const char *fileNamePrefix, char *dstPath) { #else char *tmpDir = "/tmp/"; #endif - int64_t ts = taosGetTimestampUs(); + strcpy(tmpPath, tmpDir); strcat(tmpPath, tdengineTmpFileNamePrefix); strcat(tmpPath, fileNamePrefix); - strcat(tmpPath, "-%d-%"PRIu64"-%u-%"PRIu64); - snprintf(dstPath, PATH_MAX, tmpPath, getpid(), taosGetPthreadId(), atomic_add_fetch_32(&tmpFileSerialNum, 1), ts); + strcat(tmpPath, "-%d-%s"); + + char rand[8] = {0}; + taosRandStr(rand, tListLen(rand) - 1); + snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); +} + +void taosRandStr(char* str, int32_t size) { + const char* set = "abcdefghijklmnopqrstuvwxyz0123456789-_."; + int32_t len = 39; + + for(int32_t i = 0; i < size; ++i) { + str[i] = set[rand()%len]; + } } int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes) { @@ -582,18 +592,18 @@ int taosCheckVersion(char *input_client_version, char *input_server_version, int if (!taosGetVersionNumber(client_version, clientVersionNumber)) { uError("invalid client version:%s", client_version); - return TSDB_CODE_INVALID_CLIENT_VERSION; + return TSDB_CODE_TSC_INVALID_VERSION; } if (!taosGetVersionNumber(server_version, serverVersionNumber)) { uError("invalid server version:%s", server_version); - return TSDB_CODE_INVALID_CLIENT_VERSION; + return TSDB_CODE_TSC_INVALID_VERSION; } for(int32_t i = 0; i < comparedSegments; ++i) { if (clientVersionNumber[i] != serverVersionNumber[i]) { uError("the %d-th number of server version:%s not matched with client version:%s", i, server_version, version); - return TSDB_CODE_INVALID_CLIENT_VERSION; + return TSDB_CODE_TSC_INVALID_VERSION; } } diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 3d8cf67d02..d1dfa24cbe 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -82,14 +82,14 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { if (mkdir(rootDir, 0755) != 0) { vPrint("vgId:%d, failed to create vnode, reason:%s dir:%s", pVnodeCfg->cfg.vgId, strerror(errno), rootDir); if (errno == EACCES) { - return TSDB_CODE_NO_DISK_PERMISSIONS; + return TSDB_CODE_VND_NO_DISK_PERMISSIONS; } else if (errno == ENOSPC) { - return TSDB_CODE_SERV_NO_DISKSPACE; + return TSDB_CODE_VND_NO_DISKSPACE; } else if (errno == ENOENT) { - return TSDB_CODE_NOT_SUCH_FILE_OR_DIR; + return TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR; } else if (errno == EEXIST) { } else { - return TSDB_CODE_VG_INIT_FAILED; + return TSDB_CODE_VND_INIT_FAILED; } } @@ -116,7 +116,7 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { code = tsdbCreateRepo(tsdbDir, &tsdbCfg, NULL); if (code != TSDB_CODE_SUCCESS) { vError("vgId:%d, failed to create tsdb in vnode, reason:%s", pVnodeCfg->cfg.vgId, tstrerror(code)); - return TSDB_CODE_VG_INIT_FAILED; + return TSDB_CODE_VND_INIT_FAILED; } vPrint("vgId:%d, vnode is created, clog:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.walLevel); @@ -128,13 +128,13 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { int32_t vnodeDrop(int32_t vgId) { if (tsDnodeVnodesHash == NULL) { vTrace("vgId:%d, failed to drop, vgId not exist", vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_VND_INVALID_VGROUP_ID; } SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) { vTrace("vgId:%d, failed to drop, vgId not find", vgId); - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_VND_INVALID_VGROUP_ID; } SVnodeObj *pVnode = *ppVnode; @@ -326,7 +326,7 @@ void *vnodeGetVnode(int32_t vgId) { SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) { - terrno = TSDB_CODE_INVALID_VGROUP_ID; + terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; vPrint("vgId:%d, not exist", vgId); return NULL; } @@ -494,7 +494,7 @@ static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) { char * content = calloc(1, maxLen + 1); if (content == NULL) { fclose(fp); - return TSDB_CODE_NO_RESOURCE; + return TSDB_CODE_VND_OUT_OF_MEMORY; } len += snprintf(content + len, maxLen - len, "{\n"); @@ -545,7 +545,7 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) { char cfgFile[TSDB_FILENAME_LEN + 30] = {0}; int maxLen = 1000; - terrno = TSDB_CODE_OTHERS; + terrno = TSDB_CODE_VND_APP_ERROR; sprintf(cfgFile, "%s/vnode%d/config.json", tsVnodeDir, pVnode->vgId); FILE *fp = fopen(cfgFile, "r"); if (!fp) { @@ -777,7 +777,7 @@ static int32_t vnodeReadVersion(SVnodeObj *pVnode) { cJSON *root = NULL; int maxLen = 100; - terrno = TSDB_CODE_OTHERS; + terrno = TSDB_CODE_VND_APP_ERROR; sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId); FILE *fp = fopen(versionFile, "r"); if (!fp) { diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index ef2cb20171..2cf72bb15d 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -40,10 +40,14 @@ int32_t vnodeProcessRead(void *param, int msgType, void *pCont, int32_t contLen, SVnodeObj *pVnode = (SVnodeObj *)param; if (vnodeProcessReadMsgFp[msgType] == NULL) - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_VND_MSG_NOT_PROCESSED; if (pVnode->status == TAOS_VN_STATUS_DELETING || pVnode->status == TAOS_VN_STATUS_CLOSING) - return TSDB_CODE_INVALID_VGROUP_ID; + return TSDB_CODE_VND_INVALID_VGROUP_ID; + + // TODO: Later, let slave to support query + if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) + return TSDB_CODE_RPC_NOT_READY; return (*vnodeProcessReadMsgFp[msgType])(pVnode, pCont, contLen, ret); } @@ -69,7 +73,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, void *pCont, int32_t cont } else { assert(pCont != NULL); pQInfo = pCont; - code = TSDB_CODE_ACTION_IN_PROGRESS; + code = TSDB_CODE_VND_ACTION_IN_PROGRESS; } if (pQInfo != NULL) { @@ -99,7 +103,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, void *pCont, int32_t cont if (qHasMoreResultsToRetrieve(pQInfo)) { pRet->qhandle = pQInfo; - code = TSDB_CODE_ACTION_NEED_REPROCESSED; + code = TSDB_CODE_VND_ACTION_NEED_REPROCESSED; } else { // no further execution invoked, release the ref to vnode qDestroyQueryInfo(pQInfo); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 4dfe492932..fa322757e2 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -51,14 +51,14 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) { SWalHead *pHead = param2; if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL) - return TSDB_CODE_MSG_NOT_PROCESSED; + return TSDB_CODE_VND_MSG_NOT_PROCESSED; if (pHead->version == 0) { // from client or CQ if (pVnode->status != TAOS_VN_STATUS_READY) - return TSDB_CODE_INVALID_VGROUP_ID; // it may be in deleting or closing state + return TSDB_CODE_VND_INVALID_VGROUP_ID; // it may be in deleting or closing state if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) - return TSDB_CODE_NOT_READY; + return TSDB_CODE_RPC_NOT_READY; // assign version pVnode->version++; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index ebfc9d98bb..09225984c4 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -68,11 +68,19 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { pWal->num = 0; pWal->level = pCfg->walLevel; pWal->keep = pCfg->keep; - strcpy(pWal->path, path); + tstrncpy(pWal->path, path, sizeof(pWal->path)); pthread_mutex_init(&pWal->mutex, NULL); - if (access(path, F_OK) != 0) mkdir(path, 0755); - + if (access(path, F_OK) != 0) { + if (mkdir(path, 0755) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + wError("wal:%s, failed to create directory(%s)", path, strerror(errno)); + pthread_mutex_destroy(&pWal->mutex); + free(pWal); + pWal = NULL; + } + } + if (pCfg->keep == 1) return pWal; if (walHandleExistingFiles(path) == 0) @@ -80,7 +88,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { if (pWal->fd <0) { terrno = TAOS_SYSTEM_ERROR(errno); - wError("wal:%s, failed to open", path); + wError("wal:%s, failed to open(%s)", path, strerror(errno)); pthread_mutex_destroy(&pWal->mutex); free(pWal); pWal = NULL; @@ -119,7 +127,8 @@ void walClose(void *handle) { int walRenew(void *handle) { if (handle == NULL) return 0; SWal *pWal = handle; - int code = 0; + + terrno = 0; pthread_mutex_lock(&pWal->mutex); @@ -135,8 +144,8 @@ int walRenew(void *handle) { pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); if (pWal->fd < 0) { - wError("wal:%d, failed to open(%s)", pWal->name, strerror(errno)); - code = -1; + wError("wal:%s, failed to open(%s)", pWal->name, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); } else { wTrace("wal:%s, it is created", pWal->name); @@ -156,14 +165,15 @@ int walRenew(void *handle) { pthread_mutex_unlock(&pWal->mutex); - return code; + return terrno; } int walWrite(void *handle, SWalHead *pHead) { SWal *pWal = handle; - int code = 0; if (pWal == NULL) return -1; + terrno = 0; + // no wal if (pWal->level == TAOS_WAL_NOLOG) return 0; if (pHead->version <= pWal->version) return 0; @@ -174,12 +184,12 @@ int walWrite(void *handle, SWalHead *pHead) { if(write(pWal->fd, pHead, contLen) != contLen) { wError("wal:%s, failed to write(%s)", pWal->name, strerror(errno)); - code = -1; + terrno = TAOS_SYSTEM_ERROR(errno); } else { pWal->version = pHead->version; } - return code; + return terrno; } void walFsync(void *handle) { @@ -196,11 +206,11 @@ void walFsync(void *handle) { int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) { SWal *pWal = handle; - int code = 0; struct dirent *ent; int count = 0; uint32_t maxId = 0, minId = -1, index =0; + terrno = 0; int plen = strlen(walPrefix); char opath[TSDB_FILENAME_LEN+5]; @@ -224,30 +234,30 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) closedir(dir); if (count == 0) { - if (pWal->keep) code = walRenew(pWal); - return code; + if (pWal->keep) terrno = walRenew(pWal); + return terrno; } if ( count != (maxId-minId+1) ) { wError("wal:%s, messed up, count:%d max:%d min:%d", opath, count, maxId, minId); - code = -1; + terrno = TSDB_CODE_WAL_APP_ERROR; } else { wTrace("wal:%s, %d files will be restored", opath, count); for (index = minId; index<=maxId; ++index) { sprintf(pWal->name, "%s/%s%d", opath, walPrefix, index); - code = walRestoreWalFile(pWal, pVnode, writeFp); - if (code < 0) break; + terrno = walRestoreWalFile(pWal, pVnode, writeFp); + if (terrno < 0) break; } } - if (code == 0) { + if (terrno == 0) { if (pWal->keep == 0) { - code = walRemoveWalFiles(opath); - if (code == 0) { + terrno = walRemoveWalFiles(opath); + if (terrno == 0) { if (remove(opath) < 0) { wError("wal:%s, failed to remove directory(%s)", opath, strerror(errno)); - code = -1; + terrno = TAOS_SYSTEM_ERROR(errno); } } } else { @@ -258,12 +268,12 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) pWal->fd = open(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO); if (pWal->fd < 0) { wError("wal:%s, failed to open file(%s)", pWal->name, strerror(errno)); - code = -1; + terrno = TAOS_SYSTEM_ERROR(errno); } } } - return code; + return terrno; } int walGetWalFile(void *handle, char *name, uint32_t *index) { @@ -292,40 +302,47 @@ int walGetWalFile(void *handle, char *name, uint32_t *index) { } static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) { - int code = 0; char *name = pWal->name; + terrno = 0; char *buffer = malloc(1024000); // size for one record - if (buffer == NULL) return -1; + if (buffer == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } SWalHead *pHead = (SWalHead *)buffer; int fd = open(name, O_RDONLY); if (fd < 0) { wError("wal:%s, failed to open for restore(%s)", name, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); free(buffer); - return -1; + return terrno; } wTrace("wal:%s, start to restore", name); while (1) { int ret = read(fd, pHead, sizeof(SWalHead)); - if ( ret == 0) { code = 0; break;} + if ( ret == 0) break; if (ret != sizeof(SWalHead)) { wWarn("wal:%s, failed to read head, skip, ret:%d(%s)", name, ret, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); break; } if (!taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) { wWarn("wal:%s, cksum is messed up, skip the rest of file", name); + terrno = TAOS_SYSTEM_ERROR(errno); break; } ret = read(fd, pHead->cont, pHead->len); if ( ret != pHead->len) { wWarn("wal:%s, failed to read body, skip, len:%d ret:%d", name, pHead->len, ret); + terrno = TAOS_SYSTEM_ERROR(errno); break; } @@ -336,11 +353,10 @@ static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) { close(fd); free(buffer); - return code; + return terrno; } int walHandleExistingFiles(const char *path) { - int code = 0; char oname[TSDB_FILENAME_LEN * 3]; char nname[TSDB_FILENAME_LEN * 3]; char opath[TSDB_FILENAME_LEN]; @@ -350,6 +366,7 @@ int walHandleExistingFiles(const char *path) { struct dirent *ent; DIR *dir = opendir(path); int plen = strlen(walPrefix); + terrno = 0; if (access(opath, F_OK) == 0) { // old directory is there, it means restore process is not finished @@ -360,13 +377,19 @@ int walHandleExistingFiles(const char *path) { int count = 0; while ((ent = readdir(dir))!= NULL) { if ( strncmp(ent->d_name, walPrefix, plen) == 0) { - if (access(opath, F_OK) != 0) mkdir(opath, 0755); - sprintf(oname, "%s/%s", path, ent->d_name); sprintf(nname, "%s/old/%s", path, ent->d_name); + if (access(opath, F_OK) != 0) { + if (mkdir(opath, 0755) != 0) { + wError("wal:%s, failed to create directory:%s(%s)", oname, opath, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + break; + } + } + if (rename(oname, nname) < 0) { wError("wal:%s, failed to move to new:%s", oname, nname); - code = -1; + terrno = TAOS_SYSTEM_ERROR(errno); break; } @@ -378,14 +401,14 @@ int walHandleExistingFiles(const char *path) { } closedir(dir); - return code; + return terrno; } static int walRemoveWalFiles(const char *path) { int plen = strlen(walPrefix); char name[TSDB_FILENAME_LEN * 3]; - int code = 0; - + + terrno = 0; if (access(path, F_OK) != 0) return 0; struct dirent *ent; @@ -396,13 +419,13 @@ static int walRemoveWalFiles(const char *path) { sprintf(name, "%s/%s", path, ent->d_name); if (remove(name) <0) { wError("wal:%s, failed to remove(%s)", name, strerror(errno)); - code = -1; break; + terrno = TAOS_SYSTEM_ERROR(errno); } } } closedir(dir); - return code; + return terrno; } diff --git a/tests/examples/C#/TDengineDriver.cs b/tests/examples/C#/TDengineDriver.cs index a11dae8e48..2797c362c1 100644 --- a/tests/examples/C#/TDengineDriver.cs +++ b/tests/examples/C#/TDengineDriver.cs @@ -79,8 +79,6 @@ namespace TDengineDriver class TDengine { public const int TSDB_CODE_SUCCESS = 0; - public const int TSDB_CODE_DB_ALREADY_EXIST = 33; - public const int TSDB_CODE_TABLE_ALREADY_EXIST = 34; [DllImport("taos.dll", EntryPoint = "taos_init", CallingConvention = CallingConvention.StdCall)] static extern public void Init(); diff --git a/tests/pytest/query/filter.py b/tests/pytest/query/filter.py index 43c8e5bf0a..f107985f15 100644 --- a/tests/pytest/query/filter.py +++ b/tests/pytest/query/filter.py @@ -87,7 +87,7 @@ class TDTestCase: # <> for timestamp type tdSql.query("select * from db.st where ts <> '2020-05-13 10:00:00.002'") - #tdSql.checkRows(4) + # tdSql.checkRows(4) # <> for numeric type tdSql.query("select * from db.st where tagtype <> 2") @@ -96,7 +96,7 @@ class TDTestCase: # <> for nchar type tdSql.query("select * from db.st where name <> 'first'") tdSql.checkRows(4) - + # % for nchar type tdSql.query("select * from db.st where name like 'fi%'") tdSql.checkRows(2) diff --git a/tests/pytest/query/filterCombo.py b/tests/pytest/query/filterCombo.py index c9c7ade73e..f72b913c92 100644 --- a/tests/pytest/query/filterCombo.py +++ b/tests/pytest/query/filterCombo.py @@ -42,14 +42,17 @@ class TDTestCase: ('2020-05-13 10:00:00.005', 3, 'third')""") # query with filter condition A OR condition B - tdSql.query("select * from db.st where ts > '2020-05-13 10:00:00.002' AND tagtype < 2") + tdSql.query( + "select * from db.st where ts > '2020-05-13 10:00:00.002' AND tagtype < 2") tdSql.checkRows(1) # query with filter condition A OR condition B, error expected - tdSql.error("select * from db.st where ts > '2020-05-13 10:00:00.002' OR tagtype < 2") + tdSql.error( + "select * from db.st where ts > '2020-05-13 10:00:00.002' OR tagtype < 2") # illegal condition - tdSql.error("select * from db.st where ts != '2020-05-13 10:00:00.002' OR tagtype < 2") + tdSql.error( + "select * from db.st where ts != '2020-05-13 10:00:00.002' OR tagtype < 2") tdSql.error("select * from db.st where tagtype <> 1 OR tagtype < 2") def stop(self): diff --git a/tests/pytest/query/queryError.py b/tests/pytest/query/queryError.py index 95924f48cc..f1fd9c0dec 100644 --- a/tests/pytest/query/queryError.py +++ b/tests/pytest/query/queryError.py @@ -41,18 +41,17 @@ class TDTestCase: ('2020-05-13 10:00:00.002', 3, 'third') dev_002 VALUES('2020-05-13 10:00:00.003', 1, 'first'), ('2020-05-13 10:00:00.004', 2, 'second'), ('2020-05-13 10:00:00.005', 3, 'third')""") - # query first .. as .. - tdSql.error("select first(*) as one from st") + tdSql.error("select first(*) as one from st") # query last .. as .. - tdSql.error("select last(*) as latest from st") + tdSql.error("select last(*) as latest from st") # query last row .. as .. - tdSql.error("select last_row as latest from st") + tdSql.error("select last_row as latest from st") # query distinct on normal colnum - tdSql.error("select distinct tagtype from st") + tdSql.error("select distinct tagtype from st") # query .. order by non-time field tdSql.error("select * from st order by name") diff --git a/tests/pytest/query/queryNormal.py b/tests/pytest/query/queryNormal.py index 442661f72a..814c627d89 100644 --- a/tests/pytest/query/queryNormal.py +++ b/tests/pytest/query/queryNormal.py @@ -28,17 +28,20 @@ class TDTestCase: print("==============step1") - tdSql.execute("create table stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 binary(10), t3 nchar(10))") - tdSql.execute("insert into tb1 using stb1 tags(1,'tb1', '表1') values ('2020-04-18 15:00:00.000', 1, 0.1), ('2020-04-18 15:00:01.000', 2, 0.1)") - tdSql.execute("insert into tb2 using stb1 tags(2,'tb2', '表2') values ('2020-04-18 15:00:02.000', 3, 2.1), ('2020-04-18 15:00:03.000', 4, 2.2)") - - # inner join --- bug + tdSql.execute( + "create table stb1 (ts timestamp, c1 int, c2 float) tags(t1 int, t2 binary(10), t3 nchar(10))") + tdSql.execute( + "insert into tb1 using stb1 tags(1,'tb1', '表1') values ('2020-04-18 15:00:00.000', 1, 0.1), ('2020-04-18 15:00:01.000', 2, 0.1)") + tdSql.execute( + "insert into tb2 using stb1 tags(2,'tb2', '表2') values ('2020-04-18 15:00:02.000', 3, 2.1), ('2020-04-18 15:00:03.000', 4, 2.2)") + + # inner join --- bug tdSql.query("select * from tb1 a, tb2 b where a.ts = b.ts") tdSql.checkRows(1) # join 3 tables -- bug exists tdSql.query("select stb_t.ts, stb_t.dscrption, stb_t.temperature, stb_p.id, stb_p.dscrption, stb_p.pressure,stb_v.velocity from stb_p, stb_t, stb_v where stb_p.ts=stb_t.ts and stb_p.ts=stb_v.ts and stb_p.id = stb_t.id") - + # query show stable tdSql.query("show stables") tdSql.checkRows(1) @@ -51,15 +54,15 @@ class TDTestCase: tdSql.query("select count(*) from stb1") tdSql.checkData(0, 0, 4) - # query first + # query first tdSql.query("select first(*) from stb1") tdSql.checkData(0, 1, 1) - - # query last + + # query last tdSql.query("select last(*) from stb1") tdSql.checkData(0, 1, 4) - # query last_row + # query last_row tdSql.query("select last_row(*) from stb1") tdSql.checkData(0, 1, 4) @@ -70,7 +73,7 @@ class TDTestCase: # query first ... as tdSql.query("select first(*) as begin from stb1") tdSql.checkData(0, 1, 1) - + # query last ... as tdSql.query("select last(*) as end from stb1") tdSql.checkData(0, 1, 4) @@ -93,7 +96,7 @@ class TDTestCase: # query ... alias for table ---- bug tdSql.query("select t.ts from tb1 t") - tdSql.checkRows(2) + tdSql.checkRows(2) # query ... tbname tdSql.query("select tbname from stb1") diff --git a/tests/pytest/random-test/random-test-multi-threading-3.py b/tests/pytest/random-test/random-test-multi-threading-3.py index c7b39ca1a1..db85ce2fe0 100644 --- a/tests/pytest/random-test/random-test-multi-threading-3.py +++ b/tests/pytest/random-test/random-test-multi-threading-3.py @@ -13,7 +13,7 @@ import sys import random -import threading +from threading import Thread, Event from util.log import * from util.cases import * @@ -23,15 +23,15 @@ from util.dnodes import * last_tb = "" last_stb = "" written = 0 +last_timestamp = 0 -class Test (threading.Thread): - def __init__(self, threadId, name): - threading.Thread.__init__(self) +class Test (Thread): + def __init__(self, threadId, name, events): + Thread.__init__(self) self.threadId = threadId self.name = name - - self.threadLock = threading.Lock() + self.dataEvent, self.dbEvent, self.queryEvent = events def create_table(self): tdLog.info("create_table") @@ -47,7 +47,7 @@ class Test (threading.Thread): try: tdSql.execute( - 'create table %s (ts timestamp, speed int)' % + 'create table %s (ts timestamp, speed int, c2 nchar(10))' % current_tb) last_tb = current_tb written = 0 @@ -58,21 +58,28 @@ class Test (threading.Thread): tdLog.info("insert_data") global last_tb global written + global last_timestamp if (last_tb == ""): tdLog.info("no table, create first") self.create_table() + start_time = 1500000000000 + tdLog.info("will insert data to table") for i in range(0, 10): insertRows = 1000 tdLog.info("insert %d rows to %s" % (insertRows, last_tb)) for j in range(0, insertRows): - ret = tdSql.execute( - 'insert into %s values (now + %dm, %d)' % - (last_tb, j, j)) + if (last_tb == ""): + tdLog.info("no table, return") + return + tdSql.execute( + 'insert into %s values (%d + %da, %d, "test")' % + (last_tb, start_time, last_timestamp, last_timestamp)) written = written + 1 + last_timestamp = last_timestamp + 1 def query_data(self): tdLog.info("query_data") @@ -89,6 +96,7 @@ class Test (threading.Thread): global last_tb global last_stb global written + global last_timestamp current_stb = "stb%d" % int(round(time.time() * 1000)) @@ -106,11 +114,15 @@ class Test (threading.Thread): "create table %s using %s tags (1, '表1')" % (current_tb, last_stb)) last_tb = current_tb - tdSql.execute( - "insert into %s values (now, 27, '我是nchar字符串')" % - last_tb) - written = written + 1 + written = 0 + start_time = 1500000000000 + + tdSql.execute( + "insert into %s values (%d+%da, 27, '我是nchar字符串')" % + (last_tb, start_time, last_timestamp)) + written = written + 1 + last_timestamp = last_timestamp + 1 def drop_stable(self): tdLog.info("drop_stable") @@ -152,7 +164,6 @@ class Test (threading.Thread): last_tb = "" written = 0 - def query_data_from_stable(self): tdLog.info("query_data_from_stable") global last_stb @@ -164,7 +175,6 @@ class Test (threading.Thread): tdLog.info("will query data from super table") tdSql.execute('select * from %s' % last_stb) - def reset_query_cache(self): tdLog.info("reset_query_cache") global last_tb @@ -182,15 +192,16 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) + tdDnodes.start(1) + tdSql.prepare() last_tb = "" last_stb = "" written = 0 - tdDnodes.start(1) - tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb + global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -198,16 +209,15 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - last_tb = "" - written = 0 tdDnodes.start(1) tdSql.prepare() + last_tb = "" + last_stb = "" + written = 0 def run(self): dataOp = { 1: self.insert_data, - 2: self.query_data, - 3: self.query_data_from_stable, } dbOp = { @@ -229,26 +239,33 @@ class Test (threading.Thread): if (self.threadId == 1): while True: - self.threadLock.acquire() + self.dataEvent.wait() tdLog.notice("first thread") - randDataOp = random.randint(1, 3) - dataOp.get(randDataOp , lambda: "ERROR")() - self.threadLock.release() + randDataOp = random.randint(1, 1) + dataOp.get(randDataOp, lambda: "ERROR")() + self.dataEvent.clear() + self.queryEvent.clear() + self.dbEvent.set() elif (self.threadId == 2): while True: + self.dbEvent.wait() tdLog.notice("second thread") - self.threadLock.acquire() randDbOp = random.randint(1, 9) dbOp.get(randDbOp, lambda: "ERROR")() - self.threadLock.release() + self.dbEvent.clear() + self.dataEvent.clear() + self.queryEvent.set() + elif (self.threadId == 3): while True: + self.queryEvent.wait() tdLog.notice("third thread") - self.threadLock.acquire() randQueryOp = random.randint(1, 9) queryOp.get(randQueryOp, lambda: "ERROR")() - self.threadLock.release() + self.queryEvent.clear() + self.dbEvent.clear() + self.dataEvent.set() class TDTestCase: @@ -259,13 +276,19 @@ class TDTestCase: def run(self): tdSql.prepare() - test1 = Test(1, "data operation") - test2 = Test(2, "db operation") - test2 = Test(3, "query operation") + events = [Event() for _ in range(3)] + events[0].set() + events[1].clear() + events[1].clear() + + test1 = Test(1, "data operation", events) + test2 = Test(2, "db operation", events) + test3 = Test(3, "query operation", events) test1.start() test2.start() test3.start() + test1.join() test2.join() test3.join() diff --git a/tests/pytest/random-test/random-test-multi-threading.py b/tests/pytest/random-test/random-test-multi-threading.py index d887b714ba..7d1a8a155d 100644 --- a/tests/pytest/random-test/random-test-multi-threading.py +++ b/tests/pytest/random-test/random-test-multi-threading.py @@ -23,6 +23,7 @@ from util.dnodes import * last_tb = "" last_stb = "" written = 0 +last_timestamp = 0 class Test (threading.Thread): @@ -47,7 +48,7 @@ class Test (threading.Thread): try: tdSql.execute( - 'create table %s (ts timestamp, speed int)' % + 'create table %s (ts timestamp, speed int, c1 nchar(10))' % current_tb) last_tb = current_tb written = 0 @@ -58,21 +59,28 @@ class Test (threading.Thread): tdLog.info("insert_data") global last_tb global written + global last_timestamp if (last_tb == ""): tdLog.info("no table, create first") self.create_table() + start_time = 1500000000000 + tdLog.info("will insert data to table") for i in range(0, 10): insertRows = 1000 tdLog.info("insert %d rows to %s" % (insertRows, last_tb)) for j in range(0, insertRows): - ret = tdSql.execute( - 'insert into %s values (now + %dm, %d)' % - (last_tb, j, j)) + if (last_tb == ""): + tdLog.info("no table, return") + return + tdSql.execute( + 'insert into %s values (%d + %da, %d, "test")' % + (last_tb, start_time, last_timestamp, last_timestamp)) written = written + 1 + last_timestamp = last_timestamp + 1 def query_data(self): tdLog.info("query_data") @@ -89,6 +97,7 @@ class Test (threading.Thread): global last_tb global last_stb global written + global last_timestamp current_stb = "stb%d" % int(round(time.time() * 1000)) @@ -106,11 +115,15 @@ class Test (threading.Thread): "create table %s using %s tags (1, '表1')" % (current_tb, last_stb)) last_tb = current_tb - tdSql.execute( - "insert into %s values (now, 27, '我是nchar字符串')" % - last_tb) - written = written + 1 + written = 0 + start_time = 1500000000000 + + tdSql.execute( + "insert into %s values (%d+%da, 27, '我是nchar字符串')" % + (last_tb, start_time, last_timestamp)) + written = written + 1 + last_timestamp = last_timestamp + 1 def drop_stable(self): tdLog.info("drop_stable") @@ -131,7 +144,7 @@ class Test (threading.Thread): tdDnodes.stop(1) tdDnodes.start(1) - tdLog.sleep(5) +# tdLog.sleep(5) def force_restart_database(self): tdLog.info("force_restart_database") @@ -140,7 +153,7 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.start(1) - tdLog.sleep(10) +# tdLog.sleep(10) def drop_table(self): tdLog.info("drop_table") @@ -154,7 +167,6 @@ class Test (threading.Thread): last_tb = "" written = 0 - def query_data_from_stable(self): tdLog.info("query_data_from_stable") global last_stb @@ -166,7 +178,6 @@ class Test (threading.Thread): tdLog.info("will query data from super table") tdSql.execute('select * from %s' % last_stb) - def reset_query_cache(self): tdLog.info("reset_query_cache") global last_tb @@ -174,7 +185,7 @@ class Test (threading.Thread): tdLog.info("reset query cache") tdSql.execute("reset query cache") - tdLog.sleep(1) +# tdLog.sleep(1) def reset_database(self): tdLog.info("reset_database") @@ -184,15 +195,16 @@ class Test (threading.Thread): tdDnodes.forcestop(1) tdDnodes.deploy(1) + tdDnodes.start(1) + tdSql.prepare() last_tb = "" last_stb = "" written = 0 - tdDnodes.start(1) - tdSql.prepare() def delete_datafiles(self): tdLog.info("delete_data_files") global last_tb + global last_stb global written dnodesDir = tdDnodes.getDnodesRootDir() @@ -200,11 +212,12 @@ class Test (threading.Thread): deleteCmd = 'rm -rf %s' % dataDir os.system(deleteCmd) - last_tb = "" - written = 0 tdDnodes.start(1) - tdLog.sleep(10) +# tdLog.sleep(10) tdSql.prepare() + last_tb = "" + last_stb = "" + written = 0 def run(self): dataOp = { @@ -230,7 +243,7 @@ class Test (threading.Thread): self.threadLock.acquire() tdLog.notice("first thread") randDataOp = random.randint(1, 3) - dataOp.get(randDataOp , lambda: "ERROR")() + dataOp.get(randDataOp, lambda: "ERROR")() self.threadLock.release() elif (self.threadId == 2): diff --git a/tests/pytest/random-test/random-test.py b/tests/pytest/random-test/random-test.py index a8ff4d81d1..855cabdedd 100644 --- a/tests/pytest/random-test/random-test.py +++ b/tests/pytest/random-test/random-test.py @@ -112,7 +112,6 @@ class Test: tdSql.execute('drop table %s' % self.last_stb) self.last_stb = "" - def query_data_from_stable(self): tdLog.info("query_data_from_stable") if (self.last_stb == ""): @@ -122,20 +121,21 @@ class Test: tdLog.info("will query data from super table") tdSql.execute('select * from %s' % self.last_stb) - def restart_database(self): tdLog.info("restart_databae") tdDnodes.stop(1) tdDnodes.start(1) tdLog.sleep(5) - def force_restart_database(self): tdLog.info("force_restart_database") tdDnodes.forcestop(1) tdDnodes.start(1) tdLog.sleep(5) tdSql.prepare() + self.last_tb = "" + self.last_stb = "" + self.written = 0 def drop_table(self): tdLog.info("drop_table") @@ -159,6 +159,9 @@ class Test: tdDnodes.start(1) tdLog.sleep(5) tdSql.prepare() + self.last_tb = "" + self.last_stb = "" + self.written = 0 def delete_datafiles(self): tdLog.info("delete_datafiles") @@ -173,6 +176,9 @@ class Test: tdDnodes.start(1) tdLog.sleep(10) tdSql.prepare() + self.last_tb = "" + self.last_stb = "" + self.written = 0 class TDTestCase: diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 4c839d87a3..50d054a301 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -160,7 +160,7 @@ class TDDnode: self.cfg("logDir", self.logDir) self.cfg("numOfLogLines", "100000000") self.cfg("mnodeEqualVnodeNum", "0") - self.cfg("clog", "1") + self.cfg("walLevel", "1") self.cfg("statusInterval", "1") self.cfg("numOfTotalVnodes", "64") self.cfg("numOfMnodes", "3") diff --git a/tests/pytest/valgrind-test.sh b/tests/pytest/valgrind-test.sh index 55bb03c966..bf42cd59cd 100755 --- a/tests/pytest/valgrind-test.sh +++ b/tests/pytest/valgrind-test.sh @@ -1,42 +1,42 @@ #!/bin/bash # insert -python3 ./test.py -g -f insert/basic.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/int.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/float.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/bigint.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/bool.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/double.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/smallint.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/tinyint.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/binary.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/date.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/nchar.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f insert/multi.py -python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/basic.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/int.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/float.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/bigint.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/bool.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/double.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/smallint.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/tinyint.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/binary.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/date.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/nchar.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f insert/multi.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 # table -python3 ./test.py -g -f table/column_name.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f table/column_num.py -python3 ./test.py -g -s && sleep 1 -python3 ./test.py -g -f table/db_table.py -python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f table/column_name.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f table/column_num.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f table/db_table.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 # import -python3 ./test.py -g -f import_merge/importDataLastSub.py -python3 ./test.py -g -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py -g -f import_merge/importDataLastSub.py +PYTHONMALLOC=malloc python3 ./test.py -g -s && sleep 1 #tag -python3 ./test.py $1 -f tag_lite/filter.py -python3 ./test.py $1 -s && sleep 1 +PYTHONMALLOC=malloc python3 ./test.py $1 -f tag_lite/filter.py +PYTHONMALLOC=malloc python3 ./test.py $1 -s && sleep 1 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 ee41335110..cfd992db3a 100644 --- a/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync.sim +++ b/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync.sim @@ -2,11 +2,11 @@ # 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-15d) and new data(now+15d), control data rows in order to save in cache, not falling disc +# 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-16d, now+16d +# step 6: insert two data rows: now-21d, now-41d # step 7: restart dnode2, waiting sync end -# expect: in dnode2, the files 1840 and 1842 will be removed +# expect: in dnode2, the files 1837 and 1839 will be removed system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 @@ -14,10 +14,10 @@ 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/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 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 @@ -39,11 +39,6 @@ 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 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 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 @@ -64,16 +59,16 @@ sql connect print ============== step2: start dnode2/dnode3 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 dnode3 -s start sql create dnode $hostname2 -#sql create dnode $hostname3 +sql create dnode $hostname3 sleep 3000 $totalTableNum = 1 $sleepTimer = 3000 $db = db -sql create database $db replica 1 cache 1 +sql create database $db replica 2 cache 1 sql use $db # create table , insert data @@ -82,7 +77,7 @@ sql create table $stb (ts timestamp, c1 double) tags(t1 int) $rowNum = 130000 $tblNum = $totalTableNum $totalRows = 0 -#$tsStart = 1420041600000 +$tsStart = 1577808000000 # 2020-01-01 00:00:00.000 # insert over 2M data in order to falling disc, generate one file $i = 0 @@ -102,19 +97,24 @@ while $i < $tblNum endw sql select count(*) from $stb -sleep 1000 -print data00 $data00 -if $data00 != $totalRows then - return -1 +print rows:$rows data00:$data00 +if $rows != 1 then + return -1 endi +if $data00 == 0 then + return -1 +endi + +$totalRows = $data00 + print ============== step3: insert old data(now-15d) and new data(now+15d), control data rows in order to save in cache, not falling disc -sql insert into $tb values ( now - 15d , -15 ) -sql insert into $tb values ( now + 15d , 15 ) +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 +system sh/exec.sh -n dnode2 -s stop -x SIGINT sleep $sleepTimer wait_dnode2_offline: @@ -153,48 +153,14 @@ if $data00 != $totalRows then endi print ============== step5: insert two data rows: now-16d, now+16d, -sql insert into $tb values ( now - 16d , -16 ) -sql insert into $tb values ( now + 16d , 16 ) +sql insert into $tb values ( now - 21d , -21 ) +sql insert into $tb values ( now - 41d , -41 ) $totalRows = $totalRows + 2 -return 1 - - - -print ============== step5: restart dnode2, waiting sync end -system sh/exec.sh -n dnode2 -s start -sleep 3000 - -wait_dnode2_ready: -sql show dnodes -if $rows != 3 then - sleep 2000 - goto wait_dnode2_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 -#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 $dnode2Status != ready then - sleep 2000 - goto wait_dnode2_ready -endi - -sleep $sleepTimer -# check using select sql select count(*) from $stb print data00 $data00 if $data00 != $totalRows then return -1 endi -print ============== step6: in dnode2, the files 1840 and 1842 will be removed -# how check in script ??? \ No newline at end of file +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/ diff --git a/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync_second.sim b/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync_second.sim new file mode 100644 index 0000000000..80a050f883 --- /dev/null +++ b/tests/script/unique/arbitrator/dn2_mn1_cache_file_sync_second.sim @@ -0,0 +1,52 @@ +# 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 +# expect: in dnode2, the files 1837 and 1839 will be removed + +sql connect +sleep 3000 + +print ============== step7: restart dnode2, waiting sync end +system sh/exec.sh -n dnode2 -s start +sleep 3000 + +wait_dnode2_ready: +sql show dnodes +if $rows != 3 then + sleep 2000 + goto wait_dnode2_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 +#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 $dnode2Status != ready then + sleep 2000 + goto wait_dnode2_ready +endi + +sleep 1000 +# check using select +$db = db +$stb = stb +sql use $db +sql select count(*) from $stb +print data00 $data00, should equal to dn2_mn1_cache_file_sync.sim output +#if $data00 != $totalRows then +# return -1 +#endi + +print ============== step8: please check there should be 1 file in sim/dnode2/data/vnode/vnode2/tsdb/data/, and 1 file sim/dnode3/data/vnode/vnode2/tsdb/data/ 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 34d7981e8a..ef6954d4ee 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim @@ -23,28 +23,39 @@ 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 200 +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 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 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 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 20 -system sh/cfg.sh -n dnode2 -c offlineThreshold -v 20 -system sh/cfg.sh -n dnode3 -c offlineThreshold -v 20 -system sh/cfg.sh -n dnode4 -c offlineThreshold -v 20 -system sh/cfg.sh -n dnode5 -c offlineThreshold -v 20 +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 @@ -63,9 +74,9 @@ sql connect print ============== step2: start dnode2/dnode3 and add into cluster, then create database, create table , and insert data system sh/exec.sh -n dnode2 -s start system sh/exec.sh -n dnode3 -s start -sleep 1000 sql create dnode $hostname2 sql create dnode $hostname3 +sleep 3000 $rowNum = 100 $tblNum = 16 @@ -151,7 +162,7 @@ endi # return -1 #endi -sleep 30000 +sleep 15000 wait_drop: sql show dnodes @@ -174,22 +185,36 @@ endi if $dnode2Status != ready then return -1 endi +if $dnode3Status != null then + return -1 +endi if $dnode4Status != ready then return -1 endi - -print ============== step5: start dnode5 and add into cluster , drop database -sql drop database $db -sleep 1000 -system sh/exec.sh -n dnode5 -s start -sql create dnode $hostname5 +print ============== step4-1: restart dnode3, adn add into cluster +system rm -rf ../../sim/dnode3 sleep 3000 -wait_dnode5: + +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 arbitrator -v $arbitrator +system sh/cfg.sh -n dnode3 -c offlineThreshold -v 10 +system sh/cfg.sh -n dnode3 -c enableCoreFile -v 1 + +system sh/exec.sh -n dnode3 -s start +sql create dnode $hostname3 +sleep 3000 + +wait_dnode3_ready: sql show dnodes +print rows: $rows if $rows != 4 then sleep 3000 - goto wait_dnode5 + 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 @@ -198,6 +223,7 @@ print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 $dnode1Status = $data4_1 $dnode2Status = $data4_2 +$dnode3Status = $data4_3 $dnode4Status = $data4_4 $dnode5Status = $data4_5 @@ -207,6 +233,9 @@ endi if $dnode2Status != ready then return -1 endi +if $dnode3Status != null then + return -1 +endi if $dnode4Status != ready then return -1 endi @@ -214,10 +243,58 @@ if $dnode5Status != ready then return -1 endi +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +print ============== step5: start dnode5 and add into cluster , drop database +sql drop database $db +sleep 1000 +system sh/exec.sh -n dnode5 -s start +sql create dnode $hostname5 +sleep 3000 +wait_dnode5: +sql show dnodes +if $rows != 5 then + sleep 3000 + goto wait_dnode5 +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 +$dnode4Status = $data4_4 +$dnode5Status = $data4_5 +$dnode6Status = $data4_6 + +if $dnode1Status != ready then + return -1 +endi +if $dnode2Status != ready then + return -1 +endi +if $dnode3Status != null then + return -1 +endi +if $dnode4Status != ready then + return -1 +endi +if $dnode5Status != ready then + return -1 +endi +if $dnode6Status != ready then + return -1 +endi print ============== step6: create database and table until not free vnodes $rowNum = 100 -$tblNum = 24 +$tblNum = 32 $totalRows = 0 $tsStart = 1420041600000 @@ -259,8 +336,9 @@ if $data00 != $totalRows then return -1 endi -print ============== step7: drop dnode3, and system should prompt cannot drop dnodes -sql_error drop dnode $hostname3 -print ============== step8: add one new table, and system should prompt 'need more dnode' +print ============== step7: drop dnode $hostname5, system should prompt "DB error: no enough dnodes" +sql_error drop dnode $hostname5 +print error: $error +print ============== step8: create table tb_more using $stb tags( 1000 ), system should prompt 'DB error: no enough dnodes' sql_error create table tb_more using $stb tags( 1000 ) - +print error: $error diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim b/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim index 8b75bba29b..09654ca8a9 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim @@ -89,11 +89,8 @@ if $data00 != $totalRows then return -1 endi - - - -print ============== step2-1: start dnode2 for falling disc, then restart dnode2, and check rows -system sh/exec.sh -n dnode2 -s stop +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 wait_dnode2_offline_0: sql show dnodes @@ -151,10 +148,6 @@ if $data00 != $totalRows then endi - - - - print ============== step3: start dnode3 and add into cluster , then alter replica from 1 to 2, and waiting sync system sh/exec.sh -n dnode3 -s start sql create dnode $hostname3 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim new file mode 100644 index 0000000000..c156d7d55c --- /dev/null +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim @@ -0,0 +1,273 @@ +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/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 dnode1 -c walLevel -v 2 +system sh/cfg.sh -n dnode2 -c walLevel -v 2 +system sh/cfg.sh -n dnode3 -c walLevel -v 2 +system sh/cfg.sh -n dnode4 -c walLevel -v 2 + +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 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 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 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 + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1, only deploy mnode +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 +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +sql create dnode $hostname2 +sql create dnode $hostname3 +sql create dnode $hostname4 +sleep 3000 + +$totalTableNum = 100 +$sleepTimer = 3000 + +$db = db +sql create database $db replica 3 maxTables $totalTableNum +sql use $db + +# create table , insert data +$stb = stb +sql create table $stb (ts timestamp, c1 int) tags(t1 int) +$rowNum = 100 +$tblNum = $totalTableNum +$totalRows = 0 +$tsStart = 1420041600000 + +$i = 0 +while $i < $tblNum + $tb = tb . $i + sql create table $tb using $stb tags( $i ) + + $x = 0 + while $x < $rowNum + $ts = $tsStart + $x + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 1a , $x ) ( $ts + 2a , $x ) ( $ts + 3a , $x ) ( $ts + 4a , $x ) ( $ts + 5a , $x ) ( $ts + 6a , $x ) ( $ts + 7a , $x ) ( $ts + 8a , $x ) ( $ts + 9a , $x ) ( $ts + 10a , $x ) ( $ts + 11a , $x ) ( $ts + 12a , $x ) ( $ts + 13a , $x ) ( $ts + 14a , $x ) ( $ts + 15a , $x ) ( $ts + 16a , $x ) ( $ts + 17a , $x ) ( $ts + 18a , $x ) ( $ts + 19a , $x ) ( $ts + 20a , $x ) ( $ts + 21a , $x ) ( $ts + 22a , $x ) ( $ts + 23a , $x ) ( $ts + 24a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 35a , $x ) ( $ts + 36a , $x ) ( $ts + 37a , $x ) ( $ts + 38a , $x ) ( $ts + 39a , $x ) ( $ts + 40a , $x ) ( $ts + 41a , $x ) ( $ts + 42a , $x ) ( $ts + 43a , $x ) ( $ts + 44a , $x ) ( $ts + 45a , $x ) ( $ts + 46a , $x ) ( $ts + 47a , $x ) ( $ts + 48a , $x ) ( $ts + 49a , $x ) ( $ts + 50a , $x ) ( $ts + 51a , $x ) ( $ts + 52a , $x ) ( $ts + 53a , $x ) ( $ts + 54a , $x ) ( $ts + 55a , $x ) ( $ts + 56a , $x ) ( $ts + 57a , $x ) ( $ts + 58a , $x ) ( $ts + 59a , $x ) + $x = $x + 60 + endw + $totalRows = $totalRows + $x + print info: inserted $x rows into $tb and totalRows: $totalRows + $i = $i + 1 +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 +system sh/exec.sh -n dnode4 -s stop -x SIGINT +sleep $sleepTimer +wait_dnode4_offline_0: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode4_offline_0 +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 $dnode4Status != offline then + sleep 2000 + goto wait_dnode4_offline_0 +endi + +wait_dnode4_vgroup_offline: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode4_vgroup_offline +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 +$dnode4Vtatus = $data4_2 +$dnode3Vtatus = $data7_2 + +if $dnode4Vtatus != offline then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi +if $dnode3Vtatus != master then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi + + +system rm -rf ../../../sim/dnode4/data/vnode/* +sleep 1000 + +print ============== step4: restart dnode4, waiting sync end +system sh/exec.sh -n dnode4 -s start +sleep $sleepTimer +wait_dnode4_reready: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode4_reready +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 $dnode4Status != ready then + sleep 2000 + goto wait_dnode4_reready +endi + +wait_dnode4_vgroup_slave: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode4_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 +$dnode4Vtatus = $data4_2 +$dnode3Vtatus = $data7_2 + +print dnode4Vtatus: $dnode4Vtatus +print dnode3Vtatus: $dnode3Vtatus +if $dnode4Vtatus != slave then + sleep 2000 + goto wait_dnode4_vgroup_slave +endi +if $dnode3Vtatus != master then + sleep 2000 + goto wait_dnode4_vgroup_slave +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 +sleep $sleepTimer + +wait_dnode23_offline: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode23_offline +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 $dnode2Status != offline then + sleep 2000 + goto wait_dnode23_offline +endi +if $dnode3Status != offline then + sleep 2000 + goto wait_dnode23_offline +endi +if $dnode4Status != ready then + sleep 2000 + goto wait_dnode23_offline +endi + +wait_dnode4_vgroup_master: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode4_vgroup_master +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 +$dnode4Vtatus = $data4_2 +$dnode3Vtatus = $data7_2 + +print dnode4Vtatus: $dnode4Vtatus +print dnode3Vtatus: $dnode3Vtatus +if $dnode4Vtatus != master then + sleep 2000 + goto wait_dnode4_vgroup_master +endi +if $dnode3Vtatus != offline then + sleep 2000 + goto wait_dnode4_vgroup_master +endi + +# check using select +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +sql insert into $tb values ( now , 20000 ) ( now + 1a, 20001 ) ( now + 2a, 20002 ) +$totalRows = $totalRows + 3 + +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_nomaster.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim new file mode 100644 index 0000000000..b6a2b7e1d5 --- /dev/null +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim @@ -0,0 +1,269 @@ +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/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 dnode1 -c walLevel -v 2 +system sh/cfg.sh -n dnode2 -c walLevel -v 2 +system sh/cfg.sh -n dnode3 -c walLevel -v 2 +system sh/cfg.sh -n dnode4 -c walLevel -v 2 + +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 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 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 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 + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1, only deploy mnode +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 +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +sql create dnode $hostname2 +sql create dnode $hostname3 +sql create dnode $hostname4 +sleep 3000 + +$totalTableNum = 100 +$sleepTimer = 3000 + +$db = db +sql create database $db replica 3 maxTables $totalTableNum +sql use $db + +# create table , insert data +$stb = stb +sql create table $stb (ts timestamp, c1 int) tags(t1 int) +$rowNum = 100 +$tblNum = $totalTableNum +$totalRows = 0 +$tsStart = 1420041600000 + +$i = 0 +while $i < $tblNum + $tb = tb . $i + sql create table $tb using $stb tags( $i ) + + $x = 0 + while $x < $rowNum + $ts = $tsStart + $x + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 1a , $x ) ( $ts + 2a , $x ) ( $ts + 3a , $x ) ( $ts + 4a , $x ) ( $ts + 5a , $x ) ( $ts + 6a , $x ) ( $ts + 7a , $x ) ( $ts + 8a , $x ) ( $ts + 9a , $x ) ( $ts + 10a , $x ) ( $ts + 11a , $x ) ( $ts + 12a , $x ) ( $ts + 13a , $x ) ( $ts + 14a , $x ) ( $ts + 15a , $x ) ( $ts + 16a , $x ) ( $ts + 17a , $x ) ( $ts + 18a , $x ) ( $ts + 19a , $x ) ( $ts + 20a , $x ) ( $ts + 21a , $x ) ( $ts + 22a , $x ) ( $ts + 23a , $x ) ( $ts + 24a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 35a , $x ) ( $ts + 36a , $x ) ( $ts + 37a , $x ) ( $ts + 38a , $x ) ( $ts + 39a , $x ) ( $ts + 40a , $x ) ( $ts + 41a , $x ) ( $ts + 42a , $x ) ( $ts + 43a , $x ) ( $ts + 44a , $x ) ( $ts + 45a , $x ) ( $ts + 46a , $x ) ( $ts + 47a , $x ) ( $ts + 48a , $x ) ( $ts + 49a , $x ) ( $ts + 50a , $x ) ( $ts + 51a , $x ) ( $ts + 52a , $x ) ( $ts + 53a , $x ) ( $ts + 54a , $x ) ( $ts + 55a , $x ) ( $ts + 56a , $x ) ( $ts + 57a , $x ) ( $ts + 58a , $x ) ( $ts + 59a , $x ) + $x = $x + 60 + endw + $totalRows = $totalRows + $x + print info: inserted $x rows into $tb and totalRows: $totalRows + $i = $i + 1 +endw + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +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 +wait_dnode4_offline_0: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode4_offline_0 +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 $dnode4Status != offline then + sleep 2000 + goto wait_dnode4_offline_0 +endi +if $dnode2Status != offline then + sleep 2000 + goto wait_dnode4_offline_0 +endi + +wait_dnode4_vgroup_offline: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode4_vgroup_offline +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 +$dnode4Vtatus = $data4_2 +$dnode3Vtatus = $data7_2 + +if $dnode4Vtatus != offline then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi +if $dnode3Vtatus != unsynced then + sleep 2000 + goto wait_dnode4_vgroup_offline +endi + +sql_error select count(*) from $stb +sql_error insert into $tb values (now, 9988) + +print ============== step4: restart dnode2, then create database with replica 2, and create table, insert data +system sh/exec.sh -n dnode2 -s start +sleep 3000 + +$totalTableNum = 100 +$sleepTimer = 3000 + +$db = db1 +sql create database $db replica 2 maxTables $totalTableNum +sql use $db + +# create table , insert data +$stb = stb +sql create table $stb (ts timestamp, c1 int) tags(t1 int) +$rowNum = 100 +$tblNum = $totalTableNum +$totalRows = 0 +$tsStart = 1420041600000 + +$i = 0 +while $i < $tblNum + $tb = tb . $i + sql create table $tb using $stb tags( $i ) + + $x = 0 + while $x < $rowNum + $ts = $tsStart + $x + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 1a , $x ) ( $ts + 2a , $x ) ( $ts + 3a , $x ) ( $ts + 4a , $x ) ( $ts + 5a , $x ) ( $ts + 6a , $x ) ( $ts + 7a , $x ) ( $ts + 8a , $x ) ( $ts + 9a , $x ) ( $ts + 10a , $x ) ( $ts + 11a , $x ) ( $ts + 12a , $x ) ( $ts + 13a , $x ) ( $ts + 14a , $x ) ( $ts + 15a , $x ) ( $ts + 16a , $x ) ( $ts + 17a , $x ) ( $ts + 18a , $x ) ( $ts + 19a , $x ) ( $ts + 20a , $x ) ( $ts + 21a , $x ) ( $ts + 22a , $x ) ( $ts + 23a , $x ) ( $ts + 24a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 25a , $x ) ( $ts + 26a , $x ) ( $ts + 27a , $x ) ( $ts + 28a , $x ) ( $ts + 29a , $x ) ( $ts + 30a , $x ) ( $ts + 31a , $x ) ( $ts + 32a , $x ) ( $ts + 33a , $x ) ( $ts + 34a , $x ) ( $ts + 35a , $x ) ( $ts + 36a , $x ) ( $ts + 37a , $x ) ( $ts + 38a , $x ) ( $ts + 39a , $x ) ( $ts + 40a , $x ) ( $ts + 41a , $x ) ( $ts + 42a , $x ) ( $ts + 43a , $x ) ( $ts + 44a , $x ) ( $ts + 45a , $x ) ( $ts + 46a , $x ) ( $ts + 47a , $x ) ( $ts + 48a , $x ) ( $ts + 49a , $x ) ( $ts + 50a , $x ) ( $ts + 51a , $x ) ( $ts + 52a , $x ) ( $ts + 53a , $x ) ( $ts + 54a , $x ) ( $ts + 55a , $x ) ( $ts + 56a , $x ) ( $ts + 57a , $x ) ( $ts + 58a , $x ) ( $ts + 59a , $x ) + $x = $x + 60 + endw + $totalRows = $totalRows + $x + print info: inserted $x rows into $tb and totalRows: $totalRows + $i = $i + 1 +endw + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +print ============== step5: stop dnode3 +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep $sleepTimer +wait_dnode3_offline_0: +sql show dnodes +if $rows != 4 then + sleep 2000 + goto wait_dnode3_offline_0 +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 + +$dnode1Status = $data4_1 +$dnode2Status = $data4_2 +$dnode3Status = $data4_3 +$dnode4Status = $data4_4 +print dnode1Status $dnode1Status +print dnode2Status $dnode2Status +print dnode3Status $dnode3Status +print dnode4Status $dnode4Status + +if $dnode3Status != offline then + sleep 2000 + goto wait_dnode3_offline_0 +endi +if $dnode2Status != ready then + sleep 2000 + goto wait_dnode3_offline_0 +endi + +wait_dnode2_vgroup_master: +sql show vgroups +if $rows != 1 then + sleep 2000 + goto wait_dnode2_vgroup_master +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 +$dnode3Vtatus = $data4_3 +$dnode2Vtatus = $data7_3 + +if $dnode3Vtatus != offline then + sleep 2000 + goto wait_dnode2_vgroup_master +endi +if $dnode2Vtatus != master then + sleep 2000 + 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 select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + + + + + + + + + + + + + + + + + diff --git a/tests/script/unique/arbitrator/insert_duplicationTs.sim b/tests/script/unique/arbitrator/insert_duplicationTs.sim new file mode 100644 index 0000000000..aae1f46180 --- /dev/null +++ b/tests/script/unique/arbitrator/insert_duplicationTs.sim @@ -0,0 +1,194 @@ +# 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-15d) and new data(now+15d), 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-16d, now+16d +# step 7: restart dnode2, waiting sync end +# expect: in dnode2, the files 1840 and 1842 will be removed + +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/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 +system sh/cfg.sh -n dnode3 -c walLevel -v 2 +system sh/cfg.sh -n dnode4 -c walLevel -v 2 + +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 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 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 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 + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1, only deploy mnode +system sh/exec.sh -n dnode1 -s start +sleep 3000 +sql connect + +print ============== step2: start dnode2/dnode3 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 +sql create dnode $hostname2 +sql create dnode $hostname3 +sleep 3000 + +$totalTableNum = 1 +$sleepTimer = 3000 + +$db = db +sql create database $db replica 2 cache 1 +sql use $db + +# create table , insert data +$stb = stb +sql create table $stb (ts timestamp, c1 double) tags(t1 int) +$rowNum = 130000 +$tblNum = $totalTableNum +$totalRows = 0 +$tsStart = 1577808000000 # 2020-01-01 00:00:00.000 + +# insert over 2M data in order to falling disc, generate one file +$i = 0 +while $i < $tblNum + $tb = tb . $i + sql create table $tb using $stb tags( $i ) + + $x = 0 + while $x < $rowNum +# $ts = $tsStart + $x + sql insert into $tb values ( now + 0s , $x ) ( now + 1s , $x ) ( now + 2s , $x ) ( now + 3s , $x ) ( now + 4s , $x ) ( now + 5s , $x ) ( now + 6s , $x ) ( now + 7s , $x ) ( now + 8s , $x ) ( now + 9s , $x ) + $x = $x + 10 + endw + $totalRows = $totalRows + $x + print info: inserted $x rows into $tb and totalRows: $totalRows + $i = $i + 1 +endw + +sql select count(*) from $stb +print rows:$rows data00:$data00 +if $rows != 1 then + return -1 +endi + +if $data00 == 0 then + return -1 +endi + +$totalRows = $data00 + +print ============== step3: insert old data(now-15d) and new data(now+15d), control data rows in order to save in cache, not falling disc +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 +sleep $sleepTimer + +wait_dnode2_offline: +sql show dnodes +if $rows != 3 then + sleep 2000 + goto wait_dnode2_offline +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 $dnode2Status != offline then + sleep 2000 + goto wait_dnode2_offline +endi +if $dnode3Status != ready then + sleep 2000 + goto wait_dnode2_offline +endi + +sleep $sleepTimer # waitting for move master vnode of dnode2 to dnode3 +# check using select +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows 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 ) +$totalRows = $totalRows + 2 + +print ============== step5: restart dnode2, waiting sync end +system sh/exec.sh -n dnode2 -s start +sleep 3000 + +wait_dnode2_ready: +sql show dnodes +if $rows != 3 then + sleep 2000 + goto wait_dnode2_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 +#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 $dnode2Status != ready then + sleep 2000 + goto wait_dnode2_ready +endi + +sleep $sleepTimer +# check using select +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + diff --git a/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim b/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim index dd6cdfdcf2..4a133d2aac 100644 --- a/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim +++ b/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim @@ -2,18 +2,42 @@ 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/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 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 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 dnode1 -c walLevel -v 2 +system sh/cfg.sh -n dnode2 -c walLevel -v 2 +system sh/cfg.sh -n dnode3 -c walLevel -v 2 +system sh/cfg.sh -n dnode4 -c walLevel -v 2 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 dnode1 -c numOfTotalVnodes -v 8 +system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 8 +system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 8 +system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 8 + +system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 +#system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 +#system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 +#system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4 + +system sh/cfg.sh -n dnode1 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode2 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode3 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode4 -c alternativeRole -v 0 + +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 @@ -22,21 +46,23 @@ system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator print ============== step0: start tarbitrator system sh/exec_tarbitrator.sh -s start - -print ============== step1: replica is 1, and start 1 dnode +print ============== step1: replica is 1, and start 1 dnode, then create tables and insert data system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect -$db = replica_db1 -sql create database $db replica 1 maxTables 4 +$totalTableNum = 12 + +$db = db +sql create database $db replica 1 maxTables $totalTableNum sql use $db # create table , insert data -$stb = repl_stb +$stb = stb sql create table $stb (ts timestamp, c1 int) tags(t1 int) $rowNum = 10 -$tblNum = 12 +$tblNum = $totalTableNum +$totalRows = $rowNum * $tblNum $ts0 = 1420041600000 $ts = $ts0 @@ -55,46 +81,136 @@ while $i < $tblNum $x = $x + 1 endw $i = $i + 1 + print $tb inserted rows: $x endw +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + print ============== step2: add 1 new dnode, expect balanced system sh/exec.sh -n dnode2 -s start sql create dnode $hostname2 +sleep 3000 # expect after balanced, 2 vondes in dnode1, 1 vonde in dnode2 -$x = 0 -show2: - $x = $x + 1 - sleep 2000 - if $x == 10 then - return -1 - endi - +wait_dnode2_ready: sql show dnodes -print dnode1 openVnodes $data2_1 -print dnode2 openVnodes $data2_2 -if $data2_1 != 2 then - goto show2 +if $rows != 2 then + sleep 2000 + goto wait_dnode2_ready endi -if $data2_2 != 1 then - goto show2 +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 + goto wait_dnode2_ready +endi +if $dnode2Status != ready then + sleep 2000 + goto wait_dnode2_ready endi -print ============== step4: stop dnode1, and wait dnode2 master +print ============== step3: stop dnode1/dnode2, modify cfg mpeers to 2, and restart dnode1/dnode2 system sh/exec.sh -n dnode1 -s stop +system sh/exec.sh -n dnode2 -s stop +sleep 3000 -$x = 0 -loop_wait: - $x = $x + 1 - sleep 2000 - if $x == 10 then - print ERROR: after dnode1 stop, dnode2 didn't become a master! - return -1 - endi -sql show mnodes -$dnodeRole = $data2_1 -print dnodeRole ==> $dnodeRole +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 2 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 2 -if $dnodeRole != master then - goto loop_wait +system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 + +system sh/cfg.sh -n dnode1 -c alternativeRole -v 1 +system sh/cfg.sh -n dnode2 -c alternativeRole -v 0 + +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sleep 5000 + + +print ============= step4: wait dnode ready +wait_dnode_ready: +sql show dnodes +if $rows != 2 then + sleep 2000 + goto wait_dnode_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 +#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 + goto wait_dnode_ready +endi +if $dnode2Status != ready then + sleep 2000 + goto wait_dnode_ready +endi + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + +print ============== step5: stop dnode1 +system sh/exec.sh -n dnode1 -s stop +sleep 3000 + +wait_dnode2_master: +sql show mnodes +if $rows != 2 then + sleep 2000 + goto wait_dnode2_master +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 $data2_1 != offline then + sleep 2000 + goto wait_dnode2_master +endi +if $data2_2 != master then + sleep 2000 + goto wait_dnode2_master +endi + +sql select count(*) from $stb +print data00 $data00 +if $data00 != $totalRows then + return -1 +endi + + diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 1230f52f63..f13e861907 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -538,7 +538,7 @@ int simExecuteRestFulCommand(SScript *script, char *command) { FILE *fp = popen(buf, "r"); if (fp == NULL) { simError("failed to execute %s", buf); - return TSDB_CODE_OTHERS; + return -1; } int mallocSize = 2000; @@ -642,7 +642,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { pSql = taos_query(script->taos, rest); ret = taos_errno(pSql); - if (ret == TSDB_CODE_TABLE_ALREADY_EXIST || ret == TSDB_CODE_DB_ALREADY_EXIST) { + if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) { simTrace("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret, tstrerror(ret)); ret = 0; break; @@ -791,8 +791,8 @@ bool simExecuteRestFulSqlCommand(SScript *script, char *rest) { int ret = -1; for (int attempt = 0; attempt < 10; ++attempt) { ret = simExecuteRestFulCommand(script, command); - if (ret == TSDB_CODE_TABLE_ALREADY_EXIST || - ret == TSDB_CODE_DB_ALREADY_EXIST) { + if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || + ret == TSDB_CODE_MND_DB_ALREADY_EXIST) { simTrace("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret, tstrerror(ret)); ret = 0; break;