TDengine/source/client/src/clientHb.c

927 lines
27 KiB
C
Raw Normal View History

2022-01-07 06:57:45 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-01-26 00:50:32 +00:00
#include "catalog.h"
2022-03-01 09:49:14 +00:00
#include "clientInt.h"
2022-01-26 00:50:32 +00:00
#include "clientLog.h"
2022-04-25 03:41:42 +00:00
#include "scheduler.h"
2022-03-01 09:49:14 +00:00
#include "trpc.h"
2022-01-07 06:57:45 +00:00
static SClientHbMgr clientHbMgr = {0};
static int32_t hbCreateThread();
static void hbStopThread();
2022-04-14 06:42:51 +00:00
static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; }
2022-03-04 09:08:46 +00:00
static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; }
2022-01-07 08:48:35 +00:00
2022-05-06 06:13:56 +00:00
static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
int32_t code = 0;
SUserAuthBatchRsp batchRsp = {0};
if (tDeserializeSUserAuthBatchRsp(value, valueLen, &batchRsp) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
int32_t numOfBatchs = taosArrayGetSize(batchRsp.pArray);
for (int32_t i = 0; i < numOfBatchs; ++i) {
SGetUserAuthRsp *rsp = taosArrayGet(batchRsp.pArray, i);
tscDebug("hb user auth rsp, user:%s, version:%d", rsp->user, rsp->version);
catalogUpdateUserAuthInfo(pCatalog, rsp);
}
2022-05-20 07:37:39 +00:00
taosArrayDestroy(batchRsp.pArray);
2022-05-06 06:13:56 +00:00
return TSDB_CODE_SUCCESS;
}
2022-01-26 00:50:32 +00:00
static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
int32_t code = 0;
2022-02-14 07:27:38 +00:00
SUseDbBatchRsp batchUseRsp = {0};
if (tDeserializeSUseDbBatchRsp(value, valueLen, &batchUseRsp) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
2022-01-26 09:42:31 +00:00
2022-02-14 07:27:38 +00:00
int32_t numOfBatchs = taosArrayGetSize(batchUseRsp.pArray);
for (int32_t i = 0; i < numOfBatchs; ++i) {
SUseDbRsp *rsp = taosArrayGet(batchUseRsp.pArray, i);
2022-03-01 09:49:14 +00:00
tscDebug("hb db rsp, db:%s, vgVersion:%d, uid:%" PRIx64, rsp->db, rsp->vgVersion, rsp->uid);
2022-01-26 00:50:32 +00:00
if (rsp->vgVersion < 0) {
2022-01-28 09:50:16 +00:00
code = catalogRemoveDB(pCatalog, rsp->db, rsp->uid);
2022-01-26 00:50:32 +00:00
} else {
2022-06-27 10:29:28 +00:00
SDBVgInfo *vgInfo = taosMemoryCalloc(1, sizeof(SDBVgInfo));
if (NULL == vgInfo) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
vgInfo->vgVersion = rsp->vgVersion;
vgInfo->hashMethod = rsp->hashMethod;
vgInfo->vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
if (NULL == vgInfo->vgHash) {
taosMemoryFree(vgInfo);
2022-01-26 00:50:32 +00:00
tscError("hash init[%d] failed", rsp->vgNum);
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
2022-02-14 07:27:38 +00:00
for (int32_t j = 0; j < rsp->vgNum; ++j) {
SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j);
2022-06-27 10:29:28 +00:00
if (taosHashPut(vgInfo->vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) {
2022-01-26 00:50:32 +00:00
tscError("hash push failed, errno:%d", errno);
2022-06-27 10:29:28 +00:00
taosHashCleanup(vgInfo->vgHash);
taosMemoryFree(vgInfo);
2022-01-26 00:50:32 +00:00
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
2022-03-01 09:49:14 +00:00
}
2022-06-27 10:29:28 +00:00
catalogUpdateDBVgInfo(pCatalog, rsp->db, rsp->uid, vgInfo);
2022-01-26 00:50:32 +00:00
}
if (code) {
return code;
}
}
2022-02-15 08:56:07 +00:00
tFreeSUseDbBatchRsp(&batchUseRsp);
2022-01-26 00:50:32 +00:00
return TSDB_CODE_SUCCESS;
}
2022-02-06 07:37:16 +00:00
static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
int32_t code = 0;
2022-06-13 02:38:45 +00:00
SSTbHbRsp hbRsp = {0};
if (tDeserializeSSTbHbRsp(value, valueLen, &hbRsp) != 0) {
2022-02-15 07:24:27 +00:00
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
2022-06-13 06:06:11 +00:00
int32_t numOfMeta = taosArrayGetSize(hbRsp.pMetaRsp);
for (int32_t i = 0; i < numOfMeta; ++i) {
STableMetaRsp *rsp = taosArrayGet(hbRsp.pMetaRsp, i);
2022-02-15 07:24:27 +00:00
2022-02-06 07:37:16 +00:00
if (rsp->numOfColumns < 0) {
tscDebug("hb remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
2022-02-11 11:52:07 +00:00
catalogRemoveStbMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->stbName, rsp->suid);
2022-02-06 07:37:16 +00:00
} else {
2022-02-08 08:53:00 +00:00
tscDebug("hb update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
2022-02-15 07:24:27 +00:00
if (rsp->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
tscError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", rsp->pSchemas[0].colId);
2022-06-13 02:38:45 +00:00
tFreeSSTbHbRsp(&hbRsp);
2022-02-08 08:53:00 +00:00
return TSDB_CODE_TSC_INVALID_VALUE;
2022-02-06 07:37:16 +00:00
}
2022-06-01 12:28:29 +00:00
catalogUpdateTableMeta(pCatalog, rsp);
2022-02-06 07:37:16 +00:00
}
}
2022-06-13 06:06:11 +00:00
int32_t numOfIndex = taosArrayGetSize(hbRsp.pIndexRsp);
for (int32_t i = 0; i < numOfIndex; ++i) {
STableIndexRsp *rsp = taosArrayGet(hbRsp.pIndexRsp, i);
catalogUpdateTableIndex(pCatalog, rsp);
}
taosArrayDestroy(hbRsp.pIndexRsp);
hbRsp.pIndexRsp = NULL;
2022-06-13 02:38:45 +00:00
tFreeSSTbHbRsp(&hbRsp);
2022-02-06 07:37:16 +00:00
return TSDB_CODE_SUCCESS;
}
2022-03-04 09:08:46 +00:00
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
2022-06-04 14:33:30 +00:00
SClientHbReq *pReq = taosHashGet(pAppHbMgr->activeInfo, &pRsp->connKey, sizeof(SClientHbKey));
if (NULL == pReq) {
tscWarn("pReq to get activeInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid,
2022-04-25 03:41:42 +00:00
pRsp->connKey.connType);
2022-01-25 10:29:26 +00:00
return TSDB_CODE_SUCCESS;
}
2022-04-12 11:10:52 +00:00
if (pRsp->query) {
STscObj *pTscObj = (STscObj *)acquireTscObj(pRsp->connKey.tscRid);
if (NULL == pTscObj) {
tscDebug("tscObj rid %" PRIx64 " not exist", pRsp->connKey.tscRid);
2022-05-24 13:34:18 +00:00
} else {
2022-05-24 13:22:03 +00:00
if (pRsp->query->totalDnodes > 1 && !isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &pRsp->query->epSet)) {
2022-06-10 09:07:24 +00:00
SEpSet* pOrig = &pTscObj->pAppInfo->mgmtEp.epSet;
SEp* pOrigEp = &pOrig->eps[pOrig->inUse];
SEp* pNewEp = &pRsp->query->epSet.eps[pRsp->query->epSet.inUse];
tscDebug("mnode epset updated from %d/%d=>%s:%d to %d/%d=>%s:%d in hb",
pOrig->inUse, pOrig->numOfEps, pOrigEp->fqdn, pOrigEp->port,
pRsp->query->epSet.inUse, pRsp->query->epSet.numOfEps, pNewEp->fqdn, pNewEp->port);
2022-05-24 13:22:03 +00:00
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
}
2022-06-24 07:18:40 +00:00
pTscObj->pAppInfo->totalDnodes = pRsp->query->totalDnodes;
pTscObj->pAppInfo->onlineDnodes = pRsp->query->onlineDnodes;
2022-04-12 11:10:52 +00:00
pTscObj->connId = pRsp->query->connId;
2022-04-25 03:41:42 +00:00
2022-04-12 11:10:52 +00:00
if (pRsp->query->killRid) {
2022-06-16 13:06:04 +00:00
tscDebug("request rid %" PRIx64 " need to be killed now", pRsp->query->killRid);
2022-04-12 11:10:52 +00:00
SRequestObj *pRequest = acquireRequest(pRsp->query->killRid);
if (NULL == pRequest) {
tscDebug("request 0x%" PRIx64 " not exist to kill", pRsp->query->killRid);
} else {
taos_stop_query((TAOS_RES *)pRequest);
releaseRequest(pRsp->query->killRid);
}
}
2022-04-25 03:41:42 +00:00
2022-04-12 11:10:52 +00:00
if (pRsp->query->killConnection) {
taos_close_internal(pTscObj);
2022-04-12 11:10:52 +00:00
}
2022-05-31 06:03:47 +00:00
if (pRsp->query->pQnodeList) {
updateQnodeList(pTscObj->pAppInfo, pRsp->query->pQnodeList);
}
2022-04-12 11:10:52 +00:00
releaseTscObj(pRsp->connKey.tscRid);
}
}
2022-04-25 03:41:42 +00:00
2022-01-25 10:29:26 +00:00
int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0;
2022-01-26 09:42:31 +00:00
tscDebug("hb got %d rsp kv", kvNum);
2022-03-01 09:49:14 +00:00
2022-01-25 10:29:26 +00:00
for (int32_t i = 0; i < kvNum; ++i) {
SKv *kv = taosArrayGet(pRsp->info, i);
switch (kv->key) {
2022-05-06 06:13:56 +00:00
case HEARTBEAT_KEY_USER_AUTHINFO: {
if (kv->valueLen <= 0 || NULL == kv->value) {
tscError("invalid hb user auth info, len:%d, value:%p", kv->valueLen, kv->value);
break;
}
struct SCatalog *pCatalog = NULL;
2022-06-04 14:33:30 +00:00
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
2022-05-06 06:13:56 +00:00
if (code != TSDB_CODE_SUCCESS) {
2022-06-04 14:33:30 +00:00
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
2022-05-06 06:13:56 +00:00
break;
}
hbProcessUserAuthInfoRsp(kv->value, kv->valueLen, pCatalog);
break;
}
2022-01-26 00:50:32 +00:00
case HEARTBEAT_KEY_DBINFO: {
if (kv->valueLen <= 0 || NULL == kv->value) {
tscError("invalid hb db info, len:%d, value:%p", kv->valueLen, kv->value);
break;
}
struct SCatalog *pCatalog = NULL;
2022-03-01 09:49:14 +00:00
2022-06-04 14:33:30 +00:00
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
2022-01-26 00:50:32 +00:00
if (code != TSDB_CODE_SUCCESS) {
2022-06-04 14:33:30 +00:00
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
2022-01-26 00:50:32 +00:00
break;
}
hbProcessDBInfoRsp(kv->value, kv->valueLen, pCatalog);
2022-01-25 10:29:26 +00:00
break;
2022-01-26 00:50:32 +00:00
}
2022-03-01 09:49:14 +00:00
case HEARTBEAT_KEY_STBINFO: {
2022-02-06 07:37:16 +00:00
if (kv->valueLen <= 0 || NULL == kv->value) {
tscError("invalid hb stb info, len:%d, value:%p", kv->valueLen, kv->value);
break;
}
2022-01-25 10:29:26 +00:00
2022-02-06 07:37:16 +00:00
struct SCatalog *pCatalog = NULL;
2022-03-01 09:49:14 +00:00
2022-06-04 14:33:30 +00:00
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
2022-02-06 07:37:16 +00:00
if (code != TSDB_CODE_SUCCESS) {
2022-06-04 14:33:30 +00:00
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
2022-02-06 07:37:16 +00:00
break;
}
hbProcessStbInfoRsp(kv->value, kv->valueLen, pCatalog);
2022-01-25 10:29:26 +00:00
break;
2022-02-06 07:37:16 +00:00
}
2022-01-25 10:29:26 +00:00
default:
tscError("invalid hb key type:%d", kv->key);
break;
}
}
return TSDB_CODE_SUCCESS;
}
2022-06-29 09:15:08 +00:00
static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
2022-01-26 09:42:31 +00:00
static int32_t emptyRspNum = 0;
2022-03-01 09:49:14 +00:00
char *key = (char *)param;
2022-01-26 00:50:32 +00:00
SClientHbBatchRsp pRsp = {0};
2022-07-10 05:58:30 +00:00
if (TSDB_CODE_SUCCESS == code) {
tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp);
}
2022-01-26 09:42:31 +00:00
int32_t rspNum = taosArrayGetSize(pRsp.rsps);
2022-01-25 10:29:26 +00:00
2022-06-28 01:28:50 +00:00
taosThreadMutexLock(&appInfo.mutex);
2022-03-01 09:49:14 +00:00
SAppInstInfo **pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
2022-01-25 10:29:26 +00:00
if (pInst == NULL || NULL == *pInst) {
2022-06-28 01:28:50 +00:00
taosThreadMutexUnlock(&appInfo.mutex);
2022-03-01 09:49:14 +00:00
tscError("cluster not exist, key:%s", key);
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(param);
2022-01-26 09:42:31 +00:00
tFreeClientHbBatchRsp(&pRsp);
2022-01-25 10:29:26 +00:00
return -1;
}
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(param);
2022-01-26 09:42:31 +00:00
2022-07-08 09:51:03 +00:00
if (code != 0) {
(*pInst)->onlineDnodes = 0;
}
2022-01-26 09:42:31 +00:00
if (rspNum) {
2022-03-01 09:49:14 +00:00
tscDebug("hb got %d rsp, %d empty rsp received before", rspNum,
atomic_val_compare_exchange_32(&emptyRspNum, emptyRspNum, 0));
2022-01-26 09:42:31 +00:00
} else {
atomic_add_fetch_32(&emptyRspNum, 1);
}
for (int32_t i = 0; i < rspNum; ++i) {
2022-03-01 09:49:14 +00:00
SClientHbRsp *rsp = taosArrayGet(pRsp.rsps, i);
2022-04-14 11:54:59 +00:00
code = (*clientHbMgr.rspHandle[rsp->connKey.connType])((*pInst)->pAppHbMgr, rsp);
2022-01-25 10:29:26 +00:00
if (code) {
break;
}
}
2022-01-26 09:42:31 +00:00
2022-06-28 01:28:50 +00:00
taosThreadMutexUnlock(&appInfo.mutex);
2022-01-26 09:42:31 +00:00
tFreeClientHbBatchRsp(&pRsp);
2022-03-01 09:49:14 +00:00
2022-01-25 10:29:26 +00:00
return code;
2022-01-14 02:48:05 +00:00
}
2022-04-12 11:10:52 +00:00
int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
2022-04-25 03:41:42 +00:00
int64_t now = taosGetTimestampUs();
2022-04-12 11:10:52 +00:00
SQueryDesc desc = {0};
2022-04-25 03:41:42 +00:00
int32_t code = 0;
2022-04-12 11:10:52 +00:00
2022-04-25 03:41:42 +00:00
void *pIter = taosHashIterate(pObj->pRequests, NULL);
2022-04-12 11:10:52 +00:00
while (pIter != NULL) {
2022-04-25 03:41:42 +00:00
int64_t *rid = pIter;
2022-04-12 11:10:52 +00:00
SRequestObj *pRequest = acquireRequest(*rid);
2022-06-16 13:06:04 +00:00
if (NULL == pRequest || pRequest->killed) {
2022-05-20 07:37:39 +00:00
pIter = taosHashIterate(pObj->pRequests, pIter);
2022-04-12 11:10:52 +00:00
continue;
}
tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql));
desc.stime = pRequest->metric.start / 1000;
2022-04-25 03:41:42 +00:00
desc.queryId = pRequest->requestId;
2022-04-12 11:10:52 +00:00
desc.useconds = now - pRequest->metric.start;
2022-04-25 03:41:42 +00:00
desc.reqRid = pRequest->self;
desc.stableQuery = pRequest->stableQuery;
2022-04-12 11:10:52 +00:00
taosGetFqdn(desc.fqdn);
2022-06-26 07:13:22 +00:00
desc.subPlanNum = pRequest->body.subplanNum;
2022-04-12 11:10:52 +00:00
if (desc.subPlanNum) {
desc.subDesc = taosArrayInit(desc.subPlanNum, sizeof(SQuerySubDesc));
if (NULL == desc.subDesc) {
releaseRequest(*rid);
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
code = schedulerGetTasksStatus(pRequest->body.queryJob, desc.subDesc);
if (code) {
taosArrayDestroy(desc.subDesc);
desc.subDesc = NULL;
desc.subPlanNum = 0;
2022-04-12 11:10:52 +00:00
}
2022-05-22 11:41:33 +00:00
} else {
desc.subDesc = NULL;
2022-04-12 11:10:52 +00:00
}
2022-04-25 03:41:42 +00:00
releaseRequest(*rid);
2022-04-12 11:10:52 +00:00
taosArrayPush(hbBasic->queryDesc, &desc);
2022-04-25 03:41:42 +00:00
2022-04-12 11:10:52 +00:00
pIter = taosHashIterate(pObj->pRequests, pIter);
}
return TSDB_CODE_SUCCESS;
}
int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid);
if (NULL == pTscObj) {
tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid);
return TSDB_CODE_QRY_APP_ERROR;
}
2022-04-25 03:41:42 +00:00
2022-04-12 11:10:52 +00:00
SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic));
if (NULL == hbBasic) {
tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic));
releaseTscObj(connKey->tscRid);
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
hbBasic->connId = pTscObj->connId;
int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0;
if (numOfQueries <= 0) {
req->query = hbBasic;
releaseTscObj(connKey->tscRid);
tscDebug("no queries on connection");
return TSDB_CODE_SUCCESS;
}
2022-04-12 11:10:52 +00:00
hbBasic->queryDesc = taosArrayInit(numOfQueries, sizeof(SQueryDesc));
if (NULL == hbBasic->queryDesc) {
tscWarn("taosArrayInit %d queryDesc failed", numOfQueries);
releaseTscObj(connKey->tscRid);
taosMemoryFree(hbBasic);
return TSDB_CODE_QRY_OUT_OF_MEMORY;
}
2022-04-25 03:41:42 +00:00
2022-04-12 11:10:52 +00:00
int32_t code = hbBuildQueryDesc(hbBasic, pTscObj);
if (code) {
releaseTscObj(connKey->tscRid);
taosMemoryFree(hbBasic);
return code;
}
req->query = hbBasic;
releaseTscObj(connKey->tscRid);
return TSDB_CODE_SUCCESS;
}
2022-05-06 06:13:56 +00:00
int32_t hbGetExpiredUserInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
SUserAuthVersion *users = NULL;
uint32_t userNum = 0;
int32_t code = 0;
code = catalogGetExpiredUsers(pCatalog, &users, &userNum);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
if (userNum <= 0) {
return TSDB_CODE_SUCCESS;
}
for (int32_t i = 0; i < userNum; ++i) {
SUserAuthVersion *user = &users[i];
user->version = htonl(user->version);
}
SKv kv = {
.key = HEARTBEAT_KEY_USER_AUTHINFO,
.valueLen = sizeof(SUserAuthVersion) * userNum,
.value = users,
};
tscDebug("hb got %d expired users, valueLen:%d", userNum, kv.valueLen);
2022-05-21 13:59:04 +00:00
if (NULL == req->info) {
req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
}
2022-05-06 06:13:56 +00:00
taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
return TSDB_CODE_SUCCESS;
}
2022-01-25 10:29:26 +00:00
int32_t hbGetExpiredDBInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
SDbVgVersion *dbs = NULL;
2022-03-01 09:49:14 +00:00
uint32_t dbNum = 0;
int32_t code = 0;
2022-01-25 10:29:26 +00:00
code = catalogGetExpiredDBs(pCatalog, &dbs, &dbNum);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
2022-01-26 09:42:31 +00:00
if (dbNum <= 0) {
return TSDB_CODE_SUCCESS;
}
2022-01-25 10:29:26 +00:00
for (int32_t i = 0; i < dbNum; ++i) {
SDbVgVersion *db = &dbs[i];
db->dbId = htobe64(db->dbId);
db->vgVersion = htonl(db->vgVersion);
2022-03-05 02:54:36 +00:00
db->numOfTable = htonl(db->numOfTable);
2022-01-25 10:29:26 +00:00
}
2022-03-04 09:08:46 +00:00
SKv kv = {
.key = HEARTBEAT_KEY_DBINFO,
.valueLen = sizeof(SDbVgVersion) * dbNum,
.value = dbs,
};
2022-01-26 09:42:31 +00:00
tscDebug("hb got %d expired db, valueLen:%d", dbNum, kv.valueLen);
2022-05-21 13:59:04 +00:00
if (NULL == req->info) {
req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
}
2022-01-25 10:29:26 +00:00
taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
return TSDB_CODE_SUCCESS;
}
2022-02-06 07:37:16 +00:00
int32_t hbGetExpiredStbInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
2022-06-13 02:38:45 +00:00
SSTableVersion *stbs = NULL;
2022-03-01 09:49:14 +00:00
uint32_t stbNum = 0;
int32_t code = 0;
2022-02-06 07:37:16 +00:00
code = catalogGetExpiredSTables(pCatalog, &stbs, &stbNum);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
if (stbNum <= 0) {
return TSDB_CODE_SUCCESS;
}
for (int32_t i = 0; i < stbNum; ++i) {
2022-06-13 02:38:45 +00:00
SSTableVersion *stb = &stbs[i];
2022-02-06 07:37:16 +00:00
stb->suid = htobe64(stb->suid);
stb->sversion = htons(stb->sversion);
2022-03-01 09:49:14 +00:00
stb->tversion = htons(stb->tversion);
2022-06-13 02:38:45 +00:00
stb->smaVer = htonl(stb->smaVer);
2022-02-06 07:37:16 +00:00
}
2022-03-04 09:08:46 +00:00
SKv kv = {
.key = HEARTBEAT_KEY_STBINFO,
2022-06-13 02:38:45 +00:00
.valueLen = sizeof(SSTableVersion) * stbNum,
2022-03-04 09:08:46 +00:00
.value = stbs,
};
2022-02-06 07:37:16 +00:00
tscDebug("hb got %d expired stb, valueLen:%d", stbNum, kv.valueLen);
2022-05-21 13:59:04 +00:00
if (NULL == req->info) {
req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
}
2022-02-06 07:37:16 +00:00
taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
return TSDB_CODE_SUCCESS;
}
2022-06-15 12:59:33 +00:00
int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) {
SAppHbReq* pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId));
if (NULL != pApp) {
memcpy(&req->app, pApp, sizeof(*pApp));
} else {
memset(&req->app.summary, 0, sizeof(req->app.summary));
req->app.pid = taosGetPId();
req->app.appId = clientHbMgr.appId;
taosGetAppName(req->app.name, NULL);
}
return TSDB_CODE_SUCCESS;
}
2022-03-01 09:49:14 +00:00
int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) {
int64_t *clusterId = (int64_t *)param;
2022-01-25 10:29:26 +00:00
struct SCatalog *pCatalog = NULL;
int32_t code = catalogGetHandle(*clusterId, &pCatalog);
if (code != TSDB_CODE_SUCCESS) {
2022-03-01 09:49:14 +00:00
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", *clusterId, tstrerror(code));
2022-01-25 10:29:26 +00:00
return code;
}
2022-03-01 09:49:14 +00:00
2022-06-15 12:59:33 +00:00
hbGetAppInfo(*clusterId, req);
2022-04-12 11:10:52 +00:00
hbGetQueryBasicInfo(connKey, req);
2022-04-25 03:41:42 +00:00
2022-05-06 06:13:56 +00:00
code = hbGetExpiredUserInfo(connKey, pCatalog, req);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
2022-01-25 10:29:26 +00:00
code = hbGetExpiredDBInfo(connKey, pCatalog, req);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
2022-02-06 07:37:16 +00:00
code = hbGetExpiredStbInfo(connKey, pCatalog, req);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
2022-01-25 10:29:26 +00:00
return TSDB_CODE_SUCCESS;
}
void hbMgrInitMqHbHandle() {
2022-04-14 11:54:59 +00:00
clientHbMgr.reqHandle[CONN_TYPE__QUERY] = hbQueryHbReqHandle;
clientHbMgr.reqHandle[CONN_TYPE__TMQ] = hbMqHbReqHandle;
2022-04-14 06:42:51 +00:00
2022-04-14 11:54:59 +00:00
clientHbMgr.rspHandle[CONN_TYPE__QUERY] = hbQueryHbRspHandle;
clientHbMgr.rspHandle[CONN_TYPE__TMQ] = hbMqHbRspHandle;
2022-01-07 08:48:35 +00:00
}
2022-01-07 06:57:45 +00:00
static FORCE_INLINE void hbMgrInitHandle() {
// init all handle
2022-01-25 10:29:26 +00:00
hbMgrInitMqHbHandle();
2022-01-07 06:57:45 +00:00
}
2022-03-01 09:49:14 +00:00
SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
2022-03-25 16:29:53 +00:00
SClientHbBatchReq *pBatchReq = taosMemoryCalloc(1, sizeof(SClientHbBatchReq));
2022-01-14 07:54:07 +00:00
if (pBatchReq == NULL) {
2022-01-07 06:57:45 +00:00
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
return NULL;
}
2022-01-10 08:13:05 +00:00
int32_t connKeyCnt = atomic_load_32(&pAppHbMgr->connKeyCnt);
2022-01-14 07:54:07 +00:00
pBatchReq->reqs = taosArrayInit(connKeyCnt, sizeof(SClientHbReq));
2022-01-07 06:57:45 +00:00
2022-01-25 10:29:26 +00:00
int32_t code = 0;
2022-03-01 09:49:14 +00:00
void *pIter = taosHashIterate(pAppHbMgr->activeInfo, NULL);
2022-01-07 06:57:45 +00:00
while (pIter != NULL) {
2022-03-01 09:49:14 +00:00
SClientHbReq *pOneReq = pIter;
2022-01-25 10:29:26 +00:00
2022-05-21 13:59:04 +00:00
pOneReq = taosArrayPush(pBatchReq->reqs, pOneReq);
2022-06-04 14:33:30 +00:00
code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, &pOneReq->clusterId, pOneReq);
if (code) {
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
continue;
2022-01-25 10:29:26 +00:00
}
2022-05-20 07:37:39 +00:00
//hbClearClientHbReq(pOneReq);
2022-01-07 08:48:35 +00:00
2022-01-10 08:13:05 +00:00
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
2022-01-07 08:48:35 +00:00
}
2022-04-25 03:41:42 +00:00
// if (code) {
// taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq);
// taosMemoryFreeClear(pBatchReq);
// }
2022-01-07 06:57:45 +00:00
2022-01-14 07:54:07 +00:00
return pBatchReq;
2022-01-07 06:57:45 +00:00
}
2022-05-25 08:30:26 +00:00
void hbThreadFuncUnexpectedStopped(void) {
atomic_store_8(&clientHbMgr.threadStop, 2);
}
2022-06-15 12:59:33 +00:00
void hbMergeSummary(SAppClusterSummary* dst, SAppClusterSummary* src) {
dst->numOfInsertsReq += src->numOfInsertsReq;
dst->numOfInsertRows += src->numOfInsertRows;
dst->insertElapsedTime += src->insertElapsedTime;
dst->insertBytes += src->insertBytes;
dst->fetchBytes += src->fetchBytes;
dst->queryElapsedTime += src->queryElapsedTime;
dst->numOfSlowQueries += src->numOfSlowQueries;
dst->totalRequests += src->totalRequests;
dst->currentRequests += src->currentRequests;
}
int32_t hbGatherAppInfo(void) {
SAppHbReq req = {0};
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
if (sz > 0) {
req.pid = taosGetPId();
req.appId = clientHbMgr.appId;
taosGetAppName(req.name, NULL);
}
2022-06-16 02:24:01 +00:00
taosHashClear(clientHbMgr.appSummary);
2022-06-15 12:59:33 +00:00
for (int32_t i = 0; i < sz; ++i) {
SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i);
uint64_t clusterId = pAppHbMgr->pAppInstInfo->clusterId;
SAppHbReq* pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId));
if (NULL == pApp) {
memcpy(&req.summary, &pAppHbMgr->pAppInstInfo->summary, sizeof(req.summary));
2022-06-16 02:24:01 +00:00
req.startTime = pAppHbMgr->startTime;
2022-06-15 12:59:33 +00:00
taosHashPut(clientHbMgr.appSummary, &clusterId, sizeof(clusterId), &req, sizeof(req));
} else {
if (pAppHbMgr->startTime < pApp->startTime) {
pApp->startTime = pAppHbMgr->startTime;
}
hbMergeSummary(&pApp->summary, &pAppHbMgr->pAppInstInfo->summary);
}
}
return TSDB_CODE_SUCCESS;
}
2022-03-01 09:49:14 +00:00
static void *hbThreadFunc(void *param) {
2022-01-07 06:57:45 +00:00
setThreadName("hb");
2022-05-25 11:29:34 +00:00
#ifdef WINDOWS
2022-06-16 07:46:51 +00:00
if (taosCheckCurrentInDll()) {
atexit(hbThreadFuncUnexpectedStopped);
}
2022-05-25 11:29:34 +00:00
#endif
2022-01-07 06:57:45 +00:00
while (1) {
int8_t threadStop = atomic_val_compare_exchange_8(&clientHbMgr.threadStop, 1, 2);
2022-03-01 09:49:14 +00:00
if (1 == threadStop) {
2022-01-07 08:48:35 +00:00
break;
}
2022-03-19 16:47:45 +00:00
taosThreadMutexLock(&clientHbMgr.lock);
2022-01-10 08:13:05 +00:00
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
2022-06-15 12:59:33 +00:00
if (sz > 0) {
hbGatherAppInfo();
}
2022-03-01 09:49:14 +00:00
for (int i = 0; i < sz; i++) {
SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i);
2022-01-14 09:30:57 +00:00
2022-01-14 08:45:15 +00:00
int32_t connCnt = atomic_load_32(&pAppHbMgr->connKeyCnt);
if (connCnt == 0) {
continue;
}
2022-03-01 09:49:14 +00:00
SClientHbBatchReq *pReq = hbGatherAllInfo(pAppHbMgr);
2022-01-14 08:45:15 +00:00
if (pReq == NULL) {
continue;
}
2022-03-01 09:49:14 +00:00
int tlen = tSerializeSClientHbBatchReq(NULL, 0, pReq);
2022-03-25 16:29:53 +00:00
void *buf = taosMemoryMalloc(tlen);
2022-01-14 02:48:05 +00:00
if (buf == NULL) {
2022-01-25 10:29:26 +00:00
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
2022-05-21 13:59:04 +00:00
tFreeClientHbBatchReq(pReq);
//hbClearReqInfo(pAppHbMgr);
2022-01-14 02:48:05 +00:00
break;
}
2022-03-01 09:49:14 +00:00
2022-02-14 07:27:38 +00:00
tSerializeSClientHbBatchReq(buf, tlen, pReq);
2022-03-25 16:29:53 +00:00
SMsgSendInfo *pInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
2022-01-14 09:30:57 +00:00
if (pInfo == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
2022-05-21 13:59:04 +00:00
tFreeClientHbBatchReq(pReq);
//hbClearReqInfo(pAppHbMgr);
2022-03-25 16:29:53 +00:00
taosMemoryFree(buf);
2022-01-14 09:30:57 +00:00
break;
}
2022-03-04 09:08:46 +00:00
pInfo->fp = hbAsyncCallBack;
2022-01-14 09:30:57 +00:00
pInfo->msgInfo.pData = buf;
pInfo->msgInfo.len = tlen;
pInfo->msgType = TDMT_MND_HEARTBEAT;
2022-01-25 10:29:26 +00:00
pInfo->param = strdup(pAppHbMgr->key);
2022-01-14 09:30:57 +00:00
pInfo->requestId = generateRequestId();
pInfo->requestObjRefId = 0;
2022-01-14 02:48:05 +00:00
SAppInstInfo *pAppInstInfo = pAppHbMgr->pAppInstInfo;
2022-03-01 09:49:14 +00:00
int64_t transporterId = 0;
SEpSet epSet = getEpSet_s(&pAppInstInfo->mgmtEp);
2022-01-14 09:30:57 +00:00
asyncSendMsgToServer(pAppInstInfo->pTransporter, &epSet, &transporterId, pInfo);
2022-05-21 13:59:04 +00:00
tFreeClientHbBatchReq(pReq);
//hbClearReqInfo(pAppHbMgr);
2022-01-10 08:13:05 +00:00
atomic_add_fetch_32(&pAppHbMgr->reportCnt, 1);
}
2022-03-19 16:47:45 +00:00
taosThreadMutexUnlock(&clientHbMgr.lock);
2022-03-01 09:49:14 +00:00
2022-01-14 02:48:05 +00:00
taosMsleep(HEARTBEAT_INTERVAL);
2022-01-07 06:57:45 +00:00
}
return NULL;
}
static int32_t hbCreateThread() {
2022-03-19 16:47:45 +00:00
TdThreadAttr thAttr;
taosThreadAttrInit(&thAttr);
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
2022-01-07 06:57:45 +00:00
2022-04-11 06:15:09 +00:00
if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
2022-04-14 06:42:51 +00:00
}
2022-04-11 06:15:09 +00:00
taosThreadAttrDestroy(&thAttr);
2022-01-07 06:57:45 +00:00
return 0;
}
2022-01-07 08:48:35 +00:00
static void hbStopThread() {
2022-05-20 12:45:53 +00:00
if (0 == atomic_load_8(&clientHbMgr.inited)) {
return;
}
if (atomic_val_compare_exchange_8(&clientHbMgr.threadStop, 0, 1)) {
2022-01-27 02:57:12 +00:00
tscDebug("hb thread already stopped");
return;
}
2022-03-01 09:49:14 +00:00
while (2 != atomic_load_8(&clientHbMgr.threadStop)) {
2022-03-10 03:56:11 +00:00
taosUsleep(10);
}
2022-01-27 02:57:12 +00:00
2022-03-01 09:49:14 +00:00
tscDebug("hb thread stopped");
2022-01-07 08:48:35 +00:00
}
2022-03-01 09:49:14 +00:00
SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
2022-01-14 02:48:05 +00:00
hbMgrInit();
2022-03-25 16:29:53 +00:00
SAppHbMgr *pAppHbMgr = taosMemoryMalloc(sizeof(SAppHbMgr));
2022-01-10 08:13:05 +00:00
if (pAppHbMgr == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
// init stat
pAppHbMgr->startTime = taosGetTimestampMs();
2022-01-18 08:24:54 +00:00
pAppHbMgr->connKeyCnt = 0;
pAppHbMgr->reportCnt = 0;
pAppHbMgr->reportBytes = 0;
2022-01-25 10:29:26 +00:00
pAppHbMgr->key = strdup(key);
2022-01-10 08:13:05 +00:00
2022-01-14 02:48:05 +00:00
// init app info
pAppHbMgr->pAppInstInfo = pAppInstInfo;
2022-01-10 08:13:05 +00:00
// init hash info
pAppHbMgr->activeInfo = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
2022-01-14 08:45:15 +00:00
if (pAppHbMgr->activeInfo == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
2022-03-25 16:29:53 +00:00
taosMemoryFree(pAppHbMgr);
2022-01-14 08:45:15 +00:00
return NULL;
}
2022-03-01 09:31:05 +00:00
2022-06-13 06:54:38 +00:00
// taosHashSetFreeFp(pAppHbMgr->activeInfo, tFreeClientHbReq);
2022-01-14 08:45:15 +00:00
2022-03-19 16:47:45 +00:00
taosThreadMutexLock(&clientHbMgr.lock);
2022-01-10 08:13:05 +00:00
taosArrayPush(clientHbMgr.appHbMgrs, &pAppHbMgr);
2022-03-19 16:47:45 +00:00
taosThreadMutexUnlock(&clientHbMgr.lock);
2022-03-01 09:49:14 +00:00
2022-01-10 08:13:05 +00:00
return pAppHbMgr;
}
2022-06-27 05:33:29 +00:00
void hbFreeAppHbMgr(SAppHbMgr *pTarget) {
void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
while (pIter != NULL) {
SClientHbReq *pOneReq = pIter;
tFreeClientHbReq(pOneReq);
pIter = taosHashIterate(pTarget->activeInfo, pIter);
}
taosHashCleanup(pTarget->activeInfo);
pTarget->activeInfo = NULL;
taosMemoryFree(pTarget->key);
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);
}
2022-01-27 09:32:45 +00:00
void appHbMgrCleanup(void) {
2022-01-10 08:13:05 +00:00
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
for (int i = 0; i < sz; i++) {
2022-03-01 09:49:14 +00:00
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
2022-06-27 05:33:29 +00:00
hbFreeAppHbMgr(pTarget);
2022-01-10 08:13:05 +00:00
}
}
int hbMgrInit() {
2022-01-07 06:57:45 +00:00
// init once
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 0, 1);
if (old == 1) return 0;
2022-06-15 12:59:33 +00:00
clientHbMgr.appId = tGenIdPI64();
tscDebug("app %" PRIx64 " initialized", clientHbMgr.appId);
clientHbMgr.appSummary = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
2022-03-01 09:49:14 +00:00
clientHbMgr.appHbMgrs = taosArrayInit(0, sizeof(void *));
2022-03-19 16:47:45 +00:00
taosThreadMutexInit(&clientHbMgr.lock, NULL);
2022-01-07 06:57:45 +00:00
// init handle funcs
hbMgrInitHandle();
// init backgroud thread
2022-05-20 07:37:39 +00:00
hbCreateThread();
2022-01-07 08:48:35 +00:00
2022-01-07 06:57:45 +00:00
return 0;
}
void hbMgrCleanUp() {
2022-05-20 07:37:39 +00:00
hbStopThread();
2022-03-01 09:49:14 +00:00
2022-01-10 08:13:05 +00:00
// destroy all appHbMgr
2022-01-07 06:57:45 +00:00
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
if (old == 0) return;
2022-03-19 16:47:45 +00:00
taosThreadMutexLock(&clientHbMgr.lock);
2022-01-27 09:32:45 +00:00
appHbMgrCleanup();
2022-03-01 09:49:14 +00:00
taosArrayDestroy(clientHbMgr.appHbMgrs);
2022-03-19 16:47:45 +00:00
taosThreadMutexUnlock(&clientHbMgr.lock);
2022-03-01 09:49:14 +00:00
clientHbMgr.appHbMgrs = NULL;
2022-01-07 06:57:45 +00:00
}
2022-06-04 14:33:30 +00:00
int hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, int64_t clusterId) {
2022-01-07 06:57:45 +00:00
// init hash in activeinfo
2022-03-01 09:49:14 +00:00
void *data = taosHashGet(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
2022-01-07 06:57:45 +00:00
if (data != NULL) {
return 0;
}
2022-04-12 11:10:52 +00:00
SClientHbReq hbReq = {0};
2022-01-07 06:57:45 +00:00
hbReq.connKey = connKey;
2022-06-04 14:33:30 +00:00
hbReq.clusterId = clusterId;
2022-05-21 13:59:04 +00:00
//hbReq.info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
2022-03-01 09:49:14 +00:00
2022-01-10 08:13:05 +00:00
taosHashPut(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey), &hbReq, sizeof(SClientHbReq));
2022-03-01 09:49:14 +00:00
2022-01-10 08:13:05 +00:00
atomic_add_fetch_32(&pAppHbMgr->connKeyCnt, 1);
2022-01-07 06:57:45 +00:00
return 0;
}
2022-04-14 11:54:59 +00:00
int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType) {
2022-03-04 09:08:46 +00:00
SClientHbKey connKey = {
2022-04-12 11:10:52 +00:00
.tscRid = tscRefId,
2022-04-14 11:54:59 +00:00
.connType = connType,
2022-03-04 09:08:46 +00:00
};
2022-01-25 10:29:26 +00:00
2022-04-14 11:54:59 +00:00
switch (connType) {
case CONN_TYPE__QUERY: {
2022-06-04 14:33:30 +00:00
return hbRegisterConnImpl(pAppHbMgr, connKey, clusterId);
2022-01-25 10:29:26 +00:00
}
2022-04-14 11:54:59 +00:00
case CONN_TYPE__TMQ: {
2022-04-14 06:42:51 +00:00
return 0;
2022-01-25 10:29:26 +00:00
}
default:
2022-04-14 06:42:51 +00:00
return 0;
2022-01-25 10:29:26 +00:00
}
}
2022-03-01 09:49:14 +00:00
void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) {
2022-04-19 06:18:58 +00:00
SClientHbReq *pReq = taosHashGet(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
if (pReq) {
2022-05-21 13:59:04 +00:00
tFreeClientHbReq(pReq);
2022-04-19 06:18:58 +00:00
taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
}
2022-06-04 14:33:30 +00:00
if (NULL == pReq) {
2022-01-27 05:29:53 +00:00
return;
}
2022-04-25 03:41:42 +00:00
2022-01-10 08:13:05 +00:00
atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
2022-01-07 06:57:45 +00:00
}