From 78031df22c43807b6b27d40dd992eaf20864d996 Mon Sep 17 00:00:00 2001 From: slguan Date: Tue, 31 Mar 2020 19:42:15 +0800 Subject: [PATCH] [TD-16] --- src/client/src/tscServer.c | 21 ++++- src/mnode/src/mgmtDb.c | 5 +- src/mnode/src/mgmtUser.c | 9 ++- tests/script/sh/exec_up.sh | 109 ++++++++++++++++++++++++++ tests/script/unique/account/basic.sim | 45 +++++++++++ tests/script/unique/testSuite.sim | 3 + 6 files changed, 185 insertions(+), 7 deletions(-) create mode 100755 tests/script/sh/exec_up.sh create mode 100644 tests/script/unique/account/basic.sim create mode 100644 tests/script/unique/testSuite.sim diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 111ebc4e8c..8b896fb90e 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1065,7 +1065,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_SUCCESS; } -int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { +int32_t tscBuildDropUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCMDropUserMsg); pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_USER; @@ -1082,6 +1082,23 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_SUCCESS; } +int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { + SSqlCmd *pCmd = &pSql->cmd; + pCmd->payloadLen = sizeof(SCMDropUserMsg); + pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_ACCT; + + if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { + tscError("%p failed to malloc for query msg", pSql); + return TSDB_CODE_CLI_OUT_OF_MEMORY; + } + + SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; + STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); + strcpy(pDropMsg->user, pTableMetaInfo->name); + + return TSDB_CODE_SUCCESS; +} + int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCMUseDbMsg); @@ -2550,7 +2567,7 @@ void tscInitMsgsFp() { tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAcctMsg; tscBuildMsg[TSDB_SQL_CREATE_TABLE] = tscBuildCreateTableMsg; - tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropAcctMsg; + tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropUserMsg; tscBuildMsg[TSDB_SQL_DROP_ACCT] = tscBuildDropAcctMsg; tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg; tscBuildMsg[TSDB_SQL_DROP_TABLE] = tscBuildDropTableMsg; diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 41e7a70276..5f28c30423 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -903,9 +903,10 @@ static void mgmtProcessDropDbMsg(SQueuedMsg *pMsg) { void mgmtDropAllDbs(SAcctObj *pAcct) { int32_t numOfDbs = 0; SDbObj *pDb = NULL; + void *pNode = NULL; while (1) { - void *pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb); + pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb); if (pDb == NULL) break; if (pDb->pAcct == pAcct) { @@ -914,5 +915,5 @@ void mgmtDropAllDbs(SAcctObj *pAcct) { } } - mTrace("acct:%s, all dbs is is set dirty", pAcct->acctId, numOfDbs); + mTrace("acct:%s, all dbs is is set dirty", pAcct->user, numOfDbs); } \ No newline at end of file diff --git a/src/mnode/src/mgmtUser.c b/src/mnode/src/mgmtUser.c index f4a0b4d82b..c497fd6e8f 100644 --- a/src/mnode/src/mgmtUser.c +++ b/src/mnode/src/mgmtUser.c @@ -61,7 +61,9 @@ static int32_t mgmtUserActionDelete(SSdbOperDesc *pOper) { SUserObj *pUser = pOper->pObj; SAcctObj *pAcct = acctGetAcct(pUser->acct); - acctRemoveUser(pAcct, pUser); + if (pAcct != NULL) { + acctRemoveUser(pAcct, pUser); + } return TSDB_CODE_SUCCESS; } @@ -448,7 +450,8 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) { return ; } - if (strcmp(pUser->user, "monitor") == 0 || (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { + if (strcmp(pUser->user, "monitor") == 0 || strcmp(pUser->user, pUser->acct) == 0 || + (strcmp(pUser->user + 1, pUser->acct) == 0 && pUser->user[0] == '_')) { mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_NO_RIGHTS); return ; } @@ -507,5 +510,5 @@ void mgmtDropAllUsers(SAcctObj *pAcct) { } } - mTrace("acct:%s, all users is dropped from sdb", pAcct->acctId, numOfUsers); + mTrace("acct:%s, all users:%d is dropped from sdb", pAcct->user, numOfUsers); } \ No newline at end of file diff --git a/tests/script/sh/exec_up.sh b/tests/script/sh/exec_up.sh new file mode 100755 index 0000000000..ee4aabc175 --- /dev/null +++ b/tests/script/sh/exec_up.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +# if [ $# != 4 || $# != 5 ]; then + # echo "argument list need input : " + # echo " -n nodeName" + # echo " -s start/stop" + # echo " -c clear" + # exit 1 +# fi + +NODE_NAME= +EXEC_OPTON= +CLEAR_OPTION="false" +while getopts "n:s:u:x:ct" arg +do + case $arg in + n) + NODE_NAME=$OPTARG + ;; + s) + EXEC_OPTON=$OPTARG + ;; + c) + CLEAR_OPTION="clear" + ;; + t) + SHELL_OPTION="true" + ;; + u) + USERS=$OPTARG + ;; + x) + SIGNAL=$OPTARG + ;; + ?) + echo "unkown argument" + ;; + esac +done + +SCRIPT_DIR=`dirname $0` +cd $SCRIPT_DIR/../ +SCRIPT_DIR=`pwd` + +cd ../../ +TAOS_DIR=`pwd` + +BUILD_DIR=$TAOS_DIR/../debug/build +SIM_DIR=$TAOS_DIR/sim +NODE_DIR=$SIM_DIR/$NODE_NAME +EXE_DIR=$BUILD_DIR/bin +CFG_DIR=$NODE_DIR/cfg +LOG_DIR=$NODE_DIR/log +DATA_DIR=$NODE_DIR/data +MGMT_DIR=$NODE_DIR/data/mgmt +TSDB_DIR=$NODE_DIR/data/tsdb + +TAOS_CFG=$NODE_DIR/cfg/taos.cfg + +echo ------------ $EXEC_OPTON $NODE_NAME + +TAOS_FLAG=$SIM_DIR/tsim/flag +if [ -f "$TAOS_FLAG" ]; then + EXE_DIR=/usr/local/bin/taos +fi + +if [ "$CLEAR_OPTION" = "clear" ]; then + echo rm -rf $MGMT_DIR $TSDB_DIR + rm -rf $TSDB_DIR + rm -rf $MGMT_DIR +fi + +if [ "$SHELL_OPTION" = "true" ]; then + if [ "$EXEC_OPTON" = "start" ]; then + echo "ExcuteCmd:" $EXE_DIR/taos -c $CFG_DIR -u $USERS -p + $EXE_DIR/taos -c $CFG_DIR -u $USERS -p + else + #relative path + RCFG_DIR=sim/$NODE_NAME/cfg + PID=`ps -ef|grep -v taosd | grep taos | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` + if [ -n "$PID" ]; then + sudo kill -9 $PID + fi + fi + return +fi + +if [ "$EXEC_OPTON" = "start" ]; then + echo "ExcuteCmd:" $EXE_DIR/taosd -c $CFG_DIR + nohup $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & + #TT=`date +%s` + #mkdir ${LOG_DIR}/${TT} + #echo valgrind --log-file=${LOG_DIR}/${TT}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR + #nohup valgrind --log-file=${LOG_DIR}/${TT}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & + +else + #relative path + RCFG_DIR=sim/$NODE_NAME/cfg + PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` + if [ -n "$PID" ]; then + if [ "$SIGNAL" = "SIGINT" ]; then + echo killed by signal + sudo kill -sigint $PID + else + sudo kill -9 $PID + fi + fi +fi + diff --git a/tests/script/unique/account/basic.sim b/tests/script/unique/account/basic.sim new file mode 100644 index 0000000000..6f64975ac2 --- /dev/null +++ b/tests/script/unique/account/basic.sim @@ -0,0 +1,45 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1 +system sh/exec_up.sh -n dnode1 -s start +sql connect + +print =============== show accounts +sql show accounts +if $rows != 1 then + return -1 +endi + +print $data00 $data01 $data02 + +print =============== create account1 +sql create account account1 PASS 'account1' +sql show accounts +if $rows != 2 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data22 + +print =============== create account2 +sql create account account2 PASS 'account2' +sql show accounts +if $rows != 3 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data22 +print $data20 $data11 $data22 + +print =============== drop account1 +sql drop account account1 +sql show accounts +if $rows != 2 then + return -1 +endi + +print $data00 $data01 $data02 +print $data10 $data11 $data22 + + diff --git a/tests/script/unique/testSuite.sim b/tests/script/unique/testSuite.sim new file mode 100644 index 0000000000..1782f3ccd5 --- /dev/null +++ b/tests/script/unique/testSuite.sim @@ -0,0 +1,3 @@ +################################# +run unique/account/basic.sim +################################## -- GitLab