feat: support uniq grant

This commit is contained in:
kailixu 2024-02-04 14:59:47 +08:00
parent a9316c3710
commit 6cf7809e8d
9 changed files with 38 additions and 15 deletions

View File

@ -232,7 +232,7 @@ struct SConfig *taosGetCfg();
void taosSetAllDebugFlag(int32_t flag);
void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
int8_t taosGranted();
int8_t taosGranted(int8_t type);
#ifdef __cplusplus
}

View File

@ -92,8 +92,6 @@ typedef struct SScanLogicNode {
STimeWindow scanRange;
SName tableName;
bool showRewrite;
bool isView;
bool isAudit;
double ratio;
SNodeList* pDynamicScanFuncs;
int32_t dataRequired;

View File

@ -517,8 +517,6 @@ typedef struct SQuery {
SArray* pTableList;
SArray* pDbList;
bool showRewrite;
// bool isView;
// bool isAudit;
int32_t placeholderNum;
SArray* pPlaceholderValues;
SNode* pPrepareRoot;

View File

@ -70,7 +70,7 @@ typedef enum {
#define QUERY_MSG_MASK_AUDIT() (1 << 2)
#define TEST_SHOW_REWRITE_MASK(m) (((m)&QUERY_MSG_MASK_SHOW_REWRITE()) != 0)
#define TEST_VIEW_MASK(m) (((m)&QUERY_MSG_MASK_VIEW()) != 0)
#define TEST_AUDIT_MASK(m) (((m)&QUERY_MSG_MASK_MASK()) != 0)
#define TEST_AUDIT_MASK(m) (((m)&QUERY_MSG_MASK_AUDIT()) != 0)
typedef struct STableComInfo {

View File

@ -458,8 +458,6 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
.mgmtEpSet = getEpSet_s(&pAppInfo->mgmtEp),
.pAstRoot = pQuery->pRoot,
.showRewrite = pQuery->showRewrite,
.isView = pQuery->isView;
.isAudit = pQuery->isAudit;
.pMsg = pRequest->msgBuf,
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
.pUser = pRequest->pTscObj->user,

View File

@ -1801,4 +1801,17 @@ void taosSetAllDebugFlag(int32_t flag) {
if (terrno == TSDB_CODE_CFG_NOT_FOUND) terrno = TSDB_CODE_SUCCESS; // ignore not exist
}
int8_t taosGranted() { return atomic_load_8(&tsGrant); }
int8_t taosGranted(int8_t type) {
switch (type) {
case TSDB_GRANT_ALL:
return atomic_load_8(&tsGrant) & GRANT_ALL_FLAG;
case TSDB_GRANT_AUDIT:
return atomic_load_8(&tsGrant) & GRANT_AUDIT_FLAG;
case TSDB_GRANT_VIEW:
return atomic_load_8(&tsGrant) & GRANT_VIEW_FLAG;
default:
ASSERTS(0, "undefined grant type:%" PRIi8, type);
break;
}
return 0;
}

View File

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

View File

@ -2164,6 +2164,8 @@ static SSubplan* makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubpl
pSubplan->level = pLogicSubplan->level;
pSubplan->rowsThreshold = 4096;
pSubplan->dynamicRowThreshold = false;
pSubplan->isView = pCxt->pPlanCxt->isView;
pSubplan->isAudit = pCxt->pPlanCxt->isAudit;
if (NULL != pCxt->pPlanCxt->pUser) {
snprintf(pSubplan->user, sizeof(pSubplan->user), "%s", pCxt->pPlanCxt->pUser);
}

View File

@ -360,12 +360,26 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg, bool chkGran
QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
if (chkGrant && (!TEST_SHOW_REWRITE_MASK(msg.msgMask)) && !taosGranted()) {
if (chkGrant) {
if ((!TEST_SHOW_REWRITE_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_ALL)) {
QW_ELOG("query failed cause of grant expired, msgMask:%d", msg.msgMask);
tFreeSSubQueryMsg(&msg);
QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED);
}
if ((TEST_VIEW_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_VIEW)) {
QW_ELOG("query failed cause of view grant expired, msgMask:%d", msg.msgMask);
tFreeSSubQueryMsg(&msg);
QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED);
}
if ((TEST_AUDIT_MASK(msg.msgMask)) && !taosGranted(TSDB_GRANT_AUDIT)) {
QW_ELOG("query failed cause of audit grant expired, msgMask:%d", msg.msgMask);
tFreeSSubQueryMsg(&msg);
QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED);
}
}
uint64_t sId = msg.sId;
uint64_t qId = msg.queryId;
uint64_t tId = msg.taskId;