From ddc13d294cef52d81451604498fe8d87accbcedc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 2 Jan 2021 02:57:58 +0000 Subject: [PATCH 01/49] share rpc obj --- src/client/inc/tsclient.h | 10 +++- src/client/src/tscSql.c | 16 +++--- src/client/src/tscSystem.c | 106 ++++++++++++++++++++++++++++--------- src/client/src/tscUtil.c | 7 +-- 4 files changed, 100 insertions(+), 39 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 6879470145..0f2f0513a3 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -307,6 +307,7 @@ typedef struct STscObj { struct SSqlStream *streamList; SRpcCorEpSet *tscCorMgmtEpSet; void* pDnodeConn; + void* pRpcObj; pthread_mutex_t mutex; int32_t numOfObj; // number of sqlObj from this tscObj } STscObj; @@ -377,7 +378,14 @@ typedef struct SSqlStream { void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable); -int32_t tscInitRpc(const char *user, const char *secret, void** pDnodeConn); +typedef struct { + char key[512]; + void *pDnodeConn; +} SRpcObj; + +void *tscAcquireRpc(const char *insKey); +void tscReleaseRpc(void *param); +int32_t tscInitRpc(const char *key, const char *user, const char *secret, void **pRpcObj, void** pDnodeConn); void tscInitMsgsFp(); int tsParseSql(SSqlObj *pSql, bool initial); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index fa7bc99a9f..e70db12a7b 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -90,9 +90,12 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa } else { if (tscSetMgmtEpSetFromCfg(tsFirst, tsSecond, &corMgmtEpSet) < 0) return NULL; } + char rpcKey[512] = {0}; + sprintf(rpcKey, "%s:%s:%s:%d", user, pass, ip, port); + void *pRpcObj = NULL; void *pDnodeConn = NULL; - if (tscInitRpc(user, secretEncrypt, &pDnodeConn) != 0) { + if (tscInitRpc(rpcKey, user, secretEncrypt, &pRpcObj, &pDnodeConn) != 0) { terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } @@ -100,20 +103,21 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - rpcClose(pDnodeConn); + tscReleaseRpc(pRpcObj); return NULL; } // set up tscObj's mgmtEpSet pObj->tscCorMgmtEpSet = (SRpcCorEpSet *)malloc(sizeof(SRpcCorEpSet)); if (NULL == pObj->tscCorMgmtEpSet) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - rpcClose(pDnodeConn); + tscReleaseRpc(pRpcObj); free(pObj->tscCorMgmtEpSet); free(pObj); } memcpy(pObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(SRpcCorEpSet)); pObj->signature = pObj; + pObj->pRpcObj = pRpcObj; pObj->pDnodeConn = pDnodeConn; tstrncpy(pObj->user, user, sizeof(pObj->user)); @@ -125,7 +129,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa /* db name is too long */ if (len >= TSDB_DB_NAME_LEN) { terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; - rpcClose(pDnodeConn); + tscReleaseRpc(pRpcObj); free(pObj->tscCorMgmtEpSet); free(pObj); return NULL; @@ -143,7 +147,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (NULL == pSql) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - rpcClose(pDnodeConn); + tscReleaseRpc(pRpcObj); free(pObj->tscCorMgmtEpSet); free(pObj); return NULL; @@ -160,7 +164,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - rpcClose(pDnodeConn); + tscReleaseRpc(pRpcObj); free(pSql); free(pObj->tscCorMgmtEpSet); free(pObj); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ff605dad72..4e23bd8a03 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -40,39 +40,81 @@ void *tscCheckDiskUsageTmr; int tscRefId = -1; int tscNumOfObj = 0; // number of sqlObj in current process. +int32_t tscNumOfThreads = 1; +void * tscRpcCache; +static pthread_mutex_t rpcObjMutex; static pthread_once_t tscinit = PTHREAD_ONCE_INIT; void tscCheckDiskUsage(void *UNUSED_PARAM(para), void* UNUSED_PARAM(param)) { taosGetDisk(); taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr); } - -int32_t tscInitRpc(const char *user, const char *secretEncrypt, void **pDnodeConn) { - SRpcInit rpcInit; - - if (*pDnodeConn == NULL) { - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.localPort = 0; - rpcInit.label = "TSC"; - rpcInit.numOfThreads = 1; // every DB connection has only one thread - rpcInit.cfp = tscProcessMsgFromServer; - rpcInit.sessions = tsMaxConnections; - rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.user = (char *)user; - rpcInit.idleTime = 2000; - rpcInit.ckey = "key"; - rpcInit.spi = 1; - rpcInit.secret = (char *)secretEncrypt; - - *pDnodeConn = rpcOpen(&rpcInit); - if (*pDnodeConn == NULL) { - tscError("failed to init connection to TDengine"); - return -1; - } else { - tscDebug("dnodeConn:%p is created, user:%s", *pDnodeConn, user); - } +void tscFreeRpcObj(void *param) { + assert(param); + SRpcObj *pRpcObj = (SRpcObj *)(param); + rpcClose(pRpcObj->pDnodeConn); +} +void *tscAcquireRpc(const char *key) { + SRpcObj *pRpcObj = taosCacheAcquireByKey(tscRpcCache, key, strlen(key)); + if (pRpcObj == NULL) { + return NULL; } + return pRpcObj; +} +void tscReleaseRpc(void *param) { + if (param == NULL) { + return; + } + pthread_mutex_lock(&rpcObjMutex); + taosCacheRelease(tscRpcCache, (void *)¶m, false); + pthread_mutex_unlock(&rpcObjMutex); +} + +int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj, void **pDnodeConn) { + pthread_mutex_lock(&rpcObjMutex); + + SRpcObj *pRpcObj = (SRpcObj *)tscAcquireRpc(key); + if (pRpcObj != NULL) { + *ppRpcObj = pRpcObj; + *pDnodeConn = pRpcObj->pDnodeConn; + pthread_mutex_unlock(&rpcObjMutex); + return 0; + } + + SRpcInit rpcInit; + memset(&rpcInit, 0, sizeof(rpcInit)); + rpcInit.localPort = 0; + rpcInit.label = "TSC"; + rpcInit.numOfThreads = 1; + rpcInit.cfp = tscProcessMsgFromServer; + rpcInit.sessions = tsMaxConnections; + rpcInit.connType = TAOS_CONN_CLIENT; + rpcInit.user = (char *)user; + rpcInit.idleTime = 2000; + rpcInit.ckey = "key"; + rpcInit.spi = 1; + rpcInit.secret = (char *)secretEncrypt; + + SRpcObj rpcObj; + memset(&rpcObj, 0, sizeof(rpcObj)); + strncpy(rpcObj.key, key, strlen(key)); + rpcObj.pDnodeConn = rpcOpen(&rpcInit); + if (rpcObj.pDnodeConn == NULL) { + pthread_mutex_unlock(&rpcObjMutex); + tscError("failed to init connection to TDengine"); + return -1; + } + pRpcObj = taosCachePut(tscRpcCache, rpcObj.key, strlen(rpcObj.key), &rpcObj, sizeof(rpcObj), 1000*10); + if (pRpcObj == NULL) { + rpcClose(rpcObj.pDnodeConn); + pthread_mutex_unlock(&rpcObjMutex); + return -1; + } + + *ppRpcObj = pRpcObj; + *pDnodeConn = pRpcObj->pDnodeConn; + pthread_mutex_unlock(&rpcObjMutex); return 0; } @@ -113,7 +155,7 @@ void taos_init_imp(void) { int queueSize = tsMaxConnections*2; double factor = (tscEmbedded == 0)? 2.0:4.0; - int32_t tscNumOfThreads = (int)(tsNumOfCores * tsNumOfThreadsPerCore / factor); + tscNumOfThreads = (int)(tsNumOfCores * tsNumOfThreadsPerCore / factor); if (tscNumOfThreads < 2) { tscNumOfThreads = 2; } @@ -135,6 +177,8 @@ void taos_init_imp(void) { tscObjRef = taosOpenRef(40960, tscFreeRegisteredSqlObj); tscHashMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); } + tscRpcCache = taosCacheInit(TSDB_DATA_TYPE_BINARY, refreshTime, true, tscFreeRpcObj, "rpcObj"); + pthread_mutex_init(&rpcObjMutex, NULL); tscRefId = taosOpenRef(200, tscCloseTscObj); @@ -169,6 +213,16 @@ void taos_cleanup(void) { taosCloseRef(tscRefId); taosCleanupKeywordsTable(); taosCloseLog(); + + m = tscRpcCache; + if (m != NULL && atomic_val_compare_exchange_ptr(&tscRpcCache, m, 0) == m) { + pthread_mutex_lock(&rpcObjMutex); + taosCacheCleanup(tscRpcCache); + tscRpcCache = NULL; + pthread_mutex_unlock(&rpcObjMutex); + pthread_mutex_destroy(&rpcObjMutex); + } + if (tscEmbedded == 0) rpcCleanup(); m = tscTmr; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 52e26fe95a..7936c31634 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -895,15 +895,10 @@ void tscCloseTscObj(void *param) { pObj->signature = NULL; taosTmrStopA(&(pObj->pTimer)); - void* p = pObj->pDnodeConn; - if (pObj->pDnodeConn != NULL) { - rpcClose(pObj->pDnodeConn); - pObj->pDnodeConn = NULL; - } + tscReleaseRpc(pObj->pRpcObj); tfree(pObj->tscCorMgmtEpSet); pthread_mutex_destroy(&pObj->mutex); - tscDebug("%p DB connection is closed, dnodeConn:%p", pObj, p); tfree(pObj); } From ea28d23512387d910fb30d3282015c3c9ad02081 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 2 Jan 2021 05:48:53 +0000 Subject: [PATCH 02/49] avoid invalid read --- src/client/src/tscUtil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 7936c31634..c6182dcb5f 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -458,14 +458,14 @@ void tscFreeRegisteredSqlObj(void *pSql) { SSqlObj* p = *(SSqlObj**)pSql; STscObj* pTscObj = p->pTscObj; + int32_t num = atomic_sub_fetch_32(&pTscObj->numOfObj, 1); + int32_t total = atomic_sub_fetch_32(&tscNumOfObj, 1); + tscDebug("%p free SqlObj, total in tscObj:%d, total:%d", pSql, num, total); assert(RID_VALID(p->self)); tscFreeSqlObj(p); taosReleaseRef(tscRefId, pTscObj->rid); - int32_t num = atomic_sub_fetch_32(&pTscObj->numOfObj, 1); - int32_t total = atomic_sub_fetch_32(&tscNumOfObj, 1); - tscDebug("%p free SqlObj, total in tscObj:%d, total:%d", pSql, num, total); } void tscFreeTableMetaHelper(void *pTableMeta) { From b00ac2f5bb57211a26415639f6affb86e18ced5e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 2 Jan 2021 10:49:13 +0000 Subject: [PATCH 03/49] share rpc obj --- src/client/inc/tsclient.h | 18 ++--- src/client/src/tscServer.c | 24 ++++--- src/client/src/tscSql.c | 27 ++------ src/client/src/tscSystem.c | 12 ++-- src/client/src/tscUtil.c | 1 - src/rpc/src/rpcTcp.c | 130 +++++++++++++++++++++++++------------ 6 files changed, 125 insertions(+), 87 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 0f2f0513a3..c11c524f96 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -290,6 +290,12 @@ typedef struct { struct SLocalReducer *pLocalReducer; } SSqlRes; +typedef struct { + char key[512]; + SRpcCorEpSet *tscCorMgmtEpSet; + void *pDnodeConn; +} SRpcObj; + typedef struct STscObj { void * signature; void * pTimer; @@ -305,9 +311,7 @@ typedef struct STscObj { int64_t hbrid; struct SSqlObj * sqlList; struct SSqlStream *streamList; - SRpcCorEpSet *tscCorMgmtEpSet; - void* pDnodeConn; - void* pRpcObj; + SRpcObj *pRpcObj; pthread_mutex_t mutex; int32_t numOfObj; // number of sqlObj from this tscObj } STscObj; @@ -378,14 +382,10 @@ typedef struct SSqlStream { void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable); -typedef struct { - char key[512]; - void *pDnodeConn; -} SRpcObj; -void *tscAcquireRpc(const char *insKey); +void *tscAcquireRpc(const char *key); void tscReleaseRpc(void *param); -int32_t tscInitRpc(const char *key, const char *user, const char *secret, void **pRpcObj, void** pDnodeConn); +int32_t tscInitRpc(const char *key, const char *user, const char *secret, void **pRpcObj); void tscInitMsgsFp(); int tsParseSql(SSqlObj *pSql, bool initial); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index f7a2236262..8a56ccdc9b 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -72,7 +72,7 @@ static void tscSetDnodeEpSet(SRpcEpSet* pEpSet, SVgroupInfo* pVgroupInfo) { } static void tscDumpMgmtEpSet(SSqlObj *pSql) { - SRpcCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; + SRpcCorEpSet *pCorEpSet = pSql->pTscObj->pRpcObj->tscCorMgmtEpSet; taosCorBeginRead(&pCorEpSet->version); pSql->epSet = pCorEpSet->epSet; taosCorEndRead(&pCorEpSet->version); @@ -95,7 +95,7 @@ bool tscEpSetIsEqual(SRpcEpSet *s1, SRpcEpSet *s2) { } void tscUpdateMgmtEpSet(SSqlObj *pSql, SRpcEpSet *pEpSet) { // no need to update if equal - SRpcCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; + SRpcCorEpSet *pCorEpSet = pSql->pTscObj->pRpcObj->tscCorMgmtEpSet; taosCorBeginWrite(&pCorEpSet->version); pCorEpSet->epSet = *pEpSet; taosCorEndWrite(&pCorEpSet->version); @@ -151,13 +151,16 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { SRpcEpSet *epSet = &pRsp->epSet; if (epSet->numOfEps > 0) { tscEpSetHtons(epSet); - if (!tscEpSetIsEqual(&pSql->pTscObj->tscCorMgmtEpSet->epSet, epSet)) { - tscTrace("%p updating epset: numOfEps: %d, inUse: %d", pSql, epSet->numOfEps, epSet->inUse); - for (int8_t i = 0; i < epSet->numOfEps; i++) { - tscTrace("endpoint %d: fqdn=%s, port=%d", i, epSet->fqdn[i], epSet->port[i]); - } - tscUpdateMgmtEpSet(pSql, epSet); - } + + //SRpcCorEpSet *pCorEpSet = pSql->pTscObj->pRpcObj->tscCorMgmtEpSet; + //if (!tscEpSetIsEqual(&pCorEpSet->epSet, epSet)) { + // tscTrace("%p updating epset: numOfEps: %d, inUse: %d", pSql, epSet->numOfEps, epSet->inUse); + // for (int8_t i = 0; i < epSet->numOfEps; i++) { + // tscTrace("endpoint %d: fqdn=%s, port=%d", i, epSet->fqdn[i], epSet->port[i]); + // } + //} + //concurrency problem, update mgmt epset anyway + tscUpdateMgmtEpSet(pSql, epSet); } pSql->pTscObj->connId = htonl(pRsp->connId); @@ -264,7 +267,8 @@ int tscSendMsgToServer(SSqlObj *pSql) { .code = 0 }; - rpcSendRequest(pObj->pDnodeConn, &pSql->epSet, &rpcMsg, &pSql->rpcRid); + + rpcSendRequest(pObj->pRpcObj->pDnodeConn, &pSql->epSet, &rpcMsg, &pSql->rpcRid); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index e70db12a7b..0f1824c1ed 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -94,8 +94,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa sprintf(rpcKey, "%s:%s:%s:%d", user, pass, ip, port); void *pRpcObj = NULL; - void *pDnodeConn = NULL; - if (tscInitRpc(rpcKey, user, secretEncrypt, &pRpcObj, &pDnodeConn) != 0) { + if (tscInitRpc(rpcKey, user, secretEncrypt, &pRpcObj) != 0) { terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } @@ -106,20 +105,9 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa tscReleaseRpc(pRpcObj); return NULL; } - // set up tscObj's mgmtEpSet - pObj->tscCorMgmtEpSet = (SRpcCorEpSet *)malloc(sizeof(SRpcCorEpSet)); - if (NULL == pObj->tscCorMgmtEpSet) { - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tscReleaseRpc(pRpcObj); - free(pObj->tscCorMgmtEpSet); - free(pObj); - } - memcpy(pObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(SRpcCorEpSet)); - pObj->signature = pObj; - pObj->pRpcObj = pRpcObj; - pObj->pDnodeConn = pDnodeConn; - + pObj->pRpcObj = (SRpcObj *)pRpcObj; + memcpy(pObj->pRpcObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(SRpcCorEpSet)); tstrncpy(pObj->user, user, sizeof(pObj->user)); secretEncryptLen = MIN(secretEncryptLen, sizeof(pObj->pass)); memcpy(pObj->pass, secretEncrypt, secretEncryptLen); @@ -130,7 +118,6 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (len >= TSDB_DB_NAME_LEN) { terrno = TSDB_CODE_TSC_INVALID_DB_LENGTH; tscReleaseRpc(pRpcObj); - free(pObj->tscCorMgmtEpSet); free(pObj); return NULL; } @@ -148,7 +135,6 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (NULL == pSql) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscReleaseRpc(pRpcObj); - free(pObj->tscCorMgmtEpSet); free(pObj); return NULL; } @@ -166,7 +152,6 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscReleaseRpc(pRpcObj); free(pSql); - free(pObj->tscCorMgmtEpSet); free(pObj); return NULL; } @@ -205,7 +190,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, return NULL; } - tscDebug("%p DB connection is opening, dnodeConn:%p", pObj, pObj->pDnodeConn); + tscDebug("%p DB connection is opening, rpcObj: %p, dnodeConn:%p", pObj, pObj->pRpcObj, pObj->pRpcObj->pDnodeConn); taos_free_result(pSql); // version compare only requires the first 3 segments of the version string @@ -282,7 +267,7 @@ void taos_close(TAOS *taos) { return; } - tscDebug("%p try to free tscObj and close dnodeConn:%p", pObj, pObj->pDnodeConn); + tscDebug("%p try to free tscObj", pObj); if (pObj->signature != pObj) { tscDebug("%p already closed or invalid tscObj", pObj); return; @@ -302,7 +287,7 @@ void taos_close(TAOS *taos) { } } - tscDebug("%p all sqlObj are freed, free tscObj and close dnodeConn:%p", pObj, pObj->pDnodeConn); + tscDebug("%p all sqlObj are freed, free tscObj", pObj); taosRemoveRef(tscRefId, pObj->rid); } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 4e23bd8a03..f37daee3ca 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -53,6 +53,7 @@ void tscFreeRpcObj(void *param) { assert(param); SRpcObj *pRpcObj = (SRpcObj *)(param); rpcClose(pRpcObj->pDnodeConn); + tfree(pRpcObj->tscCorMgmtEpSet); } void *tscAcquireRpc(const char *key) { SRpcObj *pRpcObj = taosCacheAcquireByKey(tscRpcCache, key, strlen(key)); @@ -71,13 +72,12 @@ void tscReleaseRpc(void *param) { pthread_mutex_unlock(&rpcObjMutex); } -int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj, void **pDnodeConn) { +int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj) { pthread_mutex_lock(&rpcObjMutex); SRpcObj *pRpcObj = (SRpcObj *)tscAcquireRpc(key); if (pRpcObj != NULL) { *ppRpcObj = pRpcObj; - *pDnodeConn = pRpcObj->pDnodeConn; pthread_mutex_unlock(&rpcObjMutex); return 0; } @@ -86,7 +86,7 @@ int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = 0; rpcInit.label = "TSC"; - rpcInit.numOfThreads = 1; + rpcInit.numOfThreads = tscNumOfThreads * 2; rpcInit.cfp = tscProcessMsgFromServer; rpcInit.sessions = tsMaxConnections; rpcInit.connType = TAOS_CONN_CLIENT; @@ -111,9 +111,13 @@ int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, pthread_mutex_unlock(&rpcObjMutex); return -1; } + pRpcObj->tscCorMgmtEpSet = malloc(sizeof(SRpcCorEpSet)); + if (pRpcObj->tscCorMgmtEpSet == NULL) { + rpcClose(rpcObj.pDnodeConn); + pthread_mutex_unlock(&rpcObjMutex); + } *ppRpcObj = pRpcObj; - *pDnodeConn = pRpcObj->pDnodeConn; pthread_mutex_unlock(&rpcObjMutex); return 0; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index c6182dcb5f..5507748720 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -896,7 +896,6 @@ void tscCloseTscObj(void *param) { taosTmrStopA(&(pObj->pTimer)); tscReleaseRpc(pObj->pRpcObj); - tfree(pObj->tscCorMgmtEpSet); pthread_mutex_destroy(&pObj->mutex); tfree(pObj); diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 178b96c423..b82e197bf7 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -55,6 +55,13 @@ typedef struct SThreadObj { void *(*processData)(SRecvInfo *pPacket); } SThreadObj; +typedef struct { + char label[TSDB_LABEL_LEN]; + int32_t index; + int numOfThreads; + SThreadObj **pThreadObj; +} SClientObj; + typedef struct { SOCKET fd; uint32_t ip; @@ -121,6 +128,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread pThreadObj->processData = fp; tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); pThreadObj->shandle = shandle; + pThreadObj->stop = false; } // initialize mutex, thread, fd which may fail @@ -171,6 +179,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread } static void taosStopTcpThread(SThreadObj* pThreadObj) { + if (pThreadObj == NULL) { return;} // save thread into local variable and signal thread to stop pthread_t thread = pThreadObj->thread; if (!taosCheckPthreadValid(thread)) { @@ -275,48 +284,77 @@ static void *taosAcceptTcpConnection(void *arg) { return NULL; } -void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *fp, void *shandle) { - SThreadObj *pThreadObj; +void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) { + SClientObj *pClientObj = (SClientObj *)calloc(1, sizeof(SClientObj)); + if (pClientObj == NULL) { + tError("TCP:%s no enough memory", label); + terrno = TAOS_SYSTEM_ERROR(errno); + return NULL; + } + + + tstrncpy(pClientObj->label, label, sizeof(pClientObj->label)); + pClientObj->numOfThreads = numOfThreads; + pClientObj->pThreadObj = (SThreadObj **)calloc(numOfThreads, sizeof(SThreadObj*)); + if (pClientObj->pThreadObj == NULL) { + tError("TCP:%s no enough memory", label); + tfree(pClientObj); + terrno = TAOS_SYSTEM_ERROR(errno); + } + + int code = 0; pthread_attr_t thattr; - - pThreadObj = (SThreadObj *)malloc(sizeof(SThreadObj)); - memset(pThreadObj, 0, sizeof(SThreadObj)); - tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); - pThreadObj->ip = ip; - pThreadObj->shandle = shandle; - - if (pthread_mutex_init(&(pThreadObj->mutex), NULL) < 0) { - tError("%s failed to init TCP client mutex(%s)", label, strerror(errno)); - free(pThreadObj); - terrno = TAOS_SYSTEM_ERROR(errno); - return NULL; - } - - pThreadObj->pollFd = (SOCKET)epoll_create(10); // size does not matter - if (pThreadObj->pollFd < 0) { - tError("%s failed to create TCP client epoll", label); - free(pThreadObj); - terrno = TAOS_SYSTEM_ERROR(errno); - return NULL; - } - - pThreadObj->processData = fp; - pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - int code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); - pthread_attr_destroy(&thattr); - if (code != 0) { - taosCloseSocket(pThreadObj->pollFd); - free(pThreadObj); - terrno = TAOS_SYSTEM_ERROR(errno); - tError("%s failed to create TCP read data thread(%s)", label, strerror(errno)); - return NULL; + + for (int i = 0; i < numOfThreads; ++i) { + SThreadObj *pThreadObj = (SThreadObj *)calloc(1, sizeof(SThreadObj)); + if (pThreadObj == NULL) { + tError("TCP:%s no enough memory", label); + terrno = TAOS_SYSTEM_ERROR(errno); + for (int j=0; jpThreadObj[j]); + free(pClientObj); + pthread_attr_destroy(&thattr); + return NULL; + } + pClientObj->pThreadObj[i] = pThreadObj; + taosResetPthread(&pThreadObj->thread); + pThreadObj->ip = ip; + pThreadObj->stop = false; + tstrncpy(pThreadObj->label, label, sizeof(pThreadObj->label)); + pThreadObj->shandle = shandle; + pThreadObj->processData = fp; } - tDebug("%s TCP client is initialized, ip:%u:%hu", label, ip, port); + // initialize mutex, thread, fd which may fail + for (int i = 0; i < numOfThreads; ++i) { + SThreadObj *pThreadObj = pClientObj->pThreadObj[i]; + code = pthread_mutex_init(&(pThreadObj->mutex), NULL); + if (code < 0) { + tError("%s failed to init TCP process data mutex(%s)", label, strerror(errno)); + break; + } - return pThreadObj; + pThreadObj->pollFd = (int64_t)epoll_create(10); // size does not matter + if (pThreadObj->pollFd < 0) { + tError("%s failed to create TCP epoll", label); + code = -1; + break; + } + + code = pthread_create(&(pThreadObj->thread), &thattr, taosProcessTcpData, (void *)(pThreadObj)); + if (code != 0) { + tError("%s failed to create TCP process data thread(%s)", label, strerror(errno)); + break; + } + pThreadObj->threadId = i; + } + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + taosCleanUpTcpClient(pClientObj); + pClientObj = NULL; + } + return pClientObj; } void taosStopTcpClient(void *chandle) { @@ -327,15 +365,23 @@ void taosStopTcpClient(void *chandle) { } void taosCleanUpTcpClient(void *chandle) { - SThreadObj *pThreadObj = chandle; - if (pThreadObj == NULL) return; - - tDebug ("%s TCP client will be cleaned up", pThreadObj->label); - taosStopTcpThread(pThreadObj); + SClientObj *pClientObj = chandle; + if (pClientObj == NULL) return; + for (int i = 0; i < pClientObj->numOfThreads; ++i) { + SThreadObj *pThreadObj= pClientObj->pThreadObj[i]; + taosStopTcpThread(pThreadObj); + } + + tDebug("%s TCP client is cleaned up", pClientObj->label); + tfree(pClientObj->pThreadObj); + tfree(pClientObj); } void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port) { - SThreadObj * pThreadObj = shandle; + SClientObj * pClientObj = shandle; + int32_t index = atomic_load_32(&pClientObj->index) % pClientObj->numOfThreads; + atomic_store_32(&pClientObj->index, index + 1); + SThreadObj *pThreadObj = pClientObj->pThreadObj[index]; SOCKET fd = taosOpenTcpClientSocket(ip, port, pThreadObj->ip); if (fd < 0) return NULL; From 19c3c7c6f3de40d02ef34593c6909a065a3f6969 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 2 Jan 2021 11:05:57 +0000 Subject: [PATCH 04/49] add debug log --- src/client/src/tscSystem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index f37daee3ca..e4a1cbc7d5 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -52,6 +52,7 @@ void tscCheckDiskUsage(void *UNUSED_PARAM(para), void* UNUSED_PARAM(param)) { void tscFreeRpcObj(void *param) { assert(param); SRpcObj *pRpcObj = (SRpcObj *)(param); + tscDebug("free rpcObj:%p and free pDnodeConn: %p", pRpcObj, pRpcObj->pDnodeConn); rpcClose(pRpcObj->pDnodeConn); tfree(pRpcObj->tscCorMgmtEpSet); } From 3414548772e69ff920a4f159f380a98dab87438c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 2 Jan 2021 12:11:30 +0000 Subject: [PATCH 05/49] share mgmt ep set --- src/client/inc/tsclient.h | 2 +- src/client/src/tscSql.c | 3 +-- src/client/src/tscSystem.c | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c11c524f96..d6cf9a6553 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -385,7 +385,7 @@ void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable); void *tscAcquireRpc(const char *key); void tscReleaseRpc(void *param); -int32_t tscInitRpc(const char *key, const char *user, const char *secret, void **pRpcObj); +int32_t tscInitRpc(const char *key, const char *user, const char *secret, void **pRpcObj, SRpcCorEpSet *corMgmtEpSet); void tscInitMsgsFp(); int tsParseSql(SSqlObj *pSql, bool initial); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 0f1824c1ed..653574c8d0 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -94,7 +94,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa sprintf(rpcKey, "%s:%s:%s:%d", user, pass, ip, port); void *pRpcObj = NULL; - if (tscInitRpc(rpcKey, user, secretEncrypt, &pRpcObj) != 0) { + if (tscInitRpc(rpcKey, user, secretEncrypt, &pRpcObj, &corMgmtEpSet) != 0) { terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } @@ -107,7 +107,6 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa } pObj->signature = pObj; pObj->pRpcObj = (SRpcObj *)pRpcObj; - memcpy(pObj->pRpcObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(SRpcCorEpSet)); tstrncpy(pObj->user, user, sizeof(pObj->user)); secretEncryptLen = MIN(secretEncryptLen, sizeof(pObj->pass)); memcpy(pObj->pass, secretEncrypt, secretEncryptLen); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index e4a1cbc7d5..41c0ae1bad 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -73,7 +73,7 @@ void tscReleaseRpc(void *param) { pthread_mutex_unlock(&rpcObjMutex); } -int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj) { +int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj, SRpcCorEpSet *corMgmtEpSet) { pthread_mutex_lock(&rpcObjMutex); SRpcObj *pRpcObj = (SRpcObj *)tscAcquireRpc(key); @@ -117,6 +117,7 @@ int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, rpcClose(rpcObj.pDnodeConn); pthread_mutex_unlock(&rpcObjMutex); } + memcpy(pRpcObj->tscCorMgmtEpSet, corMgmtEpSet, sizeof(*corMgmtEpSet)); *ppRpcObj = pRpcObj; pthread_mutex_unlock(&rpcObjMutex); From 31534ad1976858d9346561cd49713265c198b9ec Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 2 Jan 2021 21:32:25 +0000 Subject: [PATCH 06/49] refactor rpc code --- src/client/inc/tsclient.h | 5 ++--- src/client/src/tscSql.c | 2 +- src/client/src/tscSystem.c | 11 ++--------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index d6cf9a6553..8c8e18c825 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -383,10 +383,9 @@ typedef struct SSqlStream { void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable); -void *tscAcquireRpc(const char *key); +int tscAcquireRpc(const char *key, const char *user, const char *secret, SRpcCorEpSet *corMgmtEpSet, void **pRpcObj); void tscReleaseRpc(void *param); -int32_t tscInitRpc(const char *key, const char *user, const char *secret, void **pRpcObj, SRpcCorEpSet *corMgmtEpSet); -void tscInitMsgsFp(); +void tscInitMsgsFp(); int tsParseSql(SSqlObj *pSql, bool initial); diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 653574c8d0..0730fffdd5 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -94,7 +94,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa sprintf(rpcKey, "%s:%s:%s:%d", user, pass, ip, port); void *pRpcObj = NULL; - if (tscInitRpc(rpcKey, user, secretEncrypt, &pRpcObj, &corMgmtEpSet) != 0) { + if (tscAcquireRpc(rpcKey, user, secretEncrypt,&corMgmtEpSet, &pRpcObj) != 0) { terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 41c0ae1bad..7a92b4fc05 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -56,13 +56,6 @@ void tscFreeRpcObj(void *param) { rpcClose(pRpcObj->pDnodeConn); tfree(pRpcObj->tscCorMgmtEpSet); } -void *tscAcquireRpc(const char *key) { - SRpcObj *pRpcObj = taosCacheAcquireByKey(tscRpcCache, key, strlen(key)); - if (pRpcObj == NULL) { - return NULL; - } - return pRpcObj; -} void tscReleaseRpc(void *param) { if (param == NULL) { @@ -73,10 +66,10 @@ void tscReleaseRpc(void *param) { pthread_mutex_unlock(&rpcObjMutex); } -int32_t tscInitRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj, SRpcCorEpSet *corMgmtEpSet) { +int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncrypt, SRpcCorEpSet *corMgmtEpSet, void **ppRpcObj) { pthread_mutex_lock(&rpcObjMutex); - SRpcObj *pRpcObj = (SRpcObj *)tscAcquireRpc(key); + SRpcObj *pRpcObj = (SRpcObj *)taosCacheAcquireByKey(tscRpcCache, key, strlen(key)); if (pRpcObj != NULL) { *ppRpcObj = pRpcObj; pthread_mutex_unlock(&rpcObjMutex); From 3d0ce022f03b10c8998c1ec9722601682d49df60 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 3 Jan 2021 12:43:02 +0000 Subject: [PATCH 07/49] refactor code --- src/client/src/tscSql.c | 2 +- src/client/src/tscSystem.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 0730fffdd5..2390df5f21 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -91,7 +91,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa if (tscSetMgmtEpSetFromCfg(tsFirst, tsSecond, &corMgmtEpSet) < 0) return NULL; } char rpcKey[512] = {0}; - sprintf(rpcKey, "%s:%s:%s:%d", user, pass, ip, port); + snprintf(rpcKey, sizeof(rpcKey), "%s:%s:%s:%d", user, pass, ip, port); void *pRpcObj = NULL; if (tscAcquireRpc(rpcKey, user, secretEncrypt,&corMgmtEpSet, &pRpcObj) != 0) { diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 7a92b4fc05..66fe4100b2 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -109,6 +109,7 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry if (pRpcObj->tscCorMgmtEpSet == NULL) { rpcClose(rpcObj.pDnodeConn); pthread_mutex_unlock(&rpcObjMutex); + return -1; } memcpy(pRpcObj->tscCorMgmtEpSet, corMgmtEpSet, sizeof(*corMgmtEpSet)); From b740129fcf19a7fb97f8afd40bdcff1835cb4519 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 3 Jan 2021 13:20:56 +0000 Subject: [PATCH 08/49] resolve conflicts --- src/client/src/tscSystem.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ac68d6e31d..27d23b8ee5 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -223,7 +223,6 @@ void taos_cleanup(void) { taosCleanupKeywordsTable(); taosCloseLog(); -<<<<<<< HEAD m = tscRpcCache; if (m != NULL && atomic_val_compare_exchange_ptr(&tscRpcCache, m, 0) == m) { @@ -235,8 +234,6 @@ void taos_cleanup(void) { } if (tscEmbedded == 0) rpcCleanup(); -======= ->>>>>>> ca3888c190d0415c151964a89652811e37089afd if (tscEmbedded == 0) { rpcCleanup(); From 289ede045ea2826cc637c5df603681c7fcaf780a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 3 Jan 2021 13:41:17 +0000 Subject: [PATCH 09/49] handle conflict --- src/client/src/tscSystem.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 27d23b8ee5..ce0ceb689d 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -181,6 +181,8 @@ void taos_init_imp(void) { tscTableMetaInfo = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); tscDebug("TableMeta:%p", tscTableMetaInfo); } + + int refreshTime = 5; tscRpcCache = taosCacheInit(TSDB_DATA_TYPE_BINARY, refreshTime, true, tscFreeRpcObj, "rpcObj"); pthread_mutex_init(&rpcObjMutex, NULL); @@ -224,12 +226,11 @@ void taos_cleanup(void) { taosCleanupKeywordsTable(); taosCloseLog(); - m = tscRpcCache; - if (m != NULL && atomic_val_compare_exchange_ptr(&tscRpcCache, m, 0) == m) { - pthread_mutex_lock(&rpcObjMutex); - taosCacheCleanup(tscRpcCache); - tscRpcCache = NULL; - pthread_mutex_unlock(&rpcObjMutex); + p = tscRpcCache; + tscRpcCache = NULL; + + if (p != NULL) { + taosCacheCleanup(p); pthread_mutex_destroy(&rpcObjMutex); } From d1d1b4c80a1aca05406212fe26028fb2aa4b2c59 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 3 Jan 2021 15:40:03 +0000 Subject: [PATCH 10/49] delete redundancy code --- src/client/src/tscSystem.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ce0ceb689d..bb10f9fae9 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -236,10 +236,6 @@ void taos_cleanup(void) { if (tscEmbedded == 0) rpcCleanup(); - if (tscEmbedded == 0) { - rpcCleanup(); - } - p = tscTmr; tscTmr = NULL; taosTmrCleanUp(p); From 7c008851e13814c0f494d7d8fa12008ca02c85ea Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 00:34:37 +0000 Subject: [PATCH 11/49] TD-2850 --- src/client/src/tscSQLParser.c | 1 + src/client/src/tscUtil.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ec699408de..4811a3b35d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5427,6 +5427,7 @@ int32_t validateColumnName(char* name) { if (token.type == TK_STRING) { strdequote(token.z); + strntolower(token.z, token.z, token.n); token.n = (uint32_t)strtrim(token.z); int32_t k = tSQLGetToken(token.z, &token.type); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d045000e24..bad4a870d5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1420,9 +1420,11 @@ int32_t tscValidateName(SStrToken* pToken) { char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true); if (sep == NULL) { // single part if (pToken->type == TK_STRING) { + strdequote(pToken->z); + strntolower(pToken->z, pToken->z, pToken->n); pToken->n = (uint32_t)strtrim(pToken->z); - + int len = tSQLGetToken(pToken->z, &pToken->type); // single token, validate it From da00ccd0f19bfee4664b21172e4586dd83afb578 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 12:21:21 +0000 Subject: [PATCH 12/49] validate failed --- src/client/src/tscUtil.c | 4 ++++ tests/script/general/parser/dbtbnameValidate.sim | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index bad4a870d5..f33e1e292e 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1476,6 +1476,8 @@ int32_t tscValidateName(SStrToken* pToken) { if (pToken->type == TK_STRING && validateQuoteToken(pToken) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_SQL; } + + strntolower(pToken->z, pToken->z, pToken->n); // re-build the whole name string if (pStr[firstPartLen] == TS_PATH_DELIMITER[0]) { @@ -1488,6 +1490,8 @@ int32_t tscValidateName(SStrToken* pToken) { } pToken->n += (firstPartLen + sizeof(TS_PATH_DELIMITER[0])); pToken->z = pStr; + + strntolower(pToken->z, pToken->z, pToken->n); } return TSDB_CODE_SUCCESS; diff --git a/tests/script/general/parser/dbtbnameValidate.sim b/tests/script/general/parser/dbtbnameValidate.sim index 072fd740d4..48c5d4a1f9 100644 --- a/tests/script/general/parser/dbtbnameValidate.sim +++ b/tests/script/general/parser/dbtbnameValidate.sim @@ -26,11 +26,11 @@ sql use ' XYZ ' sql drop database 'abc123' sql drop database '_ab1234' -sql drop database 'ABC123' +sql_error drop database 'ABC123' sql drop database '_ABC123' sql drop database 'aABb123' sql drop database ' xyz ' -sql drop database ' XYZ ' +sql_error drop database ' XYZ ' sql use abc @@ -67,9 +67,9 @@ sql describe mt sql describe sub_001 sql describe sub_dy_tbl -sql_error describe Dd -sql_error describe FF -sql_error describe gG +sql describe Dd +sql describe FF +sql describe gG sql drop table abc.cc sql drop table 'abc.Dd' @@ -119,4 +119,4 @@ if $rows != 4 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 647a679fa078a5552513204f161e8aabd20fe260 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 13:42:17 +0000 Subject: [PATCH 13/49] failed at some case --- src/client/src/tscUtil.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index f33e1e292e..c46662097b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -32,6 +32,14 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo); static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo); +static void tscStrToLower(char *str, int32_t n) { + if (str == NULL || n <= 0) { return;} + for (int32_t i = 0; i < n; i++) { + if (str[i] >= 'A' && str[i] <= 'Z') { + str[i] -= ('A' - 'a'); + } + } +} SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) { if (pTagCond->pCond == NULL) { return NULL; @@ -1422,7 +1430,7 @@ int32_t tscValidateName(SStrToken* pToken) { if (pToken->type == TK_STRING) { strdequote(pToken->z); - strntolower(pToken->z, pToken->z, pToken->n); + tscStrToLower(pToken->z, pToken->n); pToken->n = (uint32_t)strtrim(pToken->z); int len = tSQLGetToken(pToken->z, &pToken->type); @@ -1477,8 +1485,6 @@ int32_t tscValidateName(SStrToken* pToken) { return TSDB_CODE_TSC_INVALID_SQL; } - strntolower(pToken->z, pToken->z, pToken->n); - // re-build the whole name string if (pStr[firstPartLen] == TS_PATH_DELIMITER[0]) { // first part do not have quote do nothing @@ -1491,7 +1497,7 @@ int32_t tscValidateName(SStrToken* pToken) { pToken->n += (firstPartLen + sizeof(TS_PATH_DELIMITER[0])); pToken->z = pStr; - strntolower(pToken->z, pToken->z, pToken->n); + tscStrToLower(pToken->z,pToken->n); } return TSDB_CODE_SUCCESS; From 236c46548798add8d37c33757b7bbe3ed8c367a1 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 22 Jan 2021 23:40:35 +0000 Subject: [PATCH 14/49] fix case failure --- src/client/inc/tsclient.h | 4 ++-- src/client/src/tscServer.c | 6 +++--- src/client/src/tscSql.c | 12 +++++++++++- src/client/src/tscSystem.c | 10 +--------- src/client/src/tscUtil.c | 1 + 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index e8b03c0db9..c9702ad1fc 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -299,7 +299,6 @@ typedef struct { typedef struct { char key[512]; - SRpcCorEpSet *tscCorMgmtEpSet; void *pDnodeConn; } SRpcObj; @@ -319,6 +318,7 @@ typedef struct STscObj { struct SSqlObj * sqlList; struct SSqlStream *streamList; SRpcObj *pRpcObj; + SRpcCorEpSet *tscCorMgmtEpSet; pthread_mutex_t mutex; int32_t numOfObj; // number of sqlObj from this tscObj } STscObj; @@ -396,7 +396,7 @@ typedef struct SSqlStream { void tscSetStreamDestTable(SSqlStream* pStream, const char* dstTable); -int tscAcquireRpc(const char *key, const char *user, const char *secret, SRpcCorEpSet *corMgmtEpSet, void **pRpcObj); +int tscAcquireRpc(const char *key, const char *user, const char *secret,void **pRpcObj); void tscReleaseRpc(void *param); void tscInitMsgsFp(); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 381ee15912..a81e47f3ad 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -69,7 +69,7 @@ static void tscSetDnodeEpSet(SRpcEpSet* pEpSet, SVgroupInfo* pVgroupInfo) { } static void tscDumpMgmtEpSet(SSqlObj *pSql) { - SRpcCorEpSet *pCorEpSet = pSql->pTscObj->pRpcObj->tscCorMgmtEpSet; + SRpcCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; taosCorBeginRead(&pCorEpSet->version); pSql->epSet = pCorEpSet->epSet; taosCorEndRead(&pCorEpSet->version); @@ -94,7 +94,7 @@ bool tscEpSetIsEqual(SRpcEpSet *s1, SRpcEpSet *s2) { void tscUpdateMgmtEpSet(SSqlObj *pSql, SRpcEpSet *pEpSet) { // no need to update if equal - SRpcCorEpSet *pCorEpSet = pSql->pTscObj->pRpcObj->tscCorMgmtEpSet; + SRpcCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; taosCorBeginWrite(&pCorEpSet->version); pCorEpSet->epSet = *pEpSet; taosCorEndWrite(&pCorEpSet->version); @@ -158,7 +158,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { if (epSet->numOfEps > 0) { tscEpSetHtons(epSet); - //SRpcCorEpSet *pCorEpSet = pSql->pTscObj->pRpcObj->tscCorMgmtEpSet; + //SRpcCorEpSet *pCorEpSet = pSql->pTscObj->tscCorMgmtEpSet; //if (!tscEpSetIsEqual(&pCorEpSet->epSet, epSet)) { // tscTrace("%p updating epset: numOfEps: %d, inUse: %d", pSql, epSet->numOfEps, epSet->inUse); // for (int8_t i = 0; i < epSet->numOfEps; i++) { diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 04e7e764f4..448eea16bf 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -94,7 +94,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa snprintf(rpcKey, sizeof(rpcKey), "%s:%s:%s:%d", user, pass, ip, port); void *pRpcObj = NULL; - if (tscAcquireRpc(rpcKey, user, secretEncrypt,&corMgmtEpSet, &pRpcObj) != 0) { + if (tscAcquireRpc(rpcKey, user, secretEncrypt, &pRpcObj) != 0) { terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; return NULL; } @@ -105,6 +105,16 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa tscReleaseRpc(pRpcObj); return NULL; } + + pObj->tscCorMgmtEpSet = malloc(sizeof(SRpcCorEpSet)); + if (pObj->tscCorMgmtEpSet == NULL) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + tscReleaseRpc(pRpcObj); + free(pObj); + return NULL; + } + memcpy(pObj->tscCorMgmtEpSet, &corMgmtEpSet, sizeof(corMgmtEpSet)); + pObj->signature = pObj; pObj->pRpcObj = (SRpcObj *)pRpcObj; tstrncpy(pObj->user, user, sizeof(pObj->user)); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index bb10f9fae9..fe1c45bd39 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -58,7 +58,6 @@ void tscFreeRpcObj(void *param) { SRpcObj *pRpcObj = (SRpcObj *)(param); tscDebug("free rpcObj:%p and free pDnodeConn: %p", pRpcObj, pRpcObj->pDnodeConn); rpcClose(pRpcObj->pDnodeConn); - tfree(pRpcObj->tscCorMgmtEpSet); } void tscReleaseRpc(void *param) { @@ -70,7 +69,7 @@ void tscReleaseRpc(void *param) { pthread_mutex_unlock(&rpcObjMutex); } -int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncrypt, SRpcCorEpSet *corMgmtEpSet, void **ppRpcObj) { +int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncrypt, void **ppRpcObj) { pthread_mutex_lock(&rpcObjMutex); SRpcObj *pRpcObj = (SRpcObj *)taosCacheAcquireByKey(tscRpcCache, key, strlen(key)); @@ -109,13 +108,6 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry pthread_mutex_unlock(&rpcObjMutex); return -1; } - pRpcObj->tscCorMgmtEpSet = malloc(sizeof(SRpcCorEpSet)); - if (pRpcObj->tscCorMgmtEpSet == NULL) { - rpcClose(rpcObj.pDnodeConn); - pthread_mutex_unlock(&rpcObjMutex); - return -1; - } - memcpy(pRpcObj->tscCorMgmtEpSet, corMgmtEpSet, sizeof(*corMgmtEpSet)); *ppRpcObj = pRpcObj; pthread_mutex_unlock(&rpcObjMutex); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 756dc93098..c77d5e5764 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -897,6 +897,7 @@ void tscCloseTscObj(void *param) { pObj->signature = NULL; taosTmrStopA(&(pObj->pTimer)); + tfree(pObj->tscCorMgmtEpSet); tscReleaseRpc(pObj->pRpcObj); pthread_mutex_destroy(&pObj->mutex); From b1e781b1673edf7d61570c5e0bc4a7e4a590937b Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 27 Jan 2021 10:58:26 +0800 Subject: [PATCH 15/49] fix bug --- src/cq/src/cqMain.c | 127 +++++++++++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 31 deletions(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 5f1fecc494..083028a32c 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -54,6 +54,7 @@ typedef struct { typedef struct SCqObj { tmr_h tmrId; + int64_t rid; uint64_t uid; int32_t tid; // table ID int32_t rowSize; // bytes of a row @@ -69,6 +70,77 @@ typedef struct SCqObj { static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row); static void cqCreateStream(SCqContext *pContext, SCqObj *pObj); +int32_t cqObjRef = -1; + + + +void cqFree(void *handle) { + if (tsEnableStream == 0) { + return; + } + SCqObj *pObj = handle; + SCqContext *pContext = pObj->pContext; + int32_t last = 0; + + pthread_mutex_lock(&pContext->mutex); + + if (pObj->prev) { + pObj->prev->next = pObj->next; + } else { + pContext->pHead = pObj->next; + } + + if (pObj->next) { + pObj->next->prev = pObj->prev; + } + + if (pContext->pHead == NULL) { + last = 1; + } + + // free the resources associated + if (pObj->pStream) { + taos_close_stream(pObj->pStream); + pObj->pStream = NULL; + } else { + taosTmrStop(pObj->tmrId); + pObj->tmrId = 0; + } + + cInfo("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr); + tdFreeSchema(pObj->pSchema); + free(pObj->dstTable); + free(pObj->sqlStr); + free(pObj); + + pthread_mutex_unlock(&pContext->mutex); + + if (last) { + pthread_mutex_unlock(&pContext->mutex); + + pthread_mutex_destroy(&pContext->mutex); + + taosTmrCleanUp(pContext->tmrCtrl); + pContext->tmrCtrl = NULL; + + cDebug("vgId:%d, CQ is closed", pContext->vgId); + free(pContext); + } +} + + +void cqCreateRef() { + int32_t ref = atomic_load_32(&cqObjRef); + if (ref == -1) { + ref = taosOpenRef(4096, cqFree); + + if (atomic_val_compare_exchange_32(&cqObjRef, -1, ref) != -1) { + taosCloseRef(ref); + } + } +} + + void *cqOpen(void *ahandle, const SCqCfg *pCfg) { if (tsEnableStream == 0) { return NULL; @@ -79,6 +151,8 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { return NULL; } + cqCreateRef(); + pContext->tmrCtrl = taosTmrInit(0, 0, 0, "CQ"); tstrncpy(pContext->user, pCfg->user, sizeof(pContext->user)); @@ -97,6 +171,7 @@ void *cqOpen(void *ahandle, const SCqCfg *pCfg) { pthread_mutex_init(&pContext->mutex, NULL); + cDebug("vgId:%d, CQ is opened", pContext->vgId); return pContext; @@ -119,20 +194,9 @@ void cqClose(void *handle) { while (pObj) { SCqObj *pTemp = pObj; pObj = pObj->next; - tdFreeSchema(pTemp->pSchema); - tfree(pTemp->sqlStr); - free(pTemp); + + taosReleaseRef(cqObjRef, pTemp->rid); } - - pthread_mutex_unlock(&pContext->mutex); - - pthread_mutex_destroy(&pContext->mutex); - - taosTmrCleanUp(pContext->tmrCtrl); - pContext->tmrCtrl = NULL; - - cDebug("vgId:%d, CQ is closed", pContext->vgId); - free(pContext); } void cqStart(void *handle) { @@ -213,10 +277,13 @@ void *cqCreate(void *handle, uint64_t uid, int32_t sid, const char* dstTable, ch if (pContext->pHead) pContext->pHead->prev = pObj; pContext->pHead = pObj; + pObj->rid = taosAddRef(cqObjRef, pObj); + cqCreateStream(pContext, pObj); pthread_mutex_unlock(&pContext->mutex); + return pObj; } @@ -229,16 +296,6 @@ void cqDrop(void *handle) { pthread_mutex_lock(&pContext->mutex); - if (pObj->prev) { - pObj->prev->next = pObj->next; - } else { - pContext->pHead = pObj->next; - } - - if (pObj->next) { - pObj->next->prev = pObj->prev; - } - // free the resources associated if (pObj->pStream) { taos_close_stream(pObj->pStream); @@ -248,17 +305,17 @@ void cqDrop(void *handle) { pObj->tmrId = 0; } - cInfo("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr); - tdFreeSchema(pObj->pSchema); - free(pObj->dstTable); - free(pObj->sqlStr); - free(pObj); + taosReleaseRef(cqObjRef, pObj->rid); pthread_mutex_unlock(&pContext->mutex); } static void doCreateStream(void *param, TAOS_RES *result, int32_t code) { - SCqObj* pObj = (SCqObj*)param; + SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)param); + if (pObj == NULL) { + return; + } + SCqContext* pContext = pObj->pContext; SSqlObj* pSql = (SSqlObj*)result; if (atomic_val_compare_exchange_ptr(&(pContext->dbConn), NULL, pSql->pTscObj) != NULL) { @@ -267,10 +324,16 @@ static void doCreateStream(void *param, TAOS_RES *result, int32_t code) { pthread_mutex_lock(&pContext->mutex); cqCreateStream(pContext, pObj); pthread_mutex_unlock(&pContext->mutex); + + taosReleaseRef(cqObjRef, (int64_t)param); } static void cqProcessCreateTimer(void *param, void *tmrId) { - SCqObj* pObj = (SCqObj*)param; + SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)param); + if (pObj == NULL) { + return; + } + SCqContext* pContext = pObj->pContext; if (pContext->dbConn == NULL) { @@ -281,6 +344,8 @@ static void cqProcessCreateTimer(void *param, void *tmrId) { cqCreateStream(pContext, pObj); pthread_mutex_unlock(&pContext->mutex); } + + taosReleaseRef(cqObjRef, (int64_t)param); } static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { @@ -288,7 +353,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { if (pContext->dbConn == NULL) { cDebug("vgId:%d, create dbConn after 1000 ms", pContext->vgId); - pObj->tmrId = taosTmrStart(cqProcessCreateTimer, 1000, pObj, pContext->tmrCtrl); + pObj->tmrId = taosTmrStart(cqProcessCreateTimer, 1000, (void *)pObj->rid, pContext->tmrCtrl); return; } pObj->tmrId = 0; From 2327cbb9b8dd4f03b7081cec4fdcb517d6f99dc4 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 27 Jan 2021 13:48:59 +0800 Subject: [PATCH 16/49] fix bug --- src/cq/src/cqMain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 083028a32c..5203d66d16 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -305,9 +305,9 @@ void cqDrop(void *handle) { pObj->tmrId = 0; } - taosReleaseRef(cqObjRef, pObj->rid); - pthread_mutex_unlock(&pContext->mutex); + + taosReleaseRef(cqObjRef, pObj->rid); } static void doCreateStream(void *param, TAOS_RES *result, int32_t code) { From c7c0fd1dd5736da22cdacfafde1718cf5b4095b3 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 27 Jan 2021 15:56:10 +0800 Subject: [PATCH 17/49] fix bug --- src/cq/src/cqMain.c | 85 +++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 5203d66d16..f90a1d5f5e 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -50,6 +50,8 @@ typedef struct { void *dbConn; void *tmrCtrl; pthread_mutex_t mutex; + int32_t delete; + int32_t cqObjNum; } SCqContext; typedef struct SCqObj { @@ -72,17 +74,10 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj); int32_t cqObjRef = -1; +void cqRmFromList(SCqObj *pObj) { + //LOCK in caller - -void cqFree(void *handle) { - if (tsEnableStream == 0) { - return; - } - SCqObj *pObj = handle; SCqContext *pContext = pObj->pContext; - int32_t last = 0; - - pthread_mutex_lock(&pContext->mutex); if (pObj->prev) { pObj->prev->next = pObj->next; @@ -94,10 +89,18 @@ void cqFree(void *handle) { pObj->next->prev = pObj->prev; } - if (pContext->pHead == NULL) { - last = 1; - } +} +void cqFree(void *handle) { + if (tsEnableStream == 0) { + return; + } + SCqObj *pObj = handle; + SCqContext *pContext = pObj->pContext; + int32_t delete = 0; + + pthread_mutex_lock(&pContext->mutex); + // free the resources associated if (pObj->pStream) { taos_close_stream(pObj->pStream); @@ -113,9 +116,15 @@ void cqFree(void *handle) { free(pObj->sqlStr); free(pObj); + pContext->cqObjNum--; + + if (pContext->cqObjNum <= 0 && pContext->delete) { + delete = 1; + } + pthread_mutex_unlock(&pContext->mutex); - if (last) { + if (delete) { pthread_mutex_unlock(&pContext->mutex); pthread_mutex_destroy(&pContext->mutex); @@ -184,19 +193,30 @@ void cqClose(void *handle) { SCqContext *pContext = handle; if (handle == NULL) return; + pContext->delete = 1; + // stop all CQs cqStop(pContext); - // free all resources - pthread_mutex_lock(&pContext->mutex); + int64_t rid = 0; - SCqObj *pObj = pContext->pHead; - while (pObj) { - SCqObj *pTemp = pObj; - pObj = pObj->next; + while (1) { + pthread_mutex_lock(&pContext->mutex); - taosReleaseRef(cqObjRef, pTemp->rid); - } + SCqObj *pObj = pContext->pHead; + if (pObj) { + cqRmFromList(pObj); + + rid = pObj->rid; + } else { + pthread_mutex_unlock(&pContext->mutex); + break; + } + + pthread_mutex_unlock(&pContext->mutex); + + taosReleaseRef(cqObjRef, rid); + } } void cqStart(void *handle) { @@ -255,7 +275,8 @@ void *cqCreate(void *handle, uint64_t uid, int32_t sid, const char* dstTable, ch return NULL; } SCqContext *pContext = handle; - + int64_t rid = 0; + SCqObj *pObj = calloc(sizeof(SCqObj), 1); if (pObj == NULL) return NULL; @@ -277,25 +298,36 @@ void *cqCreate(void *handle, uint64_t uid, int32_t sid, const char* dstTable, ch if (pContext->pHead) pContext->pHead->prev = pObj; pContext->pHead = pObj; + pContext->cqObjNum++; + pObj->rid = taosAddRef(cqObjRef, pObj); cqCreateStream(pContext, pObj); + rid = pObj->rid; + pthread_mutex_unlock(&pContext->mutex); - return pObj; + return (void *)rid; } void cqDrop(void *handle) { if (tsEnableStream == 0) { return; } - SCqObj *pObj = handle; - SCqContext *pContext = pObj->pContext; + SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)handle); + if (pObj == NULL) { + return; + } + + SCqContext *pContext = pObj->pContext; + pthread_mutex_lock(&pContext->mutex); + cqRmFromList(pObj); + // free the resources associated if (pObj->pStream) { taos_close_stream(pObj->pStream); @@ -307,7 +339,8 @@ void cqDrop(void *handle) { pthread_mutex_unlock(&pContext->mutex); - taosReleaseRef(cqObjRef, pObj->rid); + taosRemoveRef(cqObjRef, (int64_t)handle); + taosReleaseRef(cqObjRef, (int64_t)handle); } static void doCreateStream(void *param, TAOS_RES *result, int32_t code) { From 7d1b99f92a02d323e7430fac054f2d769da04d1f Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 27 Jan 2021 17:37:08 +0800 Subject: [PATCH 18/49] fix bug --- src/cq/src/cqMain.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index f90a1d5f5e..908042ba06 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -392,7 +392,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pObj->tmrId = 0; if (pObj->pStream == NULL) { - pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, pObj, NULL); + pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, (void *)pObj->rid, NULL); // TODO the pObj->pStream may be released if error happens if (pObj->pStream) { @@ -406,18 +406,28 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { } static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { - SCqObj *pObj = (SCqObj *)param; + SCqObj* pObj = (SCqObj*)taosAcquireRef(cqObjRef, (int64_t)param); + if (pObj == NULL) { + return; + } + if (tres == NULL && row == NULL) { taos_close_stream(pObj->pStream); pObj->pStream = NULL; + + taosReleaseRef(cqObjRef, (int64_t)param); + return; } SCqContext *pContext = pObj->pContext; STSchema *pSchema = pObj->pSchema; - if (pObj->pStream == NULL) return; - + if (pObj->pStream == NULL) { + taosReleaseRef(cqObjRef, (int64_t)param); + return; + } + cDebug("vgId:%d, id:%d CQ:%s stream result is ready", pContext->vgId, pObj->tid, pObj->sqlStr); int32_t size = sizeof(SWalHead) + sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + TD_DATA_ROW_HEAD_SIZE + pObj->rowSize; @@ -468,5 +478,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { // write into vnode write queue pContext->cqWrite(pContext->vgId, pHead, TAOS_QTYPE_CQ, NULL); free(buffer); + + taosReleaseRef(cqObjRef, (int64_t)param); } From 6b87bab62490cc249556fa368ddf35cff498831a Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 27 Jan 2021 17:53:22 +0800 Subject: [PATCH 19/49] fix bug --- src/cq/src/cqMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 908042ba06..a5de27d7fc 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -215,7 +215,7 @@ void cqClose(void *handle) { pthread_mutex_unlock(&pContext->mutex); - taosReleaseRef(cqObjRef, rid); + taosRemoveRef(cqObjRef, rid); } } From 969ae432e703783c147d90469cd2b5cbdcaab223 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Wed, 27 Jan 2021 18:09:50 +0800 Subject: [PATCH 20/49] fix bug --- src/client/src/tscServer.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6035a270c5..1bbad90977 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -292,8 +292,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { if (pObj->signature != pObj) { tscDebug("%p DB connection is closed, cmd:%d pObj:%p signature:%p", pSql, pCmd->command, pObj, pObj->signature); - taosRemoveRef(tscObjRef, pSql->self); - taosReleaseRef(tscObjRef, pSql->self); + taosRemoveRef(tscObjRef, handle); + taosReleaseRef(tscObjRef, handle); rpcFreeCont(rpcMsg->pCont); return; } @@ -303,8 +303,8 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { tscDebug("%p sqlObj needs to be released or DB connection is closed, cmd:%d type:%d, pObj:%p signature:%p", pSql, pCmd->command, pQueryInfo->type, pObj, pObj->signature); - taosRemoveRef(tscObjRef, pSql->self); - taosReleaseRef(tscObjRef, pSql->self); + taosRemoveRef(tscObjRef, handle); + taosReleaseRef(tscObjRef, handle); rpcFreeCont(rpcMsg->pCont); return; } @@ -350,7 +350,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { // if there is an error occurring, proceed to the following error handling procedure. if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { - taosReleaseRef(tscObjRef, pSql->self); + taosReleaseRef(tscObjRef, handle); rpcFreeCont(rpcMsg->pCont); return; } @@ -418,13 +418,15 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { (*pSql->fp)(pSql->param, pSql, rpcMsg->code); } - taosReleaseRef(tscObjRef, pSql->self); + if (shouldFree) { // in case of table-meta/vgrouplist query, automatically free it - taosRemoveRef(tscObjRef, pSql->self); + taosRemoveRef(tscObjRef, handle); tscDebug("%p sqlObj is automatically freed", pSql); } + taosReleaseRef(tscObjRef, handle); + rpcFreeCont(rpcMsg->pCont); } From 321e97d7d8a5a1e894fd19df8f5a01670b636c0b Mon Sep 17 00:00:00 2001 From: Hui Li Date: Thu, 28 Jan 2021 11:55:17 +0800 Subject: [PATCH 21/49] [TD-2823] modify start count by systemd --- packaging/deb/makedeb.sh | 4 +++ packaging/rpm/tdengine.spec | 4 +++ packaging/tools/install.sh | 4 +-- packaging/tools/install_power.sh | 1 + packaging/tools/make_install.sh | 6 +++- packaging/tools/makeclient.sh | 3 +- packaging/tools/makeclient_power.sh | 1 + packaging/tools/makepkg.sh | 3 +- packaging/tools/makepkg_power.sh | 5 ++- packaging/tools/post.sh | 1 + packaging/tools/startPre.sh | 50 +++++++++++++++++++++++++++++ 11 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 packaging/tools/startPre.sh diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index 431093be95..f0024eb9dc 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -43,10 +43,14 @@ mkdir -p ${pkg_dir}${install_home_path}/include mkdir -p ${pkg_dir}${install_home_path}/init.d mkdir -p ${pkg_dir}${install_home_path}/script +echo "" > ${pkg_dir}${install_home_path}/email cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script cp ${compile_dir}/../packaging/tools/preun.sh ${pkg_dir}${install_home_path}/script +cp ${compile_dir}/../packaging/tools/startPre.sh ${pkg_dir}${install_home_path}/bin +cp ${compile_dir}/../packaging/tools/set_core.sh ${pkg_dir}${install_home_path}/bin +cp ${compile_dir}/../packaging/tools/taosd-dump-cfg.gdb ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taosdemo ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taosdemox ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taosdump ${pkg_dir}${install_home_path}/bin diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index 6f012aa80e..c659ca67ae 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -51,10 +51,14 @@ mkdir -p %{buildroot}%{homepath}/include mkdir -p %{buildroot}%{homepath}/init.d mkdir -p %{buildroot}%{homepath}/script +echo "" > %{buildroot}%{homepath}/email cp %{_compiledir}/../packaging/cfg/taos.cfg %{buildroot}%{homepath}/cfg cp %{_compiledir}/../packaging/rpm/taosd %{buildroot}%{homepath}/init.d cp %{_compiledir}/../packaging/tools/post.sh %{buildroot}%{homepath}/script cp %{_compiledir}/../packaging/tools/preun.sh %{buildroot}%{homepath}/script +cp %{_compiledir}/../packaging/tools/startPre.sh %{buildroot}%{homepath}/bin +cp %{_compiledir}/../packaging/tools/set_core.sh %{buildroot}%{homepath}/bin +cp %{_compiledir}/../packaging/tools/taosd-dump-cfg.gdb %{buildroot}%{homepath}/bin cp %{_compiledir}/build/bin/taos %{buildroot}%{homepath}/bin cp %{_compiledir}/build/bin/taosd %{buildroot}%{homepath}/bin cp %{_compiledir}/build/bin/taosdemo %{buildroot}%{homepath}/bin diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index d98ed2185f..e74a61801b 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -604,9 +604,7 @@ function install_service_on_systemd() { ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/setDelay.sh' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'ExecStartPost=/usr/local/taos/bin/resetDelay.sh' >> ${taosd_service_config}" - #${csudo} bash -c "echo 'ExecStopPost=/usr/local/taos/bin/resetDelay.sh' >> ${taosd_service_config}" + ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" diff --git a/packaging/tools/install_power.sh b/packaging/tools/install_power.sh index b14d5d400b..89b5ce5b4f 100755 --- a/packaging/tools/install_power.sh +++ b/packaging/tools/install_power.sh @@ -578,6 +578,7 @@ function install_service_on_systemd() { ${csudo} bash -c "echo '[Service]' >> ${powerd_service_config}" ${csudo} bash -c "echo 'Type=simple' >> ${powerd_service_config}" ${csudo} bash -c "echo 'ExecStart=/usr/bin/powerd' >> ${powerd_service_config}" + ${csudo} bash -c "echo 'ExecStartPre=/usr/local/power/bin/startPre.sh' >> ${powerd_service_config}" ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${powerd_service_config}" ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${powerd_service_config}" ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${powerd_service_config}" diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 474b6f4619..a102f539fe 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -149,10 +149,13 @@ function install_bin() { ${csudo} rm -f ${bin_link_dir}/rmtaos || : ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin + ${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin if [ "$osType" != "Darwin" ]; then - ${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin + ${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin ${csudo} cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin + ${csudo} cp -r ${script_dir}/core.sh ${install_main_dir}/bin + ${csudo} cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin else ${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin fi @@ -330,6 +333,7 @@ function install_service_on_systemd() { ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" + ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 00dfcb7559..52a4e05906 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -45,7 +45,8 @@ if [ "$osType" != "Darwin" ]; then strip ${build_dir}/bin/taos bin_files="${build_dir}/bin/taos ${script_dir}/remove_client.sh" else - bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdemox ${script_dir}/remove_client.sh ${script_dir}/set_core.sh ${script_dir}/get_client.sh" + bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdemox\ + ${script_dir}/remove_client.sh ${script_dir}/set_core.sh ${script_dir}/get_client.sh ${script_dir}/taosd-dump-cfg.gdb" fi lib_files="${build_dir}/lib/libtaos.so.${version}" else diff --git a/packaging/tools/makeclient_power.sh b/packaging/tools/makeclient_power.sh index 509df31297..15f8994e94 100755 --- a/packaging/tools/makeclient_power.sh +++ b/packaging/tools/makeclient_power.sh @@ -81,6 +81,7 @@ if [ "$osType" != "Darwin" ]; then cp ${build_dir}/bin/taosdump ${install_dir}/bin/powerdump cp ${script_dir}/set_core.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin + cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin fi else cp ${bin_files} ${install_dir}/bin diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 0b4659a911..267338ed06 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -36,7 +36,8 @@ if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taos bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${script_dir}/remove.sh" else - bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdemox ${build_dir}/bin/tarbitrator ${script_dir}/remove.sh ${script_dir}/set_core.sh ${script_dir}/get_client.sh" + bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/taosdemox ${build_dir}/bin/tarbitrator\ + ${script_dir}/remove.sh ${script_dir}/set_core.sh ${script_dir}/startPre.sh ${script_dir}/taosd-dump-cfg.gdb" fi lib_files="${build_dir}/lib/libtaos.so.${version}" diff --git a/packaging/tools/makepkg_power.sh b/packaging/tools/makepkg_power.sh index ba57fe5e96..7227a08b7a 100755 --- a/packaging/tools/makepkg_power.sh +++ b/packaging/tools/makepkg_power.sh @@ -36,7 +36,8 @@ fi # strip ${build_dir}/bin/taos # bin_files="${build_dir}/bin/powerd ${build_dir}/bin/power ${script_dir}/remove_power.sh" #else -# bin_files="${build_dir}/bin/powerd ${build_dir}/bin/power ${build_dir}/bin/powerdemo ${build_dir}/bin/tarbitrator ${script_dir}/remove_power.sh ${script_dir}/set_core.sh" +# bin_files="${build_dir}/bin/powerd ${build_dir}/bin/power ${build_dir}/bin/powerdemo ${build_dir}/bin/tarbitrator ${script_dir}/remove_power.sh\ +# ${script_dir}/set_core.sh ${script_dir}/startPre.sh ${script_dir}/taosd-dump-cfg.gdb" #fi lib_files="${build_dir}/lib/libtaos.so.${version}" @@ -82,6 +83,8 @@ else cp ${build_dir}/bin/tarbitrator ${install_dir}/bin cp ${script_dir}/set_core.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin + cp ${script_dir}/startPre.sh ${install_dir}/bin + cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin fi chmod a+x ${install_dir}/bin/* || : diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index 6bfbf33fd1..c6ef73932d 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -406,6 +406,7 @@ function install_service_on_systemd() { ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" + ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" diff --git a/packaging/tools/startPre.sh b/packaging/tools/startPre.sh new file mode 100644 index 0000000000..3c16a5a938 --- /dev/null +++ b/packaging/tools/startPre.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# +# if enable core dump, set start count to 3, disable core dump, set start count to 20. +# set -e +# set -x + +taosd=/etc/systemd/system/taosd.service +line=`grep StartLimitBurst ${taosd}` +num=${line##*=} +#echo "burst num: ${num}" + +startSeqFile=/usr/local/taos/.startSeq +recordFile=/usr/local/taos/.startRecord + +startSeq=0 + +if [[ ! -e ${startSeqFile} ]]; then + startSeq=0 +else + startSeq=$(cat ${startSeqFile}) +fi + +nextSeq=`expr $startSeq + 1` +echo "${nextSeq}" > ${startSeqFile} + +curTime=$(date "+%Y-%m-%d %H:%M:%S") +echo "startSeq:${startSeq} startPre.sh exec ${curTime}, burstCnt:${num}" >> ${recordFile} + + +coreFlag=`ulimit -c` +echo "coreFlag: ${coreFlag}" >> ${recordFile} + +if [ ${coreFlag} = "0" ];then + #echo "core is 0" + if [ ${num} != "20" ];then + sed -i "s/^.*StartLimitBurst.*$/StartLimitBurst=20/" ${taosd} + systemctl daemon-reload + echo "modify burst count from ${num} to 20" >> ${recordFile} + fi +fi + +if [ ${coreFlag} = "unlimited" ];then + #echo "core is unlimited" + if [ ${num} != "3" ];then + sed -i "s/^.*StartLimitBurst.*$/StartLimitBurst=3/" ${taosd} + systemctl daemon-reload + echo "modify burst count from ${num} to 3" >> ${recordFile} + fi +fi + From 7ff19911e4420ead00bf1b6d07204a4b9c13ec0c Mon Sep 17 00:00:00 2001 From: Hui Li Date: Thu, 28 Jan 2021 11:59:04 +0800 Subject: [PATCH 22/49] [TD-2823] modify start count by systemd --- packaging/deb/makedeb.sh | 1 - packaging/rpm/tdengine.spec | 1 - 2 files changed, 2 deletions(-) diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index f0024eb9dc..850c636940 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -43,7 +43,6 @@ mkdir -p ${pkg_dir}${install_home_path}/include mkdir -p ${pkg_dir}${install_home_path}/init.d mkdir -p ${pkg_dir}${install_home_path}/script -echo "" > ${pkg_dir}${install_home_path}/email cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d cp ${compile_dir}/../packaging/tools/post.sh ${pkg_dir}${install_home_path}/script diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index c659ca67ae..d20a6c91cd 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -51,7 +51,6 @@ mkdir -p %{buildroot}%{homepath}/include mkdir -p %{buildroot}%{homepath}/init.d mkdir -p %{buildroot}%{homepath}/script -echo "" > %{buildroot}%{homepath}/email cp %{_compiledir}/../packaging/cfg/taos.cfg %{buildroot}%{homepath}/cfg cp %{_compiledir}/../packaging/rpm/taosd %{buildroot}%{homepath}/init.d cp %{_compiledir}/../packaging/tools/post.sh %{buildroot}%{homepath}/script From f53e76e0a77d8ec9d68f0bb896df3e4b4604fc1a Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 28 Jan 2021 13:34:15 +0800 Subject: [PATCH 23/49] change query buffer size configuration --- src/common/inc/tglobal.h | 3 ++- src/common/src/tglobal.c | 7 ++++++- src/query/src/qExecutor.c | 13 +++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 284e718016..9b498e8bd2 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -57,7 +57,8 @@ extern int32_t tsCompressMsgSize; extern char tsTempDir[]; //query buffer management -extern int32_t tsQueryBufferSize; // maximum allowed usage buffer for each data node during query processing +extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing +extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node during query processing extern int32_t tsRetrieveBlockingModel;// retrieve threads will be blocked extern int8_t tsKeepOriginalColumnName; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 4a9b4c3e43..43b63de935 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -105,6 +105,7 @@ int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance // 0 no query allowed, queries are disabled // positive value (in MB) int32_t tsQueryBufferSize = -1; +int64_t tsQueryBufferSizeBytes = -1; // in retrieve blocking model, the retrieve threads will wait for the completion of the query processing. int32_t tsRetrieveBlockingModel = 0; @@ -283,7 +284,7 @@ bool taosCfgDynamicOptions(char *msg) { int32_t cfgLen = (int32_t)strlen(cfg->option); if (cfgLen != olen) continue; if (strncasecmp(option, cfg->option, olen) != 0) continue; - if (cfg->valType != TAOS_CFG_VTYPE_INT32) { + if (cfg->valType == TAOS_CFG_VTYPE_INT32) { *((int32_t *)cfg->ptr) = vint; } else { *((int8_t *)cfg->ptr) = (int8_t)vint; @@ -1488,6 +1489,10 @@ int32_t taosCheckGlobalCfg() { tsSyncPort = tsServerPort + TSDB_PORT_SYNC; tsHttpPort = tsServerPort + TSDB_PORT_HTTP; + if (tsQueryBufferSize >= 0) { + tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576; + } + taosPrintGlobalCfg(); return 0; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6e1945407c..f13e9ef623 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7730,15 +7730,15 @@ static int64_t getQuerySupportBufSize(size_t numOfTables) { int32_t checkForQueryBuf(size_t numOfTables) { int64_t t = getQuerySupportBufSize(numOfTables); - if (tsQueryBufferSize < 0) { + if (tsQueryBufferSizeBytes < 0) { return TSDB_CODE_SUCCESS; - } else if (tsQueryBufferSize > 0) { + } else if (tsQueryBufferSizeBytes > 0) { while(1) { - int64_t s = tsQueryBufferSize; + int64_t s = tsQueryBufferSizeBytes; int64_t remain = s - t; if (remain >= 0) { - if (atomic_val_compare_exchange_64(&tsQueryBufferSize, s, remain) == s) { + if (atomic_val_compare_exchange_64(&tsQueryBufferSizeBytes, s, remain) == s) { return TSDB_CODE_SUCCESS; } } else { @@ -7752,14 +7752,14 @@ int32_t checkForQueryBuf(size_t numOfTables) { } void releaseQueryBuf(size_t numOfTables) { - if (tsQueryBufferSize <= 0) { + if (tsQueryBufferSizeBytes < 0) { return; } int64_t t = getQuerySupportBufSize(numOfTables); // restore value is not enough buffer available - atomic_add_fetch_64(&tsQueryBufferSize, t); + atomic_add_fetch_64(&tsQueryBufferSizeBytes, t); } void* qGetResultRetrieveMsg(qinfo_t qinfo) { @@ -7915,3 +7915,4 @@ void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle) { taosCacheRelease(pQueryMgmt->qinfoPool, pQInfo, freeHandle); return 0; } + \ No newline at end of file From c83dca2359c11a38df63bc2822e4c953d22c2d0e Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 28 Jan 2021 13:47:27 +0800 Subject: [PATCH 24/49] fix bug --- src/query/src/qExecutor.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index f13e9ef623..38ba6b5400 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7915,4 +7915,3 @@ void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle) { taosCacheRelease(pQueryMgmt->qinfoPool, pQInfo, freeHandle); return 0; } - \ No newline at end of file From 0a291d3d36f78b01f4c1d53f58297a898110a50b Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 28 Jan 2021 13:57:54 +0800 Subject: [PATCH 25/49] fix bug --- packaging/cfg/taos.cfg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 73004fe7b7..5ac0e39dcc 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -270,3 +270,9 @@ # in retrieve blocking model, only in 50% query threads will be used in query processing in dnode # retrieveBlockingModel 0 + +# the maximum allowed query buffer size in MB during query processing for each data node +# -1 no limit (default) +# 0 no query allowed, queries are disabled +# queryBufferSize -1 + From ddf6b297e9b13d81514cd4a49de9ccc075a094e0 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 28 Jan 2021 14:09:42 +0800 Subject: [PATCH 26/49] fix bug --- src/common/src/tglobal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 43b63de935..a2d02be683 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -1490,7 +1490,7 @@ int32_t taosCheckGlobalCfg() { tsHttpPort = tsServerPort + TSDB_PORT_HTTP; if (tsQueryBufferSize >= 0) { - tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576; + tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } taosPrintGlobalCfg(); From 0095ed9a7826de62c72205a5529e93677ef6a31b Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Thu, 28 Jan 2021 14:16:19 +0800 Subject: [PATCH 27/49] modify test case suite --- tests/test-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-all.sh b/tests/test-all.sh index bcbf013096..1c1657cf12 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -155,7 +155,7 @@ if [ "$2" != "python" ]; then elif [ "$1" == "b1" ]; then echo "### run TSIM b1 test ###" runSimCaseOneByOne jenkins/basic_1.txt - # runSimCaseOneByOne jenkins/basic_4.txt + runSimCaseOneByOne jenkins/basic_4.txt elif [ "$1" == "b2" ]; then echo "### run TSIM b2 test ###" runSimCaseOneByOne jenkins/basic_2.txt From cf72ddb16de51d040a9470f6e593c5ed98221d9d Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:19:43 +0800 Subject: [PATCH 28/49] change --- tests/examples/JDBC/SpringJdbcTemplate/pom.xml | 2 +- .../{jdbc => }/example/jdbcTemplate/App.java | 8 ++++---- .../jdbcTemplate/dao/ExecuteAsStatement.java | 2 +- .../example/jdbcTemplate/dao/WeatherDao.java | 4 ++-- .../dao/impl/ExecuteAsStatementImpl.java | 4 ++-- .../jdbcTemplate/dao/impl/WeatherDaoImpl.java | 10 +++------- .../example/jdbcTemplate/domain/Weather.java | 2 +- .../jdbcTemplate/BatcherInsertTest.java | 8 ++++---- .../test/java/com/taosdata/jdbc/AppTest.java | 18 ------------------ 9 files changed, 18 insertions(+), 40 deletions(-) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/{jdbc => }/example/jdbcTemplate/App.java (86%) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/{jdbc => }/example/jdbcTemplate/dao/ExecuteAsStatement.java (58%) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/{jdbc => }/example/jdbcTemplate/dao/WeatherDao.java (65%) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/{jdbc => }/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java (75%) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/{jdbc => }/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java (84%) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/{jdbc => }/example/jdbcTemplate/domain/Weather.java (94%) rename tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/{jdbc => }/example/jdbcTemplate/BatcherInsertTest.java (89%) delete mode 100644 tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest.java diff --git a/tests/examples/JDBC/SpringJdbcTemplate/pom.xml b/tests/examples/JDBC/SpringJdbcTemplate/pom.xml index 15aed1cf03..33c37f21e1 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/pom.xml +++ b/tests/examples/JDBC/SpringJdbcTemplate/pom.xml @@ -69,7 +69,7 @@ - com.taosdata.jdbc.example.jdbcTemplate.App + com.taosdata.example.jdbcTemplate.App diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/App.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/App.java similarity index 86% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/App.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/App.java index a03ca3924f..6942d62a83 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/App.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/App.java @@ -1,9 +1,9 @@ -package com.taosdata.jdbc.example.jdbcTemplate; +package com.taosdata.example.jdbcTemplate; -import com.taosdata.jdbc.example.jdbcTemplate.dao.ExecuteAsStatement; -import com.taosdata.jdbc.example.jdbcTemplate.dao.WeatherDao; -import com.taosdata.jdbc.example.jdbcTemplate.domain.Weather; +import com.taosdata.example.jdbcTemplate.dao.ExecuteAsStatement; +import com.taosdata.example.jdbcTemplate.dao.WeatherDao; +import com.taosdata.example.jdbcTemplate.domain.Weather; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/ExecuteAsStatement.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/ExecuteAsStatement.java similarity index 58% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/ExecuteAsStatement.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/ExecuteAsStatement.java index f146684cc0..5947438e40 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/ExecuteAsStatement.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/ExecuteAsStatement.java @@ -1,4 +1,4 @@ -package com.taosdata.jdbc.example.jdbcTemplate.dao; +package com.taosdata.example.jdbcTemplate.dao; public interface ExecuteAsStatement{ diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/WeatherDao.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDao.java similarity index 65% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/WeatherDao.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDao.java index 28962ee1e6..19a07597f8 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/WeatherDao.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDao.java @@ -1,6 +1,6 @@ -package com.taosdata.jdbc.example.jdbcTemplate.dao; +package com.taosdata.example.jdbcTemplate.dao; -import com.taosdata.jdbc.example.jdbcTemplate.domain.Weather; +import com.taosdata.example.jdbcTemplate.domain.Weather; import java.util.List; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java similarity index 75% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java index 2700e701cc..0fd24d0fc2 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java @@ -1,6 +1,6 @@ -package com.taosdata.jdbc.example.jdbcTemplate.dao.impl; +package com.taosdata.example.jdbcTemplate.dao.impl; -import com.taosdata.jdbc.example.jdbcTemplate.dao.ExecuteAsStatement; +import com.taosdata.example.jdbcTemplate.dao.ExecuteAsStatement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java similarity index 84% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java index 1e0e0ab68c..c2dd23b590 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java @@ -1,20 +1,16 @@ -package com.taosdata.jdbc.example.jdbcTemplate.dao.impl; +package com.taosdata.example.jdbcTemplate.dao.impl; -import com.taosdata.jdbc.example.jdbcTemplate.dao.WeatherDao; -import com.taosdata.jdbc.example.jdbcTemplate.domain.Weather; +import com.taosdata.example.jdbcTemplate.domain.Weather; +import com.taosdata.example.jdbcTemplate.dao.WeatherDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils; -import org.springframework.jdbc.core.simple.SimpleJdbcInsert; import org.springframework.stereotype.Repository; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; -import java.util.HashMap; import java.util.List; -import java.util.Map; @Repository public class WeatherDaoImpl implements WeatherDao { diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/domain/Weather.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/domain/Weather.java similarity index 94% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/domain/Weather.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/domain/Weather.java index 023b301481..1787a08c35 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/example/jdbcTemplate/domain/Weather.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/domain/Weather.java @@ -1,4 +1,4 @@ -package com.taosdata.jdbc.example.jdbcTemplate.domain; +package com.taosdata.example.jdbcTemplate.domain; import java.sql.Timestamp; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/example/jdbcTemplate/BatcherInsertTest.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java similarity index 89% rename from tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/example/jdbcTemplate/BatcherInsertTest.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java index 2f2446eb70..29d0f79fd4 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/example/jdbcTemplate/BatcherInsertTest.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java @@ -1,9 +1,9 @@ -package com.taosdata.jdbc.example.jdbcTemplate; +package com.taosdata.example.jdbcTemplate; -import com.taosdata.jdbc.example.jdbcTemplate.dao.ExecuteAsStatement; -import com.taosdata.jdbc.example.jdbcTemplate.dao.WeatherDao; -import com.taosdata.jdbc.example.jdbcTemplate.domain.Weather; +import com.taosdata.example.jdbcTemplate.dao.ExecuteAsStatement; +import com.taosdata.example.jdbcTemplate.dao.WeatherDao; +import com.taosdata.example.jdbcTemplate.domain.Weather; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest.java deleted file mode 100644 index d0219f3db7..0000000000 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.taosdata.jdbc; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -/** - * Unit test for simple App. - */ -public class AppTest { - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() { - assertTrue(true); - } -} From 0605028372a9363160f16afec7026918f2486f29 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:24:42 +0800 Subject: [PATCH 29/49] change --- .../jdbcTemplate/dao/{impl => }/ExecuteAsStatementImpl.java | 3 +-- .../example/jdbcTemplate/dao/{impl => }/WeatherDaoImpl.java | 3 +-- .../src/main/resources/applicationContext.xml | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/{impl => }/ExecuteAsStatementImpl.java (77%) rename tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/{impl => }/WeatherDaoImpl.java (94%) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/ExecuteAsStatementImpl.java similarity index 77% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/ExecuteAsStatementImpl.java index 0fd24d0fc2..059e3dda15 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/ExecuteAsStatementImpl.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/ExecuteAsStatementImpl.java @@ -1,6 +1,5 @@ -package com.taosdata.example.jdbcTemplate.dao.impl; +package com.taosdata.example.jdbcTemplate.dao; -import com.taosdata.example.jdbcTemplate.dao.ExecuteAsStatement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java similarity index 94% rename from tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java rename to tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java index c2dd23b590..b46136b70a 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/impl/WeatherDaoImpl.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java @@ -1,7 +1,6 @@ -package com.taosdata.example.jdbcTemplate.dao.impl; +package com.taosdata.example.jdbcTemplate.dao; import com.taosdata.example.jdbcTemplate.domain.Weather; -import com.taosdata.example.jdbcTemplate.dao.WeatherDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.JdbcTemplate; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml b/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml index 19ac433385..d0638a4dbf 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml @@ -20,6 +20,6 @@ - + From 81d66d899566dff9ea4f389a109c6eaee18246cf Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:32:19 +0800 Subject: [PATCH 30/49] change --- tests/examples/JDBC/SpringJdbcTemplate/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/pom.xml b/tests/examples/JDBC/SpringJdbcTemplate/pom.xml index 33c37f21e1..64a91b951b 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/pom.xml +++ b/tests/examples/JDBC/SpringJdbcTemplate/pom.xml @@ -47,7 +47,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.4 + 2.0.18 From b11a514280ed8da340d95fc41e45e739463c2a1d Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:39:19 +0800 Subject: [PATCH 31/49] change --- .../src/main/resources/applicationContext.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml b/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml index d0638a4dbf..6d6cf6047e 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext.xml @@ -10,7 +10,7 @@ - + From 38cf5507b81fb6931944270628caac5af79eb48f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 28 Jan 2021 07:41:00 +0000 Subject: [PATCH 32/49] TD-2877 --- src/dnode/src/dnodeCfg.c | 2 +- src/dnode/src/dnodeEps.c | 2 +- src/dnode/src/dnodeMInfos.c | 2 +- src/mnode/src/mnodeUser.c | 2 +- src/vnode/src/vnodeCfg.c | 2 +- src/vnode/src/vnodeVersion.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dnode/src/dnodeCfg.c b/src/dnode/src/dnodeCfg.c index e008d2fa0d..fd5956b37f 100644 --- a/src/dnode/src/dnodeCfg.c +++ b/src/dnode/src/dnodeCfg.c @@ -156,7 +156,7 @@ static int32_t dnodeWriteCfg() { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fflush(fp); + fsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/dnode/src/dnodeEps.c b/src/dnode/src/dnodeEps.c index 1e05c696ce..9554651776 100644 --- a/src/dnode/src/dnodeEps.c +++ b/src/dnode/src/dnodeEps.c @@ -277,7 +277,7 @@ static int32_t dnodeWriteEps() { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fflush(fp); + fsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/dnode/src/dnodeMInfos.c b/src/dnode/src/dnodeMInfos.c index 884924f113..0dca116d84 100644 --- a/src/dnode/src/dnodeMInfos.c +++ b/src/dnode/src/dnodeMInfos.c @@ -286,7 +286,7 @@ static int32_t dnodeWriteMInfos() { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fflush(fp); + fsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index d12e49e3ce..55ee39b6bc 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -123,7 +123,7 @@ static void mnodePrintUserAuth() { mnodeDecUserRef(pUser); } - fflush(fp); + fsync(fileno(fp)); fclose(fp); } diff --git a/src/vnode/src/vnodeCfg.c b/src/vnode/src/vnodeCfg.c index 1ea774afae..9b7916c8bd 100644 --- a/src/vnode/src/vnodeCfg.c +++ b/src/vnode/src/vnodeCfg.c @@ -341,7 +341,7 @@ int32_t vnodeWriteCfg(SCreateVnodeMsg *pMsg) { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fflush(fp); + fsync(fileno(fp)); fclose(fp); free(content); terrno = 0; diff --git a/src/vnode/src/vnodeVersion.c b/src/vnode/src/vnodeVersion.c index 68fa32b2de..d22bc17cbe 100644 --- a/src/vnode/src/vnodeVersion.c +++ b/src/vnode/src/vnodeVersion.c @@ -90,7 +90,7 @@ int32_t vnodeSaveVersion(SVnodeObj *pVnode) { len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); - fflush(fp); + fsync(fileno(fp)); fclose(fp); free(content); terrno = 0; From 20b1ea71e20390f489f1c8c2c71b6ec3f200a541 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:41:08 +0800 Subject: [PATCH 33/49] change --- .../com/taosdata/example/jdbcTemplate/BatcherInsertTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java index 29d0f79fd4..5292b6ceff 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java @@ -39,9 +39,9 @@ public class BatcherInsertTest { // create database executor.doExecute("create database if not exists test"); //use database - executor.doExecute("use test"); + executor.doExecute("use jdbctemplate_test"); // create table - executor.doExecute("create table if not exists test.weather (ts timestamp, temperature int, humidity float)"); + executor.doExecute("create table if not exists jdbctemplate_test.weather (ts timestamp, temperature int, humidity float)"); } @Test From e728058416db868e16bbc2a46cf57a7d4df9cb38 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:43:04 +0800 Subject: [PATCH 34/49] change --- .../com/taosdata/example/jdbcTemplate/BatcherInsertTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java index 5292b6ceff..d3b471cbfd 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java @@ -41,7 +41,7 @@ public class BatcherInsertTest { //use database executor.doExecute("use jdbctemplate_test"); // create table - executor.doExecute("create table if not exists jdbctemplate_test.weather (ts timestamp, temperature int, humidity float)"); + executor.doExecute("create table if not exists weather (ts timestamp, temperature int, humidity float)"); } @Test From 152b7f00ce5a2ab1cfe307f62a710ae0dc17619e Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:44:57 +0800 Subject: [PATCH 35/49] change --- .../taosdata/example/jdbcTemplate/BatcherInsertTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java index d3b471cbfd..a1f788fdcf 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java @@ -28,6 +28,7 @@ public class BatcherInsertTest { @Autowired private ExecuteAsStatement executor; + private static final String dbname = "jdbc_template_test"; private static final int numOfRecordsPerTable = 1000; private static long ts = 1496732686000l; private static Random random = new Random(System.currentTimeMillis()); @@ -35,11 +36,11 @@ public class BatcherInsertTest { @Before public void before() { // drop database - executor.doExecute("drop database if exists test"); + executor.doExecute("drop database if exists " + dbname); // create database - executor.doExecute("create database if not exists test"); + executor.doExecute("create database if not exists " + dbname); //use database - executor.doExecute("use jdbctemplate_test"); + executor.doExecute("use " + dbname); // create table executor.doExecute("create table if not exists weather (ts timestamp, temperature int, humidity float)"); } From 71543cf0853d5f195be8d029d9acf3feb7c7aec1 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:52:31 +0800 Subject: [PATCH 36/49] change --- .../example/jdbcTemplate/dao/WeatherDaoImpl.java | 1 + .../taosdata/example/jdbcTemplate/BatcherInsertTest.java | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java index b46136b70a..8d4ca47d5e 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/example/jdbcTemplate/dao/WeatherDaoImpl.java @@ -1,6 +1,7 @@ package com.taosdata.example.jdbcTemplate.dao; import com.taosdata.example.jdbcTemplate.domain.Weather; +import com.taosdata.example.jdbcTemplate.dao.WeatherDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.JdbcTemplate; diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java index a1f788fdcf..29d0f79fd4 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/example/jdbcTemplate/BatcherInsertTest.java @@ -28,7 +28,6 @@ public class BatcherInsertTest { @Autowired private ExecuteAsStatement executor; - private static final String dbname = "jdbc_template_test"; private static final int numOfRecordsPerTable = 1000; private static long ts = 1496732686000l; private static Random random = new Random(System.currentTimeMillis()); @@ -36,13 +35,13 @@ public class BatcherInsertTest { @Before public void before() { // drop database - executor.doExecute("drop database if exists " + dbname); + executor.doExecute("drop database if exists test"); // create database - executor.doExecute("create database if not exists " + dbname); + executor.doExecute("create database if not exists test"); //use database - executor.doExecute("use " + dbname); + executor.doExecute("use test"); // create table - executor.doExecute("create table if not exists weather (ts timestamp, temperature int, humidity float)"); + executor.doExecute("create table if not exists test.weather (ts timestamp, temperature int, humidity float)"); } @Test From b7a3581cc01c9a64994026252db722e7277638d4 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 15:55:04 +0800 Subject: [PATCH 37/49] change --- .../JDBC/SpringJdbcTemplate/readme.md | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/examples/JDBC/SpringJdbcTemplate/readme.md b/tests/examples/JDBC/SpringJdbcTemplate/readme.md index 1fe8809b50..b70a6565f8 100644 --- a/tests/examples/JDBC/SpringJdbcTemplate/readme.md +++ b/tests/examples/JDBC/SpringJdbcTemplate/readme.md @@ -8,18 +8,16 @@ 修改 `src/main/resources/applicationContext.xml` 文件中 TDengine 的配置信息: ```xml + + + + + + - - - - - - - - - - - + + + ``` ### 打包运行 From b6b3ee45cf3917305b69943d0b35806f8380e0c8 Mon Sep 17 00:00:00 2001 From: zyyang Date: Thu, 28 Jan 2021 16:08:41 +0800 Subject: [PATCH 38/49] change --- tests/examples/JDBC/readme.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/examples/JDBC/readme.md diff --git a/tests/examples/JDBC/readme.md b/tests/examples/JDBC/readme.md new file mode 100644 index 0000000000..9a017f4fea --- /dev/null +++ b/tests/examples/JDBC/readme.md @@ -0,0 +1,13 @@ +# TDengine examples + +| No. | Name | Describe | +| :--: | :----------------: | ------------------------------------------------------------ | +| 1 | JDBCDemo | Example codes for JDBC-JNI, JDBC-RESTful, Subscribe | +| 2 | connectionPools | Example codes for HikariCP, Druid, dbcp, c3p0 connection pools | +| 3 | SpringJdbcTemplate | Example codes for spring jdbcTemplate | +| 4 | mybatisplus-demo | Example codes for mybatis | +| 5 | springbootdemo | Example codes for springboot | +| 6 | taosdemo | This is an internal tool for testing Our JDBC-JNI, JDBC-RESTful, RESTful interfaces | + + +more detail: https://www.taosdata.com/cn//documentation20/connector-java/ \ No newline at end of file From 52ab808f261f8641d7fb35686ed3c57d30429f5e Mon Sep 17 00:00:00 2001 From: Hui Li Date: Thu, 28 Jan 2021 16:11:07 +0800 Subject: [PATCH 39/49] [NONE] --- packaging/tools/make_install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index a102f539fe..1fd0e943b1 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -154,7 +154,6 @@ function install_bin() { if [ "$osType" != "Darwin" ]; then ${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin ${csudo} cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin - ${csudo} cp -r ${script_dir}/core.sh ${install_main_dir}/bin ${csudo} cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin else ${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin From b3dcb46df69c2bf5b38174abeeaf57d533949047 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 28 Jan 2021 18:29:27 +0800 Subject: [PATCH 40/49] fix bug --- src/common/src/ttypes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 0d5910ea38..6fa27a029b 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -632,7 +632,7 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo } // the string may be overflow according to errno - *value = issigned? strtoll(z, &endPtr, radix):strtoul(z, &endPtr, radix); + *value = issigned? strtoll(z, &endPtr, radix):strtoull(z, &endPtr, radix); // not a valid integer number, return error if (endPtr - z != n || errno == ERANGE) { From a916028334bf925d1fed794c4a3fd182a34082f6 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 28 Jan 2021 19:00:04 +0800 Subject: [PATCH 41/49] rmonotonic: a monotonic clock source --- deps/CMakeLists.txt | 1 + deps/rmonotonic/CMakeLists.txt | 6 ++ deps/rmonotonic/inc/monotonic.h | 52 ++++++++++ deps/rmonotonic/src/monotonic.c | 170 ++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+) create mode 100644 deps/rmonotonic/CMakeLists.txt create mode 100644 deps/rmonotonic/inc/monotonic.h create mode 100644 deps/rmonotonic/src/monotonic.c diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 1e59396c70..a4db6fd5fb 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -9,6 +9,7 @@ ADD_SUBDIRECTORY(lz4) ADD_SUBDIRECTORY(cJson) ADD_SUBDIRECTORY(wepoll) ADD_SUBDIRECTORY(MsvcLibX) +ADD_SUBDIRECTORY(rmonotonic) IF (TD_LINUX AND TD_MQTT) ADD_SUBDIRECTORY(MQTT-C) diff --git a/deps/rmonotonic/CMakeLists.txt b/deps/rmonotonic/CMakeLists.txt new file mode 100644 index 0000000000..5433f405d0 --- /dev/null +++ b/deps/rmonotonic/CMakeLists.txt @@ -0,0 +1,6 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCE_LIST) + +add_definitions(-DUSE_PROCESSOR_CLOCK) + +ADD_LIBRARY(rmonotonic ${SOURCE_LIST}) +TARGET_INCLUDE_DIRECTORIES(rmonotonic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc) diff --git a/deps/rmonotonic/inc/monotonic.h b/deps/rmonotonic/inc/monotonic.h new file mode 100644 index 0000000000..d7741233c6 --- /dev/null +++ b/deps/rmonotonic/inc/monotonic.h @@ -0,0 +1,52 @@ +#ifndef __MONOTONIC_H +#define __MONOTONIC_H +/* The monotonic clock is an always increasing clock source. It is unrelated to + * the actual time of day and should only be used for relative timings. The + * monotonic clock is also not guaranteed to be chronologically precise; there + * may be slight skew/shift from a precise clock. + * + * Depending on system architecture, the monotonic time may be able to be + * retrieved much faster than a normal clock source by using an instruction + * counter on the CPU. On x86 architectures (for example), the RDTSC + * instruction is a very fast clock source for this purpose. + */ + +//#include "fmacros.h" +#include +//#include + +/* A counter in micro-seconds. The 'monotime' type is provided for variables + * holding a monotonic time. This will help distinguish & document that the + * variable is associated with the monotonic clock and should not be confused + * with other types of time.*/ +typedef uint64_t monotime; + +/* Retrieve counter of micro-seconds relative to an arbitrary point in time. */ +extern monotime (*getMonotonicUs)(void); + + +/* Call once at startup to initialize the monotonic clock. Though this only + * needs to be called once, it may be called additional times without impact. + * Returns a printable string indicating the type of clock initialized. + * (The returned string is static and doesn't need to be freed.) */ +const char * monotonicInit(); + + +/* Functions to measure elapsed time. Example: + * monotime myTimer; + * elapsedStart(&myTimer); + * while (elapsedMs(myTimer) < 10) {} // loops for 10ms + */ +static inline void elapsedStart(monotime *start_time) { + *start_time = getMonotonicUs(); +} + +static inline uint64_t elapsedUs(monotime start_time) { + return getMonotonicUs() - start_time; +} + +static inline uint64_t elapsedMs(monotime start_time) { + return elapsedUs(start_time) / 1000; +} + +#endif diff --git a/deps/rmonotonic/src/monotonic.c b/deps/rmonotonic/src/monotonic.c new file mode 100644 index 0000000000..5bb4f03bfc --- /dev/null +++ b/deps/rmonotonic/src/monotonic.c @@ -0,0 +1,170 @@ +#include "monotonic.h" +#include +#include +#include +#include + +#undef NDEBUG +#include + + +/* The function pointer for clock retrieval. */ +monotime (*getMonotonicUs)(void) = NULL; + +static char monotonic_info_string[32]; + + +/* Using the processor clock (aka TSC on x86) can provide improved performance + * throughout Redis wherever the monotonic clock is used. The processor clock + * is significantly faster than calling 'clock_getting' (POSIX). While this is + * generally safe on modern systems, this link provides additional information + * about use of the x86 TSC: http://oliveryang.net/2015/09/pitfalls-of-TSC-usage + * + * To use the processor clock, either uncomment this line, or build with + * CFLAGS="-DUSE_PROCESSOR_CLOCK" +#define USE_PROCESSOR_CLOCK + */ + + +#if defined(USE_PROCESSOR_CLOCK) && defined(__x86_64__) && defined(__linux__) +#include +#include + +static long mono_ticksPerMicrosecond = 0; + +static monotime getMonotonicUs_x86() { + return __rdtsc() / mono_ticksPerMicrosecond; +} + +static void monotonicInit_x86linux() { + const int bufflen = 256; + char buf[bufflen]; + regex_t cpuGhzRegex, constTscRegex; + const size_t nmatch = 2; + regmatch_t pmatch[nmatch]; + int constantTsc = 0; + int rc; + + /* Determine the number of TSC ticks in a micro-second. This is + * a constant value matching the standard speed of the processor. + * On modern processors, this speed remains constant even though + * the actual clock speed varies dynamically for each core. */ + rc = regcomp(&cpuGhzRegex, "^model name\\s+:.*@ ([0-9.]+)GHz", REG_EXTENDED); + assert(rc == 0); + + /* Also check that the constant_tsc flag is present. (It should be + * unless this is a really old CPU. */ + rc = regcomp(&constTscRegex, "^flags\\s+:.* constant_tsc", REG_EXTENDED); + assert(rc == 0); + + FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); + if (cpuinfo != NULL) { + while (fgets(buf, bufflen, cpuinfo) != NULL) { + if (regexec(&cpuGhzRegex, buf, nmatch, pmatch, 0) == 0) { + buf[pmatch[1].rm_eo] = '\0'; + double ghz = atof(&buf[pmatch[1].rm_so]); + mono_ticksPerMicrosecond = (long)(ghz * 1000); + break; + } + } + while (fgets(buf, bufflen, cpuinfo) != NULL) { + if (regexec(&constTscRegex, buf, nmatch, pmatch, 0) == 0) { + constantTsc = 1; + break; + } + } + + fclose(cpuinfo); + } + regfree(&cpuGhzRegex); + regfree(&constTscRegex); + + if (mono_ticksPerMicrosecond == 0) { + fprintf(stderr, "monotonic: x86 linux, unable to determine clock rate"); + return; + } + if (!constantTsc) { + fprintf(stderr, "monotonic: x86 linux, 'constant_tsc' flag not present"); + return; + } + + snprintf(monotonic_info_string, sizeof(monotonic_info_string), + "X86 TSC @ %ld ticks/us", mono_ticksPerMicrosecond); + getMonotonicUs = getMonotonicUs_x86; +} +#endif + + +#if defined(USE_PROCESSOR_CLOCK) && defined(__aarch64__) +static long mono_ticksPerMicrosecond = 0; + +/* Read the clock value. */ +static inline uint64_t __cntvct() { + uint64_t virtual_timer_value; + __asm__ volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value)); + return virtual_timer_value; +} + +/* Read the Count-timer Frequency. */ +static inline uint32_t cntfrq_hz() { + uint64_t virtual_freq_value; + __asm__ volatile("mrs %0, cntfrq_el0" : "=r"(virtual_freq_value)); + return (uint32_t)virtual_freq_value; /* top 32 bits are reserved */ +} + +static monotime getMonotonicUs_aarch64() { + return __cntvct() / mono_ticksPerMicrosecond; +} + +static void monotonicInit_aarch64() { + mono_ticksPerMicrosecond = (long)cntfrq_hz() / 1000L / 1000L; + if (mono_ticksPerMicrosecond == 0) { + fprintf(stderr, "monotonic: aarch64, unable to determine clock rate"); + return; + } + + snprintf(monotonic_info_string, sizeof(monotonic_info_string), + "ARM CNTVCT @ %ld ticks/us", mono_ticksPerMicrosecond); + getMonotonicUs = getMonotonicUs_aarch64; +} +#endif + + +static monotime getMonotonicUs_posix() { + /* clock_gettime() is specified in POSIX.1b (1993). Even so, some systems + * did not support this until much later. CLOCK_MONOTONIC is technically + * optional and may not be supported - but it appears to be universal. + * If this is not supported, provide a system-specific alternate version. */ + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ((uint64_t)ts.tv_sec) * 1000000 + ts.tv_nsec / 1000; +} + +static void monotonicInit_posix() { + /* Ensure that CLOCK_MONOTONIC is supported. This should be supported + * on any reasonably current OS. If the assertion below fails, provide + * an appropriate alternate implementation. */ + struct timespec ts; + int rc = clock_gettime(CLOCK_MONOTONIC, &ts); + assert(rc == 0); + + snprintf(monotonic_info_string, sizeof(monotonic_info_string), + "POSIX clock_gettime"); + getMonotonicUs = getMonotonicUs_posix; +} + + + +const char * monotonicInit() { + #if defined(USE_PROCESSOR_CLOCK) && defined(__x86_64__) && defined(__linux__) + if (getMonotonicUs == NULL) monotonicInit_x86linux(); + #endif + + #if defined(USE_PROCESSOR_CLOCK) && defined(__aarch64__) + if (getMonotonicUs == NULL) monotonicInit_aarch64(); + #endif + + if (getMonotonicUs == NULL) monotonicInit_posix(); + + return monotonic_info_string; +} From fdf860eb8443524388916aae67bda1d2c2d9672d Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 28 Jan 2021 19:00:45 +0800 Subject: [PATCH 42/49] [TD-2875]: use monotonic clock source to fix leap-second issue --- src/util/CMakeLists.txt | 3 ++- src/util/src/ttimer.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 92e030ad81..d5b1827858 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -3,9 +3,10 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc) AUX_SOURCE_DIRECTORY(src SRC) ADD_LIBRARY(tutil ${SRC}) -TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z) +TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z rmonotonic) IF (TD_LINUX) TARGET_LINK_LIBRARIES(tutil m rt) diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 015c687b3d..1fe2d2f872 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -18,6 +18,7 @@ #include "tsched.h" #include "ttimer.h" #include "tutil.h" +#include "monotonic.h" extern int8_t tscEmbedded; @@ -186,6 +187,10 @@ static void removeTimer(uintptr_t id) { unlockTimerList(list); } +static int64_t getMonotonicMs(void) { + return (int64_t) getMonotonicUs() / 1000; +} + static void addToWheel(tmr_obj_t* timer, uint32_t delay) { timerAddRef(timer); // select a wheel for the timer, we are not an accurate timer, @@ -201,7 +206,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) { time_wheel_t* wheel = wheels + timer->wheel; timer->prev = NULL; - timer->expireAt = taosGetTimestampMs() + delay; + timer->expireAt = getMonotonicMs() + delay; pthread_mutex_lock(&wheel->mutex); @@ -334,7 +339,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle } static void taosTimerLoopFunc(int signo) { - int64_t now = taosGetTimestampMs(); + int64_t now = getMonotonicMs(); for (int i = 0; i < tListLen(wheels); i++) { // `expried` is a temporary expire list. @@ -501,7 +506,8 @@ static void taosTmrModuleInit(void) { pthread_mutex_init(&tmrCtrlMutex, NULL); - int64_t now = taosGetTimestampMs(); + tmrInfo("ttimer monotonic clock source:%s", monotonicInit()); + int64_t now = getMonotonicMs(); for (int i = 0; i < tListLen(wheels); i++) { time_wheel_t* wheel = wheels + i; if (pthread_mutex_init(&wheel->mutex, NULL) != 0) { From 711d3dc7c87ebc0c37777fbcf7282ed573331ca2 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 28 Jan 2021 20:22:39 +0800 Subject: [PATCH 43/49] clock_gettime/win: first round clock_gettime for windows --- deps/rmonotonic/src/clock_gettime_win.c | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 deps/rmonotonic/src/clock_gettime_win.c diff --git a/deps/rmonotonic/src/clock_gettime_win.c b/deps/rmonotonic/src/clock_gettime_win.c new file mode 100644 index 0000000000..98a1baaf39 --- /dev/null +++ b/deps/rmonotonic/src/clock_gettime_win.c @@ -0,0 +1,72 @@ +#if defined(_WIN32) || defined(_WIN64) +#include +#include + +#define MS_PER_SEC 1000ULL // MS = milliseconds +#define US_PER_MS 1000ULL // US = microseconds +#define HNS_PER_US 10ULL // HNS = hundred-nanoseconds (e.g., 1 hns = 100 ns) +#define NS_PER_US 1000ULL + +#define HNS_PER_SEC (MS_PER_SEC * US_PER_MS * HNS_PER_US) +#define NS_PER_HNS (100ULL) // NS = nanoseconds +#define NS_PER_SEC (MS_PER_SEC * US_PER_MS * NS_PER_US) + +int clock_gettime_monotonic(struct timespec *tv) +{ + static LARGE_INTEGER ticksPerSec; + LARGE_INTEGER ticks; + double seconds; + + if (!ticksPerSec.QuadPart) { + QueryPerformanceFrequency(&ticksPerSec); + if (!ticksPerSec.QuadPart) { + errno = ENOTSUP; + return -1; + } + } + + QueryPerformanceCounter(&ticks); + + seconds = (double) ticks.QuadPart / (double) ticksPerSec.QuadPart; + tv->tv_sec = (time_t)seconds; + tv->tv_nsec = (long)((ULONGLONG)(seconds * NS_PER_SEC) % NS_PER_SEC); + + return 0; +} + +int clock_gettime_realtime(struct timespec *tv) +{ + FILETIME ft; + ULARGE_INTEGER hnsTime; + + GetSystemTimeAsFileTime(&ft); + + hnsTime.LowPart = ft.dwLowDateTime; + hnsTime.HighPart = ft.dwHighDateTime; + + // To get POSIX Epoch as baseline, subtract the number of hns intervals from Jan 1, 1601 to Jan 1, 1970. + hnsTime.QuadPart -= (11644473600ULL * HNS_PER_SEC); + + // modulus by hns intervals per second first, then convert to ns, as not to lose resolution + tv->tv_nsec = (long) ((hnsTime.QuadPart % HNS_PER_SEC) * NS_PER_HNS); + tv->tv_sec = (long) (hnsTime.QuadPart / HNS_PER_SEC); + + return 0; +} + +int clock_gettime(clockid_t type, struct timespec *tp) +{ + if (type == CLOCK_MONOTONIC) + { + return clock_gettime_monotonic(tp); + } + else if (type == CLOCK_REALTIME) + { + return clock_gettime_realtime(tp); + } + + errno = ENOTSUP; + return -1; +} + +#endif From 6c93a8bfc59b34c2c459a6e6f1327aa57a09ce05 Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Thu, 28 Jan 2021 23:52:04 +0800 Subject: [PATCH 44/49] [TD-2801]: add test case --- tests/pytest/fulltest.sh | 1 + tests/pytest/insert/metadataUpdate.py | 67 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/pytest/insert/metadataUpdate.py diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 3be784ae95..aee8f7502c 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -20,6 +20,7 @@ python3 insert/retentionpolicy.py python3 ./test.py -f insert/alterTableAndInsert.py python3 ./test.py -f insert/insertIntoTwoTables.py #python3 ./test.py -f insert/before_1970.py +python3 ./test.py -f insert/metadataUpdate.py python3 bug2265.py #table diff --git a/tests/pytest/insert/metadataUpdate.py b/tests/pytest/insert/metadataUpdate.py new file mode 100644 index 0000000000..c3ea5c6a7e --- /dev/null +++ b/tests/pytest/insert/metadataUpdate.py @@ -0,0 +1,67 @@ +################################################################### +# 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 +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes +from multiprocessing import Process + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1538548685000 + + def updateMetadata(self): + self.host = "127.0.0.1" + self.user = "root" + self.password = "taosdata" + self.config = tdDnodes.getSimCfgPath() + + self.conn = taos.connect(host = self.host, user = self.user, password = self.password, config = self.config) + self.cursor = self.conn.cursor() + self.cursor.execute("alter table db.tb add column col2 int") + print("alter table done") + + def run(self): + tdSql.prepare() + + print("==============step1") + tdSql.execute("create table if not exists tb (ts timestamp, col1 int)") + tdSql.execute("insert into tb values(%d, 1)" % self.ts) + + print("==============step2") + tdSql.query("select * from tb") + tdSql.checkRows(1) + + p = Process(target=self.updateMetadata, args=()) + p.start() + p.join() + p.terminate() + + tdSql.execute("insert into tb values(%d, 1, 2)" % (self.ts + 1)) + + print("==============step2") + tdSql.query("select * from tb") + tdSql.checkRows(2) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From 95814895994cf9072cccb09423345033a1cd7537 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Fri, 29 Jan 2021 11:35:50 +0800 Subject: [PATCH 45/49] [TD-2830] support tar.gz pkg --- packaging/tools/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index e74a61801b..9cec9963af 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -168,6 +168,7 @@ function install_main_path() { if [ "$verMode" == "cluster" ]; then ${csudo} mkdir -p ${nginx_dir} fi + ${csudo} cp ${script_dir}/email ${install_main_dir}/ ||: } function install_bin() { From b834fb6f377e520e498693f103f0b8483ee7e8a6 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 29 Jan 2021 12:50:52 +0800 Subject: [PATCH 46/49] msvclibx/clock_gettime: add CLOCK_MONOTONIC to msvclibx --- deps/MsvcLibX/include/msvcTime.h | 1 + deps/MsvcLibX/src/clock_gettime.c | 55 ++++++++++++++++--- deps/rmonotonic/CMakeLists.txt | 1 + deps/rmonotonic/inc/monotonic.h | 4 ++ deps/rmonotonic/src/clock_gettime_win.c | 72 ------------------------- deps/rmonotonic/src/monotonic.c | 5 +- 6 files changed, 57 insertions(+), 81 deletions(-) delete mode 100644 deps/rmonotonic/src/clock_gettime_win.c diff --git a/deps/MsvcLibX/include/msvcTime.h b/deps/MsvcLibX/include/msvcTime.h index 1897da5857..6f8b5dac8f 100644 --- a/deps/MsvcLibX/include/msvcTime.h +++ b/deps/MsvcLibX/include/msvcTime.h @@ -38,6 +38,7 @@ typedef int clockid_t; /* Supported values for clockid_t */ #define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 int clock_gettime(clockid_t clock_id, struct timespec *tp); diff --git a/deps/MsvcLibX/src/clock_gettime.c b/deps/MsvcLibX/src/clock_gettime.c index fee7532e2e..cbddf7107a 100644 --- a/deps/MsvcLibX/src/clock_gettime.c +++ b/deps/MsvcLibX/src/clock_gettime.c @@ -34,15 +34,56 @@ #include "msvcTime.h" #include "sys/msvcStat.h" /* For MsvcLibX's Filetime2Timespec */ -int clock_gettime(clockid_t clock_id, struct timespec *pTS) { - FILETIME ft; - if (clock_id != CLOCK_REALTIME) { - errno = EINVAL; - return -1; +#define MS_PER_SEC 1000ULL // MS = milliseconds +#define US_PER_MS 1000ULL // US = microseconds +#define HNS_PER_US 10ULL // HNS = hundred-nanoseconds (e.g., 1 hns = 100 ns) +#define NS_PER_US 1000ULL + +#define HNS_PER_SEC (MS_PER_SEC * US_PER_MS * HNS_PER_US) +#define NS_PER_HNS (100ULL) // NS = nanoseconds +#define NS_PER_SEC (MS_PER_SEC * US_PER_MS * NS_PER_US) + +int clock_gettime_monotonic(struct timespec *tv) { + static LARGE_INTEGER ticksPerSec; + LARGE_INTEGER ticks; + double seconds; + + if (!ticksPerSec.QuadPart) { + QueryPerformanceFrequency(&ticksPerSec); + if (!ticksPerSec.QuadPart) { + errno = ENOTSUP; + return -1; + } } - GetSystemTimeAsFileTime(&ft); - Filetime2Timespec(&ft, pTS); + + QueryPerformanceCounter(&ticks); + + seconds = (double) ticks.QuadPart / (double) ticksPerSec.QuadPart; + tv->tv_sec = (time_t)seconds; + tv->tv_nsec = (long)((ULONGLONG)(seconds * NS_PER_SEC) % NS_PER_SEC); + return 0; } +int clock_gettime_realtime(struct timespec *pTS) { + FILETIME ft; + + GetSystemTimeAsFileTime(&ft); + Filetime2Timespec(&ft, pTS); + + return 0; +} + +int clock_gettime(clockid_t clock_id, struct timespec *pTS) { + if (clock_id == CLOCK_MONOTONIC) { + return clock_gettime_monotonic(pTS); + } else if (clock_id == CLOCK_REALTIME) { + return clock_gettime_realtime(pTS); + } + + errno = ENOTSUP; + + return -1; +} + #endif /* defined(_WIN32) */ diff --git a/deps/rmonotonic/CMakeLists.txt b/deps/rmonotonic/CMakeLists.txt index 5433f405d0..119b3c3114 100644 --- a/deps/rmonotonic/CMakeLists.txt +++ b/deps/rmonotonic/CMakeLists.txt @@ -4,3 +4,4 @@ add_definitions(-DUSE_PROCESSOR_CLOCK) ADD_LIBRARY(rmonotonic ${SOURCE_LIST}) TARGET_INCLUDE_DIRECTORIES(rmonotonic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc) +TARGET_LINK_LIBRARIES(rmonotonic MsvcLibXw) diff --git a/deps/rmonotonic/inc/monotonic.h b/deps/rmonotonic/inc/monotonic.h index d7741233c6..0850548d36 100644 --- a/deps/rmonotonic/inc/monotonic.h +++ b/deps/rmonotonic/inc/monotonic.h @@ -15,6 +15,10 @@ #include //#include +#if defined(_WIN32) || defined(_WIN64) + #define inline +#endif + /* A counter in micro-seconds. The 'monotime' type is provided for variables * holding a monotonic time. This will help distinguish & document that the * variable is associated with the monotonic clock and should not be confused diff --git a/deps/rmonotonic/src/clock_gettime_win.c b/deps/rmonotonic/src/clock_gettime_win.c deleted file mode 100644 index 98a1baaf39..0000000000 --- a/deps/rmonotonic/src/clock_gettime_win.c +++ /dev/null @@ -1,72 +0,0 @@ -#if defined(_WIN32) || defined(_WIN64) -#include -#include - -#define MS_PER_SEC 1000ULL // MS = milliseconds -#define US_PER_MS 1000ULL // US = microseconds -#define HNS_PER_US 10ULL // HNS = hundred-nanoseconds (e.g., 1 hns = 100 ns) -#define NS_PER_US 1000ULL - -#define HNS_PER_SEC (MS_PER_SEC * US_PER_MS * HNS_PER_US) -#define NS_PER_HNS (100ULL) // NS = nanoseconds -#define NS_PER_SEC (MS_PER_SEC * US_PER_MS * NS_PER_US) - -int clock_gettime_monotonic(struct timespec *tv) -{ - static LARGE_INTEGER ticksPerSec; - LARGE_INTEGER ticks; - double seconds; - - if (!ticksPerSec.QuadPart) { - QueryPerformanceFrequency(&ticksPerSec); - if (!ticksPerSec.QuadPart) { - errno = ENOTSUP; - return -1; - } - } - - QueryPerformanceCounter(&ticks); - - seconds = (double) ticks.QuadPart / (double) ticksPerSec.QuadPart; - tv->tv_sec = (time_t)seconds; - tv->tv_nsec = (long)((ULONGLONG)(seconds * NS_PER_SEC) % NS_PER_SEC); - - return 0; -} - -int clock_gettime_realtime(struct timespec *tv) -{ - FILETIME ft; - ULARGE_INTEGER hnsTime; - - GetSystemTimeAsFileTime(&ft); - - hnsTime.LowPart = ft.dwLowDateTime; - hnsTime.HighPart = ft.dwHighDateTime; - - // To get POSIX Epoch as baseline, subtract the number of hns intervals from Jan 1, 1601 to Jan 1, 1970. - hnsTime.QuadPart -= (11644473600ULL * HNS_PER_SEC); - - // modulus by hns intervals per second first, then convert to ns, as not to lose resolution - tv->tv_nsec = (long) ((hnsTime.QuadPart % HNS_PER_SEC) * NS_PER_HNS); - tv->tv_sec = (long) (hnsTime.QuadPart / HNS_PER_SEC); - - return 0; -} - -int clock_gettime(clockid_t type, struct timespec *tp) -{ - if (type == CLOCK_MONOTONIC) - { - return clock_gettime_monotonic(tp); - } - else if (type == CLOCK_REALTIME) - { - return clock_gettime_realtime(tp); - } - - errno = ENOTSUP; - return -1; -} - -#endif diff --git a/deps/rmonotonic/src/monotonic.c b/deps/rmonotonic/src/monotonic.c index 5bb4f03bfc..37023ce273 100644 --- a/deps/rmonotonic/src/monotonic.c +++ b/deps/rmonotonic/src/monotonic.c @@ -7,6 +7,8 @@ #undef NDEBUG #include +#include "msvcTime.h" +#include "msvcStdio.h" /* The function pointer for clock retrieval. */ monotime (*getMonotonicUs)(void) = NULL; @@ -129,8 +131,7 @@ static void monotonicInit_aarch64() { } #endif - -static monotime getMonotonicUs_posix() { +static monotime getMonotonicUs_posix(void) { /* clock_gettime() is specified in POSIX.1b (1993). Even so, some systems * did not support this until much later. CLOCK_MONOTONIC is technically * optional and may not be supported - but it appears to be universal. From ea981d08060fe069c64fb777a6a23545766f2f79 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 29 Jan 2021 13:23:28 +0800 Subject: [PATCH 47/49] monotonic/msvclibx: fix compilation on linux --- deps/rmonotonic/CMakeLists.txt | 6 +++++- deps/rmonotonic/src/monotonic.c | 2 ++ src/util/src/ttimer.c | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/deps/rmonotonic/CMakeLists.txt b/deps/rmonotonic/CMakeLists.txt index 119b3c3114..b870b7d6d7 100644 --- a/deps/rmonotonic/CMakeLists.txt +++ b/deps/rmonotonic/CMakeLists.txt @@ -2,6 +2,10 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCE_LIST) add_definitions(-DUSE_PROCESSOR_CLOCK) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../MsvcLibX/include) + ADD_LIBRARY(rmonotonic ${SOURCE_LIST}) TARGET_INCLUDE_DIRECTORIES(rmonotonic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc) -TARGET_LINK_LIBRARIES(rmonotonic MsvcLibXw) +IF (TD_WINDOWS) + TARGET_LINK_LIBRARIES(rmonotonic MsvcLibXw) +ENDIF () diff --git a/deps/rmonotonic/src/monotonic.c b/deps/rmonotonic/src/monotonic.c index 37023ce273..622ac1b075 100644 --- a/deps/rmonotonic/src/monotonic.c +++ b/deps/rmonotonic/src/monotonic.c @@ -7,8 +7,10 @@ #undef NDEBUG #include +#if defined(_WIN32) || defined(_WIN64) #include "msvcTime.h" #include "msvcStdio.h" +#endif /* The function pointer for clock retrieval. */ monotime (*getMonotonicUs)(void) = NULL; diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 1fe2d2f872..6029edf512 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -506,7 +506,6 @@ static void taosTmrModuleInit(void) { pthread_mutex_init(&tmrCtrlMutex, NULL); - tmrInfo("ttimer monotonic clock source:%s", monotonicInit()); int64_t now = getMonotonicMs(); for (int i = 0; i < tListLen(wheels); i++) { time_wheel_t* wheel = wheels + i; @@ -538,6 +537,8 @@ static void taosTmrModuleInit(void) { } void* taosTmrInit(int maxNumOfTmrs, int resolution, int longest, const char* label) { + tmrInfo("ttimer monotonic clock source:%s", monotonicInit()); + pthread_once(&tmrModuleInit, taosTmrModuleInit); pthread_mutex_lock(&tmrCtrlMutex); From a3f537f4d5b9db236ec67881c8b4fe4edbb80502 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sat, 30 Jan 2021 18:34:39 +0800 Subject: [PATCH 48/49] [TD-2891] : get process cmdline by pid on mac. --- src/os/src/darwin/darwinSysInfo.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/os/src/darwin/darwinSysInfo.c b/src/os/src/darwin/darwinSysInfo.c index 0eb784e9f0..5b42b6b0f6 100644 --- a/src/os/src/darwin/darwinSysInfo.c +++ b/src/os/src/darwin/darwinSysInfo.c @@ -18,6 +18,9 @@ #include "tconfig.h" #include "tglobal.h" #include "tulog.h" +#include +#include + static void taosGetSystemTimezone() { // get and set default timezone @@ -103,8 +106,18 @@ int taosSystem(const char *cmd) { void taosSetCoreDump() {} +char cmdline[1024]; + char *taosGetCmdlineByPID(int pid) { - return "[not supported yet]"; + + errno = 0; + + if (proc_pidpath(pid, cmdline, sizeof(cmdline)) <= 0) { + fprintf(stderr, "PID is %d, %s", pid, strerror(errno)); + return strerror(errno); + } + + return cmdline; } bool taosGetSystemUid(char *uid) { From b6a733ee8abd5d4a3a801f59e541e6dc8d3342e6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 30 Jan 2021 16:29:00 +0000 Subject: [PATCH 49/49] TD-2884 --- src/client/src/tscSystem.c | 8 +++++--- src/rpc/src/rpcTcp.c | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index fe1c45bd39..62ae2cd709 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -65,7 +65,7 @@ void tscReleaseRpc(void *param) { return; } pthread_mutex_lock(&rpcObjMutex); - taosCacheRelease(tscRpcCache, (void *)¶m, false); + taosCacheRelease(tscRpcCache, (void *)¶m, true); pthread_mutex_unlock(&rpcObjMutex); } @@ -216,7 +216,6 @@ void taos_cleanup(void) { taosCloseRef(id); taosCleanupKeywordsTable(); - taosCloseLog(); p = tscRpcCache; tscRpcCache = NULL; @@ -226,7 +225,10 @@ void taos_cleanup(void) { pthread_mutex_destroy(&rpcObjMutex); } - if (tscEmbedded == 0) rpcCleanup(); + if (tscEmbedded == 0) { + rpcCleanup(); + taosCloseLog(); + }; p = tscTmr; tscTmr = NULL; diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 111b722f76..3295c130dd 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -364,10 +364,11 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int numOfThread } void taosStopTcpClient(void *chandle) { - SThreadObj *pThreadObj = chandle; - if (pThreadObj == NULL) return; + SClientObj *pClientObj = chandle; - tDebug ("%s TCP client is stopped", pThreadObj->label); + if (pClientObj == NULL) return; + + tDebug ("%s TCP client is stopped", pClientObj->label); } void taosCleanUpTcpClient(void *chandle) {