diff --git a/.travis.yml b/.travis.yml index 74ed80da3fb92d5400c37569bc24c8c5d63f8ff6..5cff3bc72b612a62e50048a76453d3b6ac6c4dce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,12 +41,29 @@ addons: branch_pattern: coverity_scan before_script: - - mkdir build - - cd build + - mkdir debug + - cd debug script: - cmake .. - - cmake --build . + - cmake --build . || exit $? + - |- + case $TRAVIS_OS_NAME in + linux) + cd ../tests/script + sudo ./test.sh 2>&1 | tee out.txt + cat out.txt + grep success out.txt + total_success=`grep success out.txt | wc -l` + echo "Total $total_success success" + grep failed out.txt + total_failed=`grep failed out.txt | wc -l` + echo "Total $total_failed failed" + if [ "$total_failed" -ne "0" ]; then + exit $total_failed + fi + ;; + esac # # Build Matrix @@ -58,6 +75,7 @@ matrix: packages: - build-essential - cmake + - net-tools # - os: osx # addons: diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 55fa45475a658105c33ae620cd8a5d922a838466..ecbef79ae4ef5d4efe00971634b29da0da73e366 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -22,7 +22,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) # generate dynamic library (*.so) ADD_LIBRARY(taos SHARED ${SRC}) - TARGET_LINK_LIBRARIES(taos common trpc tutil pthread m rt) + TARGET_LINK_LIBRARIES(taos common query trpc tutil pthread m rt) SET_TARGET_PROPERTIES(taos PROPERTIES CLEAN_DIRECT_OUTPUT 1) #set version of .so diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index dad32e58da1dcea4b6850f2aaeca50e538e1c14d..80c3e77eff55585bb240a4f6a817b6fda0387ca1 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -351,7 +351,7 @@ typedef struct SSqlObj { char * sqlstr; char retry; char maxRetry; - SRpcIpSet *ipList; + SRpcIpSet ipList; char freed : 4; char listed : 4; tsem_t rspSem; diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 36cd42332b0d84b09798138080da33a856f26a21..62888234019cf2fe9e77fe476b731e6918499d7a 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -342,8 +342,8 @@ void tscProcessAsyncRes(SSchedMsg *pMsg) { (*pSql->fp)(pSql->param, taosres, code); if (shouldFree) { - tscFreeSqlObj(pSql); tscTrace("%p Async sql is automatically freed in async res", pSql); + tscFreeSqlObj(pSql); } } diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 00c8d776190fc2cff077fd9be87e8ac966f4d5cd..739ae7848e6222ee650031649192593991299544 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -292,7 +292,6 @@ void tscKillConnection(STscObj *pObj) { pthread_mutex_unlock(&pObj->mutex); - taos_close(pObj); - tscTrace("connection:%p is killed", pObj); + taos_close(pObj); } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 40e70c247ef2d8d4a1cce6db07ac9f48271a5085..4462af7f950b069d774ff4222310fae367d9f592 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -209,7 +209,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } int32_t code = tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo); -// assert(pQueryInfo->numOfTables == 0); STableMetaInfo* pTableMetaInfo = NULL; if (pQueryInfo->numOfTables == 0) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 1e7ad937acaff0e9761b8cdaa6a6d9b3c1847b35..46c7dd589be8f18a8a4f100ea0f131563765096f 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -169,17 +169,27 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { } int tscSendMsgToServer(SSqlObj *pSql) { - char *pMsg = rpcMallocCont(pSql->cmd.payloadLen); + SSqlCmd* pCmd = &pSql->cmd; + + char *pMsg = rpcMallocCont(pCmd->payloadLen); if (NULL == pMsg) { tscError("%p msg:%s malloc fail", pSql, taosMsg[pSql->cmd.msgType]); return TSDB_CODE_CLI_OUT_OF_MEMORY; } - pSql->ipList->ip[0] = inet_addr(tsPrivateIp); - if (pSql->cmd.command < TSDB_SQL_MGMT) { - pSql->ipList->port = tsDnodeShellPort; - tscPrint("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList->port); + STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + + pSql->ipList.numOfIps = pTableMeta->numOfVpeers; + pSql->ipList.port = tsDnodeShellPort; + pSql->ipList.inUse = 0; + + for(int32_t i = 0; i < pTableMeta->numOfVpeers; ++i) { + pSql->ipList.ip[i] = pTableMeta->vpeerDesc[i].ip; + } + + tscPrint("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList.port); memcpy(pMsg, pSql->cmd.payload + tsRpcHeadSize, pSql->cmd.payloadLen); SRpcMsg rpcMsg = { @@ -189,10 +199,12 @@ int tscSendMsgToServer(SSqlObj *pSql) { .handle = pSql, .code = 0 }; - rpcSendRequest(pVnodeConn, pSql->ipList, &rpcMsg); + rpcSendRequest(pVnodeConn, &pSql->ipList, &rpcMsg); } else { - pSql->ipList->port = tsMnodeShellPort; - tscTrace("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList->port); + pSql->ipList = tscMgmtIpList; + pSql->ipList.port = tsMnodeShellPort; + + tscTrace("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList.port); memcpy(pMsg, pSql->cmd.payload, pSql->cmd.payloadLen); SRpcMsg rpcMsg = { .msgType = pSql->cmd.msgType, @@ -201,7 +213,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { .handle = pSql, .code = 0 }; - rpcSendRequest(pTscMgmtConn, pSql->ipList, &rpcMsg); + rpcSendRequest(pTscMgmtConn, &pSql->ipList, &rpcMsg); } return TSDB_CODE_SUCCESS; @@ -254,11 +266,15 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { rpcFreeCont(rpcMsg->pCont); return; } else { - tscTrace("%p it shall renew meter meta, code:%d", pSql, tstrerror(rpcMsg->code)); + tscTrace("%p it shall renew table meta, code:%d", pSql, tstrerror(rpcMsg->code)); pSql->maxRetry = TSDB_VNODES_SUPPORT * 2; pSql->res.code = rpcMsg->code; // keep the previous error code - + if (++pSql->retry > pSql->maxRetry) { + tscError("%p max retry %d reached, ", pSql, pSql->retry); + return; + } + rpcMsg->code = tscRenewMeterMeta(pSql, pTableMetaInfo->name); if (pTableMetaInfo->pTableMeta) { @@ -343,8 +359,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { (*pSql->fp)(pSql->param, taosres, rpcMsg->code); if (shouldFree) { - tscFreeSqlObj(pSql); tscTrace("%p Async sql is automatically freed", pSql); + tscFreeSqlObj(pSql); } } @@ -405,7 +421,7 @@ int tscProcessSql(SSqlObj *pSql) { } // temp - pSql->ipList = &tscMgmtIpList; +// pSql->ipList = tscMgmtIpList; // if (UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) { // pSql->index = pTableMetaInfo->pTableMeta->index; // } else { // it must be the parent SSqlObj for super table query @@ -417,7 +433,7 @@ int tscProcessSql(SSqlObj *pSql) { // } // } } else if (pSql->cmd.command < TSDB_SQL_LOCAL) { - pSql->ipList = &tscMgmtIpList; + pSql->ipList = tscMgmtIpList; } else { // local handler return (*tscProcessMsgRsp[pCmd->command])(pSql); } @@ -501,7 +517,8 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pRetrieveMsg->free = htons(pQueryInfo->type); pMsg += sizeof(pQueryInfo->type); - pRetrieveMsg->header.vgId = htonl(1); + STableMeta* pTableMeta = pQueryInfo->pTableMetaInfo[0]->pTableMeta; + pRetrieveMsg->header.vgId = htonl(pTableMeta->vgId); pMsg += sizeof(SRetrieveTableMsg); pRetrieveMsg->header.contLen = htonl(pSql->cmd.payloadLen); @@ -532,9 +549,9 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pShellMsg->numOfBlocks = htonl(pSql->cmd.numOfTablesInSubmit); // number of meters to be inserted - // pSql->cmd.payloadLen is set during copying data into paylaod + // pSql->cmd.payloadLen is set during copying data into payload pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; - tscTrace("%p build submit msg, vgId:%d numOfVnodes:%d", pSql, pTableMeta->vgId, htons(pMsgDesc->numOfVnodes)); + tscTrace("%p build submit msg, vgId:%d numOfVnodes:%d", pSql, pTableMeta->vgId, htonl(pMsgDesc->numOfVnodes)); return TSDB_CODE_SUCCESS; } @@ -1787,6 +1804,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size = tscEstimateHeartBeatMsgLength(pSql); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { + pthread_mutex_unlock(&pObj->mutex); tscError("%p failed to malloc for heartbeat msg", pSql); return -1; } @@ -1836,6 +1854,8 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { pMetaMsg->vpeerDesc[i].vgId = htonl(pMetaMsg->vpeerDesc[i].vgId); + pMetaMsg->vpeerDesc[i].ip = htonl(pMetaMsg->vpeerDesc[i].ip); + pMetaMsg->vpeerDesc[i].dnodeId = htonl(pMetaMsg->vpeerDesc[i].dnodeId); } SSchema* pSchema = pMetaMsg->schema; @@ -2435,7 +2455,7 @@ static void tscWaitingForCreateTable(SSqlCmd *pCmd) { int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) { int code = 0; - // handle metric meta renew process + // handle table meta renew process SSqlCmd *pCmd = &pSql->cmd; SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index f6c1fee633308260da4c8c9ce8c5e327c67338fb..199b4150e81eb52ebe4914b36d4ba9a64a51e44e 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -757,8 +757,8 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { tscTrace("%p qhandle is null, abort free, fp:%p", pSql, pSql->fp); if (tscShouldFreeAsyncSqlObj(pSql)) { - tscFreeSqlObj(pSql); tscTrace("%p Async SqlObj is freed by app", pSql); + tscFreeSqlObj(pSql); } else { if (keepCmd) { tscFreeSqlResult(pSql); diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 4fadad5021b5841f482f365f9a6d07ea6777ad9b..f586db3d08d5decfa3458b789d6dd4eb856e84ef 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -582,10 +582,12 @@ void taos_close_stream(TAOS_STREAM *handle) { tscRemoveFromStreamList(pStream, pSql); taosTmrStopA(&(pStream->pTimer)); + + tscTrace("%p stream:%p is closed", pSql, pStream); + tscFreeSqlObj(pSql); pStream->pSql = NULL; - tscTrace("%p stream:%p is closed", pSql, pStream); tfree(pStream); } } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index d616a8bffa402ed8f2bcab6d8fa392c5de9c950c..3660c822d717569abe7964751ab2df73fa728c6a 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1381,6 +1381,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR } else { // all data has been retrieved to client tscAllDataRetrievedFromDnode(trsupport, pSql); } + pthread_mutex_unlock(&trsupport->queryMutex); } static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsupport, SSqlObj *prevSqlObj) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 61b7ab4ec589ed2c9d9bad992d1ce6d10c60cbe8..dd0945ab0494c99ff9a01af97614291ea8084a7c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -860,12 +860,10 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { pCmd->allocSize = size; } - memset(pCmd->payload, 0, pCmd->payloadLen); + memset(pCmd->payload, 0, pCmd->allocSize); } - //memset(pCmd->payload, 0, pCmd->allocSize); assert(pCmd->allocSize >= size); - return TSDB_CODE_SUCCESS; } diff --git a/src/common/src/dataformat.c b/src/common/src/dataformat.c index bff041df1b98c955b67bf9e8a44fa360362908f4..45850d1788d55cf25796d0d51c9518db38bf126a 100644 --- a/src/common/src/dataformat.c +++ b/src/common/src/dataformat.c @@ -141,7 +141,7 @@ STSchema *tdDupSchema(STSchema *pSchema) { * Free the SSchema object created by tdNewSchema or tdDupSchema */ void tdFreeSchema(STSchema *pSchema) { - if (pSchema == NULL) free(pSchema); + if (pSchema != NULL) free(pSchema); } /** diff --git a/src/inc/tcluster.h b/src/inc/tcluster.h index 28467ca6837fb9579881972525ac9b3601e82650..769a819b90fcb915b01f9a81740d02cda6c7f7de 100644 --- a/src/inc/tcluster.h +++ b/src/inc/tcluster.h @@ -36,6 +36,7 @@ enum _TAOS_DN_STATUS { int32_t clusterInit(); void clusterCleanUp(); char* clusterGetDnodeStatusStr(int32_t dnodeStatus); +bool clusterCheckModuleInDnode(struct _dnode_obj *pDnode, int moduleType); int32_t clusterInitDnodes(); void clusterCleanupDnodes(); diff --git a/src/mnode/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c index e6d186ac1bbac5ccc829485df0d1c298caed80ab..e4ab1140909f1a5fc892ab38075cda809e744bab 100644 --- a/src/mnode/src/mgmtDnode.c +++ b/src/mnode/src/mgmtDnode.c @@ -323,8 +323,7 @@ static int32_t clusterRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, char ipstr[32]; while (numOfRows < rows) { - clusterReleaseDnode(pDnode); - pShow->pNode = clusterGetNextDnode(pShow->pNode, (SDnodeObj **)&pDnode); + pShow->pNode = clusterGetNextDnode(pShow->pNode, &pDnode); if (pDnode == NULL) break; cols = 0; @@ -366,13 +365,14 @@ static int32_t clusterRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, #endif numOfRows++; + clusterReleaseDnode(pDnode); } pShow->numOfReads += numOfRows; return numOfRows; } -static bool clusterCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) { +bool clusterCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) { uint32_t status = pDnode->moduleStatus & (1 << moduleType); return status > 0; } diff --git a/src/mnode/src/mgmtSdb.c b/src/mnode/src/mgmtSdb.c index 60614157f19f15082208722e6cbb9d3dd7d88ddd..f3fc7d07f55c9abb4b7e459e2e818e698f1907d8 100644 --- a/src/mnode/src/mgmtSdb.c +++ b/src/mnode/src/mgmtSdb.c @@ -520,6 +520,11 @@ int32_t sdbInsertRow(SSdbOperDesc *pOper) { if (pTable->keyType == SDB_KEY_TYPE_AUTO) { *((uint32_t *)pOper->pObj) = ++pTable->autoIndex; + + // let vgId increase from 2 + if (pTable->autoIndex == 1 && strcmp(pTable->tableName, "vgroups") == 0) { + *((uint32_t *)pOper->pObj) = ++pTable->autoIndex; + } } pTable->version++; sdbVersion++; @@ -695,6 +700,7 @@ int32_t sdbUpdateRow(SSdbOperDesc *pOper) { int32_t total_size = sizeof(SRowHead) + pTable->maxRowSize + sizeof(TSCKSUM); SRowHead *rowHead = (SRowHead *)calloc(1, total_size); if (rowHead == NULL) { + pthread_mutex_unlock(&pTable->mutex); sdbError("table:%s, failed to allocate row head memory", pTable->tableName); return -1; } diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index f81e13414b6e53e5897e0fa9bf81ca6b19986af5..a14bdd058ff71258ab89838955776b711700fd0d 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -1506,9 +1506,9 @@ static int32_t mgmtDoGetChildTableMeta(SQueuedMsg *pMsg, STableMetaMsg *pMeta) { for (int32_t i = 0; i < TSDB_VNODES_SUPPORT; ++i) { if (usePublicIp) { - pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; + pMeta->vpeerDesc[i].ip = htonl(pVgroup->vnodeGid[i].publicIp); } else { - pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].privateIp; + pMeta->vpeerDesc[i].ip = htonl(pVgroup->vnodeGid[i].privateIp); } pMeta->vpeerDesc[i].vgId = htonl(pVgroup->vgId); pMeta->vpeerDesc[i].dnodeId = htonl(pVgroup->vnodeGid[i].dnodeId); diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index a6419d35492a94cc245a673b43970bd42c0d4d0b..5af0cdc687866b051612caf5ff96c96743c7daaa 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -2479,12 +2479,11 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl } if (r == BLK_DATA_NO_NEEDED) { - // qTrace("QInfo:%p vid:%d sid:%d id:%s, slot:%d, data block ignored, brange:%" PRId64 "-%" PRId64 ", - // rows:%d", GET_QINFO_ADDR(pQuery), pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->slot, - // pBlock->keyFirst, pBlock->keyLast, pBlock->numOfPoints); + qTrace("QInfo:%p slot:%d, data block ignored, brange:%" PRId64 "-%" PRId64 ", rows:%d", + GET_QINFO_ADDR(pRuntimeEnv), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->size); } else if (r == BLK_DATA_FILEDS_NEEDED) { if (tsdbRetrieveDataBlockStatisInfo(pRuntimeEnv->pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { -// return DISK_DATA_LOAD_FAILED; + // return DISK_DATA_LOAD_FAILED; } if (*pStatis == NULL) { @@ -5908,14 +5907,6 @@ static void freeQInfo(SQInfo *pQInfo) { tfree(pQuery->sdata[col]); } - // for (int col = 0; col < pQuery->numOfCols; ++col) { - // vnodeFreeColumnInfo(&pQuery->colList[col].data); - // } - // - // if (pQuery->colList[0].colIdx != PRIMARYKEY_TIMESTAMP_COL_INDEX) { - // tfree(pQuery->tsData); - // } - sem_destroy(&(pQInfo->dataReady)); teardownQueryRuntimeEnv(&pQInfo->runtimeEnv); @@ -6125,9 +6116,6 @@ void qTableQuery(SQInfo *pQInfo) { dTrace("QInfo:%p query task is launched", pQInfo); -// sem_post(&pQInfo->dataReady); -// pQInfo->runtimeEnv.pQuery->status = QUERY_OVER; - int32_t numOfTables = taosArrayGetSize(pQInfo->pTableIdList); if (numOfTables == 1) { singleTableQueryImpl(pQInfo); diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 73ea23cbf855193c396536a656d3d465d2758167..f1c6deb1d07458585ebb8a069fc182f7b53e1312 100755 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -331,6 +331,7 @@ void *rpcReallocCont(void *ptr, int contLen) { char *start = ((char *)ptr) - sizeof(SRpcReqContext) - sizeof(SRpcHead); if (contLen == 0 ) { free(start); + return NULL; } int size = contLen + RPC_MSG_OVERHEAD; @@ -1095,6 +1096,10 @@ static void rpcProcessConnError(void *param, void *id) { SRpcInfo *pRpc = pContext->pRpc; SRpcMsg rpcMsg; + if (pRpc == NULL) { + return; + } + tTrace("%s connection error happens", pRpc->label); if (pContext->numOfTry >= pContext->ipSet.numOfIps) { diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index 8a0d66068e92e5823788f8104885205e19de6708..88a3be0e02750a780b2c2b65fca152444b3c7578 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -111,7 +111,12 @@ short tsDaysPerFile = 10; int tsDaysToKeep = 3650; int tsReplications = TSDB_REPLICA_MIN_NUM; +#ifdef _MPEER int tsNumOfMPeers = 3; +#else +int tsNumOfMPeers = 1; +#endif + int tsMaxShellConns = 2000; int tsMaxTables = 100000; @@ -552,9 +557,11 @@ static void doInitGlobalConfig() { tsInitConfigOption(cfg++, "tblocks", &tsNumOfBlocksPerMeter, TSDB_CFG_VTYPE_SHORT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, 32, 4096, 0, TSDB_CFG_UTYPE_NONE); +#ifdef _MPEER tsInitConfigOption(cfg++, "numOfMPeers", &tsNumOfMPeers, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, 1, 3, 0, TSDB_CFG_UTYPE_NONE); +#endif tsInitConfigOption(cfg++, "balanceInterval", &tsBalanceStartInterval, TSDB_CFG_VTYPE_INT, TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, 1, 30000, 0, TSDB_CFG_UTYPE_NONE); diff --git a/src/vnode/main/src/vnodeMain.c b/src/vnode/main/src/vnodeMain.c index 7c92ad4f4fdca9ed1598e5c18aa2e96244053d36..182b4b62579aa478d3823c84f9a73fb8449db6a4 100644 --- a/src/vnode/main/src/vnodeMain.c +++ b/src/vnode/main/src/vnodeMain.c @@ -28,6 +28,7 @@ #include "vnode.h" #include "vnodeInt.h" +static int32_t tsOpennedVnodes; static void *tsDnodeVnodesHash; static void vnodeCleanUp(SVnodeObj *pVnode); static void vnodeBuildVloadMsg(char *pNode, void * param); @@ -39,10 +40,13 @@ static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, int static int vnodeGetWalInfo(void *ahandle, char *name, uint32_t *index); static void vnodeNotifyRole(void *ahandle, int8_t role); -// module global -static int32_t tsOpennedVnodes; static pthread_once_t vnodeModuleInit = PTHREAD_ONCE_INIT; +#ifndef _VPEER +tsync_h syncStart(SSyncInfo *info) { return NULL; } +int syncForwardToPeer(tsync_h shandle, void *pHead, void *mhandle) { return 0; } +#endif + static void vnodeInit() { vnodeInitWriteFp(); vnodeInitReadFp(); @@ -58,7 +62,6 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { pthread_once(&vnodeModuleInit, vnodeInit); SVnodeObj *pTemp = (SVnodeObj *)taosGetIntHashData(tsDnodeVnodesHash, pVnodeCfg->cfg.vgId); - if (pTemp != NULL) { dPrint("vgId:%d, vnode already exist, pVnode:%p", pVnodeCfg->cfg.vgId, pTemp); return TSDB_CODE_SUCCESS; @@ -108,13 +111,13 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { } int32_t vnodeDrop(int32_t vgId) { - - SVnodeObj *pVnode = (SVnodeObj *) taosGetIntHashData(tsDnodeVnodesHash, vgId); - if (pVnode == NULL) { + SVnodeObj **ppVnode = (SVnodeObj **)taosGetIntHashData(tsDnodeVnodesHash, vgId); + if (ppVnode == NULL || *ppVnode == NULL) { dTrace("vgId:%d, failed to drop, vgId not exist", vgId); return TSDB_CODE_INVALID_VGROUP_ID; } + SVnodeObj *pVnode = *ppVnode; dTrace("pVnode:%p vgId:%d, vnode will be dropped", pVnode, pVnode->vgId); pVnode->status = TAOS_VN_STATUS_DELETING; vnodeCleanUp(pVnode); @@ -186,10 +189,10 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { } int32_t vnodeClose(int32_t vgId) { + SVnodeObj **ppVnode = (SVnodeObj **)taosGetIntHashData(tsDnodeVnodesHash, vgId); + if (ppVnode == NULL || *ppVnode == NULL) return 0; - SVnodeObj *pVnode = *(SVnodeObj **)taosGetIntHashData(tsDnodeVnodesHash, vgId); - if (pVnode == NULL) return 0; - + SVnodeObj *pVnode = *ppVnode; dTrace("pVnode:%p vgId:%d, vnode will be closed", pVnode, pVnode->vgId); pVnode->status = TAOS_VN_STATUS_CLOSING; vnodeCleanUp(pVnode); @@ -231,13 +234,13 @@ void vnodeRelease(void *pVnodeRaw) { } void *vnodeGetVnode(int32_t vgId) { - SVnodeObj *pVnode = *(SVnodeObj **) taosGetIntHashData(tsDnodeVnodesHash, vgId); - if (pVnode == NULL) { + SVnodeObj **ppVnode = (SVnodeObj **)taosGetIntHashData(tsDnodeVnodesHash, vgId); + if (ppVnode == NULL || *ppVnode == NULL) { terrno = TSDB_CODE_INVALID_VGROUP_ID; - return NULL; + assert(false); } - return pVnode; + return *ppVnode; } void *vnodeAccquireVnode(int32_t vgId) { @@ -344,7 +347,7 @@ static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) { // TODO: this is a simple implement static int32_t vnodeReadCfg(SVnodeObj *pVnode) { - char option[4][16] = {0}; + char option[5][16] = {0}; char cfgFile[TSDB_FILENAME_LEN * 2] = {0}; sprintf(cfgFile, "%s/vnode%d/config", tsVnodeDir, pVnode->vgId); diff --git a/src/vnode/main/src/vnodeWrite.c b/src/vnode/main/src/vnodeWrite.c index 1504c92151b5672887297588765921cc943e432f..5e033054879224ed6c4ff6da1ba109c02d9dc955 100644 --- a/src/vnode/main/src/vnodeWrite.c +++ b/src/vnode/main/src/vnodeWrite.c @@ -25,6 +25,7 @@ #include "dataformat.h" #include "vnode.h" #include "vnodeInt.h" +#include "tutil.h" static int32_t (*vnodeProcessWriteMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *, void *, SRspRet *); static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pMsg, SRspRet *); @@ -155,6 +156,8 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe void *pTsdb = vnodeGetTsdb(pVnode); code = tsdbCreateTable(pTsdb, &tCfg); + tfree(pDestSchema); + dTrace("pVnode:%p vgId:%d, table:%s is created, result:%x", pVnode, pVnode->vgId, pTable->tableId, code); return code; } diff --git a/src/vnode/tsdb/src/tsdbFile.c b/src/vnode/tsdb/src/tsdbFile.c index bd6699eb8484b3ee9b1bbb9cb2415f10f1d7b8f3..8bdfe63002e392476c9ddb27395e5181d324f180 100644 --- a/src/vnode/tsdb/src/tsdbFile.c +++ b/src/vnode/tsdb/src/tsdbFile.c @@ -62,6 +62,7 @@ STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles) { // TODO } } + closedir(dir); return pFileH; } diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 61f4995e43817fa7e02717e0ebcd7973905dafba..aa185f4bf2345ed0de74ed9aa46265c0a919eb08 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -268,6 +268,9 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) { tsdbFreeCache(pRepo->tsdbCache); + tfree(pRepo->rootDir); + tfree(pRepo); + return 0; } @@ -847,6 +850,7 @@ static void *tsdbCommitData(void *arg) { tsdbLockRepo(arg); tdListMove(pCache->imem->list, pCache->pool.memPool); + tdListFree(pCache->imem->list); free(pCache->imem); pCache->imem = NULL; pRepo->commit = 0; @@ -1125,11 +1129,11 @@ static int tsdbWriteBlockToFileImpl(SFile *pFile, SDataCols *pCols, int pointsTo *len += pCompCol->len; } - if (pCompData == NULL) free((void *)pCompData); + tfree(pCompData); return 0; _err: - if (pCompData == NULL) free((void *)pCompData); + tfree(pCompData); return -1; } diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 0c6fc6170144d239daf162d7232577fb520e5b34..22f735713566edd8ae5740338855de5998a663b2 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -312,6 +312,14 @@ int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId) { // return 0; // } +static void tsdbFreeMemTable(SMemTable *pMemTable) { + if (pMemTable) { + tSkipListDestroy(pMemTable->pData); + } + + free(pMemTable); +} + static int tsdbFreeTable(STable *pTable) { // TODO: finish this function if (pTable->type == TSDB_CHILD_TABLE) { @@ -323,7 +331,10 @@ static int tsdbFreeTable(STable *pTable) { // Free content if (TSDB_TABLE_IS_SUPER_TABLE(pTable)) { tSkipListDestroy(pTable->pIndex); - } + } + + tsdbFreeMemTable(pTable->mem); + tsdbFreeMemTable(pTable->imem); free(pTable); return 0; diff --git a/src/vnode/tsdb/src/tsdbMetaFile.c b/src/vnode/tsdb/src/tsdbMetaFile.c index d3cff1772c6732d22d38c359413c45a5212d97b6..6821fc2d984c1c2b876fe70f740d04bc0cc04db7 100644 --- a/src/vnode/tsdb/src/tsdbMetaFile.c +++ b/src/vnode/tsdb/src/tsdbMetaFile.c @@ -177,6 +177,7 @@ void tsdbCloseMetaFile(SMetaFile *mfh) { close(mfh->fd); taosHashCleanup(mfh->map); + tfree(mfh); } static int32_t tsdbGetMetaFileName(char *rootDir, char *fname) { diff --git a/src/vnode/tsdb/src/tsdbRead.c b/src/vnode/tsdb/src/tsdbRead.c index 49cbd1004256892c2b66fc784629e5bf9f7550e5..a44174ae6613eccee7accaa9b14437c8b24e310a 100644 --- a/src/vnode/tsdb/src/tsdbRead.c +++ b/src/vnode/tsdb/src/tsdbRead.c @@ -37,10 +37,6 @@ typedef struct SField { // todo need the definition } SField; -typedef struct SHeaderFileInfo { - int32_t fileId; -} SHeaderFileInfo; - typedef struct SQueryFilePos { int32_t fid; int32_t slot; @@ -380,11 +376,12 @@ static bool loadQualifiedDataFromFileBlock(STsdbQueryHandle *pQueryHandle) { SArray *sa = getDefaultLoadColumns(pQueryHandle, true); if (QUERY_IS_ASC_QUERY(pQueryHandle->order)) { - // query ended in current block if (pQueryHandle->window.ekey < pBlock->keyLast) { doLoadDataFromFileBlock(pQueryHandle); filterDataInDataBlock(pQueryHandle, pCheckInfo->pDataCols, sa); + } else { // the whole block is loaded in to buffer + pQueryHandle->realNumOfRows = pBlock->numOfPoints; } } else {// todo desc query if (pQueryHandle->window.ekey > pBlock->keyFirst) { @@ -932,10 +929,6 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList STsdbQueryHandle* pHandle = (STsdbQueryHandle*) pQueryHandle; if (pHandle->cur.fid < 0) { - - - - return pHandle->pColumns; } else { STableCheckInfo* pCheckInfo = taosArrayGet(pHandle->pTableCheckInfo, pHandle->activeIndex); diff --git a/src/vnode/wal/src/walMain.c b/src/vnode/wal/src/walMain.c index 7c5602680ffab91a82ddd6cefa25e697315002b9..17389670982a0625b5b4a1d53766454f51bfe574 100644 --- a/src/vnode/wal/src/walMain.c +++ b/src/vnode/wal/src/walMain.c @@ -80,7 +80,8 @@ void *walOpen(char *path, SWalCfg *pCfg) { } void walClose(void *handle) { - + if (handle == NULL) return; + SWal *pWal = (SWal *)handle; close(pWal->fd); diff --git a/tests/script/basicSuite.sim b/tests/script/basicSuite.sim index c95695fe009e853feb9c5b1cd3cd60376316a19a..290472b15d33d2bc7422a13480e7e11016d235b6 100644 --- a/tests/script/basicSuite.sim +++ b/tests/script/basicSuite.sim @@ -1,8 +1,8 @@ ################################# -#run general/table/basic1.sim +run general/table/basic1.sim run general/table/basic2.sim -#run general/table/basic3.sim +run general/table/basic3.sim ################################## diff --git a/tests/script/general/db/basic4.sim b/tests/script/general/db/basic4.sim index f620112cfb71f361d3b6c0e7cbc962bca96b7d7f..deac9d47b4a4864e10c376ed46098cae3e7f981d 100644 --- a/tests/script/general/db/basic4.sim +++ b/tests/script/general/db/basic4.sim @@ -36,7 +36,7 @@ sql show d1.vgroups if $rows != 1 then return -1 endi -if $data00 != 1 then +if $data00 != 2 then return -1 endi if $data01 != 4 then @@ -75,7 +75,7 @@ sql show d1.vgroups if $rows != 1 then return -1 endi -if $data00 != 1 then +if $data00 != 2 then return -1 endi if $data01 != 3 then diff --git a/tests/script/general/db/basic5.sim b/tests/script/general/db/basic5.sim index ec619389bd011132a04c67882b5f5c38561e2c40..ebb7d3c9675e0e9accc3d83e90d89590742775e0 100644 --- a/tests/script/general/db/basic5.sim +++ b/tests/script/general/db/basic5.sim @@ -36,7 +36,7 @@ sql show d1.vgroups if $rows != 1 then return -1 endi -if $data00 != 1 then +if $data00 != 2 then return -1 endi if $data01 != 4 then diff --git a/tests/script/general/table/basic2.sim b/tests/script/general/table/basic2.sim index 7701ca1c1fb5575d0fc6613b948b2bdbcd7a38fa..1f6d889429de482c820b0297010326b4a03155ee 100644 --- a/tests/script/general/table/basic2.sim +++ b/tests/script/general/table/basic2.sim @@ -29,7 +29,7 @@ if $data03 != 1 then endi sql show d1.vgroups -if $data00 != 1 then +if $data00 != 2 then return -1 endi @@ -43,11 +43,12 @@ sql_error insert into d1.n2 values(now, 1) print =============== insert data2 sql insert into d1.n3 values(now, 1) -sql insert into d1.n3 values(now, 2) -sql insert into d1.n3 values(now, 3) +sql insert into d1.n3 values(now+1s, 2) +sql insert into d1.n3 values(now+2s, 3) print =============== query data sql select * from d1.n3 +print $rows if $rows != 3 then return -1 endi diff --git a/tests/script/sh/stop_dnodes.sh b/tests/script/sh/stop_dnodes.sh index acdfbe9e6ad74d2493e442207a98442d5c5e3144..a873eb565442ce359d4a3a57403ff32b5bc2f50e 100755 --- a/tests/script/sh/stop_dnodes.sh +++ b/tests/script/sh/stop_dnodes.sh @@ -6,8 +6,10 @@ if [ -n "$PID" ]; then sudo systemctl stop taosd fi -PID=`ps -ef|grep taosd | grep -v grep | awk '{print $2}'` -if [ -n "$PID" ]; then +PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` +while [ -n "$PID" ]; do echo sudo kill -9 $PID - sudo kill -9 $PID -fi + sudo pkill -9 taosd + sudo fuser -k -n tcp 6030 + PID=`ps -ef|grep -w taosd | grep -v grep | awk '{print $2}'` +done diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index d844f3b7860ea51b4a69715ad7d5c476896fbffd..912f10ba2a42001b5a970c5da57586d572953cdd 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -576,6 +576,7 @@ bool simCreateRestFulConnect(SScript *script, char *user, char *pass) { bool simCreateNativeConnect(SScript *script, char *user, char *pass) { simCloseTaosdConnect(script); void *taos = NULL; + taosMsleep(2000); for (int attempt = 0; attempt < 10; ++attempt) { taos = taos_connect(NULL, user, pass, NULL, tsMnodeShellPort); if (taos == NULL) {