feat: support uniq grant

This commit is contained in:
kailixu 2024-02-04 18:00:02 +08:00
parent d281bc70b0
commit 6098538162
16 changed files with 48 additions and 50 deletions

View File

@ -30,10 +30,10 @@ extern "C" {
#define GRANT_HEART_BEAT_MIN 2 #define GRANT_HEART_BEAT_MIN 2
#define GRANT_ACTIVE_CODE "activeCode" #define GRANT_ACTIVE_CODE "activeCode"
#define GRANT_ALL_FLAG (0x01) #define GRANT_FLAG_ALL (0x01)
#define GRANT_AUDIT_FLAG (0x02) #define GRANT_FLAG_AUDIT (0x02)
#define GRANT_CSV_FLAG (0x04) #define GRANT_FLAG_CSV (0x04)
#define GRANT_VIEW_FLAG (0x08) #define GRANT_FLAG_VIEW (0x08)
typedef enum { typedef enum {
TSDB_GRANT_ALL, TSDB_GRANT_ALL,

View File

@ -25,7 +25,6 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
#include "tarray.h" #include "tarray.h"
#include "tcommon.h" #include "tcommon.h"
#include "tgrant.h"
#include "thash.h" #include "thash.h"
#include "tmsg.h" #include "tmsg.h"
#include "tname.h" #include "tname.h"
@ -146,10 +145,6 @@ typedef struct SSTableVersion {
int32_t smaVer; int32_t smaVer;
} SSTableVersion; } SSTableVersion;
typedef struct SGrantVersion {
int32_t version;
} SGrantVersion;
typedef struct SDbCacheInfo { typedef struct SDbCacheInfo {
char dbFName[TSDB_DB_FNAME_LEN]; char dbFName[TSDB_DB_FNAME_LEN];
int64_t dbId; int64_t dbId;
@ -363,7 +358,7 @@ int32_t catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* f
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes); int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes);
int32_t catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo* pAuth, SUserAuthRes* pRes, bool* exists); int32_t catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists);
int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth); int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);

View File

@ -327,6 +327,7 @@ static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatal
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void hbProcessQueryRspKvs(int32_t kvNum, SArray* pKvs, struct SCatalog *pCatalog, SAppHbMgr *pAppHbMgr) { static void hbProcessQueryRspKvs(int32_t kvNum, SArray* pKvs, struct SCatalog *pCatalog, SAppHbMgr *pAppHbMgr) {
for (int32_t i = 0; i < kvNum; ++i) { for (int32_t i = 0; i < kvNum; ++i) {
SKv *kv = taosArrayGet(pKvs, i); SKv *kv = taosArrayGet(pKvs, i);
@ -865,6 +866,7 @@ int32_t hbGetExpiredViewInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, S
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) { int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) {
SAppHbReq *pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId)); SAppHbReq *pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId));
if (NULL != pApp) { if (NULL != pApp) {

View File

@ -1804,11 +1804,11 @@ void taosSetAllDebugFlag(int32_t flag) {
int8_t taosGranted(int8_t type) { int8_t taosGranted(int8_t type) {
switch (type) { switch (type) {
case TSDB_GRANT_ALL: case TSDB_GRANT_ALL:
return atomic_load_8(&tsGrant) & GRANT_ALL_FLAG; return atomic_load_8(&tsGrant) & GRANT_FLAG_ALL;
case TSDB_GRANT_AUDIT: case TSDB_GRANT_AUDIT:
return atomic_load_8(&tsGrant) & GRANT_AUDIT_FLAG; return atomic_load_8(&tsGrant) & GRANT_FLAG_AUDIT;
case TSDB_GRANT_VIEW: case TSDB_GRANT_VIEW:
return atomic_load_8(&tsGrant) & GRANT_VIEW_FLAG; return atomic_load_8(&tsGrant) & GRANT_FLAG_VIEW;
default: default:
ASSERTS(0, "undefined grant type:%" PRIi8, type); ASSERTS(0, "undefined grant type:%" PRIi8, type);
break; break;

View File

@ -9333,4 +9333,4 @@ void tFreeSViewHbRsp(SViewHbRsp *pRsp) {
} }
taosArrayDestroy(pRsp->pViewRsp); taosArrayDestroy(pRsp->pViewRsp);
} }

View File

@ -41,8 +41,9 @@
char **mergeActive); char **mergeActive);
#endif #endif
int32_t mndProcessConfigGrantReq(SMnode * pMnode, SRpcMsg * pReq, SMCfgClusterReq * pCfg); int32_t mndProcessConfigGrantReq(SMnode * pMnode, SRpcMsg * pReq, SMCfgClusterReq * pCfg);
int32_t mndProcessUpdGrantLog(SMnode * pMnode, SRpcMsg * pReq, SArray * pMachines, SGrantState * pState); int32_t mndProcessUpdGrantLog(SMnode * pMnode, SRpcMsg * pReq, SArray * pMachines, SGrantState * pState);
int32_t mndGrantGetLastState(SMnode * pMnode, SGrantState * pState); int32_t mndGrantGetLastState(SMnode * pMnode, SGrantState * pState);
SGrantLogObj *mndAcquireGrant(SMnode * pMnode, void **ppIter); SGrantLogObj *mndAcquireGrant(SMnode * pMnode, void **ppIter);
void mndReleaseGrant(SMnode * pMnode, SGrantLogObj * pGrant, void *pIter); void mndReleaseGrant(SMnode * pMnode, SGrantLogObj * pGrant, void *pIter);

View File

@ -18,7 +18,6 @@
#include "audit.h" #include "audit.h"
#include "mndDb.h" #include "mndDb.h"
#include "mndDnode.h" #include "mndDnode.h"
#include "mndGrant.h"
#include "mndMnode.h" #include "mndMnode.h"
#include "mndPrivilege.h" #include "mndPrivilege.h"
#include "mndQnode.h" #include "mndQnode.h"

View File

@ -548,6 +548,7 @@ typedef struct SCtgDropViewMetaMsg {
uint64_t viewId; uint64_t viewId;
} SCtgDropViewMetaMsg; } SCtgDropViewMetaMsg;
typedef struct SCtgCacheOperation { typedef struct SCtgCacheOperation {
int32_t opId; int32_t opId;
void* data; void* data;
@ -943,8 +944,8 @@ void ctgRemoveStbRent(SCatalog *pCtg, SCtgDBCache *dbCache);
void ctgRemoveViewRent(SCatalog *pCtg, SCtgDBCache *dbCache); void ctgRemoveViewRent(SCatalog *pCtg, SCtgDBCache *dbCache);
int32_t ctgUpdateRentStbVersion(SCatalog *pCtg, char *dbFName, char *tbName, uint64_t dbId, uint64_t suid, int32_t ctgUpdateRentStbVersion(SCatalog *pCtg, char *dbFName, char *tbName, uint64_t dbId, uint64_t suid,
SCtgTbCache *pCache); SCtgTbCache *pCache);
int32_t ctgUpdateRentViewVersion(SCatalog *pCtg, char *dbFName, char *viewName, uint64_t dbId, uint64_t viewId, int32_t ctgUpdateRentViewVersion(SCatalog* pCtg, char* dbFName, char* viewName, uint64_t dbId, uint64_t viewId,
SCtgViewCache *pCache); SCtgViewCache* pCache);
int32_t ctgUpdateTbMetaToCache(SCatalog* pCtg, STableMetaOutput* pOut, bool syncReq); int32_t ctgUpdateTbMetaToCache(SCatalog* pCtg, STableMetaOutput* pOut, bool syncReq);
int32_t ctgUpdateViewMetaToCache(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncReq); int32_t ctgUpdateViewMetaToCache(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncReq);
int32_t ctgStartUpdateThread(); int32_t ctgStartUpdateThread();

View File

@ -1513,6 +1513,7 @@ int32_t catalogGetExpiredViews(SCatalog* pCtg, SViewVersion** views, uint32_t* n
CTG_API_LEAVE(ctgMetaRentGet(&pCtg->viewRent, (void**)views, num, sizeof(SViewVersion))); CTG_API_LEAVE(ctgMetaRentGet(&pCtg->viewRent, (void**)views, num, sizeof(SViewVersion)));
} }
int32_t catalogGetExpiredDBs(SCatalog* pCtg, SDbCacheInfo** dbs, uint32_t* num) { int32_t catalogGetExpiredDBs(SCatalog* pCtg, SDbCacheInfo** dbs, uint32_t* num) {
CTG_API_ENTER(); CTG_API_ENTER();
@ -1675,6 +1676,7 @@ _return:
CTG_API_LEAVE(code); CTG_API_LEAVE(code);
} }
int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion) { int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion) {
CTG_API_ENTER(); CTG_API_ENTER();
@ -1745,6 +1747,7 @@ _return:
CTG_API_LEAVE(code); CTG_API_LEAVE(code);
} }
int32_t catalogAsyncUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg) { int32_t catalogAsyncUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg) {
CTG_API_ENTER(); CTG_API_ENTER();

View File

@ -2450,6 +2450,7 @@ _return:
CTG_RET(code); CTG_RET(code);
} }
void ctgClearFreeCache(SCtgCacheOperation *operation) { void ctgClearFreeCache(SCtgCacheOperation *operation) {
SCtgClearCacheMsg *msg = operation->data; SCtgClearCacheMsg *msg = operation->data;
SCatalog *pCtg = msg->pCtg; SCatalog *pCtg = msg->pCtg;

View File

@ -301,3 +301,4 @@ int32_t ctgUpdateRentViewVersion(SCatalog *pCtg, char *dbFName, char *viewName,
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -3294,6 +3294,8 @@ static const char* jkSubplanTagIndexCond = "TagIndexCond";
static const char* jkSubplanShowRewrite = "ShowRewrite"; static const char* jkSubplanShowRewrite = "ShowRewrite";
static const char* jkSubplanRowsThreshold = "RowThreshold"; static const char* jkSubplanRowsThreshold = "RowThreshold";
static const char* jkSubplanDynamicRowsThreshold = "DyRowThreshold"; static const char* jkSubplanDynamicRowsThreshold = "DyRowThreshold";
static const char* jkSubplanIsView = "IsView";
static const char* jkSubplanIsAudit = "IsAudit";
static int32_t subplanToJson(const void* pObj, SJson* pJson) { static int32_t subplanToJson(const void* pObj, SJson* pJson) {
const SSubplan* pNode = (const SSubplan*)pObj; const SSubplan* pNode = (const SSubplan*)pObj;
@ -3333,10 +3335,10 @@ static int32_t subplanToJson(const void* pObj, SJson* pJson) {
code = tjsonAddBoolToObject(pJson, jkSubplanShowRewrite, pNode->showRewrite); code = tjsonAddBoolToObject(pJson, jkSubplanShowRewrite, pNode->showRewrite);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddBoolToObject(pJson, jkSubplanShowRewrite, pNode->isView); code = tjsonAddBoolToObject(pJson, jkSubplanIsView, pNode->isView);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddBoolToObject(pJson, jkSubplanShowRewrite, pNode->isAudit); code = tjsonAddBoolToObject(pJson, jkSubplanIsAudit, pNode->isAudit);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkSubplanRowsThreshold, pNode->rowsThreshold); code = tjsonAddIntegerToObject(pJson, jkSubplanRowsThreshold, pNode->rowsThreshold);
@ -3386,10 +3388,10 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
code = tjsonGetBoolValue(pJson, jkSubplanShowRewrite, &pNode->showRewrite); code = tjsonGetBoolValue(pJson, jkSubplanShowRewrite, &pNode->showRewrite);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetBoolValue(pJson, jkSubplanShowRewrite, &pNode->isView); code = tjsonGetBoolValue(pJson, jkSubplanIsView, &pNode->isView);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetBoolValue(pJson, jkSubplanShowRewrite, &pNode->isAudit); code = tjsonGetBoolValue(pJson, jkSubplanIsAudit, &pNode->isAudit);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetIntValue(pJson, jkSubplanRowsThreshold, &pNode->rowsThreshold); code = tjsonGetIntValue(pJson, jkSubplanRowsThreshold, &pNode->rowsThreshold);

View File

@ -43,8 +43,6 @@ typedef struct STranslateContext {
bool createStream; bool createStream;
bool stableQuery; bool stableQuery;
bool showRewrite; bool showRewrite;
// bool isView;
// bool isAudit;
SNode* pPrevRoot; SNode* pPrevRoot;
SNode* pPostRoot; SNode* pPostRoot;
} STranslateContext; } STranslateContext;

View File

@ -2139,16 +2139,13 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt
} }
static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SRowsDataContext rowsDataCxt) { static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SRowsDataContext rowsDataCxt) {
int32_t code = 0;
int32_t numOfRows = 0;
// init only for file // init only for file
if (NULL == pStmt->pTableCxtHashObj) { if (NULL == pStmt->pTableCxtHashObj) {
pStmt->pTableCxtHashObj = pStmt->pTableCxtHashObj =
taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
} }
int32_t numOfRows = 0;
code = parseCsvFile(pCxt, pStmt, rowsDataCxt, &numOfRows); int32_t code = parseCsvFile(pCxt, pStmt, rowsDataCxt, &numOfRows);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
pStmt->totalRowsNum += numOfRows; pStmt->totalRowsNum += numOfRows;
pStmt->totalTbNum += 1; pStmt->totalTbNum += 1;
@ -2759,11 +2756,11 @@ static int32_t parseInsertSqlFromStart(SInsertParseContext* pCxt, SVnodeModifyOp
} }
static int32_t parseInsertSqlFromCsv(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) { static int32_t parseInsertSqlFromCsv(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
SRowsDataContext rowsDataCxt; SRowsDataContext rowsDataCxt;
if (!pStmt->stbSyntax) { if (!pStmt->stbSyntax) {
STableDataCxt* pTableCxt = NULL; STableDataCxt* pTableCxt = NULL;
code = getTableDataCxt(pCxt, pStmt, &pTableCxt); code = getTableDataCxt(pCxt, pStmt, &pTableCxt);
rowsDataCxt.pTableDataCxt = pTableCxt; rowsDataCxt.pTableDataCxt = pTableCxt;
} else { } else {

View File

@ -192,8 +192,6 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return "Out of memory"; return "Out of memory";
case TSDB_CODE_PAR_ORDERBY_AMBIGUOUS: case TSDB_CODE_PAR_ORDERBY_AMBIGUOUS:
return "ORDER BY \"%s\" is ambiguous"; return "ORDER BY \"%s\" is ambiguous";
case TSDB_CODE_GRANT_EXPIRED:
return "License expired";
default: default:
return "Unknown error"; return "Unknown error";
} }

View File

@ -361,22 +361,22 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg, bool chkGran
} }
if (chkGrant) { if (chkGrant) {
if ((!TEST_SHOW_REWRITE_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_ALL)) { if ((!TEST_SHOW_REWRITE_MASK(msg.msgMask))) {
QW_ELOG("query failed cause of grant expired, msgMask:%d", msg.msgMask); if (!taosGranted(TSDB_GRANT_ALL)) {
tFreeSSubQueryMsg(&msg); QW_ELOG("query failed cause of grant expired, msgMask:%d", msg.msgMask);
QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED); tFreeSSubQueryMsg(&msg);
} QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED);
}
if ((TEST_VIEW_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_VIEW)) { if ((TEST_VIEW_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_VIEW)) {
QW_ELOG("query failed cause of view grant expired, msgMask:%d", msg.msgMask); QW_ELOG("query failed cause of view grant expired, msgMask:%d", msg.msgMask);
tFreeSSubQueryMsg(&msg); tFreeSSubQueryMsg(&msg);
QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED); QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED);
} }
if ((TEST_AUDIT_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_AUDIT)) {
if ((TEST_AUDIT_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_AUDIT)) { QW_ELOG("query failed cause of audit grant expired, msgMask:%d", msg.msgMask);
QW_ELOG("query failed cause of audit grant expired, msgMask:%d", msg.msgMask); tFreeSSubQueryMsg(&msg);
tFreeSSubQueryMsg(&msg); QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED);
QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED); }
} }
} }