diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index c6e9cbafd751809e6bfdedb064f3b6c40480699b..ddbee3106d890abdc18db907d43c3a528ecba286 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -188,8 +188,8 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { if (tscShouldFreeHeartBeat(pHB)) { tscDebug("%p free HB object and release connection", pHB); - tscFreeSqlObj(pHB); - tscCloseTscObj(pObj); + pObj->pHb = 0; + taos_free_result(pHB); } else { int32_t code = tscProcessSql(pHB); if (code != TSDB_CODE_SUCCESS) { @@ -1959,6 +1959,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { return 0; } +// TODO multithread problem static void createHBObj(STscObj* pObj) { if (pObj->pHb != NULL) { return; @@ -1987,10 +1988,13 @@ static void createHBObj(STscObj* pObj) { pSql->pTscObj = pObj; pSql->signature = pSql; pObj->pHb = pSql; - T_REF_INC(pObj); tscAddSubqueryInfo(&pObj->pHb->cmd); + int64_t ad = (int64_t) pSql; + pSql->self = taosCachePut(tscObjCache, &ad, sizeof(int64_t), &pSql, sizeof(int64_t), 2 * 60 * 1000); + T_REF_INC(pObj); + tscDebug("%p HB is allocated, pObj:%p", pObj->pHb, pObj); } @@ -2017,8 +2021,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { pObj->connId = htonl(pConnect->connId); createHBObj(pObj); - -// taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, pObj, tscTmr, &pObj->pTimer); + taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, pObj, tscTmr, &pObj->pTimer); return 0; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 1df77d18503604637f16e7e620e59b327a62d5d9..598ec7e5469c87cacb7e845ebcfa6a8bf5937ea8 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -263,32 +263,15 @@ void taos_close(TAOS *taos) { return; } - if (pObj->pHb != NULL) { - if (pObj->pHb->pRpcCtx != NULL) { // wait for rsp from dnode - rpcCancelRequest(pObj->pHb->pRpcCtx); + SSqlObj* pHb = pObj->pHb; + if (pHb != NULL) { + if (pHb->pRpcCtx != NULL) { // wait for rsp from dnode + rpcCancelRequest(pHb->pRpcCtx); } - tscSetFreeHeatBeat(pObj); - tscFreeSqlObj(pObj->pHb); - } - - // free all sqlObjs created by using this connect before free the STscObj -// while(1) { -// pthread_mutex_lock(&pObj->mutex); -// void* p = pObj->sqlList; -// pthread_mutex_unlock(&pObj->mutex); -// -// if (p == NULL) { -// break; -// } -// -// tscDebug("%p waiting for sqlObj to be freed, %p", pObj, p); -// taosMsleep(100); -// -// // todo fix me!! two threads call taos_free_result will cause problem. -// tscDebug("%p free :%p", pObj, p); -// taos_free_result(p); -// } + pObj->pHb = NULL; + taos_free_result(pHb); + } int32_t ref = T_REF_DEC(pObj); assert(ref >= 0); diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index f59bf62ec504444c561107bb5b5dcf3ec6f8c000..cb318d5c24f26e66e2771c170ac39010e6e34ca0 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -580,6 +580,8 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerFqdn, uint16_t peerPort, void *shandle = (connType & RPC_CONN_TCP)? pRpc->tcphandle:pRpc->udphandle; pConn->chandle = (*taosOpenConn[connType])(shandle, pConn, pConn->peerIp, pConn->peerPort); if (pConn->chandle == NULL) { + tError("failed to connect to:0x%x:%d", pConn->peerIp, pConn->peerPort); + terrno = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcCloseConn(pConn); pConn = NULL; diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 4d737ebe66f1e82614d4eb71c1d93129949c5c4e..e1dd521547f3cc14e6715b07e6c28a50d0cf105a 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -260,7 +260,13 @@ static void incRefFn(void* ptNode) { } void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen) { - if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0 || pCacheObj->deleting == 1) { + if (pCacheObj == NULL || pCacheObj->deleting == 1) { + return NULL; + } + + if (taosHashGetSize(pCacheObj->pHashTable) == 0) { + atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); + uError("cache:%s, key:%p, not in cache, retrieved failed, reason: empty sqlObj cache", pCacheObj->name, key); return NULL; } @@ -274,7 +280,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(ptNode)); } else { atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); - uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key); + uError("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key); } atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1);