提交 de06f055 编写于 作者: D dapan1121

enh: stop query

上级 73dfd117
...@@ -118,6 +118,7 @@ struct SAppInstInfo { ...@@ -118,6 +118,7 @@ struct SAppInstInfo {
uint64_t clusterId; uint64_t clusterId;
void* pTransporter; void* pTransporter;
SAppHbMgr* pAppHbMgr; SAppHbMgr* pAppHbMgr;
char* instKey;
}; };
typedef struct SAppInfo { typedef struct SAppInfo {
...@@ -336,6 +337,7 @@ int hbHandleRsp(SClientHbBatchRsp* hbRsp); ...@@ -336,6 +337,7 @@ int hbHandleRsp(SClientHbBatchRsp* hbRsp);
// cluster level // cluster level
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key); SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
void appHbMgrCleanup(void); void appHbMgrCleanup(void);
void hbRemoveAppHbMrg(SAppHbMgr **pAppHbMgr);
// conn level // conn level
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType); int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
......
...@@ -79,13 +79,13 @@ static void deregisterRequest(SRequestObj *pRequest) { ...@@ -79,13 +79,13 @@ static void deregisterRequest(SRequestObj *pRequest) {
} }
// todo close the transporter properly // todo close the transporter properly
void closeTransporter(STscObj *pTscObj) { void closeTransporter(SAppInstInfo *pAppInfo) {
if (pTscObj == NULL || pTscObj->pAppInfo->pTransporter == NULL) { if (pAppInfo == NULL || pAppInfo->pTransporter == NULL) {
return; return;
} }
tscDebug("free transporter:%p in connObj: 0x%" PRIx64, pTscObj->pAppInfo->pTransporter, pTscObj->id); tscDebug("free transporter:%p in app inst %p", pAppInfo->pTransporter, pAppInfo);
rpcClose(pTscObj->pAppInfo->pTransporter); rpcClose(pAppInfo->pTransporter);
} }
static bool clientRpcRfp(int32_t code) { static bool clientRpcRfp(int32_t code) {
...@@ -130,6 +130,21 @@ void closeAllRequests(SHashObj *pRequests) { ...@@ -130,6 +130,21 @@ void closeAllRequests(SHashObj *pRequests) {
} }
} }
void destroyAppInst(SAppInstInfo* pAppInfo) {
tscDebug("destroy app inst mgr %p", pAppInfo);
hbRemoveAppHbMrg(&pAppInfo->pAppHbMgr);
taosHashRemove(appInfo.pInstMap, pAppInfo->instKey, strlen(pAppInfo->instKey));
taosMemoryFreeClear(pAppInfo->instKey);
closeTransporter(pAppInfo);
taosThreadMutexLock(&pAppInfo->qnodeMutex);
taosArrayDestroy(pAppInfo->pQnodeList);
taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
taosMemoryFree(pAppInfo);
}
void destroyTscObj(void *pObj) { void destroyTscObj(void *pObj) {
STscObj *pTscObj = pObj; STscObj *pTscObj = pObj;
...@@ -138,11 +153,12 @@ void destroyTscObj(void *pObj) { ...@@ -138,11 +153,12 @@ void destroyTscObj(void *pObj) {
int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); int64_t connNum = atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
closeAllRequests(pTscObj->pRequests); closeAllRequests(pTscObj->pRequests);
schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter); schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter);
tscDebug("connObj 0x%" PRIx64 " p:%p destroyed, remain inst totalConn:%" PRId64, pTscObj->id, pTscObj,
pTscObj->pAppInfo->numOfConns);
if (0 == connNum) { if (0 == connNum) {
closeTransporter(pTscObj); destroyAppInst(pTscObj->pAppInfo);
} }
tscDebug("connObj 0x%" PRIx64 " p:%p destroyed, totalConn:%" PRId64, pTscObj->id, pTscObj,
pTscObj->pAppInfo->numOfConns);
taosThreadMutexDestroy(&pTscObj->mutex); taosThreadMutexDestroy(&pTscObj->mutex);
taosMemoryFreeClear(pTscObj); taosMemoryFreeClear(pTscObj);
} }
...@@ -174,6 +190,8 @@ void *createTscObj(const char *user, const char *auth, const char *db, int32_t c ...@@ -174,6 +190,8 @@ void *createTscObj(const char *user, const char *auth, const char *db, int32_t c
pObj->id = taosAddRef(clientConnRefPool, pObj); pObj->id = taosAddRef(clientConnRefPool, pObj);
pObj->schemalessType = 1; pObj->schemalessType = 1;
atomic_add_fetch_64(&pObj->pAppInfo->numOfConns, 1);
tscDebug("connObj created, 0x%" PRIx64 ",p:%p", pObj->id, pObj); tscDebug("connObj created, 0x%" PRIx64 ",p:%p", pObj->id, pObj);
return pObj; return pObj;
} }
......
...@@ -790,11 +790,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { ...@@ -790,11 +790,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
return pAppHbMgr; return pAppHbMgr;
} }
void appHbMgrCleanup(void) { void hbFreeAppHbMgr(SAppHbMgr *pTarget) {
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
for (int i = 0; i < sz; i++) {
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
void *pIter = taosHashIterate(pTarget->activeInfo, NULL); void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
while (pIter != NULL) { while (pIter != NULL) {
SClientHbReq *pOneReq = pIter; SClientHbReq *pOneReq = pIter;
...@@ -806,6 +802,28 @@ void appHbMgrCleanup(void) { ...@@ -806,6 +802,28 @@ void appHbMgrCleanup(void) {
taosMemoryFree(pTarget->key); taosMemoryFree(pTarget->key);
taosMemoryFree(pTarget); taosMemoryFree(pTarget);
}
void hbRemoveAppHbMrg(SAppHbMgr **pAppHbMgr) {
taosThreadMutexLock(&clientHbMgr.lock);
int32_t mgrSize = taosArrayGetSize(clientHbMgr.appHbMgrs);
for (int32_t i = 0; i < mgrSize; ++i) {
SAppHbMgr *pItem = taosArrayGetP(clientHbMgr.appHbMgrs, i);
if (pItem == *pAppHbMgr) {
hbFreeAppHbMgr(*pAppHbMgr);
*pAppHbMgr = NULL;
taosArrayRemove(clientHbMgr.appHbMgrs, i);
break;
}
}
taosThreadMutexUnlock(&clientHbMgr.lock);
}
void appHbMgrCleanup(void) {
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
for (int i = 0; i < sz; i++) {
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
hbFreeAppHbMgr(pTarget);
} }
} }
......
...@@ -122,6 +122,9 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas ...@@ -122,6 +122,9 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas
p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores); p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores);
p->pAppHbMgr = appHbMgrInit(p, key); p->pAppHbMgr = appHbMgrInit(p, key);
taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES); taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES);
p->instKey = key;
key = NULL;
tscDebug("new app inst mgr %p, user:%s, ip:%s, port:%d", p, user, ip, port);
pInst = &p; pInst = &p;
} }
......
...@@ -87,7 +87,6 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -87,7 +87,6 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
// update the appInstInfo // update the appInstInfo
pTscObj->pAppInfo->clusterId = connectRsp.clusterId; pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
pTscObj->connType = connectRsp.connType; pTscObj->connType = connectRsp.connType;
......
...@@ -790,6 +790,8 @@ _return: ...@@ -790,6 +790,8 @@ _return:
int32_t ctgCallUserCb(void* param) { int32_t ctgCallUserCb(void* param) {
SCtgJob* pJob = (SCtgJob*)param; SCtgJob* pJob = (SCtgJob*)param;
//taosSsleep(2);
(*pJob->userFp)(&pJob->jobRes, pJob->userParam, pJob->jobResCode); (*pJob->userFp)(&pJob->jobRes, pJob->userParam, pJob->jobResCode);
taosRemoveRef(gCtgMgmt.jobPool, pJob->refId); taosRemoveRef(gCtgMgmt.jobPool, pJob->refId);
......
...@@ -368,6 +368,7 @@ void *closeThreadFp(void *arg) { ...@@ -368,6 +368,7 @@ void *closeThreadFp(void *arg) {
while (true) { while (true) {
if (qParam->taos) { if (qParam->taos) {
usleep(rand() % 10000); usleep(rand() % 10000);
//usleep(1000000);
taos_close(qParam->taos); taos_close(qParam->taos);
break; break;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册