From c29c7f1c4c11a1bfd779c75525d48ee26ce4daf6 Mon Sep 17 00:00:00 2001 From: slguan Date: Thu, 16 Apr 2020 12:49:04 +0800 Subject: [PATCH] add vgroup list to stable --- src/inc/mnode.h | 2 ++ src/mnode/src/mgmtTable.c | 44 +++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/inc/mnode.h b/src/inc/mnode.h index e8a0ba3bcc..3a55679b21 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -110,6 +110,8 @@ typedef struct SSuperTableObj { int32_t numOfTables; int16_t nextColId; SSchema * schema; + int32_t vgLen; + int32_t * vgList; } SSuperTableObj; typedef struct { diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index 37083a00c8..09923f8605 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -45,6 +45,9 @@ static int32_t tsSuperTableUpdateSize; static void * mgmtGetChildTable(char *tableId); static void * mgmtGetSuperTable(char *tableId); static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable); +static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable); +static void mgmtRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable); + static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn); @@ -109,7 +112,7 @@ static int32_t mgmtChildTableActionInsert(SSdbOperDesc *pOper) { if (pTable->info.type == TSDB_CHILD_TABLE) { pTable->superTable = mgmtGetSuperTable(pTable->superTableId); - pTable->superTable->numOfTables++; + mgmtAddTableIntoStable(pTable->superTable, pTable); grantAdd(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1); } else { @@ -152,7 +155,7 @@ static int32_t mgmtChildTableActionDelete(SSdbOperDesc *pOper) { if (pTable->info.type == TSDB_CHILD_TABLE) { grantRestore(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries -= (pTable->superTable->numOfColumns - 1); - pTable->superTable->numOfTables--; + mgmtRemoveTableFromStable(pTable->superTable, pTable); mgmtDecTableRef(pTable->superTable); } else { grantRestore(TSDB_GRANT_TIMESERIES, pTable->numOfColumns - 1); @@ -350,8 +353,40 @@ static void mgmtCleanUpChildTables() { sdbCloseTable(tsChildTableSdb); } +static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { + if (pStable->vgLen == 0) { + pStable->vgLen = 10; + pStable->vgList = calloc(pStable->vgLen, sizeof(int32_t)); + } + + bool find = false; + int32_t pos = 0; + for (int pos = 0; pos < pStable->vgLen; ++pos) { + if (pStable->vgList[pos] == 0) break; + if (pStable->vgList[pos] == pCtable->vgId) { + find = true; + break; + } + } + + if (!find) { + if (pos >= pStable->vgLen) { + pStable->vgLen *= 2; + pStable->vgList = realloc(pStable->vgList, pStable->vgLen * sizeof(int32_t)); + } + pStable->vgList[pos] = pCtable->vgId; + } + + pStable->numOfTables++; +} + +static void mgmtRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { + pStable->numOfTables--; +} + static void mgmtDestroySuperTable(SSuperTableObj *pStable) { tfree(pStable->schema); + tfree(pStable->vgList) tfree(pStable); } @@ -384,13 +419,14 @@ static int32_t mgmtSuperTableActionDelete(SSdbOperDesc *pOper) { } static int32_t mgmtSuperTableActionUpdate(SSdbOperDesc *pOper) { - SChildTableObj *pNew = pOper->pObj; - SChildTableObj *pTable = mgmtGetChildTable(pNew->info.tableId); + SSuperTableObj *pNew = pOper->pObj; + SSuperTableObj *pTable = mgmtGetSuperTable(pNew->info.tableId); if (pTable != pNew) { void *oldSchema = pTable->schema; memcpy(pTable, pNew, pOper->rowSize); pTable->schema = pNew->schema; free(pNew); + free(pNew->vgList); free(oldSchema); } -- GitLab