fix: timeseries statistics and test case

This commit is contained in:
kailixu 2025-02-14 16:53:32 +08:00
parent 217fec4496
commit 6885b942b1
3 changed files with 51 additions and 34 deletions

View File

@ -402,6 +402,7 @@ int32_t metaStatsCacheUpsert(SMeta* pMeta, SMetaStbStats* pInfo) {
if (*ppEntry) { // update if (*ppEntry) { // update
(*ppEntry)->info.ctbNum = pInfo->ctbNum; (*ppEntry)->info.ctbNum = pInfo->ctbNum;
(*ppEntry)->info.colNum = pInfo->colNum;
} else { // insert } else { // insert
if (pCache->sStbStatsCache.nEntry >= pCache->sStbStatsCache.nBucket) { if (pCache->sStbStatsCache.nEntry >= pCache->sStbStatsCache.nBucket) {
TAOS_UNUSED(metaRehashStatsCache(pCache, 1)); TAOS_UNUSED(metaRehashStatsCache(pCache, 1));

View File

@ -1612,6 +1612,10 @@ static int32_t metaHandleSuperTableUpdateImpl(SMeta *pMeta, SMetaHandleParam *pP
} }
} }
if (TSDB_CODE_SUCCESS == code) {
metaUpdateStbStats(pMeta, pEntry->uid, 0, pEntry->stbEntry.schemaRow.nCols - pOldEntry->stbEntry.schemaRow.nCols);
}
return code; return code;
} }
@ -1690,7 +1694,16 @@ static int32_t metaHandleSuperTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry
tsdbCacheInvalidateSchema(pTsdb, pEntry->uid, -1, pEntry->stbEntry.schemaRow.version); tsdbCacheInvalidateSchema(pTsdb, pEntry->uid, -1, pEntry->stbEntry.schemaRow.version);
} }
metaTimeSeriesNotifyCheck(pMeta); if (updStat) {
int64_t ctbNum = 0;
int32_t ret = metaGetStbStats(pMeta->pVnode, pEntry->uid, &ctbNum, NULL);
if (ret < 0) {
metaError("vgId:%d, failed to get stb stats:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pEntry->name,
pEntry->uid, tstrerror(ret));
}
pMeta->pVnode->config.vndStats.numOfTimeSeries += (ctbNum * deltaCol);
if (deltaCol > 0) metaTimeSeriesNotifyCheck(pMeta);
}
metaFetchEntryFree(&pOldEntry); metaFetchEntryFree(&pOldEntry);
return code; return code;
} }
@ -1789,7 +1802,9 @@ static int32_t metaHandleNormalTableUpdate(SMeta *pMeta, const SMetaEntry *pEntr
#endif #endif
tsdbCacheInvalidateSchema(pMeta->pVnode->pTsdb, 0, pEntry->uid, pEntry->ntbEntry.schemaRow.version); tsdbCacheInvalidateSchema(pMeta->pVnode->pTsdb, 0, pEntry->uid, pEntry->ntbEntry.schemaRow.version);
} }
metaTimeSeriesNotifyCheck(pMeta); int32_t deltaCol = pEntry->ntbEntry.schemaRow.nCols - pOldEntry->ntbEntry.schemaRow.nCols;
pMeta->pVnode->config.vndStats.numOfNTimeSeries += deltaCol;
if (deltaCol > 0) metaTimeSeriesNotifyCheck(pMeta);
metaFetchEntryFree(&pOldEntry); metaFetchEntryFree(&pOldEntry);
return code; return code;
} }

View File

@ -176,36 +176,37 @@ class TDTestCase:
# check timeseries # check timeseries
tss_grant = 5 tss_grant = 5
self.checkGrantsTimeSeries("initial check", tss_grant) for i in range(0, 3):
tdSql.execute("create database if not exists db100") tdLog.printNoPrefix(f"======== test timeseries: loop{i}")
tdSql.execute("create table db100.stb100(ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double) tags(t0 bigint unsigned)") self.checkGrantsTimeSeries("initial check", tss_grant)
tdSql.execute("create table db100.ctb100 using db100.stb100 tags(100)") tdSql.execute("create database if not exists db100")
tdSql.execute("create table db100.ctb101 using db100.stb100 tags(101)") tdSql.execute("create table db100.stb100(ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double) tags(t0 bigint unsigned)")
tdSql.execute("create table db100.ntb100 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)") tdSql.execute("create table db100.ctb100 using db100.stb100 tags(100)")
tdSql.execute("create table db100.ntb101 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)") tdSql.execute("create table db100.ctb101 using db100.stb100 tags(101)")
tss_grant += 20 tdSql.execute("create table db100.ntb100 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)")
self.checkGrantsTimeSeries("create tables and check", tss_grant) tdSql.execute("create table db100.ntb101 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)")
tdSql.execute("alter table db100.stb100 add column c5 int") tss_grant += 20
tdSql.execute("alter stable db100.stb100 add column c6 int") self.checkGrantsTimeSeries("create tables and check", tss_grant)
tss_grant += 4 tdSql.execute("alter table db100.stb100 add column c5 int")
self.checkGrantsTimeSeries("alter table column/tag and tss_grant", tss_grant) tdSql.execute("alter stable db100.stb100 add column c6 int")
tdSql.execute("alter table db100.stb100 add tag t1 int")
# tdSql.execute("alter table db100.stb100 add tag t1 int") tss_grant += 4
# tdSql.execute("create table db100.ctb102 using db100.stb100 tags(102, 102)") self.checkGrantsTimeSeries("alter table column/tag and check", tss_grant)
# tdSql.execute("alter table db100.ctb100 set tag t0=1000") tdSql.execute("create table db100.ctb102 using db100.stb100 tags(102, 102)")
# tdSql.execute("alter table db100.ntb100 add column c5 int") tdSql.execute("alter table db100.ctb100 set tag t0=1000")
# tss_grant += 12 tdSql.execute("alter table db100.ntb100 add column c5 int")
# self.checkGrantsTimeSeries("alter table column/tag and tss_grant", tss_grant) tss_grant += 8
# tdSql.execute("drop table db100.ctb100") self.checkGrantsTimeSeries("alter table column/tag and check", tss_grant)
# tdSql.execute("drop table db100.ntb100") tdSql.execute("drop table db100.ctb100")
# tss_grant -= 13 tdSql.execute("drop table db100.ntb100")
# self.checkGrantsTimeSeries("drop ctb/ntb and check: tss_grant", tss_grant) tss_grant -= 13
# tdSql.execute("drop table db100.stb100") self.checkGrantsTimeSeries("drop ctb/ntb and check", tss_grant)
# tss_grant -= 14 tdSql.execute("drop table db100.stb100")
# self.checkGrantsTimeSeries("drop stb and check: tss_grant", tss_grant) tss_grant -= 14
# tdSql.execute("drop database db100") self.checkGrantsTimeSeries("drop stb and check", tss_grant)
# tss_grant -= 7 tdSql.execute("drop database db100")
# self.checkGrantsTimeSeries("drop database and check: tss_grant", tss_grant) tss_grant -= 5
self.checkGrantsTimeSeries("drop database and check", tss_grant)
def s2_check_show_grants_ungranted(self): def s2_check_show_grants_ungranted(self):
tdLog.printNoPrefix("======== test show grants ungranted: ") tdLog.printNoPrefix("======== test show grants ungranted: ")
@ -285,8 +286,8 @@ class TDTestCase:
# keep the order of following steps # keep the order of following steps
self.s0_five_dnode_one_mnode() self.s0_five_dnode_one_mnode()
self.s1_check_timeseries() self.s1_check_timeseries()
# self.s2_check_show_grants_ungranted() self.s2_check_show_grants_ungranted()
# self.s3_check_show_grants_granted() self.s3_check_show_grants_granted()
def stop(self): def stop(self):