diff --git a/.travis.yml b/.travis.yml index db6ce79703bab01e55227ad11a73395883a0ba1f..39fddc20c9f1c5c2b1369f248a3859c2bf6165cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,7 +64,7 @@ matrix: memError=`grep -m 1 'ERROR SUMMARY' mem-error-out.txt | awk '{print $4}'` if [ -n "$memError" ]; then - if [ "$memError" -gt 16 ] && [ "$defiMemError" -gt 0 ]; then + if [ "$memError" -gt 16 ] || [ "$defiMemError" -gt 0 ]; then echo -e "${RED} ## Memory errors number valgrind reports is $memError.\ Definitely lost is $defiMemError. More than our threshold! ## ${NC}" travis_terminate $memError diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index c16945bbcf35ac5247ecbb505aaf667870fc9d09..d46c32d73d823d52c739fc01d1d11c0a59f27168 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -196,14 +196,14 @@ STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex); SQueryInfo *tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex); int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo); -void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache); +void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache); STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta, SVgroupsInfo* vgroupList, SArray* pTagCols); STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo); int32_t tscAddSubqueryInfo(SSqlCmd *pCmd); -void tscFreeSubqueryInfo(SSqlCmd* pCmd); +void tscFreeQueryInfo(SSqlCmd* pCmd); void tscClearSubqueryInfo(SSqlCmd* pCmd); int tscGetSTableVgroupInfo(SSqlObj* pSql, int32_t clauseIndex); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 9cc6bcb364b76b8156a95cefb34afb27d41a599f..d6fb9279c7f1fd634795967d63829163689e1ed1 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -298,6 +298,7 @@ typedef struct STscObj { char sversion[TSDB_VERSION_LEN]; char writeAuth : 1; char superAuth : 1; + void* pMgmtConn; struct SSqlObj * pSql; struct SSqlObj * pHb; struct SSqlObj * sqlList; @@ -359,7 +360,7 @@ typedef struct SSqlStream { struct SSqlStream *prev, *next; } SSqlStream; -int32_t tscInitRpc(const char *user, const char *secret); +int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn); void tscInitMsgsFp(); int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion); @@ -427,9 +428,7 @@ int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo); char * tscGetResultColumnChr(SSqlRes *pRes, SQueryInfo *pQueryInfo, int32_t column); extern void * pVnodeConn; -extern void * pTscMgmtConn; extern void * tscCacheHandle; -extern int slaveIndex; extern void * tscTmr; extern void * tscQhandle; extern int tscKeepConn[]; diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index 29dec66ee82b5b97cba9125abd2e4e50d2cde726..05b7a2be1e7091259fc3549264ab0082212bcc71 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -281,7 +281,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J int code = taos_query(tscon, dst); if (code != 0) { - jniError("jobj:%p, conn:%p, code:%d, msg:%s", jobj, tscon, code, taos_errstr(tscon)); + jniError("jobj:%p, conn:%p, code:%s, msg:%s", jobj, tscon, tstrerror(code), taos_errstr(tscon)); free(dst); return JNI_TDENGINE_ERROR; } else { @@ -290,9 +290,9 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_executeQueryImp(J if (pSql->cmd.command == TSDB_SQL_INSERT) { affectRows = taos_affected_rows(tscon); - jniTrace("jobj:%p, conn:%p, code:%d, affect rows:%d", jobj, tscon, code, affectRows); + jniTrace("jobj:%p, conn:%p, code:%s, affect rows:%d", jobj, tscon, tstrerror(code), affectRows); } else { - jniTrace("jobj:%p, conn:%p, code:%d", jobj, tscon, code); + jniTrace("jobj:%p, conn:%p, code:%s", jobj, tscon, tstrerror(code)); } free(dst); diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 99d20de48bcf8b02590b5030a4432f5d83076998..b954db0734be2ffa14a01955fc50e1573bc33ee5 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -46,7 +46,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const pSql->signature = pSql; pSql->param = param; pSql->pTscObj = pObj; - pSql->maxRetry = 1; + pSql->maxRetry = TSDB_REPLICA_MAX_NUM; pSql->fp = fp; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 0e23236b1696222300666eb2d4cf1df0ecd7df83..8d6d9baca30b767ed70c49a41d478556627732cf 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -733,7 +733,7 @@ int32_t tscSetTableId(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SS */ if (size > 0) { if (strncasecmp(oldName, pTableMetaInfo->name, tListLen(pTableMetaInfo->name)) != 0) { - tscClearMeterMetaInfo(pTableMetaInfo, false); + tscClearTableMetaInfo(pTableMetaInfo, false); } } else { assert(pTableMetaInfo->pTableMeta == NULL); @@ -2477,6 +2477,10 @@ int32_t parseGroupbyClause(SQueryInfo* pQueryInfo, tVariantList* pList, SSqlCmd* return TSDB_CODE_SUCCESS; } + if (pQueryInfo->colList == NULL) { + pQueryInfo->colList = taosArrayInit(4, POINTER_BYTES); + } + pQueryInfo->groupbyExpr.numOfGroupCols = pList->nExpr; if (pList->nExpr > TSDB_MAX_TAGS) { return invalidSqlErrMsg(pQueryInfo->msg, msg1); @@ -4915,7 +4919,7 @@ void doAddGroupColumnForSubquery(SQueryInfo* pQueryInfo, int32_t tagIndex) { list.num = 1; list.ids[0] = colIndex; - insertResultField(pQueryInfo, size - 1, &list, pSchema->bytes, pSchema->type, pSchema->name, pExpr); + insertResultField(pQueryInfo, size, &list, pSchema->bytes, pSchema->type, pSchema->name, pExpr); SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, size - 1); pInfo->visible = false; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index b8c0274dd9a24d93157ff5d20fb5c565d31176a5..21f6f9d39006e0e6572f4bc764343029e1e0c391 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -190,6 +190,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { } int tscSendMsgToServer(SSqlObj *pSql) { + STscObj* pObj = pSql->pTscObj; SSqlCmd* pCmd = &pSql->cmd; char *pMsg = rpcMallocCont(pCmd->payloadLen); @@ -223,7 +224,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { .handle = pSql, .code = 0 }; - rpcSendRequest(pTscMgmtConn, &pSql->ipList, &rpcMsg); + rpcSendRequest(pObj->pMgmtConn, &pSql->ipList, &rpcMsg); } return TSDB_CODE_SUCCESS; @@ -2607,7 +2608,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { // if (pSql->fp != NULL && pSql->pStream == NULL) { // pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); -// tscFreeSubqueryInfo(pCmd); +// tscFreeQueryInfo(pCmd); // } tscTrace("%p allocate new pSqlObj:%p to get stable vgroupInfo", pSql, pNew); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index f70beab16625eb9c80e74b921bf6b66987ca0e62..4320e8f81b39d521bba29750d709e60709d33a4b 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -66,7 +66,8 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con return NULL; } - if (tscInitRpc(user, pass) != 0) { + void* pMgmtConn = NULL; + if (tscInitRpc(user, pass, &pMgmtConn) != 0) { terrno = TSDB_CODE_NETWORK_UNAVAIL; return NULL; } @@ -118,6 +119,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con strtolower(pObj->db, tmp); } + pObj->pMgmtConn = pMgmtConn; pthread_mutex_init(&pObj->mutex, NULL); SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9f7d4887d131d7bec873f409188b188f96e16245..d69068172937692ac95dd6ca64717b00e236321b 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -147,7 +147,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf retryDelay); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0); - tscClearMeterMetaInfo(pTableMetaInfo, true); + tscClearTableMetaInfo(pTableMetaInfo, true); tscSetRetryTimer(pStream, pStream->pSql, retryDelay); return; @@ -177,7 +177,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf if (pSql == NULL || numOfRows < 0) { int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision); tscError("%p stream:%p, retrieve data failed, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime); - tscClearMeterMetaInfo(pTableMetaInfo, true); + tscClearTableMetaInfo(pTableMetaInfo, true); tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime); return; @@ -259,7 +259,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf pStream->numOfRes); // release the metric/meter meta information reference, so data in cache can be updated - tscClearMeterMetaInfo(pTableMetaInfo, false); + tscClearTableMetaInfo(pTableMetaInfo, false); tscSetNextLaunchTimer(pStream, pSql); } } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 484c9e344eb0ac377605b9700b72c3a948c83159..f1b6065f1cc971d18fe4e5b99be4028a0e2608d5 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -33,16 +33,12 @@ // global, not configurable void * pVnodeConn; -void * pVMeterConn; -void * pTscMgmtConn; -void * pSlaveConn; void * tscCacheHandle; int slaveIndex; void * tscTmr; void * tscQhandle; void * tscCheckDiskUsageTmr; int tsInsertHeadSize; -char tsLastUser[TSDB_USER_LEN + 1]; int tscNumOfThreads; @@ -55,7 +51,7 @@ void tscCheckDiskUsage(void *para, void *unused) { taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr); } -int32_t tscInitRpc(const char *user, const char *secret) { +int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn) { SRpcInit rpcInit; char secretEncrypt[32] = {0}; taosEncryptPass((uint8_t *)secret, strlen(secret), secretEncrypt); @@ -81,14 +77,7 @@ int32_t tscInitRpc(const char *user, const char *secret) { } } - // not stop service, switch users - if (strcmp(tsLastUser, user) != 0 && pTscMgmtConn != NULL) { - tscTrace("switch user from %s to %s", user, tsLastUser); - rpcClose(pTscMgmtConn); - pTscMgmtConn = NULL; - } - - if (pTscMgmtConn == NULL) { + if (*pMgmtConn == NULL) { memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localIp = tsLocalIp; rpcInit.localPort = 0; @@ -101,11 +90,11 @@ int32_t tscInitRpc(const char *user, const char *secret) { rpcInit.idleTime = 2000; rpcInit.user = (char*)user; rpcInit.ckey = "key"; + rpcInit.spi = 1; rpcInit.secret = secretEncrypt; - strcpy(tsLastUser, user); - pTscMgmtConn = rpcOpen(&rpcInit); - if (pTscMgmtConn == NULL) { + *pMgmtConn = rpcOpen(&rpcInit); + if (*pMgmtConn == NULL) { tscError("failed to init connection to mgmt"); return -1; } @@ -219,11 +208,6 @@ void taos_cleanup() { pVnodeConn = NULL; } - if (pTscMgmtConn != NULL) { - rpcClose(pTscMgmtConn); - pTscMgmtConn = NULL; - } - taosTmrCleanUp(tscTmr); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index abdab2d9a162faf544dfbf7daa958b657aaa446f..e9ff558b92e45342c615ef8904a9236f913969ce 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -337,7 +337,7 @@ void tscResetSqlCmdObj(SSqlCmd* pCmd) { pCmd->pTableList= NULL; pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); - tscFreeSubqueryInfo(pCmd); + tscFreeQueryInfo(pCmd); } /* @@ -761,6 +761,8 @@ void tscCloseTscObj(STscObj* pObj) { tscFreeSqlObj(pSql); sem_destroy(&pSql->rspSem); + rpcClose(pObj->pMgmtConn); + pthread_mutex_destroy(&pObj->mutex); tscTrace("%p DB connection is closed", pObj); @@ -1459,7 +1461,7 @@ bool tscShouldFreeHeatBeat(SSqlObj* pHb) { void tscCleanSqlCmd(SSqlCmd* pCmd) { pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); - tscFreeSubqueryInfo(pCmd); + tscFreeQueryInfo(pCmd); uint32_t allocSize = pCmd->allocSize; char* allocPtr = pCmd->payload; @@ -1601,7 +1603,7 @@ int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) { return TSDB_CODE_SUCCESS; } -static void doClearSubqueryInfo(SQueryInfo* pQueryInfo) { +static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) { tscTagCondRelease(&pQueryInfo->tagCond); tscFieldInfoClear(&pQueryInfo->fieldsInfo); @@ -1611,6 +1613,11 @@ static void doClearSubqueryInfo(SQueryInfo* pQueryInfo) { tscColumnListDestroy(pQueryInfo->colList); memset(&pQueryInfo->colList, 0, sizeof(pQueryInfo->colList)); + if (pQueryInfo->groupbyExpr.columnInfo != NULL) { + taosArrayDestroy(pQueryInfo->groupbyExpr.columnInfo); + pQueryInfo->groupbyExpr.columnInfo = NULL; + } + pQueryInfo->tsBuf = tsBufDestory(pQueryInfo->tsBuf); tfree(pQueryInfo->defaultVal); @@ -1619,11 +1626,11 @@ static void doClearSubqueryInfo(SQueryInfo* pQueryInfo) { void tscClearSubqueryInfo(SSqlCmd* pCmd) { for (int32_t i = 0; i < pCmd->numOfClause; ++i) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, i); - doClearSubqueryInfo(pQueryInfo); + freeQueryInfoImpl(pQueryInfo); } } -void tscFreeSubqueryInfo(SSqlCmd* pCmd) { +void tscFreeQueryInfo(SSqlCmd* pCmd) { if (pCmd == NULL || pCmd->numOfClause == 0) { return; } @@ -1632,7 +1639,7 @@ void tscFreeSubqueryInfo(SSqlCmd* pCmd) { char* addr = (char*)pCmd - offsetof(SSqlObj, cmd); SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, i); - doClearSubqueryInfo(pQueryInfo); + freeQueryInfoImpl(pQueryInfo); tscClearAllTableMetaInfo(pQueryInfo, (const char*)addr, false); tfree(pQueryInfo); } @@ -1691,7 +1698,7 @@ void doRemoveTableMetaInfo(SQueryInfo* pQueryInfo, int32_t index, bool removeFro STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index); - tscClearMeterMetaInfo(pTableMetaInfo, removeFromCache); + tscClearTableMetaInfo(pTableMetaInfo, removeFromCache); free(pTableMetaInfo); int32_t after = pQueryInfo->numOfTables - index - 1; @@ -1713,13 +1720,18 @@ void tscClearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool tfree(pQueryInfo->pTableMetaInfo); } -void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache) { +void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache) { if (pTableMetaInfo == NULL) { return; } taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), removeFromCache); tfree(pTableMetaInfo->vgroupList); + + if (pTableMetaInfo->tagColList != NULL) { + taosArrayDestroy(pTableMetaInfo->tagColList); + pTableMetaInfo->tagColList = NULL; + } } void tscResetForNextRetrieve(SSqlRes* pRes) { diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index a19331c7067ce0cc6b7dfab7484a0eebf99b7b72..f770c8d38ff34252f4e5d70c5d9b11301e2fd03a 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -48,11 +48,9 @@ extern int32_t tsEnableCoreFile; extern int32_t tsTotalMemoryMB; extern int32_t tsVersion; -extern int tscEmbedded; - +extern int32_t tscEmbedded; extern int64_t tsMsPerDay[2]; - extern char tsMasterIp[]; extern char tsSecondIp[]; extern uint16_t tsMnodeDnodePort; @@ -61,94 +59,88 @@ extern uint16_t tsDnodeShellPort; extern uint16_t tsDnodeMnodePort; extern uint16_t tsSyncPort; -extern int tsStatusInterval; -extern int tsShellActivityTimer; -extern int tsVnodePeerHBTimer; -extern int tsMgmtPeerHBTimer; -extern int tsMeterMetaKeepTimer; -extern int tsMetricMetaKeepTimer; - -extern float tsNumOfThreadsPerCore; -extern float tsRatioOfQueryThreads; -extern char tsPublicIp[]; -extern char tsPrivateIp[]; -extern short tsNumOfVnodesPerCore; -extern short tsNumOfTotalVnodes; -extern short tsCheckHeaderFile; +extern int32_t tsStatusInterval; +extern int32_t tsShellActivityTimer; +extern int32_t tsVnodePeerHBTimer; +extern int32_t tsMgmtPeerHBTimer; +extern int32_t tsMeterMetaKeepTimer; +extern int32_t tsMetricMetaKeepTimer; + +extern float tsNumOfThreadsPerCore; +extern float tsRatioOfQueryThreads; +extern char tsPublicIp[]; +extern char tsPrivateIp[]; +extern int16_t tsNumOfVnodesPerCore; +extern int16_t tsNumOfTotalVnodes; extern uint32_t tsPublicIpInt; -extern short tsAffectedRowsMod; - -extern int tsSessionsPerVnode; -extern int tsAverageCacheBlocks; -extern int tsCacheBlockSize; -extern int tsRowsInFileBlock; -extern float tsFileBlockMinPercent; - -extern short tsNumOfBlocksPerMeter; -extern short tsCommitTime; // seconds -extern short tsCommitLog; -extern short tsAsyncLog; -extern short tsCompression; -extern short tsDaysPerFile; -extern int tsDaysToKeep; -extern int tsReplications; - -extern int tsNumOfMPeers; -extern int tsMaxShellConns; -extern int tsMaxTables; +extern int32_t tsMaxCacheSize; +extern int32_t tsSessionsPerVnode; +extern int16_t tsDaysPerFile; +extern int32_t tsDaysToKeep; +extern int32_t tsRowsInFileBlock; +extern int16_t tsCommitTime; // seconds +extern int32_t tsTimePrecision; +extern int16_t tsCompression; +extern int16_t tsCommitLog; +extern int32_t tsReplications; + +extern int16_t tsAffectedRowsMod; +extern int32_t tsNumOfMPeers; +extern int32_t tsMaxShellConns; +extern int32_t tsMaxTables; extern char tsLocalIp[]; extern char tsDefaultDB[]; extern char tsDefaultUser[]; extern char tsDefaultPass[]; -extern int tsMaxMeterConnections; -extern int tsMaxVnodeConnections; -extern int tsMaxMgmtConnections; - -extern int tsBalanceMonitorInterval; -extern int tsBalanceStartInterval; -extern int tsBalancePolicy; -extern int tsOfflineThreshold; -extern int tsMgmtEqualVnodeNum; - -extern int tsEnableHttpModule; -extern int tsEnableMonitorModule; -extern int tsRestRowLimit; -extern int tsCompressMsgSize; -extern int tsMaxSQLStringLen; -extern int tsMaxNumOfOrderedResults; +extern int32_t tsMaxMeterConnections; +extern int32_t tsMaxVnodeConnections; +extern int32_t tsMaxMgmtConnections; + +extern int32_t tsBalanceMonitorInterval; +extern int32_t tsBalanceStartInterval; +extern int32_t tsOfflineThreshold; +extern int32_t tsMgmtEqualVnodeNum; + +extern int32_t tsEnableHttpModule; +extern int32_t tsEnableMonitorModule; + +extern int32_t tsRestRowLimit; +extern int32_t tsMaxSQLStringLen; +extern int32_t tsCompressMsgSize; +extern int32_t tsMaxNumOfOrderedResults; extern char tsSocketType[4]; -extern int tsTimePrecision; -extern int tsMinSlidingTime; -extern int tsMinIntervalTime; -extern int tsMaxStreamComputDelay; -extern int tsStreamCompStartDelay; -extern int tsStreamCompRetryDelay; +extern int32_t tsMinSlidingTime; +extern int32_t tsMinIntervalTime; +extern int32_t tsMaxStreamComputDelay; +extern int32_t tsStreamCompStartDelay; +extern int32_t tsStreamCompRetryDelay; extern float tsStreamComputDelayRatio; // the delayed computing ration of the whole time window extern int tsProjectExecInterval; extern int64_t tsMaxRetentWindow; -extern char tsHttpIp[]; +extern char tsHttpIp[]; extern uint16_t tsHttpPort; -extern int tsHttpCacheSessions; -extern int tsHttpSessionExpire; -extern int tsHttpMaxThreads; -extern int tsHttpEnableCompress; -extern int tsHttpEnableRecordSql; -extern int tsTelegrafUseFieldNum; - -extern int tsTscEnableRecordSql; -extern int tsAnyIp; - -extern char tsMonitorDbName[]; -extern char tsInternalPass[]; -extern int tsMonitorInterval; - -extern int tsNumOfLogLines; +extern int32_t tsHttpCacheSessions; +extern int32_t tsHttpSessionExpire; +extern int32_t tsHttpMaxThreads; +extern int32_t tsHttpEnableCompress; +extern int32_t tsHttpEnableRecordSql; +extern int32_t tsTelegrafUseFieldNum; + +extern int32_t tsTscEnableRecordSql; +extern int32_t tsAnyIp; + +extern char tsMonitorDbName[]; +extern char tsInternalPass[]; +extern int32_t tsMonitorInterval; + +extern int32_t tsAsyncLog; +extern int32_t tsNumOfLogLines; extern int32_t ddebugFlag; extern int32_t mdebugFlag; extern int32_t cdebugFlag; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 4998d4351871179c3762b8a28fd4887d71a23458..5aa50677c9a5e6f03028c2d17f764ef2a4f85989 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -74,16 +74,15 @@ int32_t tsVnodePeerHBTimer = 1; // second int32_t tsMgmtPeerHBTimer = 1; // second int32_t tsMeterMetaKeepTimer = 7200; // second int32_t tsMetricMetaKeepTimer = 600; // second -int tsRpcTimer = 300; -int tsRpcMaxTime = 600; // seconds; +int32_t tsRpcTimer = 300; +int32_t tsRpcMaxTime = 600; // seconds; -float tsNumOfThreadsPerCore = 1.0; -float tsRatioOfQueryThreads = 0.5; -char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0}; -char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0}; +float tsNumOfThreadsPerCore = 1.0; +float tsRatioOfQueryThreads = 0.5; +char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0}; +char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0}; int16_t tsNumOfVnodesPerCore = 8; int16_t tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM; -int16_t tsCheckHeaderFile = 0; #ifdef _TD_ARM_32_ int32_t tsSessionsPerVnode = 100; @@ -91,26 +90,22 @@ int32_t tsSessionsPerVnode = 100; int32_t tsSessionsPerVnode = 1000; #endif -int32_t tsCacheBlockSize = 16384; // 256 columns -int32_t tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS; +int32_t tsMaxCacheSize = 64; //64M +int16_t tsDaysPerFile = 10; +int32_t tsDaysToKeep = 3650; +int32_t tsRowsInFileBlock = 4096; +int16_t tsCommitTime = 3600; // seconds +int32_t tsTimePrecision = TSDB_TIME_PRECISION_MILLI; +int16_t tsCompression = TSDB_MAX_COMPRESSION_LEVEL; +int16_t tsCommitLog = 1; +int32_t tsReplications = TSDB_REPLICA_MIN_NUM; + /** * Change the meaning of affected rows: * 0: affected rows not include those duplicate records * 1: affected rows include those duplicate records */ int16_t tsAffectedRowsMod = 0; - -int32_t tsRowsInFileBlock = 4096; -float tsFileBlockMinPercent = 0.05; - -int16_t tsNumOfBlocksPerMeter = 100; -int16_t tsCommitTime = 3600; // seconds -int16_t tsCommitLog = 1; -int16_t tsCompression = TSDB_MAX_COMPRESSION_LEVEL; -int16_t tsDaysPerFile = 10; -int32_t tsDaysToKeep = 3650; -int32_t tsReplications = TSDB_REPLICA_MIN_NUM; - int32_t tsNumOfMPeers = 3; int32_t tsMaxShellConns = 2000; int32_t tsMaxTables = 100000; @@ -125,15 +120,16 @@ int32_t tsMaxVnodeConnections = 10000; int32_t tsBalanceMonitorInterval = 2; // seconds int32_t tsBalanceStartInterval = 300; // seconds -int32_t tsBalancePolicy = 0; // 1-use sys.montor int32_t tsOfflineThreshold = 864000; // seconds 10days int32_t tsMgmtEqualVnodeNum = 4; int32_t tsEnableHttpModule = 1; int32_t tsEnableMonitorModule = 0; + int32_t tsRestRowLimit = 10240; int32_t tsMaxSQLStringLen = TSDB_MAX_SQL_LEN; +int32_t tsNumOfLogLines = 10000000; int32_t mdebugFlag = 135; int32_t sdbDebugFlag = 135; int32_t ddebugFlag = 131; @@ -146,7 +142,6 @@ int32_t qdebugFlag = 131; int32_t rpcDebugFlag = 131; int32_t uDebugFlag = 131; int32_t debugFlag = 131; -int tsNumOfLogLines = 10000000; // the maximum number of results for projection query on super table that are returned from // one virtual node, to order according to timestamp @@ -165,9 +160,6 @@ int32_t tsCompressMsgSize = -1; // use UDP by default[option: udp, tcp] char tsSocketType[4] = "udp"; -// time precision, millisecond by default -int32_t tsTimePrecision = TSDB_TIME_PRECISION_MILLI; - // 10 ms for sliding time, the value will changed in case of time precision changed int32_t tsMinSlidingTime = 10; @@ -747,11 +739,11 @@ static void doInitGlobalConfig() { taosInitConfigOption(cfg); cfg.option = "cache"; - cfg.ptr = &tsCacheBlockSize; + cfg.ptr = &tsMaxCacheSize; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 100; - cfg.maxValue = 1048576; + cfg.minValue = 1; + cfg.maxValue = 100000; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_BYTE; taosInitConfigOption(cfg); @@ -766,36 +758,6 @@ static void doInitGlobalConfig() { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); - cfg.option = "fileBlockMinPercent"; - cfg.ptr = &tsFileBlockMinPercent; - cfg.valType = TAOS_CFG_VTYPE_FLOAT; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; - cfg.minValue = 0; - cfg.maxValue = 1.0; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosInitConfigOption(cfg); - - cfg.option = "ablocks"; - cfg.ptr = &tsAverageCacheBlocks; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = TSDB_MIN_AVG_BLOCKS; - cfg.maxValue = TSDB_MAX_AVG_BLOCKS; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosInitConfigOption(cfg); - - cfg.option = "tblocks"; - cfg.ptr = &tsNumOfBlocksPerMeter; - cfg.valType = TAOS_CFG_VTYPE_INT16; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 32; - cfg.maxValue = 4096; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosInitConfigOption(cfg); - // login configs cfg.option = "defaultDB"; cfg.ptr = tsDefaultDB; diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index b476c866d99cb8d1e5375e88864e167a19122510..043e58cb35e34d4b6d5791322dcb9736f6250bf4 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -222,9 +222,6 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1) #define TSDB_REPLICA_MIN_NUM 1 -/* - * this is defined in CMakeList.txt - */ #define TSDB_REPLICA_MAX_NUM 3 #define TSDB_TBNAME_COLUMN_INDEX (-1) @@ -246,8 +243,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MIN_ROWS_IN_FILEBLOCK 200 #define TSDB_MAX_ROWS_IN_FILEBLOCK 500000 -#define TSDB_MIN_CACHE_BLOCK_SIZE 100 -#define TSDB_MAX_CACHE_BLOCK_SIZE 104857600 +#define TSDB_MIN_CACHE_BLOCK_SIZE 1 +#define TSDB_MAX_CACHE_BLOCK_SIZE 1000000 #define TSDB_MIN_CACHE_BLOCKS 100 #define TSDB_MAX_CACHE_BLOCKS 409600 diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 7b060b1c65d77f9d500a234adec3ab400dd1c890..5084199ac83bae38451e265067a757a3039a6685 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -99,71 +99,71 @@ TAOS_DEFINE_ERROR(TSDB_CODE_NOT_ACTIVE_TABLE, 0, 205, "not active tabl TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ID_MISMATCH, 0, 206, "table id mismatch") // dnode & mnode -TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 300, "no enough dnodes") -TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 301, "dnode already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 302, "dnode not exist") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 303, "no master") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 304, "no remove master") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 305, "invalid query id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 306, "invalid stream id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 307, "invalid connection") -TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 308, "sdb error") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_ENOUGH_DNODES, 0, 250, "no enough dnodes") +TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_ALREADY_EXIST, 0, 251, "dnode already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_NOT_EXIST, 0, 252, "dnode not exist") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_MASTER, 0, 253, "no master") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_REMOVE_MASTER, 0, 254, "no remove master") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 255, "invalid query id") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 256, "invalid stream id") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 257, "invalid connection") +TAOS_DEFINE_ERROR(TSDB_CODE_SDB_ERROR, 0, 258, "sdb error") // acct -TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 400, "accounts already exist") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 401, "invalid account") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 402, "invalid account parameter") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 403, "too many accounts") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 404, "too many users") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 405, "too many tables") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 406, "too many databases") -TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 407, "not enough time series") +TAOS_DEFINE_ERROR(TSDB_CODE_ACCT_ALREADY_EXIST, 0, 300, "accounts already exist") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 301, "invalid account") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT_PARAMETER, 0, 302, "invalid account parameter") +TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_ACCTS, 0, 303, "too many accounts") +TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_USERS, 0, 304, "too many users") +TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TABLES, 0, 305, "too many tables") +TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_DATABASES, 0, 306, "too many databases") +TAOS_DEFINE_ERROR(TSDB_CODE_TOO_MANY_TIME_SERIES, 0, 307, "not enough time series") // grant -TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 400, "auth failure") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 401, "no rights") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 402, "no write access") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 403, "no read access") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 404, "grant expired") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 405, "grant dnode limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 406, "grant account limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 407, "grant timeseries limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 408, "grant db limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 409, "grant user limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 410, "grant conn limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 411, "grant stream limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 412, "grant speed limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 413, "grant storage limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 414, "grant query time limited") -TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 415, "grant cpu limited") +TAOS_DEFINE_ERROR(TSDB_CODE_AUTH_FAILURE, 0, 350, "auth failure") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 351, "no rights") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_WRITE_ACCESS, 0, 352, "no write access") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_READ_ACCESS, 0, 353, "no read access") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 354, "grant expired") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DNODE_LIMITED, 0, 355, "grant dnode limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_ACCT_LIMITED, 0, 356, "grant account limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TIMESERIES_LIMITED, 0, 357, "grant timeseries limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_DB_LIMITED, 0, 358, "grant db limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_USER_LIMITED, 0, 359, "grant user limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CONN_LIMITED, 0, 360, "grant conn limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STREAM_LIMITED, 0, 361, "grant stream limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_SPEED_LIMITED, 0, 362, "grant speed limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_STORAGE_LIMITED, 0, 363, "grant storage limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_QUERYTIME_LIMITED, 0, 364, "grant query time limited") +TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 365, "grant cpu limited") // server -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 500, "invalid vgroup id") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VNODE_ID, 0, 501, "invalid vnode id") -TAOS_DEFINE_ERROR(TSDB_CODE_NOT_ACTIVE_VNODE, 0, 502, "not active vnode") -TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 503, "vg init failed") -TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 504, "server no diskspace") -TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 505, "server out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 506, "no disk permissions") -TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 507, "file corrupted") -TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 508, "memory corrupted") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VGROUP_ID, 0, 400, "invalid vgroup id") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VNODE_ID, 0, 401, "invalid vnode id") +TAOS_DEFINE_ERROR(TSDB_CODE_NOT_ACTIVE_VNODE, 0, 402, "not active vnode") +TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 403, "vg init failed") +TAOS_DEFINE_ERROR(TSDB_CODE_SERV_NO_DISKSPACE, 0, 404, "server no diskspace") +TAOS_DEFINE_ERROR(TSDB_CODE_SERV_OUT_OF_MEMORY, 0, 405, "server out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 406, "no disk permissions") +TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, 0, 407, "file corrupted") +TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 408, "memory corrupted") // client -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 601, "invalid client version") -TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 602, "client out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 603, "client no disk space") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 604, "invalid timestamp") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 605, "invalid sql") -TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 606, "query cache erased") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 607, "invalid query message") // failed to validate the sql expression msg by vnode -TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 608, "sorted res too many") // too many result for ordered super table projection query -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 609, "invalid handle") -TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 610, "query cancelled") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 611, "invalid ie") -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 612, "invalid value") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CLIENT_VERSION, 0, 451, "invalid client version") +TAOS_DEFINE_ERROR(TSDB_CODE_CLI_OUT_OF_MEMORY, 0, 452, "client out of memory") +TAOS_DEFINE_ERROR(TSDB_CODE_CLI_NO_DISKSPACE, 0, 453, "client no disk space") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIME_STAMP, 0, 454, "invalid timestamp") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SQL, 0, 455, "invalid sql") +TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CACHE_ERASED, 0, 456, "query cache erased") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_MSG, 0, 457, "invalid query message") // failed to validate the sql expression msg by vnode +TAOS_DEFINE_ERROR(TSDB_CODE_SORTED_RES_TOO_MANY, 0, 458, "sorted res too many") // too many result for ordered super table projection query +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QHANDLE, 0, 459, "invalid handle") +TAOS_DEFINE_ERROR(TSDB_CODE_QUERY_CANCELLED, 0, 460, "query cancelled") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_IE, 0, 461, "invalid ie") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_VALUE, 0, 462, "invalid value") // others -TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 700, "invalid file format") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_FILE_FORMAT, 0, 500, "invalid file format") #ifdef TAOS_ERROR_C diff --git a/src/mnode/inc/mgmtDef.h b/src/mnode/inc/mgmtDef.h index 5599ad2e4f19538d345107354a4dc09eb15793e7..6cbfc72e625ba5cd316d0c5ab14fae681ef141ee 100644 --- a/src/mnode/inc/mgmtDef.h +++ b/src/mnode/inc/mgmtDef.h @@ -29,32 +29,6 @@ struct SAcctObj; struct SUserObj; struct SMnodeObj; -typedef struct { - char acct[TSDB_USER_LEN]; - char db[TSDB_DB_NAME_LEN]; - uint32_t vgId; - int32_t maxSessions; - int32_t cacheBlockSize; - union { - int32_t totalBlocks; - float fraction; - } cacheNumOfBlocks; - int32_t daysPerFile; - int32_t daysToKeep1; - int32_t daysToKeep2; - int32_t daysToKeep; - int32_t commitTime; - int32_t rowsInFileBlock; - int16_t blocksPerTable; - int8_t compression; - int8_t commitLog; - int8_t replications; - int8_t repStrategy; - int8_t loadLatest; // load into mem or not - uint8_t precision; // time resolution - int8_t reserved[16]; -} SDbCfg; - typedef struct SDnodeObj { int32_t dnodeId; uint32_t privateIp; @@ -168,12 +142,30 @@ typedef struct SVgObj { SChildTableObj **tableList; } SVgObj; +typedef struct { + int64_t maxCacheSize; + int32_t maxTables; + int32_t daysPerFile; + int32_t daysToKeep; + int32_t daysToKeep1; + int32_t daysToKeep2; + int32_t minRowsPerFileBlock; // minimum rows per file block + int32_t maxRowsPerFileBlock; // maximum rows per file block + int32_t commitTime; + int8_t precision; + int8_t compression; + int8_t commitLog; + int8_t replications; + int8_t reserved[16]; +} SDbCfg; + typedef struct SDbObj { char name[TSDB_DB_NAME_LEN + 1]; - int8_t status; + char acct[TSDB_USER_LEN + 1]; int64_t createdTime; SDbCfg cfg; - int8_t reserved[15]; + int8_t status; + int8_t reserved[14]; int8_t updateEnd[1]; int32_t refCount; int32_t numOfVgroups; diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 1a24a9661baa199c38d2a57ce47f8bf596040b19..b3424ffd63fccaff77f24cb7c33b2acd93caf32e 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -54,7 +54,7 @@ static int32_t mgmtDbActionDestroy(SSdbOper *pOper) { static int32_t mgmtDbActionInsert(SSdbOper *pOper) { SDbObj *pDb = pOper->pObj; - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); pDb->pHead = NULL; pDb->pTail = NULL; @@ -67,7 +67,7 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) { mgmtDecAcctRef(pAcct); } else { - mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->cfg.acct); + mError("db:%s, acct:%s info not exist in sdb", pDb->name, pDb->acct); return TSDB_CODE_INVALID_ACCT; } @@ -76,7 +76,7 @@ static int32_t mgmtDbActionInsert(SSdbOper *pOper) { static int32_t mgmtDbActionDelete(SSdbOper *pOper) { SDbObj *pDb = pOper->pObj; - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); mgmtDropDbFromAcct(pAcct, pDb); mgmtDropAllChildTables(pDb); @@ -176,132 +176,108 @@ SDbObj *mgmtGetDbByTableId(char *tableId) { return (SDbObj *)sdbGetRow(tsDbSdb, db); } -static int32_t mgmtCheckDBParams(SCMCreateDbMsg *pCreate) { - if (pCreate->commitLog < 0 || pCreate->commitLog > 2) { - mError("invalid db option commitLog: %d, only 0-2 allowed", pCreate->commitLog); - return TSDB_CODE_INVALID_OPTION; +static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) { + if (pCfg->maxCacheSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->maxCacheSize > TSDB_MAX_CACHE_BLOCK_SIZE) { + mError("invalid db option maxCacheSize:%d valid range: [%d, %d]", pCfg->maxCacheSize, TSDB_MIN_CACHE_BLOCK_SIZE, + TSDB_MAX_CACHE_BLOCK_SIZE); } - if (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM) { - mError("invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM, - TSDB_REPLICA_MAX_NUM); + if (pCfg->maxTables < TSDB_MIN_TABLES_PER_VNODE || pCfg->maxTables > TSDB_MAX_TABLES_PER_VNODE) { + mError("invalid db option maxTables:%d valid range: [%d, %d]", pCfg->maxTables, TSDB_MIN_TABLES_PER_VNODE, + TSDB_MAX_TABLES_PER_VNODE); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) { - mError("invalid db option daysPerFile: %d valid range: [%d, %d]", pCreate->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE, + if (pCfg->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCfg->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) { + mError("invalid db option daysPerFile:%d valid range: [%d, %d]", pCfg->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE, TSDB_FILE_MAX_PARTITION_RANGE); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->daysToKeep1 > pCreate->daysToKeep2 || pCreate->daysToKeep2 > pCreate->daysToKeep) { - mError("invalid db option daystokeep1: %d, daystokeep2: %d, daystokeep: %d", pCreate->daysToKeep1, - pCreate->daysToKeep2, pCreate->daysToKeep); + if (pCfg->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCfg->daysToKeep1 < pCfg->daysPerFile) { + mError("invalid db option daystokeep:%d", pCfg->daysToKeep); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysToKeep1 < pCreate->daysPerFile) { - mError("invalid db option daystokeep: %d", pCreate->daysToKeep); + if (pCfg->daysToKeep2 > pCfg->daysToKeep || pCfg->daysToKeep2 < pCfg->daysToKeep1) { + mError("invalid db option daystokeep1:%d, daystokeep2:%d, daystokeep:%d", pCfg->daysToKeep1, + pCfg->daysToKeep2, pCfg->daysToKeep); + return TSDB_CODE_INVALID_OPTION; + } + + if (pCfg->minRowsPerFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) { + mError("invalid db option minRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->minRowsPerFileBlock, + TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->rowsInFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCreate->rowsInFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) { - mError("invalid db option rowsInFileBlock: %d valid range: [%d, %d]", pCreate->rowsInFileBlock, + if (pCfg->maxRowsPerFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) { + mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock, TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCreate->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) { - mError("invalid db option cacheBlockSize: %d valid range: [%d, %d]", pCreate->cacheBlockSize, - TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); + if (pCfg->maxRowsPerFileBlock < pCfg->minRowsPerFileBlock) { + mError("invalid db option minRowsPerFileBlock:%d maxRowsPerFileBlock:%d", pCfg->minRowsPerFileBlock, + pCfg->maxRowsPerFileBlock); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->maxSessions < TSDB_MIN_TABLES_PER_VNODE || pCreate->maxSessions > TSDB_MAX_TABLES_PER_VNODE) { - mError("invalid db option maxSessions: %d valid range: [%d, %d]", pCreate->maxSessions, TSDB_MIN_TABLES_PER_VNODE, - TSDB_MAX_TABLES_PER_VNODE); + if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCfg->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) { + mError("invalid db option commitTime:%d valid range: [%d, %d]", pCfg->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL, + TSDB_MAX_COMMIT_TIME_INTERVAL); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) { - mError("invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI, + if (pCfg->precision != TSDB_TIME_PRECISION_MILLI && pCfg->precision != TSDB_TIME_PRECISION_MICRO) { + mError("invalid db option timePrecision:%d valid value: [%d, %d]", pCfg->precision, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS || pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS) { - mError("invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction, 0, TSDB_MAX_AVG_BLOCKS); + if (pCfg->compression < TSDB_MIN_COMPRESSION_LEVEL || pCfg->compression > TSDB_MAX_COMPRESSION_LEVEL) { + mError("invalid db option compression:%d valid range: [%d, %d]", pCfg->compression, TSDB_MIN_COMPRESSION_LEVEL, + TSDB_MAX_COMPRESSION_LEVEL); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCreate->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) { - mError("invalid db option commitTime: %d valid range: [%d, %d]", pCreate->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL, - TSDB_MAX_COMMIT_TIME_INTERVAL); + if (pCfg->commitLog < 0 || pCfg->commitLog > 2) { + mError("invalid db option commitLog:%d, only 0-2 allowed", pCfg->commitLog); return TSDB_CODE_INVALID_OPTION; } - if (pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL) { - mError("invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL, - TSDB_MAX_COMPRESSION_LEVEL); + if (pCfg->replications < TSDB_REPLICA_MIN_NUM || pCfg->replications > TSDB_REPLICA_MAX_NUM) { + mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_REPLICA_MIN_NUM, + TSDB_REPLICA_MAX_NUM); return TSDB_CODE_INVALID_OPTION; } return TSDB_CODE_SUCCESS; } -static int32_t mgmtCheckDbParams(SCMCreateDbMsg *pCreate) { - // assign default parameters - if (pCreate->maxSessions < 0) pCreate->maxSessions = tsSessionsPerVnode; - if (pCreate->cacheBlockSize < 0) pCreate->cacheBlockSize = tsCacheBlockSize; - if (pCreate->daysPerFile < 0) pCreate->daysPerFile = tsDaysPerFile; - if (pCreate->daysToKeep < 0) pCreate->daysToKeep = tsDaysToKeep; - if (pCreate->daysToKeep1 < 0) pCreate->daysToKeep1 = pCreate->daysToKeep; - if (pCreate->daysToKeep2 < 0) pCreate->daysToKeep2 = pCreate->daysToKeep; - if (pCreate->commitTime < 0) pCreate->commitTime = tsCommitTime; - if (pCreate->compression < 0) pCreate->compression = tsCompression; - if (pCreate->commitLog < 0) pCreate->commitLog = tsCommitLog; - if (pCreate->replications < 0) pCreate->replications = tsReplications; // - if (pCreate->rowsInFileBlock < 0) pCreate->rowsInFileBlock = tsRowsInFileBlock; // - if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; // - - if (mgmtCheckDBParams(pCreate) != TSDB_CODE_SUCCESS) { - return TSDB_CODE_INVALID_OPTION; - } - - pCreate->cacheNumOfBlocks.totalBlocks = (int32_t)(pCreate->cacheNumOfBlocks.fraction * pCreate->maxSessions); - - if (pCreate->cacheNumOfBlocks.totalBlocks > TSDB_MAX_CACHE_BLOCKS) { - mTrace("invalid db option cacheNumOfBlocks: %d valid range: [%d, %d]", pCreate->cacheNumOfBlocks.totalBlocks, - TSDB_MIN_CACHE_BLOCKS, TSDB_MAX_CACHE_BLOCKS); - return TSDB_CODE_INVALID_OPTION; - } - - // calculate the blocks per table - if (pCreate->blocksPerTable < 0) { - pCreate->blocksPerTable = pCreate->cacheNumOfBlocks.totalBlocks / 4; - } - - if (pCreate->blocksPerTable > pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4) { - pCreate->blocksPerTable = pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4; - } - - if (pCreate->blocksPerTable < TSDB_MIN_AVG_BLOCKS) { - pCreate->blocksPerTable = TSDB_MIN_AVG_BLOCKS; - } - - return TSDB_CODE_SUCCESS; +static void mgmtSetDefaultDbCfg(SDbCfg *pCfg) { + if (pCfg->maxCacheSize < 0) pCfg->maxCacheSize = tsMaxCacheSize; + if (pCfg->maxTables < 0) pCfg->maxTables = tsSessionsPerVnode; + if (pCfg->daysPerFile < 0) pCfg->daysPerFile = tsDaysPerFile; + if (pCfg->daysToKeep < 0) pCfg->daysToKeep = tsDaysToKeep; + if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep; + if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep; + if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsRowsInFileBlock; + if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = pCfg->minRowsPerFileBlock * 2; + if (pCfg->commitTime < 0) pCfg->commitTime = tsCommitTime; + if (pCfg->precision < 0) pCfg->precision = tsTimePrecision; + if (pCfg->compression < 0) pCfg->compression = tsCompression; + if (pCfg->commitLog < 0) pCfg->commitLog = tsCommitLog; + if (pCfg->replications < 0) pCfg->replications = tsReplications; } static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { int32_t code = acctCheck(pAcct, ACCT_GRANT_DB); - if (code != 0) { - return code; - } + if (code != 0) return code; SDbObj *pDb = mgmtGetDb(pCreate->db); if (pDb != NULL) { - mgmtDecDbRef(pDb); - + mgmtDecDbRef(pDb); if (pCreate->ignoreExist) { return TSDB_CODE_SUCCESS; } else { @@ -309,50 +285,41 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate) { } } - code = mgmtCheckDbParams(pCreate); - if (code != TSDB_CODE_SUCCESS) return code; - - assert(pCreate->daysToKeep1 <= pCreate->daysToKeep2 && pCreate->daysToKeep2 <= pCreate->daysToKeep); - code = grantCheck(TSDB_GRANT_DB); - if (code != 0) { - return code; - } + if (code != 0) return code; pDb = calloc(1, sizeof(SDbObj)); - strncpy(pDb->name, pCreate->db, TSDB_DB_NAME_LEN); - strncpy(pCreate->acct, pAcct->user, TSDB_USER_LEN); - - pDb->createdTime = taosGetTimestampMs(); - + strncpy(pDb->acct, pAcct->user, TSDB_USER_LEN); + pDb->createdTime = taosGetTimestampMs(); pDb->cfg = (SDbCfg) { - .vgId = pCreate->vgId, - .precision = pCreate->precision, - .maxSessions = pCreate->maxSessions, - .cacheNumOfBlocks.totalBlocks = pCreate->cacheNumOfBlocks.totalBlocks, - .rowsInFileBlock = pCreate->rowsInFileBlock, - .commitLog = pCreate->commitLog, - .replications = pCreate->replications, - .daysPerFile = pCreate->daysPerFile, - .cacheBlockSize = pCreate->cacheBlockSize, - .commitTime = pCreate->commitTime, - .blocksPerTable = pCreate->blocksPerTable, - .compression = pCreate->compression, - .daysToKeep = pCreate->daysToKeep, - .daysToKeep1 = pCreate->daysToKeep1, - .daysToKeep2 = pCreate->daysToKeep2, - .loadLatest = pCreate->loadLatest, - .repStrategy = pCreate->repStrategy, + .maxCacheSize = 64,//(int64_t)pCreate->cacheBlockSize * pCreate->cacheNumOfBlocks.totalBlocks, + .maxTables = pCreate->maxSessions, + .daysPerFile = pCreate->daysPerFile, + .daysToKeep = pCreate->daysToKeep, + .daysToKeep1 = pCreate->daysToKeep1, + .daysToKeep2 = pCreate->daysToKeep2, + .minRowsPerFileBlock = pCreate->rowsInFileBlock * 1, + .maxRowsPerFileBlock = pCreate->rowsInFileBlock * 2, + .commitTime = pCreate->commitTime, + .precision = pCreate->precision, + .compression = pCreate->compression, + .commitLog = pCreate->commitLog, + .replications = pCreate->replications }; - - strncpy(pDb->cfg.db, pCreate->db, TSDB_DB_NAME_LEN); - strncpy(pDb->cfg.acct, pCreate->acct, TSDB_USER_LEN); + + mgmtSetDefaultDbCfg(&pDb->cfg); + + code = mgmtCheckDbCfg(&pDb->cfg); + if (code != TSDB_CODE_SUCCESS) { + tfree(pDb); + return code; + } SSdbOper oper = { - .type = SDB_OPER_GLOBAL, - .table = tsDbSdb, - .pObj = pDb, + .type = SDB_OPER_GLOBAL, + .table = tsDbSdb, + .pObj = pDb, .rowSize = sizeof(SDbObj), }; @@ -498,19 +465,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) pShow->bytes[cols] = 4; pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "cache(b)"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_FLOAT; - strcpy(pSchema[cols].name, "ablocks"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = 2; - pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; - strcpy(pSchema[cols].name, "tblocks"); + strcpy(pSchema[cols].name, "cache(Mb)"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -625,27 +580,15 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void * if (strcmp(pUser->user, "root") == 0) { #endif pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pDb->cfg.maxSessions; // table num can be created should minus 1 - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pDb->cfg.rowsInFileBlock; - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pDb->cfg.cacheBlockSize; + *(int32_t *)pWrite = pDb->cfg.maxTables; // table num can be created should minus 1 cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; -#ifdef _TD_ARM_32_ - *(int32_t *)pWrite = (pDb->cfg.cacheNumOfBlocks.totalBlocks * 1.0 / (pDb->cfg.maxSessions)); -#else - *(float *)pWrite = (pDb->cfg.cacheNumOfBlocks.totalBlocks * 1.0 / (pDb->cfg.maxSessions)); -#endif + *(int32_t *)pWrite = pDb->cfg.minRowsPerFileBlock; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pDb->cfg.blocksPerTable; + *(int32_t *)pWrite = pDb->cfg.maxCacheSize; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -747,7 +690,7 @@ static void mgmtProcessCreateDbMsg(SQueuedMsg *pMsg) { static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { SDbCfg newCfg = pDb->cfg; int32_t daysToKeep = htonl(pAlter->daysToKeep); - int32_t maxSessions = htonl(pAlter->maxSessions); + int32_t maxTables = htonl(pAlter->maxSessions); int8_t replications = pAlter->replications; terrno = TSDB_CODE_SUCCESS; @@ -755,25 +698,28 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) { mTrace("db:%s, daysToKeep:%d change to %d", pDb->name, pDb->cfg.daysToKeep, daysToKeep); newCfg.daysToKeep = daysToKeep; - } else if (replications > 0 && replications != pDb->cfg.replications) { + } + + if (replications > 0 && replications != pDb->cfg.replications) { mTrace("db:%s, replica:%d change to %d", pDb->name, pDb->cfg.replications, replications); if (replications < TSDB_REPLICA_MIN_NUM || replications > TSDB_REPLICA_MAX_NUM) { mError("invalid db option replica: %d valid range: %d--%d", replications, TSDB_REPLICA_MIN_NUM, TSDB_REPLICA_MAX_NUM); terrno = TSDB_CODE_INVALID_OPTION; } newCfg.replications = replications; - } else if (maxSessions > 0 && maxSessions != pDb->cfg.maxSessions) { - mTrace("db:%s, tables:%d change to %d", pDb->name, pDb->cfg.maxSessions, maxSessions); - if (maxSessions < TSDB_MIN_TABLES_PER_VNODE || maxSessions > TSDB_MAX_TABLES_PER_VNODE) { - mError("invalid db option tables: %d valid range: %d--%d", maxSessions, TSDB_MIN_TABLES_PER_VNODE, TSDB_MAX_TABLES_PER_VNODE); + } + + if (maxTables > 0 && maxTables != pDb->cfg.maxTables) { + mTrace("db:%s, tables:%d change to %d", pDb->name, pDb->cfg.maxTables, maxTables); + if (maxTables < TSDB_MIN_TABLES_PER_VNODE || maxTables > TSDB_MAX_TABLES_PER_VNODE) { + mError("invalid db option tables: %d valid range: %d--%d", maxTables, TSDB_MIN_TABLES_PER_VNODE, TSDB_MAX_TABLES_PER_VNODE); terrno = TSDB_CODE_INVALID_OPTION; } - if (maxSessions < pDb->cfg.maxSessions) { - mError("invalid db option tables: %d should larger than original:%d", maxSessions, pDb->cfg.maxSessions); + if (maxTables < pDb->cfg.maxTables) { + mError("invalid db option tables: %d should larger than original:%d", maxTables, pDb->cfg.maxTables); terrno = TSDB_CODE_INVALID_OPTION; } - newCfg.maxSessions = maxSessions; - } else { + newCfg.maxTables = maxTables; } return newCfg; diff --git a/src/mnode/src/mgmtShell.c b/src/mnode/src/mgmtShell.c index 927bbe4ed1d1055ca8da8ee1422e09b253403631..f2545f43db4262f7059d96cd739b54e79eaf4584 100644 --- a/src/mnode/src/mgmtShell.c +++ b/src/mnode/src/mgmtShell.c @@ -364,7 +364,7 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *pMsg) { } static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey) { - *spi = 0; + *spi = 1; *encrypt = 0; *ckey = 0; diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index cad559b11036a7cb0bb37413b0a8a5398a81a479..0edb11972497b760042965f71f5ddf711d79d85c 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -106,9 +106,9 @@ static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) { } mgmtDecDbRef(pDb); - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); if (pAcct == NULL) { - mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->cfg.acct); + mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); return TSDB_CODE_INVALID_ACCT; } mgmtDecAcctRef(pAcct); @@ -148,9 +148,9 @@ static int32_t mgmtChildTableActionDelete(SSdbOper *pOper) { } mgmtDecDbRef(pDb); - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); if (pAcct == NULL) { - mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->cfg.acct); + mError("ctable:%s, acct:%s not exists", pTable->info.tableId, pDb->acct); return TSDB_CODE_INVALID_ACCT; } mgmtDecAcctRef(pAcct); @@ -929,7 +929,7 @@ static int32_t mgmtAddSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, SSc pStable->numOfColumns += ncols; pStable->sversion++; - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); if (pAcct != NULL) { pAcct->acctInfo.numOfTimeSeries += (ncols * pStable->numOfTables); mgmtDecAcctRef(pAcct); @@ -966,7 +966,7 @@ static int32_t mgmtDropSuperTableColumn(SDbObj *pDb, SSuperTableObj *pStable, ch int32_t schemaSize = sizeof(SSchema) * (pStable->numOfTags + pStable->numOfColumns); pStable->schema = realloc(pStable->schema, schemaSize); - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); if (pAcct != NULL) { pAcct->acctInfo.numOfTimeSeries -= pStable->numOfTables; mgmtDecAcctRef(pAcct); @@ -1218,7 +1218,7 @@ static void mgmtProcessSuperTableVgroupMsg(SQueuedMsg *pMsg) { } static void mgmtProcessDropSuperTableRsp(SRpcMsg *rpcMsg) { - mTrace("drop stable rsp received, handle:%p code:%d", rpcMsg->handle, rpcMsg->code); + mTrace("drop stable rsp received, handle:%p code:%s", rpcMsg->handle, tstrerror(rpcMsg->code)); } static void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableObj *pTable) { @@ -1505,7 +1505,7 @@ static int32_t mgmtAddNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, SSc pTable->numOfColumns += ncols; pTable->sversion++; - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); if (pAcct != NULL) { pAcct->acctInfo.numOfTimeSeries += ncols; mgmtDecAcctRef(pAcct); @@ -1539,7 +1539,7 @@ static int32_t mgmtDropNormalTableColumn(SDbObj *pDb, SChildTableObj *pTable, ch pTable->numOfColumns--; pTable->sversion++; - SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); + SAcctObj *pAcct = mgmtGetAcct(pDb->acct); if (pAcct != NULL) { pAcct->acctInfo.numOfTimeSeries--; mgmtDecAcctRef(pAcct); @@ -1876,7 +1876,7 @@ static void mgmtProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { // not implemented yet static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg) { - mTrace("alter table rsp received, handle:%p code:%d", rpcMsg->handle, rpcMsg->code); + mTrace("alter table rsp received, handle:%p code:%s", rpcMsg->handle, tstrerror(rpcMsg->code)); } static void mgmtProcessMultiTableMetaMsg(SQueuedMsg *pMsg) { diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index bec4dbe83a8718712f815bd3ce354d0515756fd0..e053ea66f5c0ca9073231e8484cce7107682def7 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -71,14 +71,14 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) { pVgroup->prev = NULL; pVgroup->next = NULL; - int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxSessions; - pVgroup->tableList = calloc(pDb->cfg.maxSessions, sizeof(SChildTableObj *)); + int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; + pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *)); if (pVgroup->tableList == NULL) { mError("vgroup:%d, failed to malloc(size:%d) for the tableList of vgroups", pVgroup->vgId, size); return -1; } - pVgroup->idPool = taosInitIdPool(pDb->cfg.maxSessions); + pVgroup->idPool = taosInitIdPool(pDb->cfg.maxTables); if (pVgroup->idPool == NULL) { mError("vgroup:%d, failed to taosInitIdPool for vgroups", pVgroup->vgId); tfree(pVgroup->tableList); @@ -146,15 +146,15 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool); SDbObj *pDb = pVgroup->pDb; if (pDb != NULL) { - if (pDb->cfg.maxSessions != oldTables) { - mPrint("vgroup:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxSessions); - taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxSessions); - int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxSessions; + if (pDb->cfg.maxTables != oldTables) { + mPrint("vgroup:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables); + taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables); + int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size); } } - mTrace("vgroup:%d, is updated, tables:%d numOfVnode:%d", pVgroup->vgId, pDb->cfg.maxSessions, pVgroup->numOfVnodes); + mTrace("vgroup:%d, is updated, tables:%d numOfVnode:%d", pVgroup->vgId, pDb->cfg.maxTables, pVgroup->numOfVnodes); return TSDB_CODE_SUCCESS; } @@ -511,7 +511,7 @@ void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { pVgroup->numOfTables++; } - if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxSessions) + if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) mgmtAddVgroupIntoDbTail(pVgroup); } @@ -522,7 +522,7 @@ void mgmtRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { pVgroup->numOfTables--; } - if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxSessions) + if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) mgmtAddVgroupIntoDbTail(pVgroup); } @@ -535,16 +535,16 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { SMDVnodeCfg *pCfg = &pVnode->cfg; pCfg->vgId = htonl(pVgroup->vgId); - pCfg->maxTables = htonl(pDb->cfg.maxSessions); - pCfg->maxCacheSize = htobe64((int64_t)pDb->cfg.cacheBlockSize * pDb->cfg.cacheNumOfBlocks.totalBlocks); - pCfg->maxCacheSize = htobe64(-1); - pCfg->minRowsPerFileBlock = htonl(-1); - pCfg->maxRowsPerFileBlock = htonl(-1); + pCfg->maxTables = htonl(pDb->cfg.maxTables); + pCfg->maxCacheSize = htobe64(pDb->cfg.maxCacheSize); + pCfg->maxCacheSize = htobe64(-1); //TODO + pCfg->minRowsPerFileBlock = htonl(-1); //TODO + pCfg->maxRowsPerFileBlock = htonl(-1); //TODO pCfg->daysPerFile = htonl(pDb->cfg.daysPerFile); pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep1); pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2); pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep); - pCfg->daysToKeep = htonl(-1); + pCfg->daysToKeep = htonl(-1); //TODO pCfg->commitTime = htonl(pDb->cfg.commitTime); pCfg->precision = pDb->cfg.precision; pCfg->compression = pDb->cfg.compression; diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index 4980c9c804159053f9e9e4ad7484d2c3f2ba65a5..fbe6757ccbcdea09bce8d8feabfae95e2691a549 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -13,11 +13,13 @@ * along with this program. If not, see . */ -#include "gcHandle.h" +#define _DEFAULT_SOURCE +#include "os.h" #include "cJSON.h" +#include "httpLog.h" +#include "gcHandle.h" #include "gcJson.h" #include "taosdef.h" -#include "httpLog.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; diff --git a/src/plugins/http/src/gcJson.c b/src/plugins/http/src/gcJson.c index 8f596337146a3937df72287f332917b3bffa21ac..09990c123e6b3c0716bc38252689fbfa1ae46394 100644 --- a/src/plugins/http/src/gcJson.c +++ b/src/plugins/http/src/gcJson.c @@ -13,10 +13,8 @@ * along with this program. If not, see . */ -#include -#include -#include - +#define _DEFAULT_SOURCE +#include "os.h" #include "gcHandle.h" #include "gcJson.h" #include "httpJson.h" diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index adbf980f972c0160b2087cfbd25c6ecc8f083539..594f51e275a6db6ecd21307c0e24808656ed779b 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -13,12 +13,14 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" +#include "tkey.h" #include "tutil.h" #include "http.h" #include "httpLog.h" #include "httpHandle.h" -#include "tkey.h" + #define KEY_DES_4 4971256377704625728L bool httpParseBasicAuthToken(HttpContext *pContext, char *token, int len) { diff --git a/src/plugins/http/src/httpCode.c b/src/plugins/http/src/httpCode.c index 230c0de2e09046eb9384817498b13adea4ddb42c..9ec07fd8511a5a240ff4cc7faa7d7b19e2081073 100644 --- a/src/plugins/http/src/httpCode.c +++ b/src/plugins/http/src/httpCode.c @@ -13,6 +13,9 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE + + char* httpMsg[] = { "success", // 0 "http server is not online", // 1 diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index 529714c8e69dc18797114b5a8963f3ebff687e79..4eaff3660a87f373cc23d278c65caa8f718aab2b 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -13,21 +13,18 @@ * along with this program. If not, see . */ -#include -#include -#include -#include - -#include "http.h" -#include "httpCode.h" -#include "httpHandle.h" -#include "httpResp.h" -#include "shash.h" +#define _DEFAULT_SOURCE +#include "os.h" #include "taos.h" #include "tglobal.h" #include "tsocket.h" #include "ttimer.h" +#include "shash.h" +#include "http.h" #include "httpLog.h" +#include "httpCode.h" +#include "httpHandle.h" +#include "httpResp.h" void httpToLowerUrl(char* url) { /*ignore case */ diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index fa74f857b37cd66c88d432894effdbcd33b399f0..cbca19b57f0b2875ec08688ba9bcfe09a36c9116 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -13,20 +13,15 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include - +#define _DEFAULT_SOURCE +#include "os.h" +#include "taosmsg.h" +#include "taoserror.h" #include "http.h" +#include "httpLog.h" #include "httpCode.h" #include "httpJson.h" #include "httpResp.h" -#include "taosmsg.h" -#include "httpLog.h" -#include "taoserror.h" #define MAX_NUM_STR_SZ 25 diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index c0a5c6d7ea256d067925bb832f294cfb4d0031ae..0e2e7b3f8563331ef3be243ea688d904aaf4b477 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -13,14 +13,14 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE +#include "os.h" +#include "taoserror.h" +#include "taosmsg.h" +#include "httpLog.h" #include "httpResp.h" -#include -#include #include "httpCode.h" #include "httpJson.h" -#include "taosmsg.h" -#include "httpLog.h" -#include "taoserror.h" const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; @@ -44,9 +44,8 @@ const char *httpRespTemplate[] = { "%s 200 OK\r\nAccess-Control-Allow-Origin:*\r\n%sAccess-Control-Allow-Methods:POST, GET, OPTIONS, DELETE, PUT\r\nAccess-Control-Allow-Headers:Accept, Content-Type\r\nContent-Type: application/json;charset=utf-8\r\nContent-Length: %d\r\n\r\n" }; -void httpSendErrorRespImp(HttpContext *pContext, int httpCode, char *httpCodeStr, int errNo, char *desc) { - httpError("context:%p, fd:%d, ip:%s, code:%d, error:%d:%s", pContext, pContext->fd, pContext->ipstr, httpCode, errNo, - desc); +static void httpSendErrorRespImp(HttpContext *pContext, int httpCode, char *httpCodeStr, int errNo, char *desc) { + httpError("context:%p, fd:%d, ip:%s, code:%d, error:%s", pContext, pContext->fd, pContext->ipstr, httpCode, desc); char head[512] = {0}; char body[512] = {0}; @@ -184,7 +183,7 @@ void httpSendErrorResp(HttpContext *pContext, int errNo) { httpSendErrorRespWith void httpSendTaosdErrorResp(HttpContext *pContext, int errCode) { int httpCode = 400; - httpSendErrorRespImp(pContext, httpCode, "Bad Request", errCode, (char*)tstrerror(errCode)); + httpSendErrorRespImp(pContext, httpCode, "Bad Request", 1000, (char*)tstrerror(errCode)); } void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg) { diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index f564863652f47fc48512379ac1759cbf83ff2a0d..f36e0440cb07c20db8894cd400fe4b60041f6452 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" #include "taosmsg.h" #include "tsocket.h" diff --git a/src/plugins/http/src/httpSession.c b/src/plugins/http/src/httpSession.c index 39b2ff7d24a1b25dcdf58acacd4ed20b7295445d..4b095aeb774071e7595885104b144f2719d617ab 100644 --- a/src/plugins/http/src/httpSession.c +++ b/src/plugins/http/src/httpSession.c @@ -13,20 +13,18 @@ * along with this program. If not, see . */ -#include -#include -#include - -#include "http.h" -#include "httpCode.h" -#include "httpHandle.h" -#include "httpResp.h" - +#define _DEFAULT_SOURCE +#include "os.h" #include "shash.h" #include "taos.h" #include "ttime.h" #include "ttimer.h" +#include "http.h" #include "httpLog.h" +#include "httpCode.h" +#include "httpHandle.h" +#include "httpResp.h" + void httpAccessSession(HttpContext *pContext) { HttpServer *server = pContext->pThread->pServer; diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index 017605093ee9dfe523a3757fa6d92d405f301d11..0d0bc3e0fd8bcbd4a2517a2eb2e5b34759a4fa25 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -13,15 +13,16 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" +#include "tnote.h" +#include "taos.h" +#include "tsclient.h" #include "http.h" +#include "httpLog.h" #include "httpCode.h" #include "httpHandle.h" #include "httpResp.h" -#include "taos.h" -#include "tsclient.h" -#include "tnote.h" -#include "httpLog.h" void *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos); @@ -55,8 +56,8 @@ void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numO pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, numOfRows, sql); if (numOfRows < 0) { - httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, retrieve failed code:%d, sql:%s", - pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, -numOfRows, sql); + httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, retrieve failed code:%s, sql:%s", + pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(numOfRows), sql); } else { taos_free_result(result); } @@ -79,21 +80,21 @@ 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) { - httpWarn("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, code:%d:inprogress, sql:%s", - pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, -code, sql); + if (code == TSDB_CODE_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; } if (code < 0) { - if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : -code)) { - singleCmd->code = -code; - httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%d, last sql:%s", - pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, -code, sql); + if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) { + singleCmd->code = code; + httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s", + pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql); } else { - singleCmd->code = -code; - httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, error code:%d, sql:%s", - pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, -code, sql); + singleCmd->code = code; + httpError("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, error code:%s, sql:%s", + pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos, tstrerror(code), sql); if (singleCmd->cmdReturnType == HTTP_CMD_RETURN_TYPE_WITH_RETURN) { if (encode->startJsonFp) (encode->startJsonFp)(pContext, singleCmd, result); @@ -209,8 +210,8 @@ void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int num pContext->user, numOfRows); if (numOfRows < 0) { - httpError("context:%p, fd:%d, ip:%s, user:%s, retrieve failed, code:%d", pContext, pContext->fd, pContext->ipstr, - pContext->user, -numOfRows); + httpError("context:%p, fd:%d, ip:%s, user:%s, retrieve failed, code:%s", pContext, pContext->fd, pContext->ipstr, + pContext->user, tstrerror(numOfRows)); } else { taos_free_result(result); } @@ -229,22 +230,22 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int code) { HttpEncodeMethod *encode = pContext->encodeMethod; - if (-code == TSDB_CODE_ACTION_IN_PROGRESS) { - httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d:inprogress, sqlObj:%p", - pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, (SSqlObj *)result); + if (code == TSDB_CODE_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; } if (code < 0) { SSqlObj *pObj = (SSqlObj *)result; - if (-code == TSDB_CODE_INVALID_SQL) { - httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d:invalidsql, sqlObj:%p, error:%s", - pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj, pObj->cmd.payload); + if (code == TSDB_CODE_INVALID_SQL) { + httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s:invalidsql, 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); } else { - httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%d, sqlObj:%p", - pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, -code, pObj); - httpSendTaosdErrorResp(pContext, -code); + httpError("context:%p, fd:%d, ip:%s, user:%s, query error, taos:%p, code:%s, sqlObj:%p", + pContext, pContext->fd, pContext->ipstr, pContext->user, pContext->session->taos, tstrerror(code), pObj); + httpSendTaosdErrorResp(pContext, code); } return; } @@ -349,9 +350,9 @@ void httpProcessRequestCb(void *param, TAOS_RES *result, int code) { if (pContext == NULL || pContext->signature != pContext) return; if (code < 0) { - httpError("context:%p, fd:%d, ip:%s, user:%s, login error, code:%d", pContext, pContext->fd, pContext->ipstr, - pContext->user, -code); - httpSendTaosdErrorResp(pContext, -code); + httpError("context:%p, fd:%d, ip:%s, user:%s, login error, code:%s", pContext, pContext->fd, pContext->ipstr, + pContext->user, tstrerror(code)); + httpSendTaosdErrorResp(pContext, code); return; } diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index 9afd5838c851dbfd49bef52d1732dcf98b962b09..355fdf2fd003f446b9ae66c1904f9946569d5e4e 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -15,17 +15,17 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "shash.h" +#include "taos.h" +#include "tglobal.h" +#include "tsocket.h" +#include "ttimer.h" #include "tadmin.h" #include "http.h" #include "httpCode.h" #include "httpHandle.h" #include "httpResp.h" #include "httpLog.h" -#include "shash.h" -#include "taos.h" -#include "tglobal.h" -#include "tsocket.h" -#include "ttimer.h" #include "gcHandle.h" #include "httpHandle.h" #include "restHandle.h" diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index c8d4737c4175569ed6f3f0236406ee41c7d06c31..fc5f771c69d45f33e1c412b3a8e7852976151405 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -13,15 +13,16 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" #include "tmd5.h" +#include "shash.h" +#include "taos.h" #include "http.h" +#include "httpLog.h" #include "httpCode.h" #include "httpHandle.h" #include "httpResp.h" -#include "shash.h" -#include "taos.h" -#include "httpLog.h" bool httpCheckUsedbSql(char *sql) { if (strstr(sql, "use ") != NULL) { diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index 79d6fe566222c6c629951729e86f85b9e44aa814..a2dc7d06a1a75fd51fa17f910599b67ea6129575 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -13,9 +13,11 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE +#include "os.h" +#include "httpLog.h" #include "restHandle.h" #include "restJson.h" -#include "httpLog.h" static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; diff --git a/src/plugins/http/src/restJson.c b/src/plugins/http/src/restJson.c index 0489bcdbe030eb15a828b0224f9153a13e77e6ba..9277d7d0456817188b24935a4cc9f396deb3283d 100644 --- a/src/plugins/http/src/restJson.c +++ b/src/plugins/http/src/restJson.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" #include "tglobal.h" #include "httpLog.h" diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 5ea5f832d5a0d61fcefc1b75c6cd2b96c7cafc88..c854e0adc341303b5aafd27b2de2e03dafe817ed 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -13,14 +13,15 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" -#include "tgHandle.h" +#include "tglobal.h" #include "shash.h" +#include "taosdef.h" #include "taosmsg.h" +#include "tgHandle.h" #include "tgJson.h" -#include "taosdef.h" #include "httpLog.h" -#include "tglobal.h" /* * taos.telegraf.cfg formats like diff --git a/src/plugins/http/src/tgJson.c b/src/plugins/http/src/tgJson.c index f19e00fb9851529804403f6177ded8f212d0bf9b..cb9c42e7920c57f276c52d013870e0623d77ee43 100644 --- a/src/plugins/http/src/tgJson.c +++ b/src/plugins/http/src/tgJson.c @@ -13,13 +13,14 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" +#include "taosmsg.h" +#include "httpLog.h" #include "httpJson.h" #include "httpResp.h" -#include "taosmsg.h" #include "tgHandle.h" #include "tgJson.h" -#include "httpLog.h" void tgInitQueryJson(HttpContext *pContext) { JsonBuf *jsonBuf = httpMallocJsonBuf(pContext); @@ -97,8 +98,8 @@ void tgBuildSqlAffectRowsJson(HttpContext *pContext, HttpSqlCmd *cmd, int affect bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { HttpSqlCmds *multiCmds = pContext->multiCmds; - httpTrace("context:%p, fd:%d, ip:%s, check telegraf command, code:%d, state:%d, type:%d, rettype:%d, tags:%d", - pContext, pContext->fd, pContext->ipstr, code, cmd->cmdState, cmd->cmdType, cmd->cmdReturnType, cmd->tagNum); + httpTrace("context:%p, fd:%d, ip:%s, check telegraf command, code:%s, state:%d, type:%d, rettype:%d, tags:%d", + pContext, pContext->fd, pContext->ipstr, tstrerror(code), cmd->cmdState, cmd->cmdType, cmd->cmdReturnType, cmd->tagNum); if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) { if (cmd->cmdState == HTTP_CMD_STATE_NOT_RUN_YET) { @@ -124,11 +125,11 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { } } else if (cmd->cmdType == HTTP_CMD_TYPE_CREATE_DB) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; - httpTrace("context:%p, fd:%d, ip:%s, code:%d, create database failed", pContext, pContext->fd, pContext->ipstr, - code); + httpTrace("context:%p, fd:%d, ip:%s, code:%s, create database failed", pContext, pContext->fd, pContext->ipstr, + tstrerror(code)); } else if (cmd->cmdType == HTTP_CMD_TYPE_CREATE_STBALE) { cmd->cmdState = HTTP_CMD_STATE_RUN_FINISHED; - httpTrace("context:%p, fd:%d, ip:%s, code:%d, create stable failed", pContext, pContext->fd, pContext->ipstr, code); + httpTrace("context:%p, fd:%d, ip:%s, code:%s, create stable failed", pContext, pContext->fd, pContext->ipstr, tstrerror(code)); } else { } @@ -137,8 +138,8 @@ bool tgCheckFinished(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { void tgSetNextCmd(struct HttpContext *pContext, HttpSqlCmd *cmd, int code) { HttpSqlCmds *multiCmds = pContext->multiCmds; - httpTrace("context:%p, fd:%d, ip:%s, get telegraf next command, pos:%d, code:%d, state:%d, type:%d, rettype:%d, tags:%d", - pContext, pContext->fd, pContext->ipstr, multiCmds->pos, code, cmd->cmdState, cmd->cmdType, + httpTrace("context:%p, fd:%d, ip:%s, get telegraf next command, pos:%d, code:%s, state:%d, type:%d, rettype:%d, tags:%d", + pContext, pContext->fd, pContext->ipstr, multiCmds->pos, tstrerror(code), cmd->cmdState, cmd->cmdType, cmd->cmdReturnType, cmd->tagNum); if (cmd->cmdType == HTTP_CMD_TYPE_INSERT) { diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index cdc7b3328cbf91e93bfb9a10cb2f07050b52ca5e..9b410ce1e5439f312b3ffdd2f7721dcadcaea7ec 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -990,9 +990,7 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat return TSDB_CODE_SUCCESS; } -static UNUSED_FUNC char *getGroupbyColumnData(SQuery *pQuery, SData **data, int16_t *type, int16_t *bytes) { - char *groupbyColumnData = NULL; - +static char *getGroupbyColumnData(SQuery *pQuery, int16_t *type, int16_t *bytes, SArray* pDataBlock) { SSqlGroupbyExpr *pGroupbyExpr = pQuery->pGroupbyExpr; for (int32_t k = 0; k < pGroupbyExpr->numOfGroupCols; ++k) { @@ -1015,12 +1013,22 @@ static UNUSED_FUNC char *getGroupbyColumnData(SQuery *pQuery, SData **data, int1 *type = pQuery->colList[colIndex].type; *bytes = pQuery->colList[colIndex].bytes; - - // groupbyColumnData = doGetDataBlocks(pQuery, data, pQuery->colList[colIndex].inf); - break; + /* + * the colIndex is acquired from the first meter of all qualified meters in this vnode during query prepare + * stage, the remain meter may not have the required column in cache actually. So, the validation of required + * column in cache with the corresponding meter schema is reinforced. + */ + int32_t numOfCols = taosArrayGetSize(pDataBlock); + + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData *p = taosArrayGet(pDataBlock, i); + if (pColIndex->colId == p->info.colId) { + return p->pData; + } + } } - - return groupbyColumnData; + + return NULL; } static int32_t doTSJoinFilter(SQueryRuntimeEnv *pRuntimeEnv, int32_t offset) { @@ -1091,8 +1099,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS char *groupbyColumnData = NULL; if (groupbyStateValue) { - assert(0); - // groupbyColumnData = getGroupbyColumnData(pQuery, data, &type, &bytes); + groupbyColumnData = getGroupbyColumnData(pQuery, &type, &bytes, pDataBlock); } for (int32_t k = 0; k < pQuery->numOfOutput; ++k) { @@ -6097,9 +6104,16 @@ int32_t qCreateQueryInfo(void *tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) STableId *id = taosArrayGet(pTableIdList, 0); id->uid = -1; // todo fix me - - /*int32_t ret =*/tsdbQueryByTagsCond(tsdb, id->uid, tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, tbnameCond, &groupInfo, pGroupColIndex, - pQueryMsg->numOfGroupCols); + + // group by normal column, do not pass the group by condition to tsdb to group table into different group + int32_t numOfGroupByCols = pQueryMsg->numOfGroupCols; + if (pQueryMsg->numOfGroupCols == 1 && !TSDB_COL_IS_TAG(pGroupColIndex->flag)) { + numOfGroupByCols = 0; + } + + // todo handle the error + /*int32_t ret =*/tsdbQueryByTagsCond(tsdb, id->uid, tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, tbnameCond, &groupInfo, pGroupColIndex, + numOfGroupByCols); if (groupInfo.numOfTables == 0) { // no qualified tables no need to do query code = TSDB_CODE_SUCCESS; goto _query_over; diff --git a/src/query/tests/patternMatchTest.cpp b/src/query/tests/patternMatchTest.cpp index 2e70f26269f170009f6939350e7eba951db64690..41156ce8ffcce87af4c275bc293d5f0b279a0dd8 100644 --- a/src/query/tests/patternMatchTest.cpp +++ b/src/query/tests/patternMatchTest.cpp @@ -58,7 +58,7 @@ TEST(testCase, patternMatchTest) { EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); str = "abcdefgabcdeju"; - ret = patternMatch("abc%f_", str, 1, &info); + ret = patternMatch("abc%f_", str, 1, &info); // pattern string is longe than the size EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH); str = "abcdefgabcdeju"; @@ -72,4 +72,8 @@ TEST(testCase, patternMatchTest) { str = "abcdefgabcdeju"; ret = patternMatch("a__", str, 2, &info); EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH); + + str = "carzero"; + ret = patternMatch("%o", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); } diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index 984730002436f870e70cf9cc0f23f48b178257eb..e5a70740f112f44428c3a75d96c0bba3927d8731 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) { doQuery(taos, "create database if not exists test"); doQuery(taos, "use test"); - doQuery(taos, "insert into tm99 values('2020-01-01 1:1:1', 99);"); + doQuery(taos, "select count(*),k,sum(k) from m1 group by k"); // doQuery(taos, "create table if not exists tm0 (ts timestamp, k int);"); // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:1', 1);"); // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:2', 2);"); @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) { // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:7', 7);"); // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:8', 8);"); // doQuery(taos, "insert into tm0 values('2020-1-1 1:1:9', 9);"); - doQuery(taos, "select sum(k),count(*) from m1 group by a"); +// doQuery(taos, "select sum(k),count(*) from m1 group by a"); taos_close(taos); return 0; diff --git a/tests/pytest/insert/float.py b/tests/pytest/insert/float.py new file mode 100644 index 0000000000000000000000000000000000000000..7c4474f7ad0be25da8ec0622061654ea620e0219 --- /dev/null +++ b/tests/pytest/insert/float.py @@ -0,0 +1,147 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import datetime + +import taos + +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def run(self): + tdSql.prepare() + + tdLog.info("=============== step1") + cmd = 'create table tb (ts timestamp, speed float)' + tdLog.info(cmd) + tdSql.execute(cmd) + cmd = 'insert into tb values (now, -3.40E+38)' + tdLog.info(cmd) + tdSql.execute(cmd) + + tdLog.info("=============== step2") + cmd = 'insert into tb values (now+1a, 3.40E+308)' + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = 'select * from tb order by ts desc' + tdLog.info(cmd) + tdSql.query(cmd) + tdSql.checkRows(1) + + tdLog.info("=============== step3") + cmd = "insert into tb values (now+2a, 2.85)" + tdLog.info(cmd) + tdSql.execute(cmd) + cmd = "select * from tb order by ts desc" + tdLog.info(cmd) + ret = tdSql.query(cmd) + tdSql.checkRows(2) + + if ((abs(tdSql.getData(0, 1) - 2.850000)) > 1.0e-7): + tdLog.exit("data is not 2.850000") + + tdLog.info("=============== step4") + cmd = "insert into tb values (now+3a, 3.4)" + tdLog.info(cmd) + tdSql.execute(cmd) + cmd = "select * from tb order by ts desc" + tdLog.info(cmd) + tdSql.query(cmd) + tdSql.checkRows(3) + if (abs(tdSql.getData(0, 1) - 3.400000) > 1.0e-7): + tdLog.exit("data is not 3.400000") + + tdLog.info("=============== step5") + cmd = "insert into tb values (now+4a, a2)" + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit("This test failed: \ + insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = "insert into tb values (now+4a, 0)" + tdLog.info(cmd) + tdSql.execute(cmd) + cmd = "select * from tb order by ts desc" + tdLog.info(cmd) + tdSql.query(cmd) + tdSql.checkRows(4) + if (abs(tdSql.getData(0, 1) - 0.000000) != 0): + tdLog.exit("data is not 0.000000") + + tdLog.info("=============== step6") + cmd = "insert into tb values (now+5a, 2a)" + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = "insert into tb values (now+5a, 2)" + tdLog.info(cmd) + tdSql.execute(cmd) + cmd = "select * from tb order by ts desc" + tdLog.info(cmd) + ret = tdSql.query(cmd) + tdSql.checkRows(5) + if (abs(tdSql.getData(0, 1) - 2.000000) > 1.0e-7): + tdLog.info("data is not 2.000000") + + tdLog.info("=============== step7") + cmd = "insert into tb values (now+6a, 2a'1)" + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = "insert into tb values (now+6a, 2)" + tdLog.info(cmd) + tdSql.execute(cmd) + cmd = "select * from tb order by ts desc" + tdLog.info(cmd) + tdSql.query(cmd) + if (abs(tdSql.getData(0, 1) - 2.000000) > 1.0e-7): + tdLog.exit("data is not 2.000000") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/insert/int.py b/tests/pytest/insert/int.py new file mode 100644 index 0000000000000000000000000000000000000000..8d38337576ccb78bd22155697b5d19c3655c11a1 --- /dev/null +++ b/tests/pytest/insert/int.py @@ -0,0 +1,184 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +import datetime + +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def run(self): + tdSql.prepare() + + tdLog.info("=============== step1") + tdSql.execute('create table tb (ts timestamp, speed int)') + + cmd = 'insert into tb values (now, NULL)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(1) + if(tdSql.getData(0, 1) is not None): + tdLog.exit("data is not NULL") + + tdLog.info("=============== step2") + cmd = 'insert into tb values (now+1m, -2147483648)' + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: INT data overflow error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("INT data overflow error catched") + + cmd = 'insert into tb values (now+1m, NULL)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(2) + + if(tdSql.getData(0, 1) is not None): + tdLog.exit("data is not NULL") + + tdLog.info("=============== step3") + cmd = 'insert into tb values (now+2m, 2147483647)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(3) + if(tdSql.getData(0, 1) != 2147483647): + tdLog.exit("data is not 2147483647") + + tdLog.info("=============== step4") + cmd = 'insert into tb values (now+3m, 2147483648)' + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: INT data overflow error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("INT data overflow error catched") + + cmd = 'insert into tb values (now+3m, NULL)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(4) + + if(tdSql.getData(0, 1) is not None): + tdLog.exit("data is not NULL") + + tdLog.info("=============== step5") + cmd = 'insert into tb values (now+4m, a2)' + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = 'insert into tb values (now+4m, 0)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(5) + + if(tdSql.getData(0, 1) != 0): + tdLog.exit("data is not 0") + + tdLog.info("=============== step6") + cmd = 'insert into tb values (now+5m, 2a)' + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = 'insert into tb values (now+5m, 2)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(6) + if (tdSql.getData(0, 1) != 2): + tdLog.exit("data is not 2") + + tdLog.info("=============== step7") + cmd = "insert into tb values (now+6m, 2a'1)" + tdLog.info(cmd) + try: + tdSql.execute(cmd) + tdLog.exit( + "This test failed: insert wrong data error _not_ catched") + except Exception as e: + tdLog.info(repr(e)) + tdLog.notice("insert wrong data error catched") + + cmd = 'insert into tb values (now+6m, 2)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(7) + if (tdSql.getData(0, 1) != 2): + tdLog.exit("data is not 2") + + tdLog.info("=============== step8") + cmd = 'insert into tb values (now+8m, "null")' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(8) + + if (tdSql.getData(0, 1) is not None): + tdLog.exit("data is not null") + + tdLog.info("=============== step9") + cmd = "insert into tb values (now+9m, 'null')" + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(9) + if (tdSql.getData(0, 1) is not None): + tdLog.exit("data is not null") + + tdLog.info("=============== step10") + cmd = 'insert into tb values (now+10m, -123)' + tdLog.info(cmd) + tdSql.execute(cmd) + tdSql.query('select * from tb order by ts desc') + tdSql.checkRows(10) + + if (tdSql.getData(0, 1) != -123): + tdLog.exit("data is not -123") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/simpletest.sh b/tests/pytest/simpletest.sh index b77c1aa142413b74256b125f6c4a84485be66cff..58345e13ee8387c824fadb670f8fc99cd9e7f8a2 100755 --- a/tests/pytest/simpletest.sh +++ b/tests/pytest/simpletest.sh @@ -1,3 +1,9 @@ #!/bin/bash python3 ./test.py -f insert/basic.py $1 python3 ./test.py -s $1 +sleep 1 +python3 ./test.py -f insert/int.py $1 +python3 ./test.py -s $1 +sleep 1 +python3 ./test.py -f insert/float.py $1 +python3 ./test.py -s $1 diff --git a/tests/pytest/test.py b/tests/pytest/test.py index 55ec46e526c89fc1c6e99671a63670a167c58aa8..479406a00b728c1ea7cbb28255db2e6db11166b2 100644 --- a/tests/pytest/test.py +++ b/tests/pytest/test.py @@ -100,7 +100,7 @@ if __name__ == "__main__": tdDnodes.deploy(1) tdDnodes.start(1) conn = taos.connect( - host='192.168.0.1', + host='127.0.0.1', config=tdDnodes.getSimCfgPath()) if fileName == "all": tdCases.runAllLinux(conn) diff --git a/tests/pytest/util/cases.py b/tests/pytest/util/cases.py index 4bd1b1e9d1a0d734852584450d02b4ff91124d0f..1771c23620dbe547733e8c2ce317bd38961a87d3 100644 --- a/tests/pytest/util/cases.py +++ b/tests/pytest/util/cases.py @@ -67,12 +67,16 @@ class TDCases: if tmp.name.find(fileName) != -1: case = testModule.TDTestCase() case.init(conn) - case.run() + try: + case.run() + except Exception as e: + tdLog.notice(repr(e)) + tdLog.notice("%s failed: %s" % (__file__, fileName)) case.stop() runNum += 1 continue - tdLog.notice("total %d Linux test case(s) executed" % (runNum)) + tdLog.success("total %d Linux test case(s) executed" % (runNum)) def runAllWindows(self, conn): # TODO: load all Windows cases here diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 6a9c2607e63f1d145af387198e1ac1fb077135ca..51eed3d25a6d8e7f116b43d3d006198f695170e8 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -19,12 +19,19 @@ from util.log import * class TDSimClient: + def __init__(self): + self.testCluster = False + def init(self, path): + self.__init__() self.path = path def getCfgDir(self): return self.cfgDir + def setTestCluster(self, value): + self.testCluster = value + def cfg(self, option, value): cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath) if os.system(cmd) != 0: @@ -55,8 +62,9 @@ class TDSimClient: if os.system(cmd) != 0: tdLog.exit(cmd) - self.cfg("masterIp", "192.168.0.1") - self.cfg("secondIp", "192.168.0.2") + if self.testCluster: + self.cfg("masterIp", "192.168.0.1") + self.cfg("secondIp", "192.168.0.2") self.cfg("logDir", self.logDir) self.cfg("numOfLogLines", "100000000") self.cfg("numOfThreadsPerCore", "2.0") @@ -128,11 +136,12 @@ class TDDnode: if self.testCluster: self.startIP() - self.cfg("masterIp", "192.168.0.1") - self.cfg("secondIp", "192.168.0.2") - self.cfg("publicIp", "192.168.0.%d" % (self.index)) - self.cfg("internalIp", "192.168.0.%d" % (self.index)) - self.cfg("privateIp", "192.168.0.%d" % (self.index)) + if self.testCluster: + self.cfg("masterIp", "192.168.0.1") + self.cfg("secondIp", "192.168.0.2") + self.cfg("publicIp", "192.168.0.%d" % (self.index)) + self.cfg("internalIp", "192.168.0.%d" % (self.index)) + self.cfg("privateIp", "192.168.0.%d" % (self.index)) self.cfg("dataDir", self.dataDir) self.cfg("logDir", self.logDir) self.cfg("numOfLogLines", "100000000") @@ -291,10 +300,6 @@ class TDDnodes: for i in range(len(self.dnodes)): self.dnodes[i].init(self.path) - self.sim = TDSimClient() - self.sim.init(self.path) - self.sim.deploy() - def setTestCluster(self, value): self.testCluster = value @@ -302,6 +307,11 @@ class TDDnodes: self.valgrind = value def deploy(self, index): + self.sim = TDSimClient() + self.sim.init(self.path) + self.sim.setTestCluster(self.testCluster) + self.sim.deploy() + self.check(index) self.dnodes[index - 1].setTestCluster(self.testCluster) self.dnodes[index - 1].setValgrind(self.valgrind) diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index b4ac845bc899b575bcd8597d191cb8b6354fa4d7..00084681306da30e0a46333030a45c891c7780e4 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -63,7 +63,7 @@ class TDSql: def checkRows(self, expectRows): if self.queryRows != expectRows: tdLog.exit( - "sql:%.40s, queryRows:%d != expect:%d" % + "failed: sql:%.40s, queryRows:%d != expect:%d" % (self.sql, self.queryRows, expectRows)) tdLog.info("sql:%.40s, queryRows:%d == expect:%d" % (self.sql, self.queryRows, expectRows)) diff --git a/tests/script/general/http/restful.sim b/tests/script/general/http/restful.sim index 4c0adae41d2608fff1b0fef9f4a9e6c642c01b5c..50f0223804ac0ee07ef224facd01d0de50452aa8 100644 --- a/tests/script/general/http/restful.sim +++ b/tests/script/general/http/restful.sim @@ -77,8 +77,8 @@ if $system_content != @{"status":"succ","code":0,"desc":"jIlItaLFFIPa8qdtNZmtONr return -1 endi -system_content curl 127.0.0.1:6020/rest/login/u2/abcd_1234 +system_content curl 127.0.0.1:6020/rest/login/u2/aabcd_1234 print curl 127.0.0.1:6020/rest/login/u2/abcd_1234 -----> $system_content -if $system_content != @{"status":"succ","code":0,"desc":"AZH3lNvWZiLa8qdtNZmtONryp201ma04QExCHYkbFFQB/46k1gwnPNryp201ma04"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then return -1 endi diff --git a/tests/script/general/http/restful_full.sim b/tests/script/general/http/restful_full.sim index 2be125021d2123486a9ce567fe1af9f998bd449c..6682aac35262d7ad1d03fc713caa6b622c408f29 100644 --- a/tests/script/general/http/restful_full.sim +++ b/tests/script/general/http/restful_full.sim @@ -1,13 +1,13 @@ system sh/stop_dnodes.sh -sleep 5000 +#sleep 5000 system sh/ip.sh -i 1 -s up system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1 system sh/cfg.sh -n dnode1 -c clog -v 0 system sh/exec.sh -n dnode1 -s start -sleep 3000 +#sleep 3000 sql connect print ============================ dnode1 start @@ -41,19 +41,19 @@ endi system_content curl 192.168.0.1:6020/rest/login/root/123 print 5-> $system_content -if $system_content != @{"status":"error","code":10,"desc":"authentication failure"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then return -1 endi system_content curl 192.168.0.1:6020/rest/login/root/123/1/1/3 print 6-> $system_content -if $system_content != @{"status":"error","code":10,"desc":"authentication failure"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then return -1 endi system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 192.168.0.1:6020/rest/login/root/1 print 7-> $system_content -if $system_content != @{"status":"error","code":10,"desc":"authentication failure"}@ then +if $system_content != @{"status":"error","code":1000,"desc":"auth failure"}@ then return -1 endi diff --git a/tests/script/general/http/testSuite.sim b/tests/script/general/http/testSuite.sim index ca93dedd3b4c4fee52f1018a756ed8beecb62a46..092eebdbdffca2974b053b9066d084c4995adb24 100644 --- a/tests/script/general/http/testSuite.sim +++ b/tests/script/general/http/testSuite.sim @@ -1,7 +1,6 @@ -run general/http/grafana.sim run general/http/restful.sim run general/http/restful_full.sim run general/http/telegraf.sim run general/http/prepare.sim run general/http/grafana_bug.sim -#run general/http/opentsdb.sim +run general/http/grafana.sim diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 41ba3c425ad9cf8e1e587ee6cdeef75c3f5514dc..907ca6848b828b7e9ae9e15a201b33d8ee2c1d6d 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -93,10 +93,10 @@ echo "privateIp $NODE_IP" >> $TAOS_CFG echo "dDebugFlag 199" >> $TAOS_CFG echo "mDebugFlag 199" >> $TAOS_CFG echo "sdbDebugFlag 199" >> $TAOS_CFG -echo "rpcDebugFlag 135" >> $TAOS_CFG +echo "rpcDebugFlag 131" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "cDebugFlag 135" >> $TAOS_CFG -echo "httpDebugFlag 131" >> $TAOS_CFG +echo "httpDebugFlag 135" >> $TAOS_CFG echo "monitorDebugFlag 131" >> $TAOS_CFG echo "udebugFlag 131" >> $TAOS_CFG echo "jnidebugFlag 131" >> $TAOS_CFG diff --git a/tests/script/general/http/opentsdb.sim b/tests/script/unique/http/opentsdb.sim similarity index 100% rename from tests/script/general/http/opentsdb.sim rename to tests/script/unique/http/opentsdb.sim diff --git a/tests/script/unique/http/testSuite.sim b/tests/script/unique/http/testSuite.sim index b3ee1792f55dc1fc464b8cbea065e06dcdd2777b..d4a6b1f5f5c7e677c081126cad91647190d30a82 100644 --- a/tests/script/unique/http/testSuite.sim +++ b/tests/script/unique/http/testSuite.sim @@ -1 +1,2 @@ -run unique/http/admin.sim \ No newline at end of file +run unique/http/admin.sim +#run general/http/opentsdb.sim \ No newline at end of file diff --git a/tests/test-all.sh b/tests/test-all.sh index dee89b9dc57da7e6a8292ee0aca82b329b8865f2..6943dd47a780c1de5cf431e9f45789af19412c09 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -25,15 +25,17 @@ if [ "$totalFailed" -ne "0" ]; then fi cd ../pytest -./simpletest.sh 2>&1 | grep 'successfully executed\|failed' | tee pytest-out.txt +./simpletest.sh 2>&1 | tee pytest-out.txt totalPySuccess=`grep 'successfully executed' pytest-out.txt | wc -l` if [ "$totalPySuccess" -gt "0" ]; then + grep 'successfully executed' pytest-out.txt echo -e "${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}" fi -totalPyFailed=`grep 'failed' pytest-out.txt | wc -l` +totalPyFailed=`grep 'failed\|fault' pytest-out.txt | wc -l` if [ "$totalPyFailed" -ne "0" ]; then + cat pytest-out.txt echo -e "${RED} ### Total $totalPyFailed python case(s) failed! ### ${NC}" exit $totalPyFailed fi