From 63f825a7e6e6f3f44044e1f06f19d6c7413f3ac9 Mon Sep 17 00:00:00 2001 From: slguan Date: Fri, 27 Mar 2020 15:06:31 +0800 Subject: [PATCH] [TD-61] --- CMakeLists.txt | 1 + src/inc/mnode.h | 11 +++++------ src/mnode/inc/mgmtDb.h | 1 + src/mnode/inc/mgmtDnode.h | 1 + src/mnode/inc/mgmtSdb.h | 1 + src/mnode/inc/mgmtUser.h | 2 ++ src/mnode/src/mgmtDb.c | 17 +++++++++++++++++ src/mnode/src/mgmtDnode.c | 1 - src/mnode/src/mgmtUser.c | 30 ++++++++++++++++++++++++++++-- 9 files changed, 56 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c8b4f6d6f..6ce6338700 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ SET(CMAKE_VERBOSE_MAKEFILE ON) SET(TD_CLUSTER FALSE) SET(TD_ACCOUNT FALSE) +SET(TD_GRANT FALSE) SET(TD_COVER FALSE) SET(TD_PAGMODE_LITE FALSE) SET(TD_GODLL FALSE) diff --git a/src/inc/mnode.h b/src/inc/mnode.h index 2a5f298afd..adb1f27885 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -38,6 +38,10 @@ extern "C" { #include "ttimer.h" #include "tutil.h" +struct _vg_obj; +struct _db_obj; +struct _acctObj; + typedef struct { int32_t mnodeId; uint32_t privateIp; @@ -103,8 +107,6 @@ typedef struct { int8_t dirty; } STableInfo; -struct _vg_obj; - typedef struct SSuperTableObj { STableInfo info; uint64_t uid; @@ -137,8 +139,6 @@ typedef struct { SSuperTableObj *superTable; } SChildTableObj; -struct _db_obj; - typedef struct _vg_obj { uint32_t vgId; char dbName[TSDB_DB_NAME_LEN + 1]; @@ -170,10 +170,9 @@ typedef struct _db_obj { int32_t numOfSuperTables; SVgObj *pHead; SVgObj *pTail; + struct _acctObj *pAcct; } SDbObj; -struct _acctObj; - typedef struct _user_obj { char user[TSDB_USER_LEN + 1]; char pass[TSDB_KEY_LEN + 1]; diff --git a/src/mnode/inc/mgmtDb.h b/src/mnode/inc/mgmtDb.h index 27918b9cf9..decf25a5c1 100644 --- a/src/mnode/inc/mgmtDb.h +++ b/src/mnode/inc/mgmtDb.h @@ -28,6 +28,7 @@ void mgmtCleanUpDbs(); SDbObj *mgmtGetDb(char *db); SDbObj *mgmtGetDbByTableId(char *db); bool mgmtCheckIsMonitorDB(char *db, char *monitordb); +void mgmtDropAllDbs(SAcctObj *pAcct); // util func void mgmtAddSuperTableIntoDb(SDbObj *pDb); diff --git a/src/mnode/inc/mgmtDnode.h b/src/mnode/inc/mgmtDnode.h index 4dc82fefe3..0929926c68 100644 --- a/src/mnode/inc/mgmtDnode.h +++ b/src/mnode/inc/mgmtDnode.h @@ -25,6 +25,7 @@ int32_t mgmtInitDnodes(); void mgmtCleanUpDnodes(); int32_t mgmtGetDnodesNum(); int32_t mgmtUpdateDnode(SDnodeObj *pDnode); +void * mgmtGetNextDnode(SShowObj *pShow, SDnodeObj **pDnode); SDnodeObj* mgmtGetDnode(int32_t dnodeId); SDnodeObj* mgmtGetDnodeByIp(uint32_t ip); diff --git a/src/mnode/inc/mgmtSdb.h b/src/mnode/inc/mgmtSdb.h index f291e93418..a598a21173 100644 --- a/src/mnode/inc/mgmtSdb.h +++ b/src/mnode/inc/mgmtSdb.h @@ -63,6 +63,7 @@ int32_t sdbUpdateRow(SSdbOperDesc *pOper); void *sdbGetRow(void *handle, void *key); void *sdbFetchRow(void *handle, void *pNode, void **ppRow); int64_t sdbGetNumOfRows(void *handle); +int64_t sdbGetId(void *handle); uint64_t sdbGetVersion(); #ifdef __cplusplus diff --git a/src/mnode/inc/mgmtUser.h b/src/mnode/inc/mgmtUser.h index 465b8e4f96..ff3bfa3be6 100644 --- a/src/mnode/inc/mgmtUser.h +++ b/src/mnode/inc/mgmtUser.h @@ -25,6 +25,8 @@ int32_t mgmtInitUsers(); void mgmtCleanUpUsers(); SUserObj *mgmtGetUser(char *name); SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp); +int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); +void mgmtDropAllUsers(SAcctObj *pAcct); #ifdef __cplusplus } diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 8c8173f781..c086e0a07e 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -899,3 +899,20 @@ static void mgmtProcessDropDbMsg(SQueuedMsg *pMsg) { newMsg->ahandle = pDb; taosTmrReset(mgmtDropDb, 10, newMsg, tsMgmtTmr, &tmpTmr); } + +void mgmtDropAllDbs(SAcctObj *pAcct) { + int32_t numOfDbs = 0; + SDbObj *pDb = NULL; + + while (1) { + void *pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb); + if (pDb == NULL) break; + + if (pDb->pAcct == pAcct) { + mgmtSetDbDirty(pDb); + numOfDbs++; + } + } + + mTrace("acct:%s, all dbs is is set dirty", pAcct->acctId, numOfDbs); +} \ No newline at end of file diff --git a/src/mnode/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c index 291cbe8a48..d14c9ac17a 100644 --- a/src/mnode/src/mgmtDnode.c +++ b/src/mnode/src/mgmtDnode.c @@ -36,7 +36,6 @@ void * (*mgmtGetNextDnodeFp)(SShowObj *pShow, SDnodeObj **pDnode) = NULL; void (*mgmtSetDnodeUnRemoveFp)(SDnodeObj *pDnode) = NULL; static SDnodeObj tsDnodeObj = {0}; -static void * mgmtGetNextDnode(SShowObj *pShow, SDnodeObj **pDnode); static bool mgmtCheckConfigShow(SGlobalConfig *cfg); static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn); diff --git a/src/mnode/src/mgmtUser.c b/src/mnode/src/mgmtUser.c index dc2418efd9..ce6339e0dc 100644 --- a/src/mnode/src/mgmtUser.c +++ b/src/mnode/src/mgmtUser.c @@ -28,7 +28,6 @@ static void *tsUserSdb = NULL; static int32_t tsUserUpdateSize = 0; -static int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); static int32_t mgmtDropUser(SAcctObj *pAcct, char *name); static int32_t mgmtUpdateUser(SUserObj *pUser); static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); @@ -155,7 +154,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) { return code; } -static int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { +int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) { int32_t code = mgmtCheckUserLimit(pAcct); if (code != 0) { return code; @@ -482,3 +481,30 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) { mgmtSendSimpleResp(pMsg->thandle, code); } + +void mgmtDropAllUsers(SAcctObj *pAcct) { + void *pNode = NULL; + void *pLastNode = NULL; + int32_t numOfUsers = 0; + int32_t acctNameLen = strlen(pAcct->user); + SUserObj *pUser = NULL; + + while (1) { + pNode = sdbFetchRow(tsUserSdb, pNode, (void **)&pUser); + if (pUser == NULL) break; + + if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) { + SSdbOperDesc oper = { + .type = SDB_OPER_TYPE_LOCAL, + .table = tsUserSdb, + .pObj = pUser, + }; + sdbDeleteRow(&oper); + pNode = pLastNode; + numOfUsers++; + continue; + } + } + + mTrace("acct:%s, all users is dropped from sdb", pAcct->acctId, numOfUsers); +} \ No newline at end of file -- GitLab