fix: CI issue

This commit is contained in:
Hongze Cheng 2024-12-05 16:57:25 +08:00
parent a51be1cee3
commit 60ffaddc92
2 changed files with 458 additions and 65 deletions

View File

@ -17,8 +17,32 @@
pEntry->type > 0 ? pEntry->name : NULL); \ pEntry->type > 0 ? pEntry->name : NULL); \
} while (0) } while (0)
typedef enum {
META_ENTRY_TABLE = 0,
META_SCHEMA_TABLE,
META_UID_IDX,
META_NAME_IDX,
META_SUID_IDX,
META_TAG_IDX,
META_BTIME_IDX,
META_TTL_IDX,
META_TABLE_MAX,
} EMetaTable;
typedef enum {
META_TABLE_OP_INSERT = 0,
META_TABLE_OP_UPDATA,
META_TABLE_OP_DELETE,
META_TABLE_OP_MAX,
} EMetaTableOp;
typedef struct {
EMetaTable table;
EMetaTableOp op;
} SMetaTableOp;
// Entry Table // Entry Table
static int32_t metaEntryTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaEntryTableUpsert(SMeta *pMeta, const SMetaEntry *pEntry, EMetaTableOp op) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t vgId = TD_VID(pMeta->pVnode); int32_t vgId = TD_VID(pMeta->pVnode);
void *value = NULL; void *value = NULL;
@ -53,7 +77,13 @@ static int32_t metaEntryTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
tEncoderClear(&encoder); tEncoderClear(&encoder);
// put to tdb // put to tdb
if (META_TABLE_OP_INSERT == op) {
code = tdbTbInsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn); code = tdbTbInsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
} else if (META_TABLE_OP_UPDATA == op) {
code = tdbTbUpsert(pMeta->pTbDb, &key, sizeof(key), value, valueSize, pMeta->txn);
} else {
code = TSDB_CODE_INVALID_PARA;
}
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code); metaErr(vgId, code);
} }
@ -61,7 +91,15 @@ static int32_t metaEntryTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
return code; return code;
} }
static int32_t metaEntryTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaEntryTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaEntryTableUpsert(pMeta, pEntry, META_TABLE_OP_INSERT);
}
static int32_t metaEntryTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaEntryTableUpsert(pMeta, pEntry, META_TABLE_OP_UPDATA);
}
static int32_t metaEntryTableDelete(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t vgId = TD_VID(pMeta->pVnode); int32_t vgId = TD_VID(pMeta->pVnode);
@ -71,7 +109,7 @@ static int32_t metaEntryTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
} }
// Schema Table // Schema Table
static int32_t metaSchemaTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaSchemaTableUpsert(SMeta *pMeta, const SMetaEntry *pEntry, EMetaTableOp op) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t vgId = TD_VID(pMeta->pVnode); int32_t vgId = TD_VID(pMeta->pVnode);
SEncoder encoder = {0}; SEncoder encoder = {0};
@ -115,7 +153,13 @@ static int32_t metaSchemaTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
tEncoderClear(&encoder); tEncoderClear(&encoder);
// put to tdb // put to tdb
if (META_TABLE_OP_INSERT == op) {
code = tdbTbInsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn); code = tdbTbInsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn);
} else if (META_TABLE_OP_UPDATA == op) {
code = tdbTbUpsert(pMeta->pSkmDb, &key, sizeof(key), value, valueSize, pMeta->txn);
} else {
code = TSDB_CODE_INVALID_PARA;
}
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code); metaErr(vgId, code);
} }
@ -123,6 +167,14 @@ static int32_t metaSchemaTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
return code; return code;
} }
static int32_t metaSchemaTableInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaSchemaTableUpsert(pMeta, pEntry, META_TABLE_OP_INSERT);
}
static int32_t metaSchemaTableUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaSchemaTableUpsert(pMeta, pEntry, META_TABLE_OP_UPDATA);
}
// Uid Index // Uid Index
static void metaBuildEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) { static void metaBuildEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
pInfo->uid = pEntry->uid; pInfo->uid = pEntry->uid;
@ -138,7 +190,8 @@ static void metaBuildEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
pInfo->skmVer = pEntry->ntbEntry.schemaRow.version; pInfo->skmVer = pEntry->ntbEntry.schemaRow.version;
} }
} }
static int32_t metaUidIdxUpsert(SMeta *pMeta, const SMetaEntry *pEntry) {
static int32_t metaUidIdxUpsert(SMeta *pMeta, const SMetaEntry *pEntry, EMetaTableOp op) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t vgId = TD_VID(pMeta->pVnode); int32_t vgId = TD_VID(pMeta->pVnode);
@ -152,30 +205,48 @@ static int32_t metaUidIdxUpsert(SMeta *pMeta, const SMetaEntry *pEntry) {
// put to tdb // put to tdb
SUidIdxVal value = { SUidIdxVal value = {
.suid = 0, .suid = info.suid,
.skmVer = 0, .skmVer = info.skmVer,
.version = pEntry->version, .version = pEntry->version,
}; };
if (META_TABLE_OP_INSERT == op) {
code = tdbTbInsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn);
} else if (META_TABLE_OP_UPDATA == op) {
code = tdbTbUpsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn); code = tdbTbUpsert(pMeta->pUidIdx, &pEntry->uid, sizeof(pEntry->uid), &value, sizeof(value), pMeta->txn);
}
return code; return code;
} }
static int32_t metaUidIdxInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaUidIdxUpsert(pMeta, pEntry, META_TABLE_OP_INSERT);
}
static int32_t metaUidIdxUpdate(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaUidIdxUpsert(pMeta, pEntry, META_TABLE_OP_UPDATA);
}
// Name Index // Name Index
static int32_t metaNameIdxInsert(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaNameIdxUpsert(SMeta *pMeta, const SMetaEntry *pEntry, EMetaTableOp op) {
int32_t code = tdbTbInsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid), int32_t code = TSDB_CODE_SUCCESS;
if (META_TABLE_OP_INSERT == op) {
code = tdbTbInsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
pMeta->txn); pMeta->txn);
if (code) { } else if (META_TABLE_OP_UPDATA == op) {
metaErr(TD_VID(pMeta->pVnode), code); code = tdbTbUpsert(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, &pEntry->uid, sizeof(pEntry->uid),
pMeta->txn);
} else {
code = TSDB_CODE_INVALID_PARA;
} }
return code; return code;
} }
static int32_t metaNameIdxDelete(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaNameIdxInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = tdbTbDelete(pMeta->pNameIdx, pEntry->name, strlen(pEntry->name) + 1, pMeta->txn); return metaNameIdxUpsert(pMeta, pEntry, META_TABLE_OP_INSERT);
if (code) {
metaErr(TD_VID(pMeta->pVnode), code);
} }
return code;
static int32_t metaNameIdxDelete(SMeta *pMeta, const SMetaEntry *pEntry) {
// TODO
return 0;
} }
// Suid Index // Suid Index
@ -189,51 +260,109 @@ static int32_t metaSUidIdxInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
// Tag Index // Tag Index
// Btime Index
static int32_t metaBtimeIdxUpsert(SMeta *pMeta, const SMetaEntry *pEntry, EMetaTableOp op) {
SBtimeIdxKey key = {
.uid = pEntry->uid,
};
if (TSDB_CHILD_TABLE == pEntry->type) {
key.btime = pEntry->ctbEntry.btime;
} else if (TSDB_NORMAL_TABLE == pEntry->type) {
key.btime = pEntry->ntbEntry.btime;
} else {
return TSDB_CODE_INVALID_PARA;
}
if (META_TABLE_OP_INSERT == op) {
return tdbTbInsert(pMeta->pBtimeIdx, &key, sizeof(key), NULL, 0, pMeta->txn);
} else if (META_TABLE_OP_UPDATA == op) {
return tdbTbUpsert(pMeta->pBtimeIdx, &key, sizeof(key), NULL, 0, pMeta->txn);
} else {
return TSDB_CODE_INVALID_PARA;
}
}
static int32_t metaBtimeIdxInsert(SMeta *pMeta, const SMetaEntry *pEntry) {
return metaBtimeIdxUpsert(pMeta, pEntry, META_TABLE_OP_INSERT);
}
static int32_t (*metaTableOpFn[META_TABLE_MAX][META_TABLE_OP_MAX])(SMeta *pMeta, const SMetaEntry *pEntry) = {
[META_ENTRY_TABLE] =
{
[META_TABLE_OP_INSERT] = metaEntryTableInsert,
[META_TABLE_OP_UPDATA] = metaEntryTableUpdate,
[META_TABLE_OP_DELETE] = metaEntryTableDelete,
},
[META_SCHEMA_TABLE] =
{
[META_TABLE_OP_INSERT] = metaSchemaTableInsert,
[META_TABLE_OP_UPDATA] = NULL,
[META_TABLE_OP_DELETE] = NULL,
},
[META_UID_IDX] =
{
[META_TABLE_OP_INSERT] = metaUidIdxInsert,
[META_TABLE_OP_UPDATA] = metaUidIdxUpdate,
[META_TABLE_OP_DELETE] = NULL,
},
[META_NAME_IDX] =
{
[META_TABLE_OP_INSERT] = metaNameIdxInsert,
[META_TABLE_OP_UPDATA] = NULL,
[META_TABLE_OP_DELETE] = NULL,
},
[META_SUID_IDX] =
{
[META_TABLE_OP_INSERT] = metaSUidIdxInsert,
[META_TABLE_OP_UPDATA] = NULL,
[META_TABLE_OP_DELETE] = NULL,
},
[META_TAG_IDX] =
{
[META_TABLE_OP_INSERT] = NULL,
[META_TABLE_OP_UPDATA] = NULL,
[META_TABLE_OP_DELETE] = NULL,
},
[META_BTIME_IDX] =
{
[META_TABLE_OP_INSERT] = metaBtimeIdxInsert,
[META_TABLE_OP_UPDATA] = NULL,
[META_TABLE_OP_DELETE] = NULL,
},
[META_TTL_IDX] =
{
[META_TABLE_OP_INSERT] = NULL,
[META_TABLE_OP_UPDATA] = NULL,
[META_TABLE_OP_DELETE] = NULL,
},
};
static int32_t metaHandleSuperTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaHandleSuperTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t vgId = TD_VID(pMeta->pVnode);
// Insert into Entry Table SMetaTableOp ops[] = {
code = metaEntryTableInsert(pMeta, pEntry); {META_ENTRY_TABLE, META_TABLE_OP_INSERT}, //
{META_SCHEMA_TABLE, META_TABLE_OP_INSERT}, //
{META_UID_IDX, META_TABLE_OP_INSERT}, //
{META_NAME_IDX, META_TABLE_OP_INSERT}, //
{META_SUID_IDX, META_TABLE_OP_INSERT}, //
};
for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
SMetaTableOp *op = &ops[i];
code = metaTableOpFn[op->table][op->op](pMeta, pEntry);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code); metaErr(TD_VID(pMeta->pVnode), code);
return code; return code;
} }
// Insert into Schema Table
code = metaSchemaTableInsert(pMeta, pEntry);
if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code);
return code;
}
// Insert to Uid Index
code = metaUidIdxUpsert(pMeta, pEntry);
if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code);
return code;
}
// Insert to Name Index
code = metaNameIdxInsert(pMeta, pEntry);
if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code);
return code;
}
// Insert to Suid Index
code = metaSUidIdxInsert(pMeta, pEntry);
if (TSDB_CODE_SUCCESS != code) {
metaErr(vgId, code);
return code;
} }
return code; return code;
} }
static int32_t metaHandleSuperTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaHandleSuperTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t vgId = TD_VID(pMeta->pVnode);
metaWLock(pMeta); metaWLock(pMeta);
code = metaHandleSuperTableCreateImpl(pMeta, pEntry); code = metaHandleSuperTableCreateImpl(pMeta, pEntry);
@ -243,14 +372,52 @@ static int32_t metaHandleSuperTableCreate(SMeta *pMeta, const SMetaEntry *pEntry
pMeta->pVnode->config.vndStats.numOfSTables++; pMeta->pVnode->config.vndStats.numOfSTables++;
pMeta->changed = true; pMeta->changed = true;
metaInfo("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", vgId, __func__, metaInfo("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", TD_VID(pMeta->pVnode),
pEntry->version, pEntry->type, pEntry->uid, pEntry->name); __func__, pEntry->version, pEntry->type, pEntry->uid, pEntry->name);
} else { } else {
metaErr(vgId, code); metaErr(TD_VID(pMeta->pVnode), code);
} }
return code; return code;
} }
static int32_t metaHandleNormalTableCreateImpl(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = TSDB_CODE_SUCCESS;
SMetaTableOp ops[] = {
{META_ENTRY_TABLE, META_TABLE_OP_INSERT}, //
{META_SCHEMA_TABLE, META_TABLE_OP_INSERT}, //
{META_UID_IDX, META_TABLE_OP_INSERT}, //
{META_NAME_IDX, META_TABLE_OP_INSERT}, //
{META_BTIME_IDX, META_TABLE_OP_INSERT}, //
{META_TTL_IDX, META_TABLE_OP_INSERT}, //
};
for (int i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) {
SMetaTableOp *op = &ops[i];
code = metaTableOpFn[op->table][op->op](pMeta, pEntry);
if (TSDB_CODE_SUCCESS != code) {
metaErr(TD_VID(pMeta->pVnode), code);
return code;
}
}
return code;
}
static int32_t metaHandleNormalTableCreate(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = TSDB_CODE_SUCCESS;
metaWLock(pMeta);
code = metaHandleNormalTableCreateImpl(pMeta, pEntry);
metaULock(pMeta);
{
// TODO: other stuff
}
return code;
}
static int32_t metaHandleNormalTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) { static int32_t metaHandleNormalTableDrop(SMeta *pMeta, const SMetaEntry *pEntry) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
// TODO // TODO
@ -287,47 +454,55 @@ int32_t metaHandleEntry2(SMeta *pMeta, const SMetaEntry *pEntry) {
} }
switch (type) { switch (type) {
case TSDB_SUPER_TABLE: case TSDB_SUPER_TABLE: {
if (isExist) { if (isExist) {
// code = metaHandleSuperTableUpdate(pMeta, pEntry); // code = metaHandleSuperTableUpdate(pMeta, pEntry);
} else { } else {
code = metaHandleSuperTableCreate(pMeta, pEntry); code = metaHandleSuperTableCreate(pMeta, pEntry);
} }
break; break;
case TSDB_CHILD_TABLE: }
case TSDB_CHILD_TABLE: {
if (isExist) { if (isExist) {
// code = metaHandleChildTableUpdate(pMeta, pEntry); // code = metaHandleChildTableUpdate(pMeta, pEntry);
} else { } else {
// code = metaHandleChildTableCreate(pMeta, pEntry); // code = metaHandleChildTableCreate(pMeta, pEntry);
} }
break; break;
case TSDB_NORMAL_TABLE: }
case TSDB_NORMAL_TABLE: {
if (isExist) { if (isExist) {
// code = metaHandleNormalTableUpdate(pMeta, pEntry); // code = metaHandleNormalTableUpdate(pMeta, pEntry);
} else { } else {
// code = metaHandleNormalTableCreate(pMeta, pEntry); code = metaHandleNormalTableCreate(pMeta, pEntry);
} }
break; break;
default: }
default: {
code = TSDB_CODE_INVALID_PARA; code = TSDB_CODE_INVALID_PARA;
break; break;
} }
}
} else { } else {
switch (type) { switch (type) {
case TSDB_SUPER_TABLE: case TSDB_SUPER_TABLE: {
// code = metaHandleSuperTableDrop(pMeta, pEntry); // code = metaHandleSuperTableDrop(pMeta, pEntry);
break; break;
case TSDB_CHILD_TABLE: }
case TSDB_CHILD_TABLE: {
// code = metaHandleChildTableDrop(pMeta, pEntry); // code = metaHandleChildTableDrop(pMeta, pEntry);
break; break;
case TSDB_NORMAL_TABLE: }
case TSDB_NORMAL_TABLE: {
// code = metaHandleNormalTableDrop(pMeta, pEntry); // code = metaHandleNormalTableDrop(pMeta, pEntry);
break; break;
default: }
default: {
code = TSDB_CODE_INVALID_PARA; code = TSDB_CODE_INVALID_PARA;
break; break;
} }
} }
}
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
metaDebug("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", vgId, __func__, metaDebug("vgId:%d, %s success, version:%" PRId64 " type:%d uid:%" PRId64 " name:%s", vgId, __func__,

View File

@ -131,8 +131,226 @@ int32_t metaCreateSuperTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq
// Alter Super Table // Alter Super Table
// Create Child Table
static int32_t metaCreateChildTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
int32_t code = TSDB_CODE_SUCCESS;
// TODO
return code;
#if 0
SMetaEntry me = {0};
SMetaReader mr = {0};
int32_t ret;
if (pReq->type == TSDB_CHILD_TABLE) {
tb_uid_t suid = metaGetTableEntryUidByName(pMeta, pReq->ctb.stbName);
if (suid != pReq->ctb.suid) {
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
}
}
// validate req
metaReaderDoInit(&mr, pMeta, META_READER_LOCK);
if (metaGetTableEntryByName(&mr, pReq->name) == 0) {
if (pReq->type == TSDB_CHILD_TABLE && pReq->ctb.suid != mr.me.ctbEntry.suid) {
metaReaderClear(&mr);
return terrno = TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
}
pReq->uid = mr.me.uid;
if (pReq->type == TSDB_CHILD_TABLE) {
pReq->ctb.suid = mr.me.ctbEntry.suid;
}
metaReaderClear(&mr);
return terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
} else if (terrno == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
terrno = TSDB_CODE_SUCCESS;
}
metaReaderClear(&mr);
bool sysTbl = (pReq->type == TSDB_CHILD_TABLE) && metaTbInFilterCache(pMeta, pReq->ctb.stbName, 1);
if (!sysTbl && ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0)) goto _err;
// build SMetaEntry
SVnodeStats *pStats = &pMeta->pVnode->config.vndStats;
me.version = version;
me.type = pReq->type;
me.uid = pReq->uid;
me.name = pReq->name;
me.ctbEntry.btime = pReq->btime;
me.ctbEntry.ttlDays = pReq->ttl;
me.ctbEntry.commentLen = pReq->commentLen;
me.ctbEntry.comment = pReq->comment;
me.ctbEntry.suid = pReq->ctb.suid;
me.ctbEntry.pTags = pReq->ctb.pTag;
++pStats->numOfCTables;
if (!sysTbl) {
int32_t nCols = 0;
ret = metaGetStbStats(pMeta->pVnode, me.ctbEntry.suid, 0, &nCols);
if (ret < 0) {
metaError("vgId:%d, failed to get stb stats:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->ctb.suid, tstrerror(ret));
}
pStats->numOfTimeSeries += nCols - 1;
}
metaWLock(pMeta);
metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1, 0);
ret = metaUidCacheClear(pMeta, me.ctbEntry.suid);
if (ret < 0) {
metaError("vgId:%d, failed to clear uid cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->ctb.suid, tstrerror(ret));
}
ret = metaTbGroupCacheClear(pMeta, me.ctbEntry.suid);
if (ret < 0) {
metaError("vgId:%d, failed to clear group cache:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->ctb.suid, tstrerror(ret));
}
metaULock(pMeta);
if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
ret = tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, me.ctbEntry.suid, NULL);
if (ret < 0) {
metaError("vgId:%d, failed to create table:%s since %s", TD_VID(pMeta->pVnode), pReq->name, tstrerror(ret));
goto _err;
}
}
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
metaTimeSeriesNotifyCheck(pMeta);
if (pMetaRsp) {
*pMetaRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
if (*pMetaRsp) {
(*pMetaRsp)->tableType = TSDB_CHILD_TABLE;
(*pMetaRsp)->tuid = pReq->uid;
(*pMetaRsp)->suid = pReq->ctb.suid;
strcpy((*pMetaRsp)->tbName, pReq->name);
}
}
pMeta->changed = true;
metaDebug("vgId:%d, table:%s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid,
pReq->type);
return 0;
_err:
metaError("vgId:%d, failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->type == TSDB_CHILD_TABLE ? "child table" : "normal table", tstrerror(terrno));
return TSDB_CODE_FAILED;
#endif
}
// Drop Child Table
// Alter Child Table
// Create Normal Table // Create Normal Table
static int32_t metaCreateNormalTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
int32_t code = TSDB_CODE_SUCCESS;
#if 0
SMetaEntry me = {0};
SMetaReader mr = {0};
int32_t ret;
// validate req
metaReaderDoInit(&mr, pMeta, META_READER_LOCK);
if (metaGetTableEntryByName(&mr, pReq->name) == 0) {
if (pReq->type == TSDB_CHILD_TABLE && pReq->ctb.suid != mr.me.ctbEntry.suid) {
metaReaderClear(&mr);
return terrno = TSDB_CODE_TDB_TABLE_IN_OTHER_STABLE;
}
pReq->uid = mr.me.uid;
if (pReq->type == TSDB_CHILD_TABLE) {
pReq->ctb.suid = mr.me.ctbEntry.suid;
}
metaReaderClear(&mr);
return terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
} else if (terrno == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
terrno = TSDB_CODE_SUCCESS;
}
metaReaderClear(&mr);
bool sysTbl = (pReq->type == TSDB_CHILD_TABLE) && metaTbInFilterCache(pMeta, pReq->ctb.stbName, 1);
if (!sysTbl && ((terrno = grantCheck(TSDB_GRANT_TIMESERIES)) < 0)) goto _err;
// build SMetaEntry
SVnodeStats *pStats = &pMeta->pVnode->config.vndStats;
me.version = version;
me.type = pReq->type;
me.uid = pReq->uid;
me.name = pReq->name;
me.ntbEntry.btime = pReq->btime;
me.ntbEntry.ttlDays = pReq->ttl;
me.ntbEntry.commentLen = pReq->commentLen;
me.ntbEntry.comment = pReq->comment;
me.ntbEntry.schemaRow = pReq->ntb.schemaRow;
me.ntbEntry.ncid = me.ntbEntry.schemaRow.pSchema[me.ntbEntry.schemaRow.nCols - 1].colId + 1;
me.colCmpr = pReq->colCmpr;
TABLE_SET_COL_COMPRESSED(me.flags);
++pStats->numOfNTables;
pStats->numOfNTimeSeries += me.ntbEntry.schemaRow.nCols - 1;
if (!TSDB_CACHE_NO(pMeta->pVnode->config)) {
ret = tsdbCacheNewTable(pMeta->pVnode->pTsdb, me.uid, -1, &me.ntbEntry.schemaRow);
if (ret < 0) {
metaError("vgId:%d, failed to create table:%s since %s", TD_VID(pMeta->pVnode), pReq->name, tstrerror(ret));
goto _err;
}
}
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
metaTimeSeriesNotifyCheck(pMeta);
if (pMetaRsp) {
*pMetaRsp = taosMemoryCalloc(1, sizeof(STableMetaRsp));
if (*pMetaRsp) {
ret = metaUpdateMetaRsp(pReq->uid, pReq->name, &pReq->ntb.schemaRow, *pMetaRsp);
if (ret < 0) {
metaError("vgId:%d, failed to update meta rsp:%s since %s", TD_VID(pMeta->pVnode), pReq->name, tstrerror(ret));
}
for (int32_t i = 0; i < pReq->colCmpr.nCols; i++) {
SColCmpr *p = &pReq->colCmpr.pColCmpr[i];
(*pMetaRsp)->pSchemaExt[i].colId = p->id;
(*pMetaRsp)->pSchemaExt[i].compress = p->alg;
}
}
}
pMeta->changed = true;
metaDebug("vgId:%d, table:%s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid,
pReq->type);
return 0;
_err:
metaError("vgId:%d, failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->type == TSDB_CHILD_TABLE ? "child table" : "normal table", tstrerror(terrno));
return TSDB_CODE_FAILED;
#endif
return code;
}
// Drop Normal Table // Drop Normal Table
// Alter Normal Table // Alter Normal Table
int32_t metaCreateTable2(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMetaRsp **ppRsp) {
int32_t code = TSDB_CODE_SUCCESS;
if (TSDB_CHILD_TABLE == pReq->type) {
code = metaCreateChildTable(pMeta, version, pReq, ppRsp);
} else if (TSDB_NORMAL_TABLE == pReq->type) {
code = metaCreateNormalTable(pMeta, version, pReq, ppRsp);
} else {
code = TSDB_CODE_INVALID_MSG;
}
return code;
}