Merge pull request #21013 from taosdata/FIX/TD-23768-main
fix: change tdbTbInsert to tdbTbUpsert for meta update in tdb
This commit is contained in:
commit
35f02cdbad
|
@ -106,6 +106,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
goto LABEL; \
|
goto LABEL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define VND_CHECK_CODE(CODE, LINO, LABEL) TSDB_CHECK_CODE(CODE, LINO, LABEL)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -187,23 +187,24 @@ _err:
|
||||||
|
|
||||||
int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t line = 0;
|
||||||
SMeta* pMeta = pWriter->pMeta;
|
SMeta* pMeta = pWriter->pMeta;
|
||||||
SMetaEntry metaEntry = {0};
|
SMetaEntry metaEntry = {0};
|
||||||
SDecoder* pDecoder = &(SDecoder){0};
|
SDecoder* pDecoder = &(SDecoder){0};
|
||||||
|
|
||||||
tDecoderInit(pDecoder, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
tDecoderInit(pDecoder, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||||
code = metaDecodeEntry(pDecoder, &metaEntry);
|
code = metaDecodeEntry(pDecoder, &metaEntry);
|
||||||
if (code) goto _err;
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
code = metaHandleEntry(pMeta, &metaEntry);
|
code = metaHandleEntry(pMeta, &metaEntry);
|
||||||
if (code) goto _err;
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
tDecoderClear(pDecoder);
|
tDecoderClear(pDecoder);
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
tDecoderClear(pDecoder);
|
tDecoderClear(pDecoder);
|
||||||
metaError("vgId:%d, vnode snapshot meta write failed since %s", TD_VID(pMeta->pVnode), tstrerror(code));
|
metaError("vgId:%d, vnode snapshot meta write failed since %s at line:%d", TD_VID(pMeta->pVnode), terrstr(), line);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1029,7 +1029,7 @@ int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
metaTrace("vgId:%d, start to save version:%" PRId64 " uid:%" PRId64 " ctime:%" PRId64, TD_VID(pMeta->pVnode),
|
metaTrace("vgId:%d, start to save version:%" PRId64 " uid:%" PRId64 " ctime:%" PRId64, TD_VID(pMeta->pVnode),
|
||||||
pME->version, pME->uid, ctimeKey.ctime);
|
pME->version, pME->uid, ctimeKey.ctime);
|
||||||
|
|
||||||
return tdbTbInsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, pMeta->txn);
|
return tdbTbUpsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
@ -1044,7 +1044,7 @@ int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
|
if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return tdbTbInsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, pMeta->txn);
|
return tdbTbUpsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
@ -1878,24 +1878,24 @@ static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
return tdbTbInsert(pMeta->pSuidIdx, &pME->uid, sizeof(tb_uid_t), NULL, 0, pMeta->txn);
|
return tdbTbUpsert(pMeta->pSuidIdx, &pME->uid, sizeof(tb_uid_t), NULL, 0, pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
return tdbTbInsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), pMeta->txn);
|
return tdbTbUpsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
STtlIdxKey ttlKey = {0};
|
STtlIdxKey ttlKey = {0};
|
||||||
metaBuildTtlIdxKey(&ttlKey, pME);
|
metaBuildTtlIdxKey(&ttlKey, pME);
|
||||||
if (ttlKey.dtime == 0) return 0;
|
if (ttlKey.dtime == 0) return 0;
|
||||||
return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, pMeta->txn);
|
return tdbTbUpsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
|
SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
|
||||||
|
|
||||||
return tdbTbInsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), pME->ctbEntry.pTags,
|
return tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), pME->ctbEntry.pTags,
|
||||||
((STag *)(pME->ctbEntry.pTags))->len, pMeta->txn);
|
((STag *)(pME->ctbEntry.pTags))->len, pMeta->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2065,49 +2065,66 @@ _exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
int32_t code = 0;
|
||||||
|
int32_t line = 0;
|
||||||
metaWLock(pMeta);
|
metaWLock(pMeta);
|
||||||
|
|
||||||
// save to table.db
|
// save to table.db
|
||||||
if (metaSaveToTbDb(pMeta, pME) < 0) goto _err;
|
code = metaSaveToTbDb(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
// update uid.idx
|
// update uid.idx
|
||||||
if (metaUpdateUidIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateUidIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
// update name.idx
|
// update name.idx
|
||||||
if (metaUpdateNameIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateNameIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
if (pME->type == TSDB_CHILD_TABLE) {
|
if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
// update ctb.idx
|
// update ctb.idx
|
||||||
if (metaUpdateCtbIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateCtbIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
// update tag.idx
|
// update tag.idx
|
||||||
if (metaUpdateTagIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateTagIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
} else {
|
} else {
|
||||||
// update schema.db
|
// update schema.db
|
||||||
if (metaSaveToSkmDb(pMeta, pME) < 0) goto _err;
|
code = metaSaveToSkmDb(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
if (pME->type == TSDB_SUPER_TABLE) {
|
if (pME->type == TSDB_SUPER_TABLE) {
|
||||||
if (metaUpdateSuidIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateSuidIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaUpdateCtimeIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateCtimeIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
|
|
||||||
if (pME->type == TSDB_NORMAL_TABLE) {
|
if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
if (metaUpdateNcolIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateNcolIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pME->type != TSDB_SUPER_TABLE) {
|
if (pME->type != TSDB_SUPER_TABLE) {
|
||||||
if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err;
|
code = metaUpdateTtlIdx(pMeta, pME);
|
||||||
|
VND_CHECK_CODE(code, line, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
metaULock(pMeta);
|
metaULock(pMeta);
|
||||||
|
metaDebug("vgId:%d, handle meta entry, ver:%" PRId64 ", uid:%" PRId64 ", name:%s", TD_VID(pMeta->pVnode),
|
||||||
|
pME->version, pME->uid, pME->name);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
metaULock(pMeta);
|
metaULock(pMeta);
|
||||||
|
metaError("vgId:%d, failed to handle meta entry since %s at line:%d, ver:%" PRId64 ", uid:%" PRId64 ", name:%s",
|
||||||
|
TD_VID(pMeta->pVnode), terrstr(), line, pME->version, pME->uid, pME->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// refactor later
|
// refactor later
|
||||||
void *metaGetIdx(SMeta *pMeta) { return pMeta->pTagIdx; }
|
void *metaGetIdx(SMeta *pMeta) { return pMeta->pTagIdx; }
|
||||||
void *metaGetIvtIdx(SMeta *pMeta) { return pMeta->pTagIvtIdx; }
|
void *metaGetIvtIdx(SMeta *pMeta) { return pMeta->pTagIvtIdx; }
|
||||||
|
|
Loading…
Reference in New Issue