diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 93347c810f..9b85ca0b45 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -402,6 +402,7 @@ int32_t metaStatsCacheUpsert(SMeta* pMeta, SMetaStbStats* pInfo) { if (*ppEntry) { // update (*ppEntry)->info.ctbNum = pInfo->ctbNum; + (*ppEntry)->info.colNum = pInfo->colNum; } else { // insert if (pCache->sStbStatsCache.nEntry >= pCache->sStbStatsCache.nBucket) { TAOS_UNUSED(metaRehashStatsCache(pCache, 1)); diff --git a/source/dnode/vnode/src/meta/metaEntry2.c b/source/dnode/vnode/src/meta/metaEntry2.c index fabed42b7b..b23059079a 100644 --- a/source/dnode/vnode/src/meta/metaEntry2.c +++ b/source/dnode/vnode/src/meta/metaEntry2.c @@ -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; } @@ -1690,7 +1694,16 @@ static int32_t metaHandleSuperTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry 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); return code; } @@ -1789,7 +1802,9 @@ static int32_t metaHandleNormalTableUpdate(SMeta *pMeta, const SMetaEntry *pEntr #endif 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); return code; } diff --git a/tests/system-test/0-others/grant.py b/tests/system-test/0-others/grant.py index 5d6770a0ae..b5fc1c1a29 100644 --- a/tests/system-test/0-others/grant.py +++ b/tests/system-test/0-others/grant.py @@ -176,36 +176,37 @@ class TDTestCase: # check timeseries tss_grant = 5 - self.checkGrantsTimeSeries("initial check", tss_grant) - tdSql.execute("create database if not exists db100") - 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.ctb100 using db100.stb100 tags(100)") - tdSql.execute("create table db100.ctb101 using db100.stb100 tags(101)") - tdSql.execute("create table db100.ntb100 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)") - tdSql.execute("create table db100.ntb101 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)") - tss_grant += 20 - self.checkGrantsTimeSeries("create tables and check", tss_grant) - tdSql.execute("alter table db100.stb100 add column c5 int") - tdSql.execute("alter stable db100.stb100 add column c6 int") - tss_grant += 4 - self.checkGrantsTimeSeries("alter table column/tag and tss_grant", tss_grant) - - # tdSql.execute("alter table db100.stb100 add tag t1 int") - # tdSql.execute("create table db100.ctb102 using db100.stb100 tags(102, 102)") - # tdSql.execute("alter table db100.ctb100 set tag t0=1000") - # tdSql.execute("alter table db100.ntb100 add column c5 int") - # tss_grant += 12 - # self.checkGrantsTimeSeries("alter table column/tag and tss_grant", tss_grant) - # tdSql.execute("drop table db100.ctb100") - # tdSql.execute("drop table db100.ntb100") - # tss_grant -= 13 - # self.checkGrantsTimeSeries("drop ctb/ntb and check: tss_grant", tss_grant) - # tdSql.execute("drop table db100.stb100") - # tss_grant -= 14 - # self.checkGrantsTimeSeries("drop stb and check: tss_grant", tss_grant) - # tdSql.execute("drop database db100") - # tss_grant -= 7 - # self.checkGrantsTimeSeries("drop database and check: tss_grant", tss_grant) + for i in range(0, 3): + tdLog.printNoPrefix(f"======== test timeseries: loop{i}") + self.checkGrantsTimeSeries("initial check", tss_grant) + tdSql.execute("create database if not exists db100") + 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.ctb100 using db100.stb100 tags(100)") + tdSql.execute("create table db100.ctb101 using db100.stb100 tags(101)") + tdSql.execute("create table db100.ntb100 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)") + tdSql.execute("create table db100.ntb101 (ts timestamp, c0 int,c1 bigint,c2 int,c3 float,c4 double)") + tss_grant += 20 + self.checkGrantsTimeSeries("create tables and check", tss_grant) + tdSql.execute("alter table db100.stb100 add column c5 int") + tdSql.execute("alter stable db100.stb100 add column c6 int") + tdSql.execute("alter table db100.stb100 add tag t1 int") + tss_grant += 4 + self.checkGrantsTimeSeries("alter table column/tag and check", tss_grant) + tdSql.execute("create table db100.ctb102 using db100.stb100 tags(102, 102)") + tdSql.execute("alter table db100.ctb100 set tag t0=1000") + tdSql.execute("alter table db100.ntb100 add column c5 int") + tss_grant += 8 + self.checkGrantsTimeSeries("alter table column/tag and check", tss_grant) + tdSql.execute("drop table db100.ctb100") + tdSql.execute("drop table db100.ntb100") + tss_grant -= 13 + self.checkGrantsTimeSeries("drop ctb/ntb and check", tss_grant) + tdSql.execute("drop table db100.stb100") + tss_grant -= 14 + self.checkGrantsTimeSeries("drop stb and check", tss_grant) + tdSql.execute("drop database db100") + tss_grant -= 5 + self.checkGrantsTimeSeries("drop database and check", tss_grant) def s2_check_show_grants_ungranted(self): tdLog.printNoPrefix("======== test show grants ungranted: ") @@ -285,8 +286,8 @@ class TDTestCase: # keep the order of following steps self.s0_five_dnode_one_mnode() self.s1_check_timeseries() - # self.s2_check_show_grants_ungranted() - # self.s3_check_show_grants_granted() + self.s2_check_show_grants_ungranted() + self.s3_check_show_grants_granted() def stop(self):