diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 6adb3e26ed30f3436ca00ecaddea50e6c0b36361..424e995c04a7714a9328c5097fe76553fe02d13e 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -236,6 +236,41 @@ static int32_t mnodeChildTableActionDelete(SSdbRow *pRow) { return TSDB_CODE_SUCCESS; } +static void mnodeTableActionUpdateTimeSeries(const char *tableId, int64_t diffCols) { + if (diffCols > 0) { + grantAdd(TSDB_GRANT_TIMESERIES, diffCols); + } else if (diffCols < 0) { + grantRestore(TSDB_GRANT_TIMESERIES, -diffCols); + } else { + return; + } + + if (tableId) { + SName sName = {0}; + char db[TSDB_DB_NAME_LEN] = {0}; + SDbObj *pDb = NULL; + SAcctObj *pAcct = NULL; + + if (tNameFromString(&sName, tableId, T_NAME_ACCT | T_NAME_DB)) { + mWarn("table:%s, failed to get SName to update timeseries", tableId); + return; + } + if (tNameExtractFullName((const SName *)&sName, db)) { + mWarn("table:%s, failed to extract SName to update timeseries", tableId); + return; + } + if (!(pDb = mnodeGetDb(db))) { + mWarn("table:%s, db:%s not exist to update timeseries", tableId, db); + return; + }; + if (!(pAcct = mnodeGetAcct(pDb->acct))) { + mWarn("table:%s, acct:%s not exist to update timeseries", tableId, pDb->acct); + return; + } + if (pAcct) pAcct->acctInfo.numOfTimeSeries += diffCols; + } +} + static int32_t mnodeChildTableActionUpdate(SSdbRow *pRow) { SCTableObj *pNew = pRow->pObj; SCTableObj *pTable = mnodeGetChildTable(pNew->info.tableId); @@ -246,6 +281,10 @@ static int32_t mnodeChildTableActionUpdate(SSdbRow *pRow) { void *oldSTable = pTable->superTable; int32_t oldRefCount = pTable->refCount; + if (pTable->info.type == TSDB_NORMAL_TABLE) { + mnodeTableActionUpdateTimeSeries(pTable->info.tableId, pNew->numOfColumns - pTable->numOfColumns); + } + memcpy(pTable, pNew, sizeof(SCTableObj)); pTable->refCount = oldRefCount; @@ -528,6 +567,9 @@ static int32_t mnodeSuperTableActionUpdate(SSdbRow *pRow) { int32_t oldRefCount = pTable->refCount; int32_t oldNumOfTables = pTable->numOfTables; + mnodeTableActionUpdateTimeSeries(pTable->info.tableId, + (int64_t)oldNumOfTables * (pNew->numOfColumns - pTable->numOfColumns)); + memcpy(pTable, pNew, sizeof(SSTableObj)); pTable->vgHash = oldVgHash; @@ -1464,6 +1506,7 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32 pAcct->acctInfo.numOfTimeSeries += (ncols * pStable->numOfTables); mnodeDecAcctRef(pAcct); } + grantAdd(TSDB_GRANT_TIMESERIES, (uint64_t)ncols * pStable->numOfTables); mInfo("msg:%p, app:%p stable %s, start to add column", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId); @@ -1514,6 +1557,7 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) { pAcct->acctInfo.numOfTimeSeries -= pStable->numOfTables; mnodeDecAcctRef(pAcct); } + grantRestore(TSDB_GRANT_TIMESERIES, pStable->numOfTables); mInfo("msg:%p, app:%p stable %s, start to delete column", pMsg, pMsg->rpcMsg.ahandle, pStable->info.tableId); @@ -2471,6 +2515,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3 pAcct->acctInfo.numOfTimeSeries += ncols; mnodeDecAcctRef(pAcct); } + grantAdd(TSDB_GRANT_TIMESERIES, ncols); mInfo("msg:%p, app:%p ctable %s, start to add column", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId); monSaveAuditLog(MON_DDL_CMD_ADD_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true); @@ -2506,6 +2551,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) { pAcct->acctInfo.numOfTimeSeries--; mnodeDecAcctRef(pAcct); } + grantRestore(TSDB_GRANT_TIMESERIES, 1); mInfo("msg:%p, app:%p ctable %s, start to drop column %s", pMsg, pMsg->rpcMsg.ahandle, pTable->info.tableId, colName); monSaveAuditLog(MON_DDL_CMD_DROP_COLUMN, mnodeGetUserFromMsg(pMsg), pTable->info.tableId, true);