enh: timeseries calculation

This commit is contained in:
kailixu 2023-09-24 08:41:45 +08:00
parent 53a9459c20
commit ff3e36e679
3 changed files with 19 additions and 6 deletions

View File

@ -1678,6 +1678,10 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray
return -1; return -1;
} }
if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) != 0) {
return -1;
}
pNew->numOfColumns = pNew->numOfColumns + ncols; pNew->numOfColumns = pNew->numOfColumns + ncols;
if (mndAllocStbSchemas(pOld, pNew) != 0) { if (mndAllocStbSchemas(pOld, pNew) != 0) {
return -1; return -1;

View File

@ -703,7 +703,7 @@ void metaUpdTimeSeriesNum(SMeta *pMeta) {
} }
} }
static FORCE_INLINE metaGetTimeSeriesNumImpl(SMeta *pMeta, bool forceUpd) { static FORCE_INLINE int64_t metaGetTimeSeriesNumImpl(SMeta *pMeta, bool forceUpd) {
// sum of (number of columns of stable - 1) * number of ctables (excluding timestamp column) // sum of (number of columns of stable - 1) * number of ctables (excluding timestamp column)
SVnodeStats *pStats = &pMeta->pVnode->config.vndStats; SVnodeStats *pStats = &pMeta->pVnode->config.vndStats;
if (forceUpd || pStats->numOfTimeSeries <= 0) { if (forceUpd || pStats->numOfTimeSeries <= 0) {

View File

@ -315,6 +315,8 @@ _drop_super_table:
tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn);
tdbTbDelete(pMeta->pSuidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn); tdbTbDelete(pMeta->pSuidIdx, &pReq->suid, sizeof(tb_uid_t), pMeta->txn);
metaStatsCacheDrop(pMeta, pReq->suid);
metaULock(pMeta); metaULock(pMeta);
metaUpdTimeSeriesNum(pMeta); metaUpdTimeSeriesNum(pMeta);
@ -389,6 +391,8 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
nStbEntry.stbEntry.schemaRow = pReq->schemaRow; nStbEntry.stbEntry.schemaRow = pReq->schemaRow;
nStbEntry.stbEntry.schemaTag = pReq->schemaTag; nStbEntry.stbEntry.schemaTag = pReq->schemaTag;
int32_t deltaCol = pReq->schemaRow.nCols - oStbEntry.stbEntry.schemaRow.nCols;
metaWLock(pMeta); metaWLock(pMeta);
// compare two entry // compare two entry
if (oStbEntry.stbEntry.schemaRow.version != pReq->schemaRow.version) { if (oStbEntry.stbEntry.schemaRow.version != pReq->schemaRow.version) {
@ -403,21 +407,23 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
// metaStatsCacheDrop(pMeta, nStbEntry.uid); // metaStatsCacheDrop(pMeta, nStbEntry.uid);
int32_t deltaCol = pReq->schemaRow.nCols - oStbEntry.stbEntry.schemaRow.nCols;
if (deltaCol != 0) { if (deltaCol != 0) {
metaUpdateStbStats(pMeta, pReq->suid, 0, deltaCol); metaUpdateStbStats(pMeta, pReq->suid, 0, deltaCol);
}
metaULock(pMeta);
if (deltaCol != 0) {
int64_t ctbNum; int64_t ctbNum;
metaGetStbStats(pMeta, pReq->suid, &ctbNum, NULL); metaGetStbStats(pMeta->pVnode, pReq->suid, &ctbNum, NULL);
pMeta->pVnode->config.vndStats.numOfTimeSeries += (ctbNum * deltaCol); pMeta->pVnode->config.vndStats.numOfTimeSeries += (ctbNum * deltaCol);
} }
metaULock(pMeta); _exit:
if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
tDecoderClear(&dc); tDecoderClear(&dc);
tdbTbcClose(pTbDbc); tdbTbcClose(pTbDbc);
tdbTbcClose(pUidIdxc); tdbTbcClose(pUidIdxc);
return 0; return ret;
} }
int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
SMetaEntry oStbEntry = {0}; SMetaEntry oStbEntry = {0};
@ -1308,6 +1314,9 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
terrno = TSDB_CODE_VND_COL_ALREADY_EXISTS; terrno = TSDB_CODE_VND_COL_ALREADY_EXISTS;
goto _err; goto _err;
} }
if ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0) {
goto _err;
}
pSchema->version++; pSchema->version++;
pSchema->nCols++; pSchema->nCols++;
pNewSchema = taosMemoryMalloc(sizeof(SSchema) * pSchema->nCols); pNewSchema = taosMemoryMalloc(sizeof(SSchema) * pSchema->nCols);