fix: handle error code

This commit is contained in:
Hongze Cheng 2024-08-08 10:22:06 +08:00
parent 5c32f4ba5d
commit dfc004ac37
4 changed files with 70 additions and 41 deletions

View File

@ -248,7 +248,7 @@ typedef struct SStoreMeta {
SMTbCursor* (*openTableMetaCursor)(void* pVnode); // metaOpenTbCursor SMTbCursor* (*openTableMetaCursor)(void* pVnode); // metaOpenTbCursor
void (*closeTableMetaCursor)(SMTbCursor* pTbCur); // metaCloseTbCursor void (*closeTableMetaCursor)(SMTbCursor* pTbCur); // metaCloseTbCursor
void (*pauseTableMetaCursor)(SMTbCursor* pTbCur); // metaPauseTbCursor void (*pauseTableMetaCursor)(SMTbCursor* pTbCur); // metaPauseTbCursor
void (*resumeTableMetaCursor)(SMTbCursor* pTbCur, int8_t first, int8_t move); // metaResumeTbCursor int32_t (*resumeTableMetaCursor)(SMTbCursor* pTbCur, int8_t first, int8_t move); // metaResumeTbCursor
int32_t (*cursorNext)(SMTbCursor* pTbCur, ETableType jumpTableType); // metaTbCursorNext int32_t (*cursorNext)(SMTbCursor* pTbCur, ETableType jumpTableType); // metaTbCursorNext
int32_t (*cursorPrev)(SMTbCursor* pTbCur, ETableType jumpTableType); // metaTbCursorPrev int32_t (*cursorPrev)(SMTbCursor* pTbCur, ETableType jumpTableType); // metaTbCursorPrev

View File

@ -131,7 +131,7 @@ typedef SVCreateTSmaReq SSmaCfg;
SMTbCursor* metaOpenTbCursor(void* pVnode); SMTbCursor* metaOpenTbCursor(void* pVnode);
void metaCloseTbCursor(SMTbCursor* pTbCur); void metaCloseTbCursor(SMTbCursor* pTbCur);
void metaPauseTbCursor(SMTbCursor* pTbCur); void metaPauseTbCursor(SMTbCursor* pTbCur);
void metaResumeTbCursor(SMTbCursor* pTbCur, int8_t first, int8_t move); int32_t metaResumeTbCursor(SMTbCursor* pTbCur, int8_t first, int8_t move);
int32_t metaTbCursorNext(SMTbCursor* pTbCur, ETableType jumpTableType); int32_t metaTbCursorNext(SMTbCursor* pTbCur, ETableType jumpTableType);
int32_t metaTbCursorPrev(SMTbCursor* pTbCur, ETableType jumpTableType); int32_t metaTbCursorPrev(SMTbCursor* pTbCur, ETableType jumpTableType);

View File

@ -231,6 +231,7 @@ _exit:
#if 1 // =================================================== #if 1 // ===================================================
SMTbCursor *metaOpenTbCursor(void *pVnode) { SMTbCursor *metaOpenTbCursor(void *pVnode) {
SMTbCursor *pTbCur = NULL; SMTbCursor *pTbCur = NULL;
int32_t code;
pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur)); pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur));
if (pTbCur == NULL) { if (pTbCur == NULL) {
@ -241,7 +242,12 @@ SMTbCursor *metaOpenTbCursor(void *pVnode) {
// tdbTbcMoveToFirst((TBC *)pTbCur->pDbc); // tdbTbcMoveToFirst((TBC *)pTbCur->pDbc);
pTbCur->pMeta = pVnodeObj->pMeta; pTbCur->pMeta = pVnodeObj->pMeta;
pTbCur->paused = 1; pTbCur->paused = 1;
metaResumeTbCursor(pTbCur, 1, 0); code = metaResumeTbCursor(pTbCur, 1, 0);
if (code) {
terrno = code;
taosMemoryFree(pTbCur);
return NULL;
}
return pTbCur; return pTbCur;
} }
@ -266,28 +272,39 @@ void metaPauseTbCursor(SMTbCursor *pTbCur) {
pTbCur->paused = 1; pTbCur->paused = 1;
} }
} }
void metaResumeTbCursor(SMTbCursor *pTbCur, int8_t first, int8_t move) { int32_t metaResumeTbCursor(SMTbCursor *pTbCur, int8_t first, int8_t move) {
int32_t code = 0;
int32_t lino;
if (pTbCur->paused) { if (pTbCur->paused) {
metaReaderDoInit(&pTbCur->mr, pTbCur->pMeta, META_READER_LOCK); metaReaderDoInit(&pTbCur->mr, pTbCur->pMeta, META_READER_LOCK);
(void)tdbTbcOpen(((SMeta *)pTbCur->pMeta)->pUidIdx, (TBC **)&pTbCur->pDbc, NULL); code = tdbTbcOpen(((SMeta *)pTbCur->pMeta)->pUidIdx, (TBC **)&pTbCur->pDbc, NULL);
TSDB_CHECK_CODE(code, lino, _exit);
if (first) { if (first) {
(void)tdbTbcMoveToFirst((TBC *)pTbCur->pDbc); code = tdbTbcMoveToFirst((TBC *)pTbCur->pDbc);
TSDB_CHECK_CODE(code, lino, _exit);
} else { } else {
int c = 1; int c = 1;
(void)tdbTbcMoveTo(pTbCur->pDbc, pTbCur->pKey, pTbCur->kLen, &c); code = tdbTbcMoveTo(pTbCur->pDbc, pTbCur->pKey, pTbCur->kLen, &c);
TSDB_CHECK_CODE(code, lino, _exit);
if (c == 0) { if (c == 0) {
if (move) tdbTbcMoveToNext(pTbCur->pDbc); if (move) tdbTbcMoveToNext(pTbCur->pDbc);
} else if (c < 0) { } else if (c < 0) {
(void)tdbTbcMoveToPrev(pTbCur->pDbc); code = tdbTbcMoveToPrev(pTbCur->pDbc);
TSDB_CHECK_CODE(code, lino, _exit);
} else { } else {
(void)tdbTbcMoveToNext(pTbCur->pDbc); code = tdbTbcMoveToNext(pTbCur->pDbc);
TSDB_CHECK_CODE(code, lino, _exit);
} }
} }
pTbCur->paused = 0; pTbCur->paused = 0;
} }
_exit:
return code;
} }
int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType) { int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType) {
@ -588,6 +605,7 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) {
int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema **ppTSchema) { int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema **ppTSchema) {
int32_t code = 0; int32_t code = 0;
int32_t lino;
void *pData = NULL; void *pData = NULL;
int nData = 0; int nData = 0;
@ -603,7 +621,8 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
skmDbKey.uid = suid ? suid : uid; skmDbKey.uid = suid ? suid : uid;
skmDbKey.sver = INT32_MAX; skmDbKey.sver = INT32_MAX;
(void)tdbTbcOpen(pMeta->pSkmDb, &pSkmDbC, NULL); code = tdbTbcOpen(pMeta->pSkmDb, &pSkmDbC, NULL);
TSDB_CHECK_CODE(code, lino, _exit);
metaRLock(pMeta); metaRLock(pMeta);
if (tdbTbcMoveTo(pSkmDbC, &skmDbKey, sizeof(skmDbKey), &c) < 0) { if (tdbTbcMoveTo(pSkmDbC, &skmDbKey, sizeof(skmDbKey), &c) < 0) {

View File

@ -312,6 +312,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb
int nData = 0; int nData = 0;
int c = 0; int c = 0;
int rc = 0; int rc = 0;
int32_t lino;
// check if super table exists // check if super table exists
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData); rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
@ -323,7 +324,11 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq, SArray *tb
// drop all child tables // drop all child tables
TBC *pCtbIdxc = NULL; TBC *pCtbIdxc = NULL;
(void)(void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); rc = tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL);
if (rc) {
return (terrno = rc);
}
rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
if (rc < 0) { if (rc < 0) {
(void)tdbTbcClose(pCtbIdxc); (void)tdbTbcClose(pCtbIdxc);
@ -379,20 +384,20 @@ _exit:
return 0; return 0;
} }
static void metaGetSubtables(SMeta *pMeta, int64_t suid, SArray *uids) { static int32_t metaGetSubtables(SMeta *pMeta, int64_t suid, SArray *uids) {
if (!uids) return; if (!uids) return TSDB_CODE_INVALID_PARA;
int c = 0; int c = 0;
void *pKey = NULL; void *pKey = NULL;
int nKey = 0; int nKey = 0;
TBC *pCtbIdxc = NULL; TBC *pCtbIdxc = NULL;
(void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL));
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
if (rc < 0) { if (rc < 0) {
(void)tdbTbcClose(pCtbIdxc); (void)tdbTbcClose(pCtbIdxc);
metaWLock(pMeta); metaWLock(pMeta);
return; return 0;
} }
for (;;) { for (;;) {
@ -405,12 +410,17 @@ static void metaGetSubtables(SMeta *pMeta, int64_t suid, SArray *uids) {
break; break;
} }
(void)taosArrayPush(uids, &(((SCtbIdxKey *)pKey)->uid)); if (taosArrayPush(uids, &(((SCtbIdxKey *)pKey)->uid)) == NULL) {
tdbFree(pKey);
(void)tdbTbcClose(pCtbIdxc);
return terrno;
}
} }
tdbFree(pKey); tdbFree(pKey);
(void)tdbTbcClose(pCtbIdxc); (void)tdbTbcClose(pCtbIdxc);
return 0;
} }
int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
@ -425,7 +435,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
int32_t ret; int32_t ret;
int32_t c = -2; int32_t c = -2;
(void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL));
ret = tdbTbcMoveTo(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &c); ret = tdbTbcMoveTo(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &c);
if (ret < 0 || c) { if (ret < 0 || c) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -442,7 +452,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
oversion = ((SUidIdxVal *)pData)[0].version; oversion = ((SUidIdxVal *)pData)[0].version;
(void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL));
ret = tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = pReq->suid, .version = oversion}), sizeof(STbDbKey), &c); ret = tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = pReq->suid, .version = oversion}), sizeof(STbDbKey), &c);
if (!(ret == 0 && c == 0)) { if (!(ret == 0 && c == 0)) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -486,7 +496,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
int16_t cid = pReq->schemaRow.pSchema[nCols - 1].colId; int16_t cid = pReq->schemaRow.pSchema[nCols - 1].colId;
int8_t col_type = pReq->schemaRow.pSchema[nCols - 1].type; int8_t col_type = pReq->schemaRow.pSchema[nCols - 1].type;
metaGetSubtables(pMeta, pReq->suid, uids); TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pReq->suid, uids));
(void)tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type); (void)tsdbCacheNewSTableColumn(pTsdb, uids, cid, col_type);
} else if (deltaCol == -1) { } else if (deltaCol == -1) {
int16_t cid = -1; int16_t cid = -1;
@ -502,7 +512,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
} }
if (cid != -1) { if (cid != -1) {
metaGetSubtables(pMeta, pReq->suid, uids); TAOS_CHECK_RETURN(metaGetSubtables(pMeta, pReq->suid, uids));
(void)tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey); (void)tsdbCacheDropSTableColumn(pTsdb, uids, cid, hasPrimaryKey);
} }
} }
@ -619,7 +629,7 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
* iterator all pTdDbc by uid and version * iterator all pTdDbc by uid and version
*/ */
TBC *pCtbIdxc = NULL; TBC *pCtbIdxc = NULL;
(void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL));
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
if (rc < 0) { if (rc < 0) {
(void)tdbTbcClose(pCtbIdxc); (void)tdbTbcClose(pCtbIdxc);
@ -756,7 +766,7 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
* iterator all pTdDbc by uid and version * iterator all pTdDbc by uid and version
*/ */
TBC *pCtbIdxc = NULL; TBC *pCtbIdxc = NULL;
(void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL));
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
if (rc < 0) { if (rc < 0) {
(void)tdbTbcClose(pCtbIdxc); (void)tdbTbcClose(pCtbIdxc);
@ -1424,7 +1434,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
// search uid index // search uid index
TBC *pUidIdxc = NULL; TBC *pUidIdxc = NULL;
(void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL));
(void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
if (c != 0) { if (c != 0) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -1438,7 +1448,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
// search table.db // search table.db
TBC *pTbDbc = NULL; TBC *pTbDbc = NULL;
(void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL));
(void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
if (c != 0) { if (c != 0) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -1689,7 +1699,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
// search uid index // search uid index
TBC *pUidIdxc = NULL; TBC *pUidIdxc = NULL;
(void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL));
(void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
if (c != 0) { if (c != 0) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -1706,7 +1716,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
SDecoder dc2 = {0}; SDecoder dc2 = {0};
/* get ctbEntry */ /* get ctbEntry */
(void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL));
(void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
if (c != 0) { if (c != 0) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -1869,7 +1879,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
// search uid index // search uid index
TBC *pUidIdxc = NULL; TBC *pUidIdxc = NULL;
(void)tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL));
(void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
if (c != 0) { if (c != 0) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -1883,7 +1893,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
// search table.db // search table.db
TBC *pTbDbc = NULL; TBC *pTbDbc = NULL;
(void)tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL));
(void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c);
if (c != 0) { if (c != 0) {
(void)tdbTbcClose(pUidIdxc); (void)tdbTbcClose(pUidIdxc);
@ -2018,7 +2028,7 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
* iterator all pTdDbc by uid and version * iterator all pTdDbc by uid and version
*/ */
TBC *pCtbIdxc = NULL; TBC *pCtbIdxc = NULL;
(void)tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL));
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
if (rc < 0) { if (rc < 0) {
(void)tdbTbcClose(pCtbIdxc); (void)tdbTbcClose(pCtbIdxc);
@ -2157,7 +2167,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair)); SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair));
TBC *pTagIdxc = NULL; TBC *pTagIdxc = NULL;
(void)tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL); TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTagIdx, &pTagIdxc, NULL));
int rc = int rc =
tdbTbcMoveTo(pTagIdxc, &(STagIdxKey){.suid = suid, .cid = INT32_MIN, .type = pCol->type}, sizeof(STagIdxKey), &c); tdbTbcMoveTo(pTagIdxc, &(STagIdxKey){.suid = suid, .cid = INT32_MIN, .type = pCol->type}, sizeof(STagIdxKey), &c);
for (;;) { for (;;) {