From 5b6136ec8280534b9653a7424a77432f466d83c4 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 16 Dec 2024 11:00:51 +0800 Subject: [PATCH 1/2] fix(meta/tsdb cache): fix drop sub tables for super table --- source/dnode/vnode/src/meta/metaEntry2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/meta/metaEntry2.c b/source/dnode/vnode/src/meta/metaEntry2.c index fd129ec5d5..2a99796359 100644 --- a/source/dnode/vnode/src/meta/metaEntry2.c +++ b/source/dnode/vnode/src/meta/metaEntry2.c @@ -1745,6 +1745,11 @@ static int32_t metaHandleSuperTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) return code; } + if (tsdbCacheDropSubTables(pMeta->pVnode->pTsdb, childList, pEntry->uid) < 0) { + metaError("vgId:%d, failed to drop stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pEntry->name, + pEntry->uid, tstrerror(terrno)); + } + // loop to drop all child tables for (int32_t i = 0; i < taosArrayGetSize(childList); i++) { SMetaEntry childEntry = { @@ -1859,4 +1864,4 @@ int32_t metaHandleEntry2(SMeta *pMeta, const SMetaEntry *pEntry) { metaErr(vgId, code); } TAOS_RETURN(code); -} \ No newline at end of file +} From 7aacaf580e4cade3b4fbc9945229d5e54f6ac0b2 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 16 Dec 2024 11:27:27 +0800 Subject: [PATCH 2/2] meta/tsdb cache: add/drop column with supertables --- source/dnode/vnode/src/meta/metaEntry2.c | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/source/dnode/vnode/src/meta/metaEntry2.c b/source/dnode/vnode/src/meta/metaEntry2.c index 2a99796359..108c6a9ae6 100644 --- a/source/dnode/vnode/src/meta/metaEntry2.c +++ b/source/dnode/vnode/src/meta/metaEntry2.c @@ -1624,6 +1624,60 @@ static int32_t metaHandleSuperTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry return code; } + int nCols = pEntry->stbEntry.schemaRow.nCols; + int onCols = pOldEntry->stbEntry.schemaRow.nCols; + int32_t deltaCol = nCols - onCols; + bool updStat = deltaCol != 0 && !metaTbInFilterCache(pMeta, pEntry->name, 1); + + if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { + STsdb *pTsdb = pMeta->pVnode->pTsdb; + SArray *uids = NULL; /*taosArrayInit(8, sizeof(int64_t)); + if (uids == NULL) { + metaErr(TD_VID(pMeta->pVnode), code); + metaFetchEntryFree(&pOldEntry); + return terrno; + }*/ + if (deltaCol == 1) { + int16_t cid = pEntry->stbEntry.schemaRow.pSchema[nCols - 1].colId; + int8_t col_type = pEntry->stbEntry.schemaRow.pSchema[nCols - 1].type; + + code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &uids); + if (code) { + metaErr(TD_VID(pMeta->pVnode), code); + metaFetchEntryFree(&pOldEntry); + return code; + } + // TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pEntry->uid, uids)); + TAOS_CHECK_RETURN(tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type)); + } else if (deltaCol == -1) { + int16_t cid = -1; + bool hasPrimaryKey = false; + if (onCols >= 2) { + hasPrimaryKey = (pOldEntry->stbEntry.schemaRow.pSchema[1].flags & COL_IS_KEY) ? true : false; + } + for (int i = 0, j = 0; i < nCols && j < onCols; ++i, ++j) { + if (pEntry->stbEntry.schemaRow.pSchema[i].colId != pOldEntry->stbEntry.schemaRow.pSchema[j].colId) { + cid = pOldEntry->stbEntry.schemaRow.pSchema[j].colId; + break; + } + } + + if (cid != -1) { + code = metaGetChildUidsOfSuperTable(pMeta, pEntry->uid, &uids); + if (code) { + metaErr(TD_VID(pMeta->pVnode), code); + metaFetchEntryFree(&pOldEntry); + return code; + } + // TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pEntry->uid, uids)); + TAOS_CHECK_RETURN(tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey)); + } + } + if (uids) taosArrayDestroy(uids); + + tsdbCacheInvalidateSchema(pTsdb, pEntry->uid, -1, pEntry->stbEntry.schemaRow.version); + } + metaFetchEntryFree(&pOldEntry); return code; }