From 412d3437a8df6ec8ee1660f55f455c1521ee9bba Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Mon, 1 Aug 2022 19:54:13 +0800 Subject: [PATCH] feat: add cloud grant cfg --- include/common/tgrant.h | 30 +++++++++++++++++++++ include/util/taoserror.h | 2 ++ source/common/CMakeLists.txt | 16 ++++++++--- source/common/src/systable.c | 18 ++----------- source/common/src/tglobal.c | 7 ++++- source/dnode/mgmt/mgmt_dnode/CMakeLists.txt | 4 +++ source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 2 ++ source/libs/command/src/command.c | 3 ++- source/util/CMakeLists.txt | 5 ++++ source/util/src/tconfig.c | 2 ++ 10 files changed, 68 insertions(+), 21 deletions(-) diff --git a/include/common/tgrant.h b/include/common/tgrant.h index 09c6e5378e..06e5ddc0ec 100644 --- a/include/common/tgrant.h +++ b/include/common/tgrant.h @@ -22,6 +22,9 @@ extern "C" { #include "os.h" #include "taoserror.h" +#ifdef GRANTS_CFG +#include "tgrantCfg.h" +#endif typedef enum { TSDB_GRANT_ALL, @@ -37,10 +40,37 @@ typedef enum { TSDB_GRANT_CONNS, TSDB_GRANT_STREAMS, TSDB_GRANT_CPU_CORES, + TSDB_GRANT_STABLE, + TSDB_GRANT_TABLE, } EGrantType; int32_t grantCheck(EGrantType grant); +#ifndef GRANTS_CFG +#define GRANTS_SCHEMA static const SSysDbTableSchema grantsSchema[] = { \ + {.name = "version", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "expire time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "storage(GB)", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "databases", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "users", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "accounts", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "connections", .bytes = 11 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "streams", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "cpu cores", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "speed(PPS)", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ + {.name = "querytime", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, \ +} +#define GRANT_CFG_ADD +#define GRANT_CFG_SET +#define GRANT_CFG_CHECK +#define GRANT_CFG_SKIP +#define GRANT_CFG_DECLARE +#define GRANT_CFG_EXTERN +#endif + #ifdef __cplusplus } #endif diff --git a/include/util/taoserror.h b/include/util/taoserror.h index da2f58307d..f3c9d5cb79 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -405,6 +405,8 @@ int32_t* taosGetErrno(); #define TSDB_CODE_GRANT_STORAGE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x0809) #define TSDB_CODE_GRANT_QUERYTIME_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080A) #define TSDB_CODE_GRANT_CPU_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080B) +#define TSDB_CODE_GRANT_STABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080C) +#define TSDB_CODE_GRANT_TABLE_LIMITED TAOS_DEF_ERROR_CODE(0, 0x080D) // sync #define TSDB_CODE_SYN_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x0903) diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index e01b113a04..2b5d440a73 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -1,14 +1,24 @@ aux_source_directory(src COMMON_SRC) add_library(common STATIC ${COMMON_SRC}) + +if (DEFINED GRANT_CFG_INCLUDE_DIR) + add_definitions(-DGRANTS_CFG) +endif() + target_include_directories( common PUBLIC "${TD_SOURCE_DIR}/include/common" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${GRANT_CFG_INCLUDE_DIR}" +) IF(${TD_WINDOWS}) - PRIVATE "${TD_SOURCE_DIR}/contrib/pthread" - PRIVATE "${TD_SOURCE_DIR}/contrib/msvcregex" + target_include_directories( + common + PRIVATE "${TD_SOURCE_DIR}/contrib/pthread" + PRIVATE "${TD_SOURCE_DIR}/contrib/msvcregex" + ) ENDIF () -) + target_link_libraries( common PUBLIC os diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 7d07946dc9..c4a3ce2d6b 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -17,6 +17,7 @@ #include "taos.h" #include "tdef.h" #include "types.h" +#include "tgrant.h" #define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE) #define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE) @@ -188,22 +189,7 @@ static const SSysDbTableSchema userUsersSchema[] = { {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; -static const SSysDbTableSchema grantsSchema[] = { - {.name = "version", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "expire time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "storage(GB)", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "databases", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "users", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "accounts", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "connections", .bytes = 11 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "streams", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "cpu cores", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "speed(PPS)", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "querytime", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, -}; +GRANTS_SCHEMA; static const SSysDbTableSchema vgroupsSchema[] = { {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 6f4a3060ed..41e3917937 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -19,6 +19,9 @@ #include "tconfig.h" #include "tdatablock.h" #include "tlog.h" +#include "tgrant.h" + +GRANT_CFG_DECLARE; SConfig *tsCfg = NULL; @@ -441,6 +444,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "ttlPushInterval", tsTtlPushInterval, 1, 100000, 1) != 0) return -1; if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1; + GRANT_CFG_ADD; return 0; } @@ -590,7 +594,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { if (tsQueryBufferSize >= 0) { tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } - + GRANT_CFG_GET; return 0; } @@ -603,6 +607,7 @@ void taosLocalCfgForbiddenToChange(char* name, bool* forbidden) { *forbidden = true; return; } + GRANT_CFG_CHECK; *forbidden = false; } diff --git a/source/dnode/mgmt/mgmt_dnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_dnode/CMakeLists.txt index a4268fc9f0..fdd0830a58 100644 --- a/source/dnode/mgmt/mgmt_dnode/CMakeLists.txt +++ b/source/dnode/mgmt/mgmt_dnode/CMakeLists.txt @@ -1,8 +1,12 @@ aux_source_directory(src MGMT_DNODE) add_library(mgmt_dnode STATIC ${MGMT_DNODE}) +if (DEFINED GRANT_CFG_INCLUDE_DIR) + add_definitions(-DGRANTS_CFG) +endif() target_include_directories( mgmt_dnode PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PUBLIC "${GRANT_CFG_INCLUDE_DIR}" ) target_link_libraries( mgmt_dnode node_util diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 27a4056249..dd98816161 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "dmInt.h" #include "systable.h" +#include "tgrant.h" extern SConfig *tsCfg; @@ -223,6 +224,7 @@ int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) { for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) { SConfigItem *pItem = taosArrayGet(tsCfg->array, i); + GRANT_CFG_SKIP; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, c++); colDataAppend(pColInfo, i, (const char *)&dnodeId, false); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index a76b457422..2ff76f937d 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -19,6 +19,7 @@ #include "scheduler.h" #include "tdatablock.h" #include "tglobal.h" +#include "tgrant.h" extern SConfig* tsCfg; @@ -563,7 +564,7 @@ int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) { for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) { SConfigItem* pItem = taosArrayGet(tsCfg->array, i); - + GRANT_CFG_SKIP; char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, c++); diff --git a/source/util/CMakeLists.txt b/source/util/CMakeLists.txt index 8553d714fc..8f3bd42a47 100644 --- a/source/util/CMakeLists.txt +++ b/source/util/CMakeLists.txt @@ -1,10 +1,15 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c") aux_source_directory(src UTIL_SRC) add_library(util STATIC ${UTIL_SRC}) +if (DEFINED GRANT_CFG_INCLUDE_DIR) + add_definitions(-DGRANTS_CFG) +endif() target_include_directories( util PUBLIC "${TD_SOURCE_DIR}/include/util" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${TD_SOURCE_DIR}/include/common" + PRIVATE "${GRANT_CFG_INCLUDE_DIR}" ) target_link_libraries( util diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index ab7e30bab2..fdb397561d 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -21,6 +21,7 @@ #include "tenv.h" #include "cJSON.h" #include "tjson.h" +#include "tgrant.h" #define CFG_NAME_PRINT_LEN 24 #define CFG_SRC_PRINT_LEN 12 @@ -301,6 +302,7 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, } int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype) { + GRANT_CFG_SET; SConfigItem *pItem = cfgGetItem(pCfg, name); if (pItem == NULL) { return -1; -- GitLab