diff --git a/src/mnode/inc/mnodeDnode.h b/src/mnode/inc/mnodeDnode.h index f95a163d838fc10ea9bb9acadef7bd9df7a83769..9e21f8f56ae5942382a162a9a2c9a4eac12f5908 100644 --- a/src/mnode/inc/mnodeDnode.h +++ b/src/mnode/inc/mnodeDnode.h @@ -47,7 +47,7 @@ void mnodeDecDnodeRef(SDnodeObj *pDnode); void * mnodeGetDnode(int32_t dnodeId); void * mnodeGetDnodeByEp(char *ep); void mnodeUpdateDnode(SDnodeObj *pDnode); -int32_t mnodeDropDnode(SDnodeObj *pDnode); +int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg); extern int32_t tsAccessSquence; diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 21fcdc102c0e8725109203cb72f886d759f301c2..7e0eb8ffc9bde8579eb9fc8d464ec5fc08c567b2 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -366,12 +366,13 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { - tfree(pDb); - return code; + tfree(pDb);; } else { mLPrint("db:%s, is created by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); - return TSDB_CODE_MND_ACTION_IN_PROGRESS; + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } + + return code; } bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { @@ -931,15 +932,13 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter, void *pMsg) { .cb = mnodeAlterDbCb }; - int32_t code = sdbUpdateRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - return code; - } else { - return TSDB_CODE_MND_ACTION_IN_PROGRESS; + code = sdbUpdateRow(&oper); + if (code == TSDB_CODE_SUCCESS) { + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } } - return TSDB_CODE_SUCCESS; + return code; } static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { @@ -967,12 +966,12 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { }; int32_t code = sdbDeleteRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - return code; - } else { + if (code == TSDB_CODE_SUCCESS) { mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); - return TSDB_CODE_MND_ACTION_IN_PROGRESS; + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } + + return code; } static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) { diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index b6721405631a3928661c876bb0cc0574e2ef4892..816bcc6c5c8a1b69db0b03f6d184b7eb0f47154b 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -44,7 +44,7 @@ static int32_t tsDnodeUpdateSize = 0; extern void * tsMnodeSdb; extern void * tsVgroupSdb; -static int32_t mnodeCreateDnode(char *ep); +static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg); static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg); @@ -118,7 +118,7 @@ static int32_t mnodeDnodeActionRestored() { int32_t numOfRows = sdbGetNumOfRows(tsDnodeSdb); if (numOfRows <= 0 && dnodeIsFirstDeploy()) { mPrint("dnode first deploy, create dnode:%s", tsLocalEp); - mnodeCreateDnode(tsLocalEp); + mnodeCreateDnode(tsLocalEp, NULL); SDnodeObj *pDnode = mnodeGetDnodeByEp(tsLocalEp); mnodeAddMnode(pDnode->dnodeId); mnodeDecDnodeRef(pDnode); @@ -369,7 +369,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } -static int32_t mnodeCreateDnode(char *ep) { +static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { int32_t grantCode = grantCheck(TSDB_GRANT_DNODE); if (grantCode != TSDB_CODE_SUCCESS) { return grantCode; @@ -393,7 +393,8 @@ static int32_t mnodeCreateDnode(char *ep) { .type = SDB_OPER_GLOBAL, .table = tsDnodeSdb, .pObj = pDnode, - .rowSize = sizeof(SDnodeObj) + .rowSize = sizeof(SDnodeObj), + .pMsg = pMsg }; int32_t code = sdbInsertRow(&oper); @@ -401,30 +402,32 @@ static int32_t mnodeCreateDnode(char *ep) { int dnodeId = pDnode->dnodeId; tfree(pDnode); mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code)); - return TSDB_CODE_MND_SDB_ERROR; + } else { + mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code)); + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } - mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code)); return code; } -int32_t mnodeDropDnode(SDnodeObj *pDnode) { +int32_t mnodeDropDnode(SDnodeObj *pDnode, void *pMsg) { SSdbOper oper = { .type = SDB_OPER_GLOBAL, .table = tsDnodeSdb, - .pObj = pDnode + .pObj = pDnode, + .pMsg = pMsg }; - int32_t code = sdbDeleteRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_MND_SDB_ERROR; + int32_t code = sdbDeleteRow(&oper); + if (code == TSDB_CODE_SUCCESS) { + mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } - mLPrint("dnode:%d, is dropped from cluster, result:%s", pDnode->dnodeId, tstrerror(code)); return code; } -static int32_t mnodeDropDnodeByEp(char *ep) { +static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) { SDnodeObj *pDnode = mnodeGetDnodeByEp(ep); if (pDnode == NULL) { mError("dnode:%s, is not exist", ep); @@ -439,7 +442,7 @@ static int32_t mnodeDropDnodeByEp(char *ep) { mPrint("dnode:%d, start to drop it", pDnode->dnodeId); #ifndef _SYNC - return mnodeDropDnode(pDnode); + return mnodeDropDnode(pDnode, pMsg); #else return balanceDropDnode(pDnode); #endif @@ -451,17 +454,7 @@ static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) { if (strcmp(pMsg->pUser->user, "root") != 0) { return TSDB_CODE_MND_NO_RIGHTS; } else { - int32_t code = mnodeCreateDnode(pCreate->ep); - - if (code == TSDB_CODE_SUCCESS) { - SDnodeObj *pDnode = mnodeGetDnodeByEp(pCreate->ep); - mLPrint("dnode:%d, %s is created by %s", pDnode->dnodeId, pCreate->ep, pMsg->pUser->user); - mnodeDecDnodeRef(pDnode); - } else { - mError("failed to create dnode:%s, reason:%s", pCreate->ep, tstrerror(code)); - } - - return code; + return mnodeCreateDnode(pCreate->ep, pMsg); } } @@ -471,15 +464,7 @@ static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) { if (strcmp(pMsg->pUser->user, "root") != 0) { return TSDB_CODE_MND_NO_RIGHTS; } else { - int32_t code = mnodeDropDnodeByEp(pDrop->ep); - - if (code == TSDB_CODE_SUCCESS) { - mLPrint("dnode:%s is dropped by %s", pDrop->ep, pMsg->pUser->user); - } else { - mError("failed to drop dnode:%s, reason:%s", pDrop->ep, tstrerror(code)); - } - - return code; + return mnodeDropDnodeByEp(pDrop->ep, pMsg); } } diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 57587fb65bf8bde44b08b296a98274ca39d24fd2..10ed4e1da2042cf6e6815f58d4caec034bba9fd3 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -181,12 +181,12 @@ static int32_t mnodeUpdateUser(SUserObj *pUser, void *pMsg) { }; int32_t code = sdbUpdateRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - return code; - } else { + if (code == TSDB_CODE_SUCCESS) { mLPrint("user:%s, is altered by %s", pUser->user, mnodeGetUserFromMsg(pMsg)); - return TSDB_CODE_MND_ACTION_IN_PROGRESS; + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } + + return code; } int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { @@ -237,11 +237,12 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pUser); - return code; } else { mLPrint("user:%s, is created by %s", pUser->user, mnodeGetUserFromMsg(pMsg)); - return TSDB_CODE_MND_ACTION_IN_PROGRESS; + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } + + return code; } static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) { @@ -253,12 +254,12 @@ static int32_t mnodeDropUser(SUserObj *pUser, void *pMsg) { }; int32_t code = sdbDeleteRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - return code; - } else { + if (code == TSDB_CODE_SUCCESS) { mLPrint("user:%s, is dropped by %s", pUser->user, mnodeGetUserFromMsg(pMsg)); - return TSDB_CODE_MND_ACTION_IN_PROGRESS; + if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } + + return code; } static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {