Merge pull request #28065 from taosdata/fix/3.0/TD-32278
fix ctg read tsma cache crash
This commit is contained in:
commit
3b3a0fbe62
|
@ -334,6 +334,7 @@ typedef struct SCtgViewCache {
|
||||||
typedef struct SCtgTSMACache {
|
typedef struct SCtgTSMACache {
|
||||||
SRWLatch tsmaLock;
|
SRWLatch tsmaLock;
|
||||||
SArray* pTsmas; // SArray<STSMACache*>
|
SArray* pTsmas; // SArray<STSMACache*>
|
||||||
|
bool retryFetch;
|
||||||
} SCtgTSMACache;
|
} SCtgTSMACache;
|
||||||
|
|
||||||
typedef struct SCtgDBCache {
|
typedef struct SCtgDBCache {
|
||||||
|
|
|
@ -2997,6 +2997,7 @@ int32_t ctgOpDropTbTSMA(SCtgCacheOperation *operation) {
|
||||||
|
|
||||||
taosArrayDestroyP(pCtgCache->pTsmas, tFreeAndClearTableTSMAInfo);
|
taosArrayDestroyP(pCtgCache->pTsmas, tFreeAndClearTableTSMAInfo);
|
||||||
pCtgCache->pTsmas = NULL;
|
pCtgCache->pTsmas = NULL;
|
||||||
|
pCtgCache->retryFetch = true;
|
||||||
|
|
||||||
ctgDebug("all tsmas for table dropped: %s.%s", msg->dbFName, msg->tbName);
|
ctgDebug("all tsmas for table dropped: %s.%s", msg->dbFName, msg->tbName);
|
||||||
code = taosHashRemove(dbCache->tsmaCache, msg->tbName, TSDB_TABLE_NAME_LEN);
|
code = taosHashRemove(dbCache->tsmaCache, msg->tbName, TSDB_TABLE_NAME_LEN);
|
||||||
|
@ -3975,17 +3976,25 @@ int32_t ctgGetTbTSMAFromCache(SCatalog* pCtg, SCtgTbTSMACtx* pCtx, int32_t dbIdx
|
||||||
|
|
||||||
// get tsma cache
|
// get tsma cache
|
||||||
pCache = taosHashAcquire(dbCache->tsmaCache, tsmaSourceTbName.tname, strlen(tsmaSourceTbName.tname));
|
pCache = taosHashAcquire(dbCache->tsmaCache, tsmaSourceTbName.tname, strlen(tsmaSourceTbName.tname));
|
||||||
if (!pCache || !pCache->pTsmas || pCache->pTsmas->size == 0) {
|
if (!pCache) {
|
||||||
if (NULL == taosArrayPush(pCtx->pResList, &(SMetaRes){0})) {
|
if (NULL == taosArrayPush(pCtx->pResList, &(SMetaRes){0})) {
|
||||||
ctgReleaseTSMAToCache(pCtg, dbCache, pCache);
|
ctgReleaseTSMAToCache(pCtg, dbCache, pCache);
|
||||||
CTG_ERR_RET(terrno);
|
CTG_ERR_RET(terrno);
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
CTG_LOCK(CTG_READ, &pCache->tsmaLock);
|
||||||
|
if ((!pCache->pTsmas || pCache->pTsmas->size == 0) && !pCache->retryFetch) {
|
||||||
|
if (NULL == taosArrayPush(pCtx->pResList, &(SMetaRes){0})) {
|
||||||
|
ctgReleaseTSMAToCache(pCtg, dbCache, pCache);
|
||||||
|
CTG_ERR_RET(terrno);
|
||||||
|
}
|
||||||
|
CTG_UNLOCK(CTG_READ, &pCache->tsmaLock);
|
||||||
|
taosHashRelease(dbCache->tsmaCache, pCache);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_LOCK(CTG_READ, &pCache->tsmaLock);
|
if (pCache->retryFetch || hasOutOfDateTSMACache(pCache->pTsmas)) {
|
||||||
if (hasOutOfDateTSMACache(pCache->pTsmas)) {
|
|
||||||
CTG_UNLOCK(CTG_READ, &pCache->tsmaLock);
|
CTG_UNLOCK(CTG_READ, &pCache->tsmaLock);
|
||||||
taosHashRelease(dbCache->tsmaCache, pCache);
|
taosHashRelease(dbCache->tsmaCache, pCache);
|
||||||
|
|
||||||
|
@ -3997,6 +4006,7 @@ int32_t ctgGetTbTSMAFromCache(SCatalog* pCtg, SCtgTbTSMACtx* pCtx, int32_t dbIdx
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_CACHE_NHIT_INC(CTG_CI_TBL_TSMA, 1);
|
CTG_CACHE_NHIT_INC(CTG_CI_TBL_TSMA, 1);
|
||||||
|
pCache->retryFetch = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -871,6 +871,7 @@ class TDTestCase:
|
||||||
.should_query_with_table('meters', '2018-09-17 09:00:00.200', '2018-09-17 09:29:59:999')
|
.should_query_with_table('meters', '2018-09-17 09:00:00.200', '2018-09-17 09:29:59:999')
|
||||||
.should_query_with_tsma('tsma2', '2018-09-17 09:30:00', '2018-09-17 09:59:59.999')
|
.should_query_with_tsma('tsma2', '2018-09-17 09:30:00', '2018-09-17 09:59:59.999')
|
||||||
.should_query_with_table('meters', '2018-09-17 10:00:00.000', '2018-09-17 10:23:19.800').get_qc())
|
.should_query_with_table('meters', '2018-09-17 10:00:00.000', '2018-09-17 10:23:19.800').get_qc())
|
||||||
|
tdSql.query('show create table test.meters')
|
||||||
self.check(ctxs)
|
self.check(ctxs)
|
||||||
if not ignore_some_tests:
|
if not ignore_some_tests:
|
||||||
tdSql.execute('create database db2')
|
tdSql.execute('create database db2')
|
||||||
|
|
Loading…
Reference in New Issue