opt index
This commit is contained in:
parent
17b7b81cd7
commit
db61fbb6a2
|
@ -2811,13 +2811,7 @@ typedef struct {
|
||||||
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
|
int32_t tSerializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
|
||||||
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
|
int32_t tDeserializeSCreateTagIdxReq(void* buf, int32_t bufLen, SCreateTagIndexReq* pReq);
|
||||||
|
|
||||||
typedef struct {
|
typedef SMDropSmaReq SDropTagIndexReq;
|
||||||
char dbFName[TSDB_DB_FNAME_LEN];
|
|
||||||
char stbName[TSDB_TABLE_FNAME_LEN];
|
|
||||||
char colName[TSDB_COL_NAME_LEN];
|
|
||||||
char idxName[TSDB_COL_NAME_LEN];
|
|
||||||
int8_t idxType;
|
|
||||||
} SDropTagIndexReq;
|
|
||||||
|
|
||||||
int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
|
int32_t tSerializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
|
||||||
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
|
int32_t tDeserializeSDropTagIdxReq(void* buf, int32_t bufLen, SDropTagIndexReq* pReq);
|
||||||
|
|
|
@ -957,11 +957,8 @@ int32_t tSerializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *pR
|
||||||
if (tStartEncode(&encoder) < 0) return -1;
|
if (tStartEncode(&encoder) < 0) return -1;
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->stbName) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->colName) < 0) return -1;
|
|
||||||
if (tEncodeCStr(&encoder, pReq->idxName) < 0) return -1;
|
|
||||||
if (tEncodeI8(&encoder, pReq->idxType) < 0) return -1;
|
|
||||||
|
|
||||||
int32_t tlen = encoder.pos;
|
int32_t tlen = encoder.pos;
|
||||||
tEncoderClear(&encoder);
|
tEncoderClear(&encoder);
|
||||||
|
@ -972,11 +969,8 @@ int32_t tDeserializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *
|
||||||
tDecoderInit(&decoder, buf, bufLen);
|
tDecoderInit(&decoder, buf, bufLen);
|
||||||
if (tStartDecode(&decoder) < 0) return -1;
|
if (tStartDecode(&decoder) < 0) return -1;
|
||||||
|
|
||||||
if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->stbName) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->colName) < 0) return -1;
|
|
||||||
if (tDecodeCStrTo(&decoder, pReq->idxName) < 0) return -1;
|
|
||||||
if (tDecodeI8(&decoder, &pReq->idxType) < 0) return -1;
|
|
||||||
|
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
|
|
|
@ -122,6 +122,42 @@ int mndSetCreateIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStb
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int mndSetDropIdxRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb, SIdxObj *pIdx) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
void *pIter = NULL;
|
||||||
|
int32_t contLen;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
if (!mndVgroupInDb(pVgroup, pDb->uid)) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pReq = mndBuildVCreateStbReq(pMnode, pVgroup, pStb, &contLen, NULL, 0);
|
||||||
|
if (pReq == NULL) {
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
action.pCont = pReq;
|
||||||
|
action.contLen = contLen;
|
||||||
|
action.msgType = TDMT_VND_DROP_INDEX;
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
taosMemoryFree(pReq);
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void mndCleanupIdx(SMnode *pMnode) {
|
void mndCleanupIdx(SMnode *pMnode) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
@ -388,14 +424,6 @@ static int32_t mndSetDropIdxCommitLogs(SMnode *pMnode, STrans *pTrans, SIdxObj *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *pIdx) {
|
|
||||||
int32_t code = -1;
|
|
||||||
SVgObj *pVgroup = NULL;
|
|
||||||
SStbObj *pStb = NULL;
|
|
||||||
STrans *pTrans = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||||
// stb
|
// stb
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -704,6 +732,7 @@ _OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *req, SDbObj *pDb, SStbObj *pStb) {
|
static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *req, SDbObj *pDb, SStbObj *pStb) {
|
||||||
SIdxObj idxObj = {0};
|
SIdxObj idxObj = {0};
|
||||||
memcpy(idxObj.name, req->idxName, TSDB_TABLE_FNAME_LEN);
|
memcpy(idxObj.name, req->idxName, TSDB_TABLE_FNAME_LEN);
|
||||||
|
@ -750,21 +779,79 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *pIdx) {
|
||||||
|
int32_t code = -1;
|
||||||
|
SStbObj *pStb = NULL;
|
||||||
|
STrans *pTrans = NULL;
|
||||||
|
|
||||||
|
SStbObj newObj = {0};
|
||||||
|
|
||||||
|
pStb = mndAcquireStb(pMnode, pIdx->stb);
|
||||||
|
if (pStb == NULL) goto _OVER;
|
||||||
|
|
||||||
|
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "drop-index");
|
||||||
|
if (pTrans == NULL) goto _OVER;
|
||||||
|
|
||||||
|
mInfo("trans:%d, used to drop idx:%s", pTrans->id, pIdx->name);
|
||||||
|
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||||
|
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||||
|
|
||||||
|
mndTransSetSerial(pTrans);
|
||||||
|
if (mndSetDropIdxRedoLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
||||||
|
if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
||||||
|
|
||||||
|
if (mndSetUpdateIdxStbCommitLogs(pMnode, pTrans, pStb, &newObj, pIdx->colName) != 0) goto _OVER;
|
||||||
|
if (mndSetDropIdxRedoActions(pMnode, pTrans, pStb, &newObj, pIdx) != 0) goto _OVER;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
mndReleaseStb(pMnode, pStb);
|
||||||
|
}
|
||||||
static int32_t mndProcessDropIdxReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropIdxReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
// SDbObj *pDb = NULL;
|
int32_t code = -1;
|
||||||
// SStbObj *pStb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
// SDropTagIndexReq dropReq = {0};
|
SIdxObj *pIdx = NULL;
|
||||||
// if (tDeserializeSDropTagIdxReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
|
||||||
// terrno = TSDB_CODE_INVALID_MSG;
|
SDropTagIndexReq req = {0};
|
||||||
// goto _OVER;
|
if (tDeserializeSDropTagIdxReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||||
// }
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
//
|
goto _OVER;
|
||||||
// return TSDB_CODE_SUCCESS;
|
}
|
||||||
//_OVER:
|
mInfo("idx:%s, start to drop", req.name);
|
||||||
// return code;
|
|
||||||
|
pIdx = mndAcquireIdx(pMnode, req.name);
|
||||||
|
if (pIdx == NULL) {
|
||||||
|
if (req.igNotExists) {
|
||||||
|
mInfo("idx:%s, not exist, ignore not exist is set", req.name);
|
||||||
|
code = 0;
|
||||||
|
goto _OVER;
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_MND_SMA_NOT_EXIST;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pDb = mndAcquireDbByIdx(pMnode, dropReq.name);
|
||||||
|
if (pDb == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pDb) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = mndDropIdx(pMnode, pReq, pDb, pIdx);
|
||||||
|
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||||
|
mError("idx:%s, failed to drop since %s", req.name, terrstr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static int32_t mndProcessGetIdxReq(SRpcMsg *pReq) {
|
static int32_t mndProcessGetIdxReq(SRpcMsg *pReq) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
Loading…
Reference in New Issue