提交 19d54f6f 编写于 作者: S Shengliang Guan

TD-10431 user update

上级 5252e177
...@@ -125,7 +125,8 @@ typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyTy ...@@ -125,7 +125,8 @@ typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyTy
typedef enum { typedef enum {
SDB_STATUS_CREATING = 1, SDB_STATUS_CREATING = 1,
SDB_STATUS_READY = 2, SDB_STATUS_READY = 2,
SDB_STATUS_DROPPED = 3 SDB_STATUS_DROPPING = 3,
SDB_STATUS_DROPPED = 4
} ESdbStatus; } ESdbStatus;
typedef enum { typedef enum {
......
add_subdirectory(acct) # add_subdirectory(acct)
add_subdirectory(cluster) # add_subdirectory(cluster)
add_subdirectory(profile) # add_subdirectory(profile)
add_subdirectory(show) # add_subdirectory(show)
add_subdirectory(user)
...@@ -222,7 +222,6 @@ TEST_F(DndTestUser, CreateUser_01) { ...@@ -222,7 +222,6 @@ TEST_F(DndTestUser, CreateUser_01) {
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER; rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER;
sendMsg(pClient, &rpcMsg); sendMsg(pClient, &rpcMsg);
// taosMsleep(10000000);
SRpcMsg* pMsg = pClient->pRsp; SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
...@@ -277,34 +276,132 @@ TEST_F(DndTestUser, CreateUser_01) { ...@@ -277,34 +276,132 @@ TEST_F(DndTestUser, CreateUser_01) {
} }
} }
// TEST_F(DndTestUser, AlterUser) { TEST_F(DndTestUser, AlterUser_01) {
// ASSERT_NE(pClient, nullptr); ASSERT_NE(pClient, nullptr);
//--- drop user ---
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p2");
SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pReq;
rpcMsg.contLen = sizeof(SDropUserMsg);
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER;
sendMsg(pClient, &rpcMsg);
SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
//--- meta ---
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
pShow->type = TSDB_MGMT_TABLE_USER;
SRpcMsg showRpcMsg = {0};
showRpcMsg.pCont = pShow;
showRpcMsg.contLen = sizeof(SShowMsg);
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
sendMsg(pClient, &showRpcMsg);
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
STableMetaMsg* pMeta = &pShowRsp->tableMeta;
pMeta->numOfColumns = htons(pMeta->numOfColumns);
EXPECT_EQ(pMeta->numOfColumns, 4);
//--- retrieve ---
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
pRetrieve->showId = pShowRsp->showId;
SRpcMsg retrieveRpcMsg = {0};
retrieveRpcMsg.pCont = pRetrieve;
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
sendMsg(pClient, &retrieveRpcMsg);
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
EXPECT_EQ(pRetrieveRsp->numOfRows, 3);
char* pData = pRetrieveRsp->data;
int32_t pos = 0;
char* strVal = NULL;
//--- name ---
{
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "u1");
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "root");
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "_root");
}
}
// SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg)); TEST_F(DndTestUser, DropUser_01) {
ASSERT_NE(pClient, nullptr);
// SRpcMsg rpcMsg = {0}; //--- drop user ---
// rpcMsg.pCont = pReq; SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
// rpcMsg.contLen = sizeof(SAlterUserMsg); strcpy(pReq->user, "u1");
// rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_ACCT;
// sendMsg(pClient, &rpcMsg); SRpcMsg rpcMsg = {0};
// SRpcMsg* pMsg = pClient->pRsp; rpcMsg.pCont = pReq;
// ASSERT_NE(pMsg, nullptr); rpcMsg.contLen = sizeof(SDropUserMsg);
// ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER;
// }
// TEST_F(DndTestUser, DropUser) { sendMsg(pClient, &rpcMsg);
// ASSERT_NE(pClient, nullptr); SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
// SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg)); //--- meta ---
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
pShow->type = TSDB_MGMT_TABLE_USER;
SRpcMsg showRpcMsg = {0};
showRpcMsg.pCont = pShow;
showRpcMsg.contLen = sizeof(SShowMsg);
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
// SRpcMsg rpcMsg = {0}; sendMsg(pClient, &showRpcMsg);
// rpcMsg.pCont = pReq; SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
// rpcMsg.contLen = sizeof(SDropUserMsg); STableMetaMsg* pMeta = &pShowRsp->tableMeta;
// rpcMsg.msgType = TSDB_MSG_TYPE_DROP_ACCT; pMeta->numOfColumns = htons(pMeta->numOfColumns);
EXPECT_EQ(pMeta->numOfColumns, 4);
// sendMsg(pClient, &rpcMsg); //--- retrieve ---
// SRpcMsg* pMsg = pClient->pRsp; SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
// ASSERT_NE(pMsg, nullptr); pRetrieve->showId = pShowRsp->showId;
// ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); SRpcMsg retrieveRpcMsg = {0};
// } retrieveRpcMsg.pCont = pRetrieve;
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
sendMsg(pClient, &retrieveRpcMsg);
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
EXPECT_EQ(pRetrieveRsp->numOfRows, 2);
char* pData = pRetrieveRsp->data;
int32_t pos = 0;
char* strVal = NULL;
//--- name ---
{
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "root");
pos += sizeof(VarDataLenT);
strVal = (char*)(pData + pos);
pos += TSDB_USER_LEN;
EXPECT_STREQ(strVal, "_root");
}
}
\ No newline at end of file
...@@ -24,7 +24,7 @@ static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct); ...@@ -24,7 +24,7 @@ static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct);
static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw); static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw);
static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct); static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct);
static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct); static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct);
static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct); static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct);
static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg);
static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg);
static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg);
...@@ -131,15 +131,15 @@ static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { ...@@ -131,15 +131,15 @@ static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
return 0; return 0;
} }
static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct) { static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) {
mTrace("acct:%s, perform update action", pDstAcct->acct); mTrace("acct:%s, perform update action", pOldAcct->acct);
memcpy(pDstAcct->acct, pSrcAcct->acct, TSDB_USER_LEN); memcpy(pOldAcct->acct, pNewAcct->acct, TSDB_USER_LEN);
pDstAcct->createdTime = pSrcAcct->createdTime; pOldAcct->createdTime = pNewAcct->createdTime;
pDstAcct->updateTime = pSrcAcct->updateTime; pOldAcct->updateTime = pNewAcct->updateTime;
pDstAcct->acctId = pSrcAcct->acctId; pOldAcct->acctId = pNewAcct->acctId;
pDstAcct->status = pSrcAcct->status; pOldAcct->status = pNewAcct->status;
pDstAcct->cfg = pSrcAcct->cfg; pOldAcct->cfg = pNewAcct->cfg;
return 0; return 0;
} }
......
...@@ -24,7 +24,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster); ...@@ -24,7 +24,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw); static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster); static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster);
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster); static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster);
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pSrcCluster, SClusterObj *pDstCluster); static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster);
static int32_t mndCreateDefaultCluster(SMnode *pMnode); static int32_t mndCreateDefaultCluster(SMnode *pMnode);
static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
static int32_t mndRetrieveClusters(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); static int32_t mndRetrieveClusters(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
...@@ -107,8 +107,8 @@ static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) { ...@@ -107,8 +107,8 @@ static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
return 0; return 0;
} }
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pSrcCluster, SClusterObj *pDstCluster) { static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster) {
mTrace("cluster:%d, perform update action", pDstCluster->id); mTrace("cluster:%d, perform update action", pOldCluster->id);
return 0; return 0;
} }
......
...@@ -101,13 +101,13 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) { ...@@ -101,13 +101,13 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
return 0; return 0;
} }
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pSrcDnode, SDnodeObj *pDstDnode) { static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode) {
mTrace("dnode:%d, perform update action", pDstDnode->id); mTrace("dnode:%d, perform update action", pOldDnode->id);
pDstDnode->id = pSrcDnode->id; pOldDnode->id = pNewDnode->id;
pDstDnode->createdTime = pSrcDnode->createdTime; pOldDnode->createdTime = pNewDnode->createdTime;
pDstDnode->updateTime = pSrcDnode->updateTime; pOldDnode->updateTime = pNewDnode->updateTime;
pDstDnode->port = pSrcDnode->port; pOldDnode->port = pNewDnode->port;
memcpy(pDstDnode->fqdn, pSrcDnode->fqdn, TSDB_FQDN_LEN); memcpy(pOldDnode->fqdn, pNewDnode->fqdn, TSDB_FQDN_LEN);
return 0; return 0;
} }
......
...@@ -81,11 +81,11 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) { ...@@ -81,11 +81,11 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) {
return 0; return 0;
} }
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pSrcMnode, SMnodeObj *pDstMnode) { static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) {
mTrace("mnode:%d, perform update action", pDstMnode->id); mTrace("mnode:%d, perform update action", pOldMnode->id);
pDstMnode->id = pSrcMnode->id; pOldMnode->id = pNewMnode->id;
pDstMnode->createdTime = pSrcMnode->createdTime; pOldMnode->createdTime = pNewMnode->createdTime;
pDstMnode->updateTime = pSrcMnode->updateTime; pOldMnode->updateTime = pNewMnode->updateTime;
return 0; return 0;
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
static SSdbRaw *mndTransActionEncode(STrans *pTrans); static SSdbRaw *mndTransActionEncode(STrans *pTrans);
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw); static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans); static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans); static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOldTrans);
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans); static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans);
int32_t mndInitTrans(SMnode *pMnode) { int32_t mndInitTrans(SMnode *pMnode) {
...@@ -244,22 +244,22 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { ...@@ -244,22 +244,22 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
return 0; return 0;
} }
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) { static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) {
mTrace("trans:%d, perform update action, stage:%d", pTrans->id, pTrans->stage); mTrace("trans:%d, perform update action, stage:%d", pOldTrans->id, pNewTrans->stage);
SArray *pArray = pDstTrans->commitLogs; SArray *pArray = pOldTrans->commitLogs;
int32_t arraySize = taosArrayGetSize(pArray); int32_t arraySize = taosArrayGetSize(pArray);
for (int32_t i = 0; i < arraySize; ++i) { for (int32_t i = 0; i < arraySize; ++i) {
SSdbRaw *pRaw = taosArrayGetP(pArray, i); SSdbRaw *pRaw = taosArrayGetP(pArray, i);
int32_t code = sdbWrite(pSdb, pRaw); int32_t code = sdbWrite(pSdb, pRaw);
if (code != 0) { if (code != 0) {
mError("trans:%d, failed to write raw:%p to sdb since %s", pDstTrans->id, pRaw, terrstr()); mError("trans:%d, failed to write raw:%p to sdb since %s", pOldTrans->id, pRaw, terrstr());
return code; return code;
} }
} }
pDstTrans->stage = pTrans->stage; pOldTrans->stage = pNewTrans->stage;
return 0; return 0;
} }
......
...@@ -27,7 +27,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser); ...@@ -27,7 +27,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw); static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw);
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser);
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser);
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser); static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser);
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg); static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg);
static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg); static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg);
static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg); static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg);
...@@ -168,16 +168,16 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { ...@@ -168,16 +168,16 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
return 0; return 0;
} }
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) { static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) {
mTrace("user:%s, perform update action", pSrcUser->user); mTrace("user:%s, perform update action", pOldUser->user);
memcpy(pDstUser->user, pSrcUser->user, TSDB_USER_LEN); memcpy(pOldUser->user, pNewUser->user, TSDB_USER_LEN);
memcpy(pDstUser->pass, pSrcUser->pass, TSDB_KEY_LEN); memcpy(pOldUser->pass, pNewUser->pass, TSDB_KEY_LEN);
memcpy(pDstUser->acct, pSrcUser->acct, TSDB_USER_LEN); memcpy(pOldUser->acct, pNewUser->acct, TSDB_USER_LEN);
pDstUser->createdTime = pSrcUser->createdTime; pOldUser->createdTime = pNewUser->createdTime;
pDstUser->updateTime = pSrcUser->updateTime; pOldUser->updateTime = pNewUser->updateTime;
pDstUser->superAuth = pSrcUser->superAuth; pOldUser->superAuth = pNewUser->superAuth;
pDstUser->readAuth = pSrcUser->readAuth; pOldUser->readAuth = pNewUser->readAuth;
pDstUser->writeAuth = pSrcUser->writeAuth; pOldUser->writeAuth = pNewUser->writeAuth;
return 0; return 0;
} }
...@@ -243,6 +243,82 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, ...@@ -243,6 +243,82 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
return 0; return 0;
} }
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) {
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
if (pTrans == NULL) {
mError("user:%s, failed to update since %s", pOldUser->user, terrstr());
return -1;
}
mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user);
SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser);
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
SSdbRaw *pUndoRaw = mndUserActionEncode(pOldUser);
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
if (mndTransPrepare(pTrans) != 0) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
mndTransDrop(pTrans);
return 0;
}
static int32_t mndDropUser(SMnode *pMnode, SUserObj *pUser, SMnodeMsg *pMsg) {
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
if (pTrans == NULL) {
mError("user:%s, failed to drop since %s", pUser->user, terrstr());
return -1;
}
mDebug("trans:%d, used to drop user:%s", pTrans->id, pUser->user);
SSdbRaw *pRedoRaw = mndUserActionEncode(pUser);
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
SSdbRaw *pUndoRaw = mndUserActionEncode(pUser);
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
SSdbRaw *pCommitRaw = mndUserActionEncode(pUser);
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
if (mndTransPrepare(pTrans) != 0) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
mndTransDrop(pTrans);
return -1;
}
mndTransDrop(pTrans);
return 0;
}
static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pMsg->pMnode;
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
...@@ -288,15 +364,88 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { ...@@ -288,15 +364,88 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
} }
static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; SMnode *pMnode = pMsg->pMnode;
mError("failed to process alter user msg since %s", terrstr()); SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
return -1;
mDebug("user:%s, start to alter", pAlter->user);
if (pAlter->user[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
}
if (pAlter->pass[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
}
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pAlter->user);
if (pUser == NULL) {
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
}
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
if (pOperUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
}
SUserObj newUser = {0};
memcpy(&newUser, pUser, sizeof(SUserObj));
memset(pUser->pass, 0, sizeof(pUser->pass));
taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass);
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg);
sdbRelease(pMnode->pSdb, pOperUser);
if (code != 0) {
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1;
}
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) {
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; SMnode *pMnode = pMsg->pMnode;
mError("failed to process drop user msg since %s", terrstr()); SDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
return -1;
mDebug("user:%s, start to drop", pDrop->user);
if (pDrop->user[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
}
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pDrop->user);
if (pUser == NULL) {
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
}
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
if (pOperUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
}
int32_t code = mndDropUser(pMnode, pUser, pMsg);
sdbRelease(pMnode->pSdb, pOperUser);
if (code != 0) {
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1;
}
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
......
...@@ -52,8 +52,8 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * ...@@ -52,8 +52,8 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SRWLatch *pLock = &pSdb->locks[pRow->type]; SRWLatch *pLock = &pSdb->locks[pRow->type];
taosWLockLatch(pLock); taosWLockLatch(pLock);
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize); SSdbRow *pOldRow = taosHashGet(hash, pRow->pObj, keySize);
if (pDstRow != NULL) { if (pOldRow != NULL) {
taosWUnLockLatch(pLock); taosWUnLockLatch(pLock);
sdbFreeRow(pRow); sdbFreeRow(pRow);
return TSDB_CODE_SDB_OBJ_ALREADY_THERE; return TSDB_CODE_SDB_OBJ_ALREADY_THERE;
...@@ -85,28 +85,28 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * ...@@ -85,28 +85,28 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
return 0; return 0;
} }
static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) {
int32_t code = 0; int32_t code = 0;
SRWLatch *pLock = &pSdb->locks[pRow->type]; SRWLatch *pLock = &pSdb->locks[pNewRow->type];
taosRLockLatch(pLock); taosRLockLatch(pLock);
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); SSdbRow **ppOldRow = taosHashGet(hash, pNewRow->pObj, keySize);
if (ppDstRow == NULL || *ppDstRow == NULL) { if (ppOldRow == NULL || *ppOldRow == NULL) {
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
return sdbInsertRow(pSdb, hash, pRaw, pRow, keySize); return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize);
} }
SSdbRow *pDstRow = *ppDstRow; SSdbRow *pOldRow = *ppOldRow;
pDstRow->status = pRaw->status; pOldRow->status = pRaw->status;
taosRUnLockLatch(pLock); taosRUnLockLatch(pLock);
SdbUpdateFp updateFp = pSdb->updateFps[pRow->type]; SdbUpdateFp updateFp = pSdb->updateFps[pNewRow->type];
if (updateFp != NULL) { if (updateFp != NULL) {
code = (*updateFp)(pSdb, pRow->pObj, pDstRow->pObj); code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj);
} }
sdbFreeRow(pRow); sdbFreeRow(pNewRow);
return code; return code;
} }
...@@ -116,24 +116,24 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * ...@@ -116,24 +116,24 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SRWLatch *pLock = &pSdb->locks[pRow->type]; SRWLatch *pLock = &pSdb->locks[pRow->type];
taosWLockLatch(pLock); taosWLockLatch(pLock);
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); SSdbRow **ppOldRow = taosHashGet(hash, pRow->pObj, keySize);
if (ppDstRow == NULL || *ppDstRow == NULL) { if (ppOldRow == NULL || *ppOldRow == NULL) {
taosWUnLockLatch(pLock); taosWUnLockLatch(pLock);
sdbFreeRow(pRow); sdbFreeRow(pRow);
return TSDB_CODE_SDB_OBJ_NOT_THERE; return TSDB_CODE_SDB_OBJ_NOT_THERE;
} }
SSdbRow *pDstRow = *ppDstRow; SSdbRow *pOldRow = *ppOldRow;
pDstRow->status = pRaw->status; pOldRow->status = pRaw->status;
taosHashRemove(hash, pDstRow->pObj, keySize); taosHashRemove(hash, pOldRow->pObj, keySize);
taosWUnLockLatch(pLock); taosWUnLockLatch(pLock);
SdbDeleteFp deleteFp = pSdb->deleteFps[pDstRow->type]; SdbDeleteFp deleteFp = pSdb->deleteFps[pOldRow->type];
if (deleteFp != NULL) { if (deleteFp != NULL) {
code = (*deleteFp)(pSdb, pDstRow->pObj); code = (*deleteFp)(pSdb, pOldRow->pObj);
} }
sdbRelease(pSdb, pDstRow->pObj); sdbRelease(pSdb, pOldRow->pObj);
sdbFreeRow(pRow); sdbFreeRow(pRow);
return code; return code;
} }
...@@ -158,6 +158,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) { ...@@ -158,6 +158,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize); code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
break; break;
case SDB_STATUS_READY: case SDB_STATUS_READY:
case SDB_STATUS_DROPPING:
code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize); code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
break; break;
case SDB_STATUS_DROPPED: case SDB_STATUS_DROPPED:
...@@ -200,7 +201,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) { ...@@ -200,7 +201,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) {
case SDB_STATUS_CREATING: case SDB_STATUS_CREATING:
terrno = TSDB_CODE_SDB_OBJ_CREATING; terrno = TSDB_CODE_SDB_OBJ_CREATING;
break; break;
case SDB_STATUS_DROPPED: case SDB_STATUS_DROPPING:
terrno = TSDB_CODE_SDB_OBJ_DROPPING; terrno = TSDB_CODE_SDB_OBJ_DROPPING;
break; break;
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册