From 19b559ed6f89f5d8ee7ee54e84146aeedb41f630 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 13 Sep 2021 11:46:04 +0800 Subject: [PATCH] [td-6563]refactor to improve the performance. --- src/client/inc/tscUtil.h | 2 +- src/client/src/tscSQLParser.c | 7 ++---- src/client/src/tscServer.c | 2 +- src/client/src/tscSubquery.c | 2 +- src/client/src/tscUtil.c | 45 ++++------------------------------- src/inc/taosmsg.h | 13 +--------- 6 files changed, 10 insertions(+), 61 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index da1d2b01c3..92df3cf104 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -285,7 +285,7 @@ void doExecuteQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo); SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *pInfo); void* tscVgroupInfoClear(SVgroupsInfo *pInfo); -void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src); + /** * The create object function must be successful expect for the out of memory issue. * diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 1cf178899f..ffcba14621 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -8389,11 +8389,8 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod SVgroupInfo *pVgroup = &pTableMetaInfo->vgroupList->vgroups[j]; pVgroup->numOfEps = existVgroupInfo.numOfEps; - pVgroup->vgId = existVgroupInfo.vgId; - for (int32_t k = 0; k < existVgroupInfo.numOfEps; ++k) { - pVgroup->epAddr[k].port = existVgroupInfo.ep[k].port; - pVgroup->epAddr[k].fqdn = strndup(existVgroupInfo.ep[k].fqdn, TSDB_FQDN_LEN); - } + pVgroup->vgId = existVgroupInfo.vgId; + memcpy(&pVgroup->epAddr, &existVgroupInfo.ep, sizeof(pVgroup->epAddr)); } } } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e781fc0727..a96fb854a9 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2305,7 +2305,7 @@ static SVgroupsInfo* createVgroupInfoFromMsg(char* pMsg, int32_t* size, uint64_t pVgroup->vgId = vmsg->vgId; for (int32_t k = 0; k < vmsg->numOfEps; ++k) { pVgroup->epAddr[k].port = vmsg->epAddr[k].port; - pVgroup->epAddr[k].fqdn = strndup(vmsg->epAddr[k].fqdn, TSDB_FQDN_LEN); + tstrncpy(pVgroup->epAddr[k].fqdn, vmsg->epAddr[k].fqdn, TSDB_FQDN_LEN); } doUpdateVgroupInfo(pVgroup->vgId, vmsg); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index a8cd56204e..f7a3d0e68b 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -748,7 +748,7 @@ void tscBuildVgroupTableInfo(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, SArr SVgroupTableInfo info = {{0}}; for (int32_t m = 0; m < pvg->numOfVgroups; ++m) { if (tt->vgId == pvg->vgroups[m].vgId) { - tscSVgroupInfoCopy(&info.vgInfo, &pvg->vgroups[m]); + memcpy(&info.vgInfo, &pvg->vgroups[m], sizeof(info.vgInfo)); break; } } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 5b919f2473..bb6caccb35 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -3273,11 +3273,6 @@ void tscFreeVgroupTableInfo(SArray* pVgroupTables) { size_t num = taosArrayGetSize(pVgroupTables); for (size_t i = 0; i < num; i++) { SVgroupTableInfo* pInfo = taosArrayGet(pVgroupTables, i); - - for(int32_t j = 0; j < pInfo->vgInfo.numOfEps; ++j) { - tfree(pInfo->vgInfo.epAddr[j].fqdn); - } - taosArrayDestroy(pInfo->itemList); } @@ -3291,10 +3286,6 @@ void tscRemoveVgroupTableGroup(SArray* pVgroupTable, int32_t index) { assert(size > index); SVgroupTableInfo* pInfo = taosArrayGet(pVgroupTable, index); - for(int32_t j = 0; j < pInfo->vgInfo.numOfEps; ++j) { - tfree(pInfo->vgInfo.epAddr[j].fqdn); - } - taosArrayDestroy(pInfo->itemList); taosArrayRemove(pVgroupTable, index); } @@ -3303,10 +3294,6 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo) { memset(info, 0, sizeof(SVgroupTableInfo)); info->vgInfo = pInfo->vgInfo; - for(int32_t j = 0; j < pInfo->vgInfo.numOfEps; ++j) { - info->vgInfo.epAddr[j].fqdn = strdup(pInfo->vgInfo.epAddr[j].fqdn); - } - if (pInfo->itemList) { info->itemList = taosArrayDup(pInfo->itemList); } @@ -4297,12 +4284,12 @@ SVgroupsInfo* tscVgroupInfoClone(SVgroupsInfo *vgroupList) { SVgroupInfo* pNewVInfo = &pNew->vgroups[i]; SVgroupInfo* pvInfo = &vgroupList->vgroups[i]; - pNewVInfo->vgId = pvInfo->vgId; + pNewVInfo->vgId = pvInfo->vgId; pNewVInfo->numOfEps = pvInfo->numOfEps; for(int32_t j = 0; j < pvInfo->numOfEps; ++j) { - pNewVInfo->epAddr[j].fqdn = strdup(pvInfo->epAddr[j].fqdn); - pNewVInfo->epAddr[j].port = pvInfo->epAddr[j].port; + tstrncpy(pNewVInfo->epAddr[j].fqdn, pvInfo->epAddr[j].fqdn, TSDB_FQDN_LEN); + pNewVInfo->epAddr[j].port = pvInfo->epAddr[j].port; } } @@ -4314,34 +4301,10 @@ void* tscVgroupInfoClear(SVgroupsInfo *vgroupList) { return NULL; } - for(int32_t i = 0; i < vgroupList->numOfVgroups; ++i) { - SVgroupInfo* pVgroupInfo = &vgroupList->vgroups[i]; - - for(int32_t j = 0; j < pVgroupInfo->numOfEps; ++j) { - tfree(pVgroupInfo->epAddr[j].fqdn); - } - - for(int32_t j = pVgroupInfo->numOfEps; j < TSDB_MAX_REPLICA; j++) { - assert( pVgroupInfo->epAddr[j].fqdn == NULL ); - } - } - tfree(vgroupList); return NULL; } -void tscSVgroupInfoCopy(SVgroupInfo* dst, const SVgroupInfo* src) { - dst->vgId = src->vgId; - dst->numOfEps = src->numOfEps; - for(int32_t i = 0; i < dst->numOfEps; ++i) { - tfree(dst->epAddr[i].fqdn); - dst->epAddr[i].port = src->epAddr[i].port; - assert(dst->epAddr[i].fqdn == NULL); - - dst->epAddr[i].fqdn = strdup(src->epAddr[i].fqdn); - } -} - char* serializeTagData(STagData* pTagData, char* pMsg) { int32_t n = (int32_t) strlen(pTagData->name); *(int32_t*) pMsg = htonl(n); @@ -4484,7 +4447,7 @@ SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo) { SVgroupsInfo* pInfo = calloc(1, size); pInfo->numOfVgroups = pVgroupsInfo->numOfVgroups; for (int32_t m = 0; m < pVgroupsInfo->numOfVgroups; ++m) { - tscSVgroupInfoCopy(&pInfo->vgroups[m], &pVgroupsInfo->vgroups[m]); + memcpy(&pInfo->vgroups[m], &pVgroupsInfo->vgroups[m], sizeof(SVgroupMsg)); } return pInfo; } diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index d3f441e72f..fe553112cc 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -206,11 +206,6 @@ typedef struct { uint16_t port; } SEpAddrMsg; -typedef struct { - char* fqdn; - uint16_t port; -} SEpAddr1; - typedef struct { int32_t numOfVnodes; } SMsgDesc; @@ -763,17 +758,11 @@ typedef struct SSTableVgroupMsg { int32_t numOfTables; } SSTableVgroupMsg, SSTableVgroupRspMsg; -typedef struct { - int32_t vgId; - int8_t numOfEps; - SEpAddr1 epAddr[TSDB_MAX_REPLICA]; -} SVgroupInfo; - typedef struct { int32_t vgId; int8_t numOfEps; SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; -} SVgroupMsg; +} SVgroupMsg, SVgroupInfo; typedef struct { int32_t numOfVgroups; -- GitLab