Skip to content

enh: grant support vnodes and storage size #31380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/common/tgrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ typedef enum {
TSDB_GRANT_DUAL_REPLICA_HA,
TSDB_GRANT_DB_ENCRYPTION,
TSDB_GRANT_TD_GPT,
TSDB_GRANT_VNODE,
} EGrantType;

int32_t checkAndGetCryptKey(const char *encryptCode, const char *machineId, char **key);
int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
int64_t grantRemain(EGrantType grant);
int32_t grantCheck(EGrantType grant);
int32_t grantCheckEx(EGrantType grant, void *param);
int32_t grantCheckExpire(EGrantType grant);
int32_t tGetMachineId(char **result);
bool grantCheckDualReplicaDnodes(void *pMnode);
Expand Down
2 changes: 0 additions & 2 deletions source/common/src/tglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3106,8 +3106,6 @@ int32_t taosGranted(int8_t type) {
int32_t grantVal = atomic_load_32(&tsGrant);
if (grantVal & GRANT_FLAG_EX_MULTI_TIER) {
return TSDB_CODE_GRANT_MULTI_STORAGE_EXPIRED;
} else if (grantVal & GRANT_FLAG_EX_VNODE) {
return TSDB_CODE_GRANT_VNODE_LIMITED;
} else if (grantVal & GRANT_FLAG_EX_STORAGE) {
return TSDB_CODE_GRANT_STORAGE_LIMITED;
}
Expand Down
1 change: 1 addition & 0 deletions source/common/src/tgrant.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef _GRANT

int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; }
int32_t grantCheckEx(EGrantType grant, void* param) { return TSDB_CODE_SUCCESS; }
int32_t grantCheckExpire(EGrantType grant) { return TSDB_CODE_SUCCESS; }

#else
Expand Down
2 changes: 2 additions & 0 deletions source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,14 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
tstrerror(code), TMSG_INFO(pMsg->msgType));
break;
}
#if 0
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
code = TSDB_CODE_VND_NO_WRITE_AUTH;
dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since %s, type:%s", pVnode->vgId, pMsg,
tstrerror(code), TMSG_INFO(pMsg->msgType));
break;
}
#endif
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
dDebug("vgId:%d, msg:%p, failed to put into vnode-write queue since its disable, type:%s", pVnode->vgId, pMsg,
TMSG_INFO(pMsg->msgType));
Expand Down
3 changes: 3 additions & 0 deletions source/dnode/mnode/impl/src/mndDb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,9 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {

TAOS_CHECK_GOTO(grantCheck(TSDB_GRANT_DB), &lino, _OVER);

int32_t nVnodes = createReq.numOfVgroups * createReq.replications;
TAOS_CHECK_GOTO(grantCheckEx(TSDB_GRANT_VNODE, &nVnodes), &lino, _OVER);

if (createReq.replications == 2) {
TAOS_CHECK_GOTO(grantCheck(TSDB_GRANT_DUAL_REPLICA_HA), &lino, _OVER);
}
Expand Down
12 changes: 5 additions & 7 deletions source/dnode/mnode/impl/src/mndMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ static int32_t minCronTime() {
}
void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
int32_t code = 0;
#ifndef TD_ASTRA
#ifndef TD_ASTRA
if (sec % tsGrantHBInterval == 0) { // put in the 1st place as to take effect ASAP
mndPullupGrant(pMnode);
}
if (sec % tsTtlPushIntervalSec == 0) {
mndPullupTtl(pMnode);
}
Expand Down Expand Up @@ -422,7 +425,7 @@ void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
mndStreamCheckNode(pMnode);
}

if (sec % (tsStreamFailedTimeout/1000) == 0) {
if (sec % (tsStreamFailedTimeout / 1000) == 0) {
mndStreamCheckStatus(pMnode);
}

Expand All @@ -433,11 +436,6 @@ void mndDoTimerPullupTask(SMnode *pMnode, int64_t sec) {
if (tsTelemInterval > 0 && sec % tsTelemInterval == 0) {
mndPullupTelem(pMnode);
}
#endif
#ifndef TD_ASTRA
if (sec % tsGrantHBInterval == 0) {
mndPullupGrant(pMnode);
}
#endif
if (sec % tsUptimeInterval == 0) {
mndIncreaseUpTime(pMnode);
Expand Down
1 change: 1 addition & 0 deletions source/dnode/vnode/inc/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ typedef struct {
int64_t pointsWritten;
int64_t totalStorage;
int64_t compStorage;
int64_t storageLastUpd;
} SVnodeStats;

struct SVnodeCfg {
Expand Down
29 changes: 27 additions & 2 deletions source/dnode/vnode/src/vnd/vnodeQuery.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,31 @@ int32_t vnodeGetVStbRefDbs(SVnode *pVnode, SRpcMsg *pMsg) {
return code;
}

static int32_t vnodeGetCompStorage(SVnode *pVnode, int64_t *output) {
int32_t code = 0;
#ifdef TD_ENTERPRISE
int32_t now = taosGetTimestampSec();
if (llabs(now - pVnode->config.vndStats.storageLastUpd) >= 30) {
pVnode->config.vndStats.storageLastUpd = now;

SDbSizeStatisInfo info = {0};
if (0 == (code = vnodeGetDBSize(pVnode, &info))) {
int64_t compSize =
info.l1Size + info.l2Size + info.l3Size + info.cacheSize + info.walSize + info.metaSize + +info.s3Size;
if (compSize >= 0) {
pVnode->config.vndStats.compStorage = compSize;
} else {
vError("vnode get comp storage failed since compSize is negative:%" PRIi64, compSize);
code = TSDB_CODE_APP_ERROR;
}
} else {
vWarn("vnode get comp storage failed since %s", tstrerror(code));
}
}
if (output) *output = pVnode->config.vndStats.compStorage;
#endif
return code;
}

int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
SSyncState state = syncGetState(pVnode->sync);
Expand All @@ -931,8 +956,8 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
VNODE_DO_META_QUERY(pVnode, pLoad->numOfTables = metaGetTbNum(pVnode->pMeta));
VNODE_DO_META_QUERY(pVnode, pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1));
pLoad->totalStorage = (int64_t)3 * 1073741824;
pLoad->compStorage = (int64_t)2 * 1073741824;
pLoad->totalStorage = (int64_t)3 * 1073741824; // TODO
vnodeGetCompStorage(pVnode, &pLoad->compStorage);
pLoad->pointsWritten = 100;
pLoad->numOfSelectReqs = 1;
pLoad->numOfInsertReqs = atomic_load_64(&pVnode->statis.nInsert);
Expand Down
5 changes: 2 additions & 3 deletions tests/system-test/0-others/information_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,9 @@ def ins_columns_check(self):
tdSql.checkEqual(20470,len(tdSql.queryResult))

tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
tdLog.info(len(tdSql.queryResult))
tdSql.checkEqual(True, len(tdSql.queryResult) in range(327, 328))
tdSql.checkRows(327)
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
tdSql.checkEqual(62, len(tdSql.queryResult))
tdSql.checkRows(62)

def ins_dnodes_check(self):
tdSql.execute('drop database if exists db2')
Expand Down
Loading