From 9e9ac674b60faa19cad20fe6c38c30c56413affd Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 29 Dec 2020 18:25:33 +0800 Subject: [PATCH] [TD-2378]: reduce table meta memory consumption. --- src/client/src/tscStream.c | 7 ++++--- src/client/src/tscSystem.c | 9 +++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 74b8e4d958..c1ed9b0ba0 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -167,7 +167,9 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf retryDelay); STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0); - taosCacheRelease(tscMetaCache, (void**)&(pTableMetaInfo->pTableMeta), true); + + char* name = pTableMetaInfo->name; + taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); pTableMetaInfo->vgroupList = tscVgroupInfoClear(pTableMetaInfo->vgroupList); tscSetRetryTimer(pStream, pStream->pSql, retryDelay); @@ -269,9 +271,8 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf tscDebug("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name, pStream->numOfRes); - // release the metric/meter meta information reference, so data in cache can be updated + tfree(pTableMetaInfo->pTableMeta); - taosCacheRelease(tscMetaCache, (void**)&(pTableMetaInfo->pTableMeta), false); tscFreeSqlResult(pSql); tfree(pSql->pSubs); pSql->subState.numOfSub = 0; diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index c213c2d11a..66e06bf766 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -31,7 +31,6 @@ #include "tlocale.h" // global, not configurable -SCacheObj *tscMetaCache; // table meta cache SHashObj *tscHashMap; // hash map to keep the global vgroup info SHashObj *tscTableMetaInfo; // table meta info int tscObjRef = -1; @@ -130,9 +129,7 @@ void taos_init_imp(void) { taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr); } - int64_t refreshTime = 10; // 10 seconds by default - if (tscMetaCache == NULL) { - tscMetaCache = taosCacheInit(TSDB_DATA_TYPE_BINARY, refreshTime, false, NULL, "tableMeta"); + if (tscTableMetaInfo == NULL) { tscObjRef = taosOpenRef(40960, tscFreeRegisteredSqlObj); tscHashMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); tscTableMetaInfo = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); @@ -154,8 +151,8 @@ void taos_init() { pthread_once(&tscinit, taos_init_imp); } void taos_cleanup(void) { tscDebug("start to cleanup client environment"); - void* m = tscMetaCache; - if (m != NULL && atomic_val_compare_exchange_ptr(&tscMetaCache, m, 0) == m) { + void* m = tscTableMetaInfo; + if (m != NULL && atomic_val_compare_exchange_ptr(&tscTableMetaInfo, m, 0) == m) { taosCacheCleanup(m); } -- GitLab