enh: grant refactor and grant check
This commit is contained in:
parent
077fbd6787
commit
6460514147
|
@ -268,26 +268,6 @@ typedef struct SSortExecInfo {
|
|||
int32_t readBytes; // read io bytes
|
||||
} SSortExecInfo;
|
||||
|
||||
//======================================================================================================================
|
||||
// for grant
|
||||
typedef enum {
|
||||
TSDB_GRANT_ALL,
|
||||
TSDB_GRANT_TIME,
|
||||
TSDB_GRANT_USER,
|
||||
TSDB_GRANT_DB,
|
||||
TSDB_GRANT_TIMESERIES,
|
||||
TSDB_GRANT_DNODE,
|
||||
TSDB_GRANT_ACCT,
|
||||
TSDB_GRANT_STORAGE,
|
||||
TSDB_GRANT_SPEED,
|
||||
TSDB_GRANT_QUERY_TIME,
|
||||
TSDB_GRANT_CONNS,
|
||||
TSDB_GRANT_STREAMS,
|
||||
TSDB_GRANT_CPU_CORES,
|
||||
} EGrantType;
|
||||
|
||||
int32_t grantCheck(EGrantType grant);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_GRANT_H_
|
||||
#define _TD_COMMON_GRANT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
typedef enum {
|
||||
TSDB_GRANT_ALL,
|
||||
TSDB_GRANT_TIME,
|
||||
TSDB_GRANT_USER,
|
||||
TSDB_GRANT_DB,
|
||||
TSDB_GRANT_TIMESERIES,
|
||||
TSDB_GRANT_DNODE,
|
||||
TSDB_GRANT_ACCT,
|
||||
TSDB_GRANT_STORAGE,
|
||||
TSDB_GRANT_SPEED,
|
||||
TSDB_GRANT_QUERY_TIME,
|
||||
TSDB_GRANT_CONNS,
|
||||
TSDB_GRANT_STREAMS,
|
||||
TSDB_GRANT_CPU_CORES,
|
||||
} EGrantType;
|
||||
|
||||
int32_t grantCheck(EGrantType grant);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_GRANT_H_*/
|
|
@ -153,9 +153,15 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
|
||||
switch (qtype) {
|
||||
case QUERY_QUEUE:
|
||||
vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pQueryQ, pMsg);
|
||||
if ((pMsg->msgType == TDMT_SCH_QUERY) && (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS)) {
|
||||
terrno = TSDB_CODE_GRANT_EXPIRED;
|
||||
code = terrno;
|
||||
dDebug("vgId:%d, msg:%p put into vnode-query queue failed since %s", pVnode->vgId, pMsg, terrstr());
|
||||
} else {
|
||||
vnodePreprocessQueryMsg(pVnode->pImpl, pMsg);
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pQueryQ, pMsg);
|
||||
}
|
||||
break;
|
||||
case STREAM_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
||||
|
@ -166,9 +172,14 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||
break;
|
||||
case WRITE_QUEUE:
|
||||
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pWriteQ, pMsg);
|
||||
if ((pMsg->msgType == TDMT_VND_SUBMIT) && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
||||
terrno = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||
code = terrno;
|
||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr());
|
||||
} else {
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pWriteQ, pMsg);
|
||||
}
|
||||
break;
|
||||
case SYNC_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "tcache.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
#include "tqueue.h"
|
||||
#include "ttime.h"
|
||||
#include "version.h"
|
||||
|
|
|
@ -509,11 +509,10 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
|
|||
SUserObj *pUser = NULL;
|
||||
SCreateDbReq createReq = {0};
|
||||
|
||||
// code = grantCheck(TSDB_GRANT_DB);
|
||||
// if (code != 0) {
|
||||
// terrno = code;
|
||||
// goto _OVER;
|
||||
// }
|
||||
if ((terrno = grantCheck(TSDB_GRANT_DB)) != 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (tDeserializeSCreateDbReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
|
|
@ -621,11 +621,10 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
|
|||
SDnodeObj *pDnode = NULL;
|
||||
SCreateDnodeReq createReq = {0};
|
||||
|
||||
// code = grantCheck(TSDB_GRANT_DNODE);
|
||||
// if (code != TSDB_CODE_SUCCESS) {
|
||||
// terrno = code;
|
||||
// goto _OVER;
|
||||
// }
|
||||
if ((terrno = grantCheck(TSDB_GRANT_DNODE)) != 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (tDeserializeSCreateDnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
|
|
@ -363,11 +363,10 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
// code = grantCheck(TSDB_GRANT_USER);
|
||||
// if (code != TSDB_CODE_SUCCESS) {
|
||||
// terrno = code;
|
||||
// goto _OVER;
|
||||
// }
|
||||
if ((terrno = grantCheck(TSDB_GRANT_USER)) != 0) {
|
||||
code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "wal.h"
|
||||
|
||||
#include "tcommon.h"
|
||||
#include "tgrant.h"
|
||||
#include "tfs.h"
|
||||
#include "tmsg.h"
|
||||
#include "trow.h"
|
||||
|
|
Loading…
Reference in New Issue