diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index fb97d6f3802689a7c6cbe1cf09f12e07629eaf1c..a159e98ed5e9efb086608e7e1b3965bb714eb292 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -67,8 +67,11 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { SAcctObj *pAcct = mnodeGetAcct(pDb->acct); pthread_mutex_init(&pDb->mutex, NULL); + pthread_mutex_lock(&pDb->mutex); pDb->vgListSize = VG_LIST_SIZE; pDb->vgList = calloc(pDb->vgListSize, sizeof(SVgObj *)); + pthread_mutex_unlock(&pDb->mutex); + pDb->numOfVgroups = 0; pDb->numOfTables = 0; pDb->numOfSuperTables = 0; @@ -395,8 +398,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { - mnodeDestroyDb(pDb); mLInfo("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code)); + mnodeDestroyDb(pDb); return code; } else { return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -605,7 +608,9 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn static char *mnodeGetDbStr(char *src) { char *pos = strstr(src, TS_PATH_DELIMITER); - return ++pos; + if (pos != NULL) ++pos; + + return pos; } static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn) { @@ -622,10 +627,13 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char* name = mnodeGetDbStr(pDb->name); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); + if (name != NULL) { + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); + } else { + STR_TO_VARSTR(pWrite, "NULL"); + } cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 42ded7ed067e0f81a0927a4954069dd73c5e16ff..dee82f53be8eb158d011cdfb994aba2b959234bc 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -453,7 +453,7 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { keySize = strlen((char *)key); } - taosHashPut(pTable->iHandle, key, keySize, &pOper->pObj, sizeof(void **)); + taosHashPut(pTable->iHandle, key, keySize, &pOper->pObj, sizeof(int64_t)); sdbIncRef(pTable, pOper->pObj); atomic_add_fetch_32(&pTable->numOfRows, 1); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 1de591df7cd627e1b6b33a28d5174024e1d55875..46255a6c8f96be2b2bd3ab642e54bd0013b12958 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -434,15 +434,22 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi } if (pDb->numOfVgroups < maxVgroupsPerDb) { - mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle, pMsg, - pDb->name, pDb->numOfVgroups, maxVgroupsPerDb); + mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle, + pMsg, pDb->name, pDb->numOfVgroups, maxVgroupsPerDb); pthread_mutex_unlock(&pDb->mutex); int32_t code = mnodeCreateVgroup(pMsg); - if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return code; + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { + return code; + } else { + pthread_mutex_lock(&pDb->mutex); + } } SVgObj *pVgroup = pDb->vgList[0]; - if (pVgroup == NULL) return TSDB_CODE_MND_NO_ENOUGH_DNODES; + if (pVgroup == NULL) { + pthread_mutex_unlock(&pDb->mutex); + return TSDB_CODE_MND_NO_ENOUGH_DNODES; + } int32_t code = mnodeAllocVgroupIdPool(pVgroup); if (code != TSDB_CODE_SUCCESS) { @@ -483,7 +490,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { } else { pVgroup->status = TAOS_VG_STATUS_READY; SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; - sdbUpdateRow(&desc); + (void)sdbUpdateRow(&desc); } mInfo("app:%p:%p, vgId:%d, is created in mnode, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, diff --git a/src/plugins/http/src/gcJson.c b/src/plugins/http/src/gcJson.c index 544a11b5fc925c8c948e26f182e5d1cbd8b1e4c3..94d53db6ef0200265aa67710794c60f1fec0cfac 100644 --- a/src/plugins/http/src/gcJson.c +++ b/src/plugins/http/src/gcJson.c @@ -121,6 +121,10 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, for (int k = 0; k < numOfRows; ++k) { TAOS_ROW row = taos_fetch_row(result); + if (row == NULL) { + cmd->numOfRows--; + continue; + } int32_t* length = taos_fetch_lengths(result); // for group by diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index cefcca78215da2267001099aa7f728527f481ffa..225977abae698ccfeb12c36562d5588a3f166027 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -108,7 +108,7 @@ HttpContext *httpCreateContext(int32_t fd) { pContext->lastAccessTime = taosGetTimestampSec(); pContext->state = HTTP_CONTEXT_STATE_READY; - HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(void *), &pContext, sizeof(void *), 3); + HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(int64_t), &pContext, sizeof(int64_t), 3); pContext->ppContext = ppContext; httpDebug("context:%p, fd:%d, is created, data:%p", pContext, fd, ppContext); diff --git a/src/plugins/http/src/restJson.c b/src/plugins/http/src/restJson.c index 53b0248149d3f72a35d99dc9757fcb36c085a857..7a73f6559f21427d04d37289338d73ec64306dc0 100644 --- a/src/plugins/http/src/restJson.c +++ b/src/plugins/http/src/restJson.c @@ -94,6 +94,10 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, for (int k = 0; k < numOfRows; ++k) { TAOS_ROW row = taos_fetch_row(result); + if (row == NULL) { + cmd->numOfRows--; + continue; + } int32_t* length = taos_fetch_lengths(result); // data row array begin diff --git a/src/plugins/mqtt/src/mqttSystem.c b/src/plugins/mqtt/src/mqttSystem.c index 2687106124497607a50c8b1435497cd2c467722a..0259ea23eb66239b1e7fbfcb6d0243a16dabb32f 100644 --- a/src/plugins/mqtt/src/mqttSystem.c +++ b/src/plugins/mqtt/src/mqttSystem.c @@ -64,7 +64,7 @@ int32_t mqttInitSystem() { } char* _begin_hostname = strstr(url, recntStatus.hostname); - if (strstr(_begin_hostname, ":") != NULL) { + if (_begin_hostname != NULL && strstr(_begin_hostname, ":") != NULL) { recntStatus.port = strbetween(_begin_hostname, ":", "/"); } else { recntStatus.port = strbetween("'1883'", "'", "'");