refactor: format sma code
This commit is contained in:
parent
2383b316d7
commit
1d149e5540
|
@ -26,7 +26,6 @@ int32_t mndInitSma(SMnode *pMnode);
|
||||||
void mndCleanupSma(SMnode *pMnode);
|
void mndCleanupSma(SMnode *pMnode);
|
||||||
SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName);
|
SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName);
|
||||||
void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma);
|
void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma);
|
||||||
int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp *rsp, bool *exist);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ static int32_t mndProcessCompactDbReq(SNodeMsg *pReq);
|
||||||
static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity);
|
static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity);
|
||||||
static void mndCancelGetNextDb(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextDb(SMnode *pMnode, void *pIter);
|
||||||
static int32_t mndProcessGetDbCfgReq(SNodeMsg *pReq);
|
static int32_t mndProcessGetDbCfgReq(SNodeMsg *pReq);
|
||||||
static int32_t mndProcessGetIndexReq(SNodeMsg *pReq);
|
|
||||||
|
|
||||||
int32_t mndInitDb(SMnode *pMnode) {
|
int32_t mndInitDb(SMnode *pMnode) {
|
||||||
SSdbTable table = {
|
SSdbTable table = {
|
||||||
|
@ -63,7 +62,6 @@ int32_t mndInitDb(SMnode *pMnode) {
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_USE_DB, mndProcessUseDbReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_USE_DB, mndProcessUseDbReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_COMPACT_DB, mndProcessCompactDbReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_COMPACT_DB, mndProcessCompactDbReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_GET_DB_CFG, mndProcessGetDbCfgReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_GET_DB_CFG, mndProcessGetDbCfgReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_GET_INDEX, mndProcessGetIndexReq);
|
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DB, mndRetrieveDbs);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DB, mndRetrieveDbs);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_DB, mndCancelGetNextDb);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_DB, mndCancelGetNextDb);
|
||||||
|
@ -1543,49 +1541,3 @@ static void mndCancelGetNextDb(SMnode *pMnode, void *pIter) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessGetIndexReq(SNodeMsg *pReq) {
|
|
||||||
SUserIndexReq indexReq = {0};
|
|
||||||
SMnode *pMnode = pReq->pNode;
|
|
||||||
int32_t code = -1;
|
|
||||||
SUserIndexRsp rsp = {0};
|
|
||||||
bool exist = false;
|
|
||||||
|
|
||||||
if (tDeserializeSUserIndexReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &indexReq) != 0) {
|
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = mndProcessGetSmaReq(pMnode, &indexReq, &rsp, &exist);
|
|
||||||
if (code) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exist) {
|
|
||||||
// TODO GET INDEX FROM FULLTEXT
|
|
||||||
code = -1;
|
|
||||||
terrno = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
|
|
||||||
} else {
|
|
||||||
int32_t contLen = tSerializeSUserIndexRsp(NULL, 0, &rsp);
|
|
||||||
void *pRsp = rpcMallocCont(contLen);
|
|
||||||
if (pRsp == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
code = -1;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
tSerializeSUserIndexRsp(pRsp, contLen, &rsp);
|
|
||||||
|
|
||||||
pReq->pRsp = pRsp;
|
|
||||||
pReq->rspLen = contLen;
|
|
||||||
|
|
||||||
code = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_OVER:
|
|
||||||
if (code != 0) {
|
|
||||||
mError("failed to get index %s since %s", indexReq.indexFName, terrstr());
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq);
|
||||||
static int32_t mndProcessMDropSmaReq(SNodeMsg *pReq);
|
static int32_t mndProcessMDropSmaReq(SNodeMsg *pReq);
|
||||||
static int32_t mndProcessVCreateSmaRsp(SNodeMsg *pRsp);
|
static int32_t mndProcessVCreateSmaRsp(SNodeMsg *pRsp);
|
||||||
static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp);
|
static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp);
|
||||||
|
static int32_t mndProcessGetSmaReq(SNodeMsg *pReq);
|
||||||
static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||||
static void mndCancelGetNextSma(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextSma(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ int32_t mndInitSma(SMnode *pMnode) {
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_SMA, mndProcessMDropSmaReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_SMA, mndProcessMDropSmaReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndProcessVCreateSmaRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndProcessVCreateSmaRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndProcessVDropSmaRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndProcessVDropSmaRsp);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_GET_INDEX, mndProcessGetSmaReq);
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveSma);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndRetrieveSma);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelGetNextSma);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_INDEX, mndCancelGetNextSma);
|
||||||
|
@ -686,7 +688,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp *rsp, bool *exist) {
|
static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp *rsp, bool *exist) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SSmaObj *pSma = NULL;
|
SSmaObj *pSma = NULL;
|
||||||
|
|
||||||
|
@ -715,6 +717,51 @@ int32_t mndProcessGetSmaReq(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexR
|
||||||
}
|
}
|
||||||
|
|
||||||
mndReleaseSma(pMnode, pSma);
|
mndReleaseSma(pMnode, pSma);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessGetSmaReq(SNodeMsg *pReq) {
|
||||||
|
SUserIndexReq indexReq = {0};
|
||||||
|
SMnode *pMnode = pReq->pNode;
|
||||||
|
int32_t code = -1;
|
||||||
|
SUserIndexRsp rsp = {0};
|
||||||
|
bool exist = false;
|
||||||
|
|
||||||
|
if (tDeserializeSUserIndexReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &indexReq) != 0) {
|
||||||
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = mndGetSma(pMnode, &indexReq, &rsp, &exist);
|
||||||
|
if (code) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exist) {
|
||||||
|
// TODO GET INDEX FROM FULLTEXT
|
||||||
|
code = -1;
|
||||||
|
terrno = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
|
||||||
|
} else {
|
||||||
|
int32_t contLen = tSerializeSUserIndexRsp(NULL, 0, &rsp);
|
||||||
|
void *pRsp = rpcMallocCont(contLen);
|
||||||
|
if (pRsp == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
code = -1;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
tSerializeSUserIndexRsp(pRsp, contLen, &rsp);
|
||||||
|
|
||||||
|
pReq->pRsp = pRsp;
|
||||||
|
pReq->rspLen = contLen;
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to get index %s since %s", indexReq.indexFName, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
|
||||||
#define TSDB_VGROUP_VER_NUMBER 1
|
#define VGROUP_VER_NUMBER 1
|
||||||
#define TSDB_VGROUP_RESERVE_SIZE 64
|
#define VGROUP_RESERVE_SIZE 64
|
||||||
|
|
||||||
static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
||||||
static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup);
|
static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup);
|
||||||
|
@ -40,13 +40,15 @@ static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
||||||
static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
int32_t mndInitVgroup(SMnode *pMnode) {
|
int32_t mndInitVgroup(SMnode *pMnode) {
|
||||||
SSdbTable table = {.sdbType = SDB_VGROUP,
|
SSdbTable table = {
|
||||||
.keyType = SDB_KEY_INT32,
|
.sdbType = SDB_VGROUP,
|
||||||
.encodeFp = (SdbEncodeFp)mndVgroupActionEncode,
|
.keyType = SDB_KEY_INT32,
|
||||||
.decodeFp = (SdbDecodeFp)mndVgroupActionDecode,
|
.encodeFp = (SdbEncodeFp)mndVgroupActionEncode,
|
||||||
.insertFp = (SdbInsertFp)mndVgroupActionInsert,
|
.decodeFp = (SdbDecodeFp)mndVgroupActionDecode,
|
||||||
.updateFp = (SdbUpdateFp)mndVgroupActionUpdate,
|
.insertFp = (SdbInsertFp)mndVgroupActionInsert,
|
||||||
.deleteFp = (SdbDeleteFp)mndVgroupActionDelete,};
|
.updateFp = (SdbUpdateFp)mndVgroupActionUpdate,
|
||||||
|
.deleteFp = (SdbDeleteFp)mndVgroupActionDelete,
|
||||||
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_VNODE_RSP, mndProcessCreateVnodeRsp);
|
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_VNODE_RSP, mndProcessCreateVnodeRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_VNODE_RSP, mndProcessAlterVnodeRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_VNODE_RSP, mndProcessAlterVnodeRsp);
|
||||||
|
@ -66,7 +68,7 @@ void mndCleanupVgroup(SMnode *pMnode) {}
|
||||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUMBER, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE);
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, VGROUP_VER_NUMBER, sizeof(SVgObj) + VGROUP_RESERVE_SIZE);
|
||||||
if (pRaw == NULL) goto _OVER;
|
if (pRaw == NULL) goto _OVER;
|
||||||
|
|
||||||
int32_t dataPos = 0;
|
int32_t dataPos = 0;
|
||||||
|
@ -83,7 +85,7 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||||
SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId, _OVER)
|
||||||
}
|
}
|
||||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, _OVER)
|
SDB_SET_RESERVE(pRaw, dataPos, VGROUP_RESERVE_SIZE, _OVER)
|
||||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
@ -105,7 +107,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||||
int8_t sver = 0;
|
int8_t sver = 0;
|
||||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||||
|
|
||||||
if (sver != TSDB_VGROUP_VER_NUMBER) {
|
if (sver != VGROUP_VER_NUMBER) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +135,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||||
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, _OVER)
|
SDB_GET_RESERVE(pRaw, dataPos, VGROUP_RESERVE_SIZE, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
|
@ -664,7 +666,6 @@ static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
SVgObj *pVgroup = NULL;
|
SVgObj *pVgroup = NULL;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
// int32_t dnodeId = pShow->replica;
|
|
||||||
|
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
pShow->pIter = sdbFetch(pSdb, SDB_VGROUP, pShow->pIter, (void **)&pVgroup);
|
pShow->pIter = sdbFetch(pSdb, SDB_VGROUP, pShow->pIter, (void **)&pVgroup);
|
||||||
|
|
Loading…
Reference in New Issue