Merge pull request #26705 from taosdata/fix/TD-30989-mnode7
fix/TD-30989
This commit is contained in:
commit
d88b33bbab
|
@ -31,17 +31,18 @@ static bool mndCheckRetrieveFinished(SShowObj *pShow);
|
|||
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq);
|
||||
|
||||
int32_t mndInitShow(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
|
||||
pMgmt->cache = taosCacheInit(TSDB_DATA_TYPE_INT, 5000, true, (__cache_free_fn_t)mndFreeShowObj, "show");
|
||||
if (pMgmt->cache == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to alloc show cache since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to alloc show cache since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveSysTableReq);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
void mndCleanupShow(SMnode *pMnode) {
|
||||
|
@ -212,6 +213,7 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
SShowObj *pShow = NULL;
|
||||
|
@ -220,10 +222,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
int32_t rowsRead = 0;
|
||||
mDebug("mndProcessRetrieveSysTableReq start");
|
||||
SRetrieveTableReq retrieveReq = {0};
|
||||
if (tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tDeserializeSRetrieveTableReq(pReq->pCont, pReq->contLen, &retrieveReq));
|
||||
|
||||
mDebug("process to retrieve systable req db:%s, tb:%s", retrieveReq.db, retrieveReq.tb);
|
||||
|
||||
|
@ -232,17 +231,17 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
if (pMeta == NULL) {
|
||||
pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
|
||||
if (pMeta == NULL) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
pShow = mndCreateShowObj(pMnode, &retrieveReq);
|
||||
if (pShow == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to process show-meta req since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to process show-meta req since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pShow->pMeta = pMeta;
|
||||
|
@ -250,9 +249,9 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
} else {
|
||||
pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
|
||||
if (pShow == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_SHOWOBJ;
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_INVALID_SHOWOBJ;
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,9 +263,9 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type];
|
||||
if (retrieveFp == NULL) {
|
||||
mndReleaseShowObj(pShow, false);
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type);
|
||||
|
@ -275,14 +274,16 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
} else {
|
||||
memcpy(pReq->info.conn.user, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER) + 1);
|
||||
}
|
||||
if (retrieveReq.db[0] && mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db) != 0) {
|
||||
return -1;
|
||||
code = -1;
|
||||
if (retrieveReq.db[0] &&
|
||||
(code = mndCheckShowPrivilege(pMnode, pReq->info.conn.user, pShow->type, retrieveReq.db)) != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (pShow->type == TSDB_MGMT_TABLE_USER_FULL) {
|
||||
if(strcmp(pReq->info.conn.user, "root") != 0){
|
||||
mError("The operation is not permitted, user:%s, pShow->type:%d", pReq->info.conn.user, pShow->type);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,11 +309,11 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
} else {
|
||||
rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead);
|
||||
if (rowsRead < 0) {
|
||||
terrno = rowsRead;
|
||||
code = rowsRead;
|
||||
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
|
||||
mndReleaseShowObj(pShow, true);
|
||||
blockDataDestroy(pBlock);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pBlock->info.rows = rowsRead;
|
||||
|
@ -325,10 +326,10 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
||||
if (pRsp == NULL) {
|
||||
mndReleaseShowObj(pShow, false);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, tstrerror(code));
|
||||
blockDataDestroy(pBlock);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRsp->handle = htobe64(pShow->id);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -170,38 +170,54 @@ static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeUndoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pUndoRaw = mndSnodeActionEncode(pObj);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pUndoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SDCreateSnodeReq createReq = {0};
|
||||
createReq.dnodeId = pDnode->id;
|
||||
|
||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &createReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
|
||||
|
||||
|
@ -212,23 +228,24 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
|||
action.msgType = TDMT_DND_CREATE_SNODE;
|
||||
action.acceptableCode = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SDDropSnodeReq dropReq = {0};
|
||||
dropReq.dnodeId = pDnode->id;
|
||||
|
||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||
|
||||
|
@ -239,12 +256,12 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
|||
action.msgType = TDMT_DND_DROP_SNODE;
|
||||
action.acceptableCode = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendUndoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndCreateSnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) {
|
||||
|
@ -256,23 +273,27 @@ static int32_t mndCreateSnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
|||
snodeObj.updateTime = snodeObj.createdTime;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-snode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
mInfo("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId);
|
||||
|
||||
if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSnodeUndoLogs(pTrans, &snodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetCreateSnodeRedoLogs(pTrans, &snodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateSnodeUndoLogs(pTrans, &snodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateSnodeCommitLogs(pTrans, &snodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -282,32 +303,27 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
|
|||
SDnodeObj *pDnode = NULL;
|
||||
SMCreateSnodeReq createReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||
|
||||
mInfo("snode:%d, start to create", createReq.dnodeId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_SNODE) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_SNODE), NULL, _OVER);
|
||||
|
||||
// pObj = mndAcquireSnode(pMnode, createReq.dnodeId);
|
||||
// if (pObj != NULL) {
|
||||
// terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST;
|
||||
// goto _OVER;
|
||||
// } else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) {
|
||||
// goto _OVER;
|
||||
// }
|
||||
// pObj = mndAcquireSnode(pMnode, createReq.dnodeId);
|
||||
// if (pObj != NULL) {
|
||||
// terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST;
|
||||
// goto _OVER;
|
||||
// } else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) {
|
||||
// goto _OVER;
|
||||
// }
|
||||
|
||||
if (sdbGetSize(pMnode->pSdb, SDB_SNODE) >= 1){
|
||||
terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST;
|
||||
code = TSDB_CODE_MND_SNODE_ALREADY_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -316,41 +332,52 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
|
|||
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
mError("snode:%d, failed to create since %s", createReq.dnodeId, terrstr());
|
||||
return -1;
|
||||
mError("snode:%d, failed to create since %s", createReq.dnodeId, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
// mndReleaseSnode(pMnode, pObj);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SDDropSnodeReq dropReq = {0};
|
||||
dropReq.dnodeId = pDnode->id;
|
||||
|
||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||
|
||||
|
@ -361,20 +388,20 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn
|
|||
action.msgType = TDMT_DND_DROP_SNODE;
|
||||
action.acceptableCode = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj, bool force) {
|
||||
if (pObj == NULL) return 0;
|
||||
if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropSnodeRedoLogs(pTrans, pObj));
|
||||
TAOS_CHECK_RETURN(mndSetDropSnodeCommitLogs(pTrans, pObj));
|
||||
if (!force) {
|
||||
if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -383,18 +410,22 @@ static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) {
|
|||
int32_t code = -1;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-snode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
mInfo("trans:%d, used to drop snode:%d", pTrans->id, pObj->id);
|
||||
if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -403,23 +434,20 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
|||
SSnodeObj *pObj = NULL;
|
||||
SMDropSnodeReq dropReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
|
||||
|
||||
mInfo("snode:%d, start to drop", dropReq.dnodeId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_SNODE) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_SNODE), NULL, _OVER);
|
||||
|
||||
if (dropReq.dnodeId <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pObj = mndAcquireSnode(pMnode, dropReq.dnodeId);
|
||||
if (pObj == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -429,12 +457,12 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
|||
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
mError("snode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
|
||||
mError("snode:%d, failed to drop since %s", dropReq.dnodeId, tstrerror(code));
|
||||
}
|
||||
|
||||
mndReleaseSnode(pMnode, pObj);
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveSnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
|
Loading…
Reference in New Issue