enh:[TD-31088] Bug fix.

This commit is contained in:
sima 2024-07-25 11:12:27 +08:00
parent a1c323b690
commit d350adf69b
4 changed files with 32 additions and 37 deletions

View File

@ -482,7 +482,7 @@ int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t
(*pObj)->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
if (NULL == (*pObj)->pRequests) {
taosMemoryFree(*pObj);
return TSDB_CODE_OUT_OF_MEMORY;
return terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
}
(*pObj)->connType = connType;
@ -495,10 +495,9 @@ int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t
tstrncpy((*pObj)->db, db, tListLen((*pObj)->db));
}
int32_t code = taosThreadMutexInit(&(*pObj)->mutex, NULL);
if (TSDB_CODE_SUCCESS != code) {
return TAOS_SYSTEM_ERROR(code);
}
TSC_ERR_RET(taosThreadMutexInit(&(*pObj)->mutex, NULL));
int32_t code = TSDB_CODE_SUCCESS;
(*pObj)->id = taosAddRef(clientConnRefPool, *pObj);
if ((*pObj)->id < 0) {

View File

@ -570,10 +570,9 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
int32_t idx = *(int32_t *)param;
SClientHbBatchRsp pRsp = {0};
if (TSDB_CODE_SUCCESS == code) {
if (TSDB_CODE_SUCCESS != tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp)) {
code = terrno;
code = tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp);
if (TSDB_CODE_SUCCESS != code) {
tscError("deserialize hb rsp failed");
goto _return;
}
int32_t now = taosGetTimestampSec();
int32_t delta = abs(now - pRsp.svrTimestamp);
@ -585,25 +584,27 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
int32_t rspNum = taosArrayGetSize(pRsp.rsps);
code = taosThreadMutexLock(&clientHbMgr.lock);
if (TSDB_CODE_SUCCESS != code) {
tscError("lock failed");
code = TAOS_SYSTEM_ERROR(code);
goto _return;
}
(void)taosThreadMutexLock(&clientHbMgr.lock);
SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, idx);
if (pAppHbMgr == NULL) {
(void)taosThreadMutexUnlock(&clientHbMgr.lock);
tscError("appHbMgr not exist, idx:%d", idx);
code = TSDB_CODE_OUT_OF_RANGE;
goto _returnunlock;
taosMemoryFree(pMsg->pData);
taosMemoryFree(pMsg->pEpSet);
tFreeClientHbBatchRsp(&pRsp);
return TSDB_CODE_OUT_OF_RANGE;
}
SAppInstInfo *pInst = pAppHbMgr->pAppInstInfo;
if (code != 0) {
pInst->onlineDnodes = pInst->totalDnodes ? 0 : -1;
tscDebug("hb rsp error %s, update server status %d/%d", tstrerror(code), pInst->onlineDnodes, pInst->totalDnodes);
goto _returnunlock;
(void)taosThreadMutexUnlock(&clientHbMgr.lock);
taosMemoryFree(pMsg->pData);
taosMemoryFree(pMsg->pEpSet);
tFreeClientHbBatchRsp(&pRsp);
return code;
}
pInst->monitorParas = pRsp.monitorParas;
@ -619,25 +620,17 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
for (int32_t i = 0; i < rspNum; ++i) {
SClientHbRsp *rsp = taosArrayGet(pRsp.rsps, i);
if (NULL == rsp) {
tscError("invalid hb rsp, idx:%d", i);
break;
}
code = (*clientHbMgr.rspHandle[rsp->connKey.connType])(pAppHbMgr, rsp);
if (code) {
break;
}
}
_returnunlock:
code = taosThreadMutexUnlock(&clientHbMgr.lock);
if (TSDB_CODE_SUCCESS != code) {
tscError("unlock failed");
code = TAOS_SYSTEM_ERROR(code);
}
(void)taosThreadMutexUnlock(&clientHbMgr.lock);
tFreeClientHbBatchRsp(&pRsp);
_return:
tFreeClientHbBatchRsp(&pRsp);
taosMemoryFree(pMsg->pData);
taosMemoryFree(pMsg->pEpSet);
return code;
@ -1111,12 +1104,14 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
tscWarn("hbGetExpiredUserInfo failed, clusterId:%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
return code;
}
if (clientHbMgr.appHbHash) {
code = taosHashPut(clientHbMgr.appHbHash, &hbParam->clusterId, sizeof(uint64_t), NULL, 0);
if (TSDB_CODE_SUCCESS != code) {
tscWarn("hbQueryHbReqHandle put clusterId failed, clusterId:%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
return code;
}
}
}
// invoke after hbGetExpiredUserInfo
if (2 != atomic_load_8(&hbParam->pAppHbMgr->connHbFlag)) {
@ -1308,7 +1303,7 @@ static void *hbThreadFunc(void *param) {
}
if (sz > 1 && !clientHbMgr.appHbHash) {
clientHbMgr.appHbHash =
taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK);
taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_NO_LOCK);
if (NULL == clientHbMgr.appHbHash) {
tscError("taosHashInit failed");
return NULL;
@ -1527,7 +1522,7 @@ int32_t hbMgrInit() {
clientHbMgr.appId = tGenIdPI64();
tscDebug("app %" PRIx64 " initialized", clientHbMgr.appId);
clientHbMgr.appSummary = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
clientHbMgr.appSummary = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
if (NULL == clientHbMgr.appSummary) {
uError("hbMgrInit:taosHashInit error") return terrno;
}

View File

@ -1569,15 +1569,16 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta
const char* errorMsg = (code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code);
tscError("failed to connect to server, reason: %s", errorMsg);
terrno = pRequest->code;
destroyRequest(pRequest);
taos_close_internal(*pTscObj);
*pTscObj = NULL;
return terrno;
} else {
tscDebug("0x%" PRIx64 " connection is opening, connId:%u, dnodeConn:%p, reqId:0x%" PRIx64, (*pTscObj)->id,
(*pTscObj)->connId, (*pTscObj)->pAppInfo->pTransporter, pRequest->requestId);
destroyRequest(pRequest);
}
return code;
}

View File

@ -897,7 +897,7 @@ int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
}
int code = TSDB_CODE_SUCCESS;
TSC_ERR_JRET(taosThreadMutexLock(&pTscObj->mutex));
(void)taosThreadMutexLock(&pTscObj->mutex);
if (database == NULL || len <= 0) {
if (required != NULL) *required = strlen(pTscObj->db) + 1;
TSC_ERR_JRET(TSDB_CODE_INVALID_PARA);
@ -910,7 +910,7 @@ int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
code = 0;
}
_return:
code = taosThreadMutexUnlock(&pTscObj->mutex);
(void)taosThreadMutexUnlock(&pTscObj->mutex);
releaseTscObj(*(int64_t *)taos);
return code;
}