feat: update table options

This commit is contained in:
Hongze Cheng 2024-12-13 12:20:08 +08:00
parent 13a4dcbc53
commit 95130d2cac
3 changed files with 115 additions and 3 deletions

View File

@ -773,8 +773,28 @@ static int32_t metaTtlIdxInsert(SMeta *pMeta, const SMetaHandleParam *pParam) {
return metaTtlIdxUpsert(pMeta, pParam, META_TABLE_OP_INSERT);
}
static int32_t metaTtlIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam);
static int32_t metaTtlIdxUpdate(SMeta *pMeta, const SMetaHandleParam *pParam) {
return metaTtlIdxUpsert(pMeta, pParam, META_TABLE_OP_UPDATA);
int32_t code = TSDB_CODE_SUCCESS;
const SMetaEntry *pEntry = pParam->pEntry;
const SMetaEntry *pOldEntry = pParam->pOldEntry;
if ((pEntry->type == TSDB_CHILD_TABLE && pOldEntry->ctbEntry.ttlDays != pEntry->ctbEntry.ttlDays) ||
(pEntry->type == TSDB_NORMAL_TABLE && pOldEntry->ntbEntry.ttlDays != pEntry->ntbEntry.ttlDays)) {
code = metaTtlIdxDelete(pMeta, pParam);
if (code) {
metaErr(TD_VID(pMeta->pVnode), code);
}
code = metaTtlIdxInsert(pMeta, pParam);
if (code) {
metaErr(TD_VID(pMeta->pVnode), code);
}
}
return TSDB_CODE_SUCCESS;
}
static int32_t metaTtlIdxDelete(SMeta *pMeta, const SMetaHandleParam *pParam) {
@ -1336,6 +1356,7 @@ static int32_t metaHandleNormalTableUpdateImpl(SMeta *pMeta, const SMetaHandlePa
{META_ENTRY_TABLE, META_TABLE_OP_UPDATA}, //
{META_SCHEMA_TABLE, META_TABLE_OP_UPDATA}, //
{META_UID_IDX, META_TABLE_OP_UPDATA}, //
{META_TTL_IDX, META_TABLE_OP_UPDATA}, //
};
for (int32_t i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
SMetaTableOp *op = &ops[i];
@ -1365,6 +1386,7 @@ static int32_t metaHandleChildTableUpdateImpl(SMeta *pMeta, const SMetaHandlePar
{META_UID_IDX, META_TABLE_OP_UPDATA}, //
{META_TAG_IDX, META_TABLE_OP_UPDATA}, //
{META_CHILD_IDX, META_TABLE_OP_UPDATA}, //
{META_TTL_IDX, META_TABLE_OP_UPDATA}, //
};
for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {

View File

@ -23,6 +23,7 @@ int32_t metaAlterTableColumnName(SMeta *pMeta, int64_t version, SVAlterTbReq *pR
int32_t metaAlterTableColumnBytes(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pRsp);
int32_t metaUpdateTableTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
int32_t metaUpdateTableMultiTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
int32_t metaUpdateTableOptions2(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq);
int32_t metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema);
@ -2999,9 +3000,8 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta
return metaUpdateTableTagValue(pMeta, version, pReq);
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL:
return metaUpdateTableMultiTagValue(pMeta, version, pReq);
return terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
return metaUpdateTableOptions(pMeta, version, pReq);
return metaUpdateTableOptions2(pMeta, version, pReq);
case TSDB_ALTER_TABLE_ADD_TAG_INDEX:
return metaAddTagIndex(pMeta, version, pReq);
case TSDB_ALTER_TABLE_DROP_TAG_INDEX:

View File

@ -1367,3 +1367,93 @@ int32_t metaUpdateTableMultiTagValue(SMeta *pMeta, int64_t version, SVAlterTbReq
metaFetchEntryFree(&pSuper);
TAOS_RETURN(code);
}
static int32_t metaCheckUpdateTableOptionsReq(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
int32_t code = TSDB_CODE_SUCCESS;
if (pReq->tbName == NULL || strlen(pReq->tbName) == 0) {
metaError("vgId:%d, %s failed at %s:%d since invalid table name, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
__FILE__, __LINE__, version);
TAOS_RETURN(TSDB_CODE_INVALID_MSG);
}
return code;
}
int32_t metaUpdateTableOptions2(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
int32_t code = 0;
code = metaCheckUpdateTableOptionsReq(pMeta, version, pReq);
if (code) {
TAOS_RETURN(code);
}
// fetch entry
SMetaEntry *pEntry = NULL;
code = metaFetchEntryByName(pMeta, pReq->tbName, &pEntry);
if (code) {
metaError("vgId:%d, %s failed at %s:%d since table %s not found, version:%" PRId64, TD_VID(pMeta->pVnode), __func__,
__FILE__, __LINE__, pReq->tbName, version);
TAOS_RETURN(code);
}
// do change the entry
pEntry->version = version;
if (pEntry->type == TSDB_CHILD_TABLE) {
if (pReq->updateTTL) {
pEntry->ctbEntry.ttlDays = pReq->newTTL;
// metaDeleteTtl(pMeta, &entry);
// entry.ctbEntry.ttlDays = pReq->newTTL;
// metaUpdateTtl(pMeta, &entry);
}
if (pReq->newCommentLen >= 0) {
char *pNewComment = taosMemoryRealloc(pEntry->ctbEntry.comment, pReq->newCommentLen + 1);
if (NULL == pNewComment) {
metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
__LINE__, tstrerror(terrno), version);
metaFetchEntryFree(&pEntry);
TAOS_RETURN(terrno);
}
pEntry->ctbEntry.comment = pNewComment;
pEntry->ctbEntry.commentLen = pReq->newCommentLen;
}
} else if (pEntry->type == TSDB_NORMAL_TABLE) {
if (pReq->updateTTL) {
pEntry->ntbEntry.ttlDays = pReq->newTTL;
// metaDeleteTtl(pMeta, &entry);
// entry.ntbEntry.ttlDays = pReq->newTTL;
// metaUpdateTtl(pMeta, &entry);
}
if (pReq->newCommentLen >= 0) {
char *pNewComment = taosMemoryRealloc(pEntry->ntbEntry.comment, pReq->newCommentLen + 1);
if (NULL == pNewComment) {
metaError("vgId:%d, %s failed at %s:%d since %s, version:%" PRId64, TD_VID(pMeta->pVnode), __func__, __FILE__,
__LINE__, tstrerror(terrno), version);
metaFetchEntryFree(&pEntry);
TAOS_RETURN(terrno);
}
pEntry->ntbEntry.comment = pNewComment;
pEntry->ntbEntry.commentLen = pReq->newCommentLen;
}
} else {
metaError("vgId:%d, %s failed at %s:%d since table %s type %d is invalid, version:%" PRId64, TD_VID(pMeta->pVnode),
__func__, __FILE__, __LINE__, pReq->tbName, pEntry->type, version);
metaFetchEntryFree(&pEntry);
TAOS_RETURN(TSDB_CODE_VND_INVALID_TABLE_ACTION);
}
// do handle entry
code = metaHandleEntry2(pMeta, pEntry);
if (code) {
metaError("vgId:%d, %s failed at %s:%d since %s, uid:%" PRId64 " name:%s version:%" PRId64, TD_VID(pMeta->pVnode),
__func__, __FILE__, __LINE__, tstrerror(code), pEntry->uid, pReq->tbName, version);
metaFetchEntryFree(&pEntry);
TAOS_RETURN(code);
} else {
metaInfo("vgId:%d, table %s uid %" PRId64 " is updated, version:%" PRId64, TD_VID(pMeta->pVnode), pReq->tbName,
pEntry->uid, version);
}
metaFetchEntryFree(&pEntry);
TAOS_RETURN(code);
}