refactor code
This commit is contained in:
parent
ab69c2e750
commit
02e0e45183
|
@ -475,6 +475,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_VND_ALREADY_IS_VOTER TAOS_DEF_ERROR_CODE(0, 0x0533) // internal
|
||||
#define TSDB_CODE_VND_DIR_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0534)
|
||||
#define TSDB_CODE_VND_META_DATA_UNSAFE_DELETE TAOS_DEF_ERROR_CODE(0, 0x0535)
|
||||
#define TSDB_CODE_VND_COLUMN_COMPRESS_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0536)
|
||||
|
||||
// tsdb
|
||||
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||
|
|
|
@ -280,6 +280,16 @@ int32_t tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t
|
|||
uint8_t l2 = COMPRESS_L2_TYPE_U32(cmprAlg); \
|
||||
uint8_t lvl = COMPRESS_L2_TYPE_LEVEL_U32(cmprAlg);
|
||||
|
||||
#define SET_COMPRESS(l1, l2, lvl, cmpr) \
|
||||
do { \
|
||||
(cmpr) &= 0x00FFFFFF; \
|
||||
(cmpr) |= ((l1) << 24); \
|
||||
(cmpr) &= 0xFF0000FF; \
|
||||
(cmpr) |= ((l2) << 8); \
|
||||
(cmpr) &= 0xFFFFFF00; \
|
||||
(cmpr) |= (lvl); \
|
||||
} while (0)
|
||||
int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint32_t *dst);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1679,27 +1679,14 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj *
|
|||
if (mndAllocStbSchemas(pOld, pNew) != 0) {
|
||||
return -1;
|
||||
}
|
||||
DEFINE_VAR((uint32_t)(p->bytes));
|
||||
|
||||
int8_t updated = 0;
|
||||
for (int i = 0; i < pNew->numOfColumns; i++) {
|
||||
SColCmpr *pCmpr = &pNew->pCmpr[i];
|
||||
if (pCmpr->id == colId) {
|
||||
uint32_t cmprAlg = pCmpr->alg;
|
||||
uint8_t tl1 = COMPRESS_L1_TYPE_U32(cmprAlg);
|
||||
uint8_t tl2 = COMPRESS_L2_TYPE_U32(cmprAlg);
|
||||
uint8_t tlvl = COMPRESS_L2_TYPE_LEVEL_U32(cmprAlg);
|
||||
if (l1 != 0) {
|
||||
updated = 1;
|
||||
setColCompressByOption((uint32_t *)&cmprAlg, l1, tl2, tlvl);
|
||||
} else if (l2 != 0) {
|
||||
updated = 1;
|
||||
setColCompressByOption((uint32_t *)&cmprAlg, tl1, l2, tlvl);
|
||||
} else if (lvl != 0) {
|
||||
updated = 1;
|
||||
setColCompressByOption((uint32_t *)&cmprAlg, tl1, tl2, lvl);
|
||||
}
|
||||
if (updated == 1) pCmpr->alg = cmprAlg;
|
||||
uint32_t dst = 0;
|
||||
updated = tUpdateCompress(pCmpr->alg, p->bytes, &dst);
|
||||
if (updated) pCmpr->alg = dst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1708,8 +1695,8 @@ static int32_t mndUpdateSuperTableColumnCompress(SMnode *pMnode, const SStbObj *
|
|||
terrno = TSDB_CODE_MND_COLUMN_COMPRESS_ALREADY_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pNew->colVer++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray *pFields, int32_t ncols) {
|
||||
|
|
|
@ -2153,6 +2153,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
pVal = NULL;
|
||||
|
||||
if (tdbTbGet(pMeta->pUidIdx, &suid, sizeof(tb_uid_t), &pVal, &nVal) == -1) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
ret = -1;
|
||||
goto _err;
|
||||
}
|
||||
|
@ -2161,6 +2162,7 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
tbDbKey.uid = suid;
|
||||
tbDbKey.version = ((SUidIdxVal *)pVal)[0].version;
|
||||
if (tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
tdbFree(pVal);
|
||||
goto _err;
|
||||
}
|
||||
|
@ -2168,17 +2170,47 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq *
|
|||
tDecoderInit(&dc, pVal, nVal);
|
||||
ret = metaDecodeEntry(&dc, &tbEntry);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
tdbFree(pVal);
|
||||
tDecoderClear(&dc);
|
||||
goto _err;
|
||||
}
|
||||
if (tbEntry.type != TSDB_NORMAL_TABLE && tbEntry.type != TSDB_SUPER_TABLE) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
tdbFree(pVal);
|
||||
tDecoderClear(&dc);
|
||||
goto _err;
|
||||
}
|
||||
int8_t updated = 0;
|
||||
SColCmprWrapper *wp = &tbEntry.colCmpr;
|
||||
for (int32_t i = 0; i < wp->nCols; i++) {
|
||||
SColCmpr *p = &wp->pColCmpr[i];
|
||||
if (p->id == pReq->colId) {
|
||||
uint32_t dst = 0;
|
||||
updated = tUpdateCompress(p->alg, pReq->compress, &dst);
|
||||
if (updated) {
|
||||
p->alg = dst;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updated == 0) {
|
||||
tdbFree(pVal);
|
||||
tDecoderClear(&dc);
|
||||
terrno = TSDB_CODE_VND_COLUMN_COMPRESS_ALREADY_EXIST;
|
||||
goto _err;
|
||||
}
|
||||
tbEntry.version = version;
|
||||
|
||||
metaWLock(pMeta);
|
||||
metaSaveToTbDb(pMeta, &tbEntry);
|
||||
metaUpdateUidIdx(pMeta, &tbEntry);
|
||||
metaUpdateChangeTime(pMeta, suid, pReq->ctimeMs);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
tdbFree(pVal);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
return 0;
|
||||
_err:
|
||||
return -1;
|
||||
|
|
|
@ -10735,6 +10735,7 @@ static int buildAlterTableColumnCompress(STranslateContext* pCxt, SAlterTableStm
|
|||
}
|
||||
|
||||
pReq->colName = taosStrdup(pStmt->colName);
|
||||
pReq->colId = pSchema->colId;
|
||||
if (NULL == pReq->colName) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -2933,3 +2933,23 @@ int32_t tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t
|
|||
*level = lvl;
|
||||
return 0;
|
||||
}
|
||||
int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint32_t *dst) {
|
||||
uint8_t ol1 = COMPRESS_L1_TYPE_U32(oldCmpr);
|
||||
uint8_t ol2 = COMPRESS_L2_TYPE_U32(oldCmpr);
|
||||
uint8_t olvl = COMPRESS_L2_TYPE_LEVEL_U32(oldCmpr);
|
||||
|
||||
uint8_t nl1 = COMPRESS_L1_TYPE_U32(newCmpr);
|
||||
uint8_t nl2 = COMPRESS_L2_TYPE_U32(newCmpr);
|
||||
uint8_t nlvl = COMPRESS_L2_TYPE_LEVEL_U32(newCmpr);
|
||||
if (nl1 != 0 && ol1 != nl1) {
|
||||
SET_COMPRESS(nl1, ol2, olvl, *dst);
|
||||
return 1;
|
||||
} else if (nl2 != 0 && ol2 != nl2) {
|
||||
SET_COMPRESS(ol1, nl2, olvl, *dst);
|
||||
return 1;
|
||||
} else if (nlvl != 0 && olvl != nlvl) {
|
||||
SET_COMPRESS(ol1, ol2, nlvl, *dst);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -372,6 +372,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_CATCH_UP, "Vnode didn't catch up
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ALREADY_IS_VOTER, "Vnode already is a voter")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_DIR_ALREADY_EXIST, "Vnode directory already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_META_DATA_UNSAFE_DELETE, "Single replica vnode data will lost permanently after this operation, if you make sure this, please use drop dnode <id> unsafe to execute")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_COLUMN_COMPRESS_ALREADY_EXIST,"Column compress already exist")
|
||||
|
||||
|
||||
// tsdb
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, "Invalid table ID")
|
||||
|
|
Loading…
Reference in New Issue