fix return code
This commit is contained in:
parent
f4927bb873
commit
ace1880ad9
|
@ -557,8 +557,7 @@ _exit:
|
||||||
int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||||
SMetaEntry oStbEntry = {0};
|
SMetaEntry oStbEntry = {0};
|
||||||
SMetaEntry nStbEntry = {0};
|
SMetaEntry nStbEntry = {0};
|
||||||
|
STbDbKey tbDbKey = {0};
|
||||||
STbDbKey tbDbKey = {0};
|
|
||||||
|
|
||||||
TBC *pUidIdxc = NULL;
|
TBC *pUidIdxc = NULL;
|
||||||
TBC *pTbDbc = NULL;
|
TBC *pTbDbc = NULL;
|
||||||
|
@ -569,32 +568,37 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
int32_t c = -2;
|
int32_t c = -2;
|
||||||
tb_uid_t suid = pReq->suid;
|
tb_uid_t suid = pReq->suid;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
// get super table
|
// get super table
|
||||||
if (tdbTbGet(pMeta->pUidIdx, &suid, sizeof(tb_uid_t), &pData, &nData) != 0) {
|
if ((code = tdbTbGet(pMeta->pUidIdx, &suid, sizeof(tb_uid_t), &pData, &nData)) != 0) {
|
||||||
ret = -1;
|
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
tbDbKey.uid = suid;
|
tbDbKey.uid = suid;
|
||||||
tbDbKey.version = ((SUidIdxVal *)pData)[0].version;
|
tbDbKey.version = ((SUidIdxVal *)pData)[0].version;
|
||||||
(void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData);
|
if ((code = tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData)) != 0) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
tDecoderInit(&dc, pData, nData);
|
tDecoderInit(&dc, pData, nData);
|
||||||
ret = metaDecodeEntry(&dc, &oStbEntry);
|
code = metaDecodeEntry(&dc, &oStbEntry);
|
||||||
if (ret < 0) {
|
if (code < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) {
|
if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) {
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oStbEntry.stbEntry.schemaTag.version == pReq->schemaTag.version) {
|
if (oStbEntry.stbEntry.schemaTag.version == pReq->schemaTag.version) {
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oStbEntry.stbEntry.schemaTag.nCols != pReq->schemaTag.nCols) {
|
if (oStbEntry.stbEntry.schemaTag.nCols != pReq->schemaTag.nCols) {
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,6 +608,7 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||||
SSchema *pOld = oStbEntry.stbEntry.schemaTag.pSchema + i;
|
SSchema *pOld = oStbEntry.stbEntry.schemaTag.pSchema + i;
|
||||||
if (pNew->type != pOld->type || pNew->colId != pOld->colId || pNew->bytes != pOld->bytes ||
|
if (pNew->type != pOld->type || pNew->colId != pOld->colId || pNew->bytes != pOld->bytes ||
|
||||||
strncmp(pOld->name, pNew->name, sizeof(pNew->name))) {
|
strncmp(pOld->name, pNew->name, sizeof(pNew->name))) {
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (IS_IDX_ON(pNew) && !IS_IDX_ON(pOld)) {
|
if (IS_IDX_ON(pNew) && !IS_IDX_ON(pOld)) {
|
||||||
|
@ -614,13 +619,14 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diffIdx == -1) {
|
if (diffIdx == -1) {
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get target schema info
|
// Get target schema info
|
||||||
SSchemaWrapper *pTagSchema = &pReq->schemaTag;
|
SSchemaWrapper *pTagSchema = &pReq->schemaTag;
|
||||||
if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
|
if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
|
||||||
terrno = TSDB_CODE_VND_COL_ALREADY_EXISTS;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
SSchema *pCol = pTagSchema->pSchema + diffIdx;
|
SSchema *pCol = pTagSchema->pSchema + diffIdx;
|
||||||
|
@ -629,17 +635,21 @@ 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;
|
||||||
TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL));
|
code = tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL);
|
||||||
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
if (code != 0) {
|
||||||
if (rc < 0) {
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
||||||
|
if (code < 0) {
|
||||||
(void)tdbTbcClose(pCtbIdxc);
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
void *pKey = NULL, *pVal = NULL;
|
void *pKey = NULL, *pVal = NULL;
|
||||||
int nKey = 0, nVal = 0;
|
int nKey = 0, nVal = 0;
|
||||||
rc = tdbTbcNext(pCtbIdxc, &pKey, &nKey, &pVal, &nVal);
|
code = tdbTbcNext(pCtbIdxc, &pKey, &nKey, &pVal, &nVal);
|
||||||
if (rc < 0) {
|
if (code < 0) {
|
||||||
tdbFree(pKey);
|
tdbFree(pKey);
|
||||||
tdbFree(pVal);
|
tdbFree(pVal);
|
||||||
(void)tdbTbcClose(pCtbIdxc);
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
|
@ -672,10 +682,10 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||||
nTagData = tDataTypes[pCol->type].bytes;
|
nTagData = tDataTypes[pCol->type].bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = metaCreateTagIdxKey(suid, pCol->colId, pTagData, nTagData, pCol->type, table->uid, &pTagIdxKey, &nTagIdxKey);
|
code = metaCreateTagIdxKey(suid, pCol->colId, pTagData, nTagData, pCol->type, table->uid, &pTagIdxKey, &nTagIdxKey);
|
||||||
tdbFree(pKey);
|
tdbFree(pKey);
|
||||||
tdbFree(pVal);
|
tdbFree(pVal);
|
||||||
if (rc < 0) {
|
if (code < 0) {
|
||||||
metaDestroyTagIdxKey(pTagIdxKey);
|
metaDestroyTagIdxKey(pTagIdxKey);
|
||||||
(void)tdbTbcClose(pCtbIdxc);
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -684,6 +694,7 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||||
metaWLock(pMeta);
|
metaWLock(pMeta);
|
||||||
(void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn);
|
(void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn);
|
||||||
metaULock(pMeta);
|
metaULock(pMeta);
|
||||||
|
|
||||||
metaDestroyTagIdxKey(pTagIdxKey);
|
metaDestroyTagIdxKey(pTagIdxKey);
|
||||||
pTagIdxKey = NULL;
|
pTagIdxKey = NULL;
|
||||||
}
|
}
|
||||||
|
@ -714,9 +725,10 @@ _err:
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
|
|
||||||
return TSDB_CODE_VND_COL_ALREADY_EXISTS;
|
return code;
|
||||||
}
|
}
|
||||||
int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) {
|
int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) {
|
||||||
|
int32_t code = 0;
|
||||||
SMetaEntry oStbEntry = {0};
|
SMetaEntry oStbEntry = {0};
|
||||||
SMetaEntry nStbEntry = {0};
|
SMetaEntry nStbEntry = {0};
|
||||||
|
|
||||||
|
@ -732,17 +744,19 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
|
||||||
|
|
||||||
tb_uid_t suid = pReq->stbUid;
|
tb_uid_t suid = pReq->stbUid;
|
||||||
|
|
||||||
if (tdbTbGet(pMeta->pUidIdx, &suid, sizeof(tb_uid_t), &pData, &nData) != 0) {
|
if ((code = tdbTbGet(pMeta->pUidIdx, &suid, sizeof(tb_uid_t), &pData, &nData)) != 0) {
|
||||||
ret = -1;
|
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
tbDbKey.uid = suid;
|
tbDbKey.uid = suid;
|
||||||
tbDbKey.version = ((SUidIdxVal *)pData)[0].version;
|
tbDbKey.version = ((SUidIdxVal *)pData)[0].version;
|
||||||
(void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData);
|
if ((code = tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData)) != 0) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
tDecoderInit(&dc, pData, nData);
|
tDecoderInit(&dc, pData, nData);
|
||||||
ret = metaDecodeEntry(&dc, &oStbEntry);
|
code = metaDecodeEntry(&dc, &oStbEntry);
|
||||||
if (ret < 0) {
|
if (code != 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -759,6 +773,7 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCol == NULL) {
|
if (pCol == NULL) {
|
||||||
|
code = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,17 +781,22 @@ 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;
|
||||||
TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL));
|
code = tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, NULL);
|
||||||
int rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
if (code != 0) {
|
||||||
if (rc < 0) {
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
||||||
|
if (code < 0) {
|
||||||
(void)tdbTbcClose(pCtbIdxc);
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
void *pKey = NULL, *pVal = NULL;
|
void *pKey = NULL, *pVal = NULL;
|
||||||
int nKey = 0, nVal = 0;
|
int nKey = 0, nVal = 0;
|
||||||
rc = tdbTbcNext(pCtbIdxc, &pKey, &nKey, &pVal, &nVal);
|
|
||||||
if (rc < 0) {
|
code = tdbTbcNext(pCtbIdxc, &pKey, &nKey, &pVal, &nVal);
|
||||||
|
if (code < 0) {
|
||||||
tdbFree(pKey);
|
tdbFree(pKey);
|
||||||
tdbFree(pVal);
|
tdbFree(pVal);
|
||||||
(void)tdbTbcClose(pCtbIdxc);
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
|
@ -809,10 +829,11 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
|
||||||
nTagData = tDataTypes[pCol->type].bytes;
|
nTagData = tDataTypes[pCol->type].bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = metaCreateTagIdxKey(suid, pCol->colId, pTagData, nTagData, pCol->type, table->uid, &pTagIdxKey, &nTagIdxKey);
|
|
||||||
|
code = metaCreateTagIdxKey(suid, pCol->colId, pTagData, nTagData, pCol->type, table->uid, &pTagIdxKey, &nTagIdxKey);
|
||||||
tdbFree(pKey);
|
tdbFree(pKey);
|
||||||
tdbFree(pVal);
|
tdbFree(pVal);
|
||||||
if (rc < 0) {
|
if (code < 0) {
|
||||||
metaDestroyTagIdxKey(pTagIdxKey);
|
metaDestroyTagIdxKey(pTagIdxKey);
|
||||||
(void)tdbTbcClose(pCtbIdxc);
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -836,6 +857,16 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
|
||||||
SSchemaWrapper *row = tCloneSSchemaWrapper(&oStbEntry.stbEntry.schemaRow);
|
SSchemaWrapper *row = tCloneSSchemaWrapper(&oStbEntry.stbEntry.schemaRow);
|
||||||
SSchemaWrapper *tag = tCloneSSchemaWrapper(&oStbEntry.stbEntry.schemaTag);
|
SSchemaWrapper *tag = tCloneSSchemaWrapper(&oStbEntry.stbEntry.schemaTag);
|
||||||
SColCmprWrapper *cmpr = tCloneSColCmprWrapper(&oStbEntry.colCmpr);
|
SColCmprWrapper *cmpr = tCloneSColCmprWrapper(&oStbEntry.colCmpr);
|
||||||
|
if (row == NULL || tag == NULL || cmpr == NULL) {
|
||||||
|
tDeleteSchemaWrapper(row);
|
||||||
|
tDeleteSchemaWrapper(tag);
|
||||||
|
tDeleteSColCmprWrapper(cmpr);
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
(void)tdbTbcClose(pCtbIdxc);
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
nStbEntry.stbEntry.schemaRow = *row;
|
nStbEntry.stbEntry.schemaRow = *row;
|
||||||
nStbEntry.stbEntry.schemaTag = *tag;
|
nStbEntry.stbEntry.schemaTag = *tag;
|
||||||
|
@ -866,7 +897,7 @@ _err:
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
|
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRsp **pMetaRsp) {
|
int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRsp **pMetaRsp) {
|
||||||
|
|
|
@ -221,12 +221,12 @@ int tdbTbcOpen(TTB *pTb, TBC **ppTbc, TXN *pTxn) {
|
||||||
*ppTbc = NULL;
|
*ppTbc = NULL;
|
||||||
pTbc = (TBC *)tdbOsMalloc(sizeof(*pTbc));
|
pTbc = (TBC *)tdbOsMalloc(sizeof(*pTbc));
|
||||||
if (pTbc == NULL) {
|
if (pTbc == NULL) {
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn)) {
|
if ((ret = tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn)) != 0) {
|
||||||
taosMemoryFree(pTbc);
|
taosMemoryFree(pTbc);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppTbc = pTbc;
|
*ppTbc = pTbc;
|
||||||
|
|
Loading…
Reference in New Issue