提交 89c8b768 编写于 作者: H Hongze Cheng

refact META 9

上级 159f3acd
...@@ -107,3 +107,4 @@ TAGS ...@@ -107,3 +107,4 @@ TAGS
contrib/* contrib/*
!contrib/CMakeLists.txt !contrib/CMakeLists.txt
!contrib/test !contrib/test
sql
\ No newline at end of file
...@@ -269,6 +269,12 @@ typedef struct SSchema { ...@@ -269,6 +269,12 @@ typedef struct SSchema {
#define SSCHMEA_BYTES(s) ((s)->bytes) #define SSCHMEA_BYTES(s) ((s)->bytes)
#define SSCHMEA_NAME(s) ((s)->name) #define SSCHMEA_NAME(s) ((s)->name)
typedef struct {
int32_t nCols;
int32_t sver;
SSchema* pSchema;
} SSchemaWrapper;
STSchema* tdGetSTSChemaFromSSChema(SSchema** pSchema, int32_t nCols); STSchema* tdGetSTSChemaFromSSChema(SSchema** pSchema, int32_t nCols);
typedef struct { typedef struct {
...@@ -1498,15 +1504,12 @@ int tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam); ...@@ -1498,15 +1504,12 @@ int tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam);
int tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam); int tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam);
typedef struct SVCreateStbReq { typedef struct SVCreateStbReq {
const char* name; const char* name;
tb_uid_t suid; tb_uid_t suid;
int8_t rollup; int8_t rollup;
int16_t nCols; SSchemaWrapper schema;
int16_t sver; SSchemaWrapper schemaTag;
SSchema* pSchema; SRSmaParam pRSmaParam;
int16_t nTags;
SSchema* pSchemaTg;
SRSmaParam pRSmaParam;
} SVCreateStbReq; } SVCreateStbReq;
int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq); int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq);
...@@ -1532,9 +1535,7 @@ typedef struct SVCreateTbReq { ...@@ -1532,9 +1535,7 @@ typedef struct SVCreateTbReq {
const void* pTag; const void* pTag;
} ctb; } ctb;
struct { struct {
int16_t nCols; SSchemaWrapper schema;
int16_t sver;
SSchema* pSchema;
} ntb; } ntb;
}; };
} SVCreateTbReq; } SVCreateTbReq;
...@@ -2160,11 +2161,6 @@ int32_t tDecodeSMqOffset(SCoder* decoder, SMqOffset* pOffset); ...@@ -2160,11 +2161,6 @@ int32_t tDecodeSMqOffset(SCoder* decoder, SMqOffset* pOffset);
int32_t tEncodeSMqCMCommitOffsetReq(SCoder* encoder, const SMqCMCommitOffsetReq* pReq); int32_t tEncodeSMqCMCommitOffsetReq(SCoder* encoder, const SMqCMCommitOffsetReq* pReq);
int32_t tDecodeSMqCMCommitOffsetReq(SCoder* decoder, SMqCMCommitOffsetReq* pReq); int32_t tDecodeSMqCMCommitOffsetReq(SCoder* decoder, SMqCMCommitOffsetReq* pReq);
typedef struct {
uint32_t nCols;
SSchema* pSchema;
} SSchemaWrapper;
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) { static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
int32_t tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedI8(buf, pSchema->type); tlen += taosEncodeFixedI8(buf, pSchema->type);
...@@ -2204,7 +2200,8 @@ static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) { ...@@ -2204,7 +2200,8 @@ static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) {
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) { static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
int32_t tlen = 0; int32_t tlen = 0;
tlen += taosEncodeFixedU32(buf, pSW->nCols); tlen += taosEncodeVariantI32(buf, pSW->nCols);
tlen += taosEncodeVariantI32(buf, pSW->sver);
for (int32_t i = 0; i < pSW->nCols; i++) { for (int32_t i = 0; i < pSW->nCols; i++) {
tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]); tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
} }
...@@ -2212,7 +2209,8 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr ...@@ -2212,7 +2209,8 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
} }
static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) { static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
buf = taosDecodeFixedU32(buf, &pSW->nCols); buf = taosDecodeVariantI32(buf, &pSW->nCols);
buf = taosDecodeVariantI32(buf, &pSW->sver);
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema)); pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
if (pSW->pSchema == NULL) { if (pSW->pSchema == NULL) {
return NULL; return NULL;
...@@ -2225,23 +2223,25 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pS ...@@ -2225,23 +2223,25 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pS
} }
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) { static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
if (tEncodeU32(pEncoder, pSW->nCols) < 0) return -1; if (tEncodeI32v(pEncoder, pSW->nCols) < 0) return -1;
if (tEncodeI32v(pEncoder, pSW->sver) < 0) return -1;
for (int32_t i = 0; i < pSW->nCols; i++) { for (int32_t i = 0; i < pSW->nCols; i++) {
if (tEncodeSSchema(pEncoder, &pSW->pSchema[i]) < 0) return -1; if (tEncodeSSchema(pEncoder, &pSW->pSchema[i]) < 0) return -1;
} }
return pEncoder->pos;
return 0;
} }
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapper* pSW) { static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapper* pSW) {
if (tDecodeU32(pDecoder, &pSW->nCols) < 0) return -1; if (tDecodeI32v(pDecoder, &pSW->nCols) < 0) return -1;
void* ptr = taosMemoryRealloc(pSW->pSchema, pSW->nCols * sizeof(SSchema)); if (tDecodeI32v(pDecoder, &pSW->sver) < 0) return -1;
if (ptr == NULL) {
return -1; pSW->pSchema = (SSchema*)TCODER_MALLOC(pDecoder, sizeof(SSchema) * pSW->nCols);
} if (pSW->pSchema == NULL) return -1;
pSW->pSchema = (SSchema*)ptr;
for (int32_t i = 0; i < pSW->nCols; i++) { for (int32_t i = 0; i < pSW->nCols; i++) {
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1; if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
} }
return 0; return 0;
} }
......
...@@ -3522,15 +3522,8 @@ int tEncodeSVCreateStbReq(SCoder *pCoder, const SVCreateStbReq *pReq) { ...@@ -3522,15 +3522,8 @@ int tEncodeSVCreateStbReq(SCoder *pCoder, const SVCreateStbReq *pReq) {
if (tEncodeCStr(pCoder, pReq->name) < 0) return -1; if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
if (tEncodeI64(pCoder, pReq->suid) < 0) return -1; if (tEncodeI64(pCoder, pReq->suid) < 0) return -1;
if (tEncodeI8(pCoder, pReq->rollup) < 0) return -1; if (tEncodeI8(pCoder, pReq->rollup) < 0) return -1;
if (tEncodeI16v(pCoder, pReq->nCols) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pReq->schema) < 0) return -1;
if (tEncodeI16v(pCoder, pReq->sver) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1;
for (int iCol = 0; iCol < pReq->nCols; iCol++) {
if (tEncodeSSchema(pCoder, pReq->pSchema + iCol) < 0) return -1;
}
if (tEncodeI16v(pCoder, pReq->nTags) < 0) return -1;
for (int iTag = 0; iTag < pReq->nTags; iTag++) {
if (tEncodeSSchema(pCoder, pReq->pSchemaTg + iTag) < 0) return -1;
}
// if (pReq->rollup) { // if (pReq->rollup) {
// if (tEncodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1; // if (tEncodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1;
// } // }
...@@ -3545,22 +3538,8 @@ int tDecodeSVCreateStbReq(SCoder *pCoder, SVCreateStbReq *pReq) { ...@@ -3545,22 +3538,8 @@ int tDecodeSVCreateStbReq(SCoder *pCoder, SVCreateStbReq *pReq) {
if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1; if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1; if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1;
if (tDecodeI8(pCoder, &pReq->rollup) < 0) return -1; if (tDecodeI8(pCoder, &pReq->rollup) < 0) return -1;
if (tEncodeSSchemaWrapper(pCoder, &pReq->schema) < 0) return -1;
if (tDecodeI16v(pCoder, &pReq->nCols) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1;
if (tDecodeI16v(pCoder, &pReq->sver) < 0) return -1;
pReq->pSchema = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pReq->nCols);
if (pReq->pSchema == NULL) return -1;
for (int iCol = 0; iCol < pReq->nCols; iCol++) {
if (tDecodeSSchema(pCoder, pReq->pSchema + iCol) < 0) return -1;
}
if (tDecodeI16v(pCoder, &pReq->nTags) < 0) return -1;
pReq->pSchemaTg = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pReq->nTags);
if (pReq->pSchemaTg == NULL) return -1;
pReq->pSchemaTg = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pReq->nTags);
for (int iTag = 0; iTag < pReq->nTags; iTag++) {
if (tDecodeSSchema(pCoder, pReq->pSchemaTg + iTag) < 0) return -1;
}
// if (pReq->rollup) { // if (pReq->rollup) {
// if (tDecodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1; // if (tDecodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1;
// } // }
...@@ -3607,12 +3586,7 @@ int tEncodeSVCreateTbReq(SCoder *pCoder, const SVCreateTbReq *pReq) { ...@@ -3607,12 +3586,7 @@ int tEncodeSVCreateTbReq(SCoder *pCoder, const SVCreateTbReq *pReq) {
if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1; if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
if (tEncodeBinary(pCoder, pReq->ctb.pTag, kvRowLen(pReq->ctb.pTag)) < 0) return -1; if (tEncodeBinary(pCoder, pReq->ctb.pTag, kvRowLen(pReq->ctb.pTag)) < 0) return -1;
} else if (pReq->type == TSDB_NORMAL_TABLE) { } else if (pReq->type == TSDB_NORMAL_TABLE) {
if (tEncodeI16v(pCoder, pReq->ntb.nCols) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pReq->ntb.schema) < 0) return -1;
if (tEncodeI16v(pCoder, pReq->ntb.sver) < 0) return -1;
for (int iCol = 0; iCol < pReq->ntb.nCols; iCol++) {
if (tEncodeSSchema(pCoder, pReq->ntb.pSchema + iCol) < 0) return -1;
}
} else { } else {
ASSERT(0); ASSERT(0);
} }
...@@ -3635,13 +3609,7 @@ int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) { ...@@ -3635,13 +3609,7 @@ int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) {
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1; if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
if (tDecodeBinary(pCoder, &pReq->ctb.pTag, NULL) < 0) return -1; if (tDecodeBinary(pCoder, &pReq->ctb.pTag, NULL) < 0) return -1;
} else if (pReq->type == TSDB_NORMAL_TABLE) { } else if (pReq->type == TSDB_NORMAL_TABLE) {
if (tDecodeI16v(pCoder, &pReq->ntb.nCols) < 0) return -1; if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schema) < 0) return -1;
if (tDecodeI16v(pCoder, &pReq->ntb.sver) < 0) return -1;
pReq->ntb.pSchema = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pReq->ntb.nCols);
if (pReq->ntb.pSchema == NULL) return -1;
for (int iCol = 0; iCol < pReq->ntb.nCols; iCol++) {
if (tDecodeSSchema(pCoder, pReq->ntb.pSchema + iCol) < 0) return -1;
}
} else { } else {
ASSERT(0); ASSERT(0);
} }
......
...@@ -407,15 +407,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt ...@@ -407,15 +407,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
req.name = (char *)tNameGetTableName(&name); req.name = (char *)tNameGetTableName(&name);
req.suid = pStb->uid; req.suid = pStb->uid;
req.rollup = pStb->aggregationMethod > -1 ? 1 : 0; req.rollup = pStb->aggregationMethod > -1 ? 1 : 0;
req.nCols = pStb->numOfColumns; req.schema.nCols = pStb->numOfColumns;
req.sver = 0; // TODO req.schema.sver = 0;
req.pSchema = pStb->pColumns; req.schema.pSchema = pStb->pColumns;
req.nTags = pStb->numOfTags; req.schemaTag.nCols = pStb->numOfTags;
req.pSchemaTg = pStb->pTags; req.schemaTag.pSchema = pStb->pTags;
// TODO: remove here // TODO: remove here
for (int iCol = 0; iCol < req.nCols; iCol++) { for (int iCol = 0; iCol < req.schema.nCols; iCol++) {
req.pSchema[iCol].flags = SCHEMA_SMA_ON; req.schema.pSchema[iCol].flags = SCHEMA_SMA_ON;
} }
if (req.rollup) { if (req.rollup) {
......
...@@ -140,11 +140,8 @@ struct SMetaEntry { ...@@ -140,11 +140,8 @@ struct SMetaEntry {
const char* name; const char* name;
union { union {
struct { struct {
int16_t nCols; SSchemaWrapper schema;
int16_t sver; SSchemaWrapper schemaTag;
SSchema* pSchema;
int16_t nTags;
SSchema* pSchemaTg;
} stbEntry; } stbEntry;
struct { struct {
int64_t ctime; int64_t ctime;
...@@ -153,11 +150,9 @@ struct SMetaEntry { ...@@ -153,11 +150,9 @@ struct SMetaEntry {
const void* pTags; const void* pTags;
} ctbEntry; } ctbEntry;
struct { struct {
int64_t ctime; int64_t ctime;
int32_t ttlDays; int32_t ttlDays;
int16_t nCols; SSchemaWrapper schema;
int16_t sver;
SSchema* pSchema;
} ntbEntry; } ntbEntry;
}; };
}; };
......
...@@ -23,16 +23,8 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) { ...@@ -23,16 +23,8 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
if (tEncodeCStr(pCoder, pME->name) < 0) return -1; if (tEncodeCStr(pCoder, pME->name) < 0) return -1;
if (pME->type == TSDB_SUPER_TABLE) { if (pME->type == TSDB_SUPER_TABLE) {
if (tEncodeI16v(pCoder, pME->stbEntry.nCols) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schema) < 0) return -1;
if (tEncodeI16v(pCoder, pME->stbEntry.sver) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
for (int iCol = 0; iCol < pME->stbEntry.nCols; iCol++) {
if (tEncodeSSchema(pCoder, pME->stbEntry.pSchema + iCol) < 0) return -1;
}
if (tEncodeI16v(pCoder, pME->stbEntry.nTags) < 0) return -1;
for (int iTag = 0; iTag < pME->stbEntry.nTags; iTag++) {
if (tEncodeSSchema(pCoder, pME->stbEntry.pSchemaTg + iTag) < 0) return -1;
}
} else if (pME->type == TSDB_CHILD_TABLE) { } else if (pME->type == TSDB_CHILD_TABLE) {
if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1; if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1;
if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1; if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1;
...@@ -41,11 +33,7 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) { ...@@ -41,11 +33,7 @@ int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
} else if (pME->type == TSDB_NORMAL_TABLE) { } else if (pME->type == TSDB_NORMAL_TABLE) {
if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1; if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1;
if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1; if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1;
if (tEncodeI16v(pCoder, pME->ntbEntry.nCols) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schema) < 0) return -1;
if (tEncodeI16v(pCoder, pME->ntbEntry.sver) < 0) return -1;
for (int iCol = 0; iCol < pME->ntbEntry.nCols; iCol++) {
if (tEncodeSSchema(pCoder, pME->ntbEntry.pSchema + iCol) < 0) return -1;
}
} else { } else {
ASSERT(0); ASSERT(0);
} }
...@@ -62,26 +50,8 @@ int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) { ...@@ -62,26 +50,8 @@ int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) {
if (tDecodeCStr(pCoder, &pME->name) < 0) return -1; if (tDecodeCStr(pCoder, &pME->name) < 0) return -1;
if (pME->type == TSDB_SUPER_TABLE) { if (pME->type == TSDB_SUPER_TABLE) {
if (tDecodeI16v(pCoder, &pME->stbEntry.nCols) < 0) return -1; if (tDecodeSSchemaWrapper(pCoder, &pME->stbEntry.schema) < 0) return -1;
if (tDecodeI16v(pCoder, &pME->stbEntry.sver) < 0) return -1; if (tDecodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
pME->stbEntry.pSchema = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pME->stbEntry.nCols);
if (pME->stbEntry.pSchema == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int iCol = 0; iCol < pME->stbEntry.nCols; iCol++) {
if (tDecodeSSchema(pCoder, pME->stbEntry.pSchema + iCol) < 0) return -1;
}
if (tDecodeI16v(pCoder, &pME->stbEntry.nTags) < 0) return -1;
pME->stbEntry.pSchemaTg = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pME->stbEntry.nTags);
if (pME->stbEntry.pSchemaTg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int iTag = 0; iTag < pME->stbEntry.nTags; iTag++) {
if (tDecodeSSchema(pCoder, pME->stbEntry.pSchemaTg + iTag) < 0) return -1;
}
} else if (pME->type == TSDB_CHILD_TABLE) { } else if (pME->type == TSDB_CHILD_TABLE) {
if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1; if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1; if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
...@@ -90,16 +60,7 @@ int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) { ...@@ -90,16 +60,7 @@ int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) {
} else if (pME->type == TSDB_NORMAL_TABLE) { } else if (pME->type == TSDB_NORMAL_TABLE) {
if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1; if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1; if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
if (tDecodeI16v(pCoder, &pME->ntbEntry.nCols) < 0) return -1; if (tDecodeSSchemaWrapper(pCoder, &pME->ntbEntry.schema) < 0) return -1;
if (tDecodeI16v(pCoder, &pME->ntbEntry.sver) < 0) return -1;
pME->ntbEntry.pSchema = (SSchema *)TCODER_MALLOC(pCoder, sizeof(SSchema) * pME->ntbEntry.nCols);
if (pME->ntbEntry.pSchema == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int iCol = 0; iCol < pME->ntbEntry.nCols; iCol++) {
if (tEncodeSSchema(pCoder, pME->ntbEntry.pSchema + iCol) < 0) return -1;
}
} else { } else {
ASSERT(0); ASSERT(0);
} }
......
...@@ -23,7 +23,6 @@ static int metaCreateChildTable(SMeta *pMeta, int64_t version, SMetaEntry *pME); ...@@ -23,7 +23,6 @@ static int metaCreateChildTable(SMeta *pMeta, int64_t version, SMetaEntry *pME);
static int metaUpdateTtlIdx(SMeta *pMeta, int64_t dtime, tb_uid_t uid); static int metaUpdateTtlIdx(SMeta *pMeta, int64_t dtime, tb_uid_t uid);
int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
SSkmDbKey skmDbKey = {0};
SMetaEntry me = {0}; SMetaEntry me = {0};
int kLen = 0; int kLen = 0;
int vLen = 0; int vLen = 0;
...@@ -42,14 +41,8 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { ...@@ -42,14 +41,8 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
me.type = TSDB_SUPER_TABLE; me.type = TSDB_SUPER_TABLE;
me.uid = pReq->suid; me.uid = pReq->suid;
me.name = pReq->name; me.name = pReq->name;
me.stbEntry.nCols = pReq->nCols; me.stbEntry.schema = pReq->schema;
me.stbEntry.sver = pReq->sver; me.stbEntry.schemaTag = pReq->schemaTag;
me.stbEntry.pSchema = pReq->pSchema;
me.stbEntry.nTags = pReq->nTags;
me.stbEntry.pSchemaTg = pReq->pSchemaTg;
skmDbKey.uid = pReq->suid;
skmDbKey.sver = 0; // (TODO)
// save to table.db // save to table.db
if (metaSaveToTbDb(pMeta, version, &me) < 0) goto _err; if (metaSaveToTbDb(pMeta, version, &me) < 0) goto _err;
...@@ -108,9 +101,7 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) { ...@@ -108,9 +101,7 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
} else { } else {
me.ntbEntry.ctime = pReq->ctime; me.ntbEntry.ctime = pReq->ctime;
me.ntbEntry.ttlDays = pReq->ttl; me.ntbEntry.ttlDays = pReq->ttl;
me.ntbEntry.nCols = pReq->ntb.nCols; me.ntbEntry.schema = pReq->ntb.schema;
me.ntbEntry.sver = pReq->ntb.sver;
me.ntbEntry.pSchema = pReq->ntb.pSchema;
} }
// save table // save table
......
...@@ -65,35 +65,35 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -65,35 +65,35 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
metaRsp.tuid = meReader1.me.uid; metaRsp.tuid = meReader1.me.uid;
if (meReader1.me.type == TSDB_SUPER_TABLE) { if (meReader1.me.type == TSDB_SUPER_TABLE) {
strcpy(metaRsp.stbName, meReader1.me.name); strcpy(metaRsp.stbName, meReader1.me.name);
metaRsp.numOfTags = meReader1.me.stbEntry.nTags; metaRsp.numOfTags = meReader1.me.stbEntry.schemaTag.nCols;
metaRsp.numOfColumns = meReader1.me.stbEntry.nCols; metaRsp.numOfColumns = meReader1.me.stbEntry.schema.nCols;
metaRsp.suid = meReader1.me.uid; metaRsp.suid = meReader1.me.uid;
metaRsp.pSchemas = taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); metaRsp.pSchemas = taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
if (metaRsp.pSchemas == NULL) { if (metaRsp.pSchemas == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;
} }
memcpy(metaRsp.pSchemas, meReader1.me.stbEntry.pSchema, sizeof(SSchema) * metaRsp.numOfColumns); memcpy(metaRsp.pSchemas, meReader1.me.stbEntry.schema.pSchema, sizeof(SSchema) * metaRsp.numOfColumns);
memcpy(metaRsp.pSchemas + metaRsp.numOfColumns, meReader1.me.stbEntry.pSchemaTg, memcpy(metaRsp.pSchemas + metaRsp.numOfColumns, meReader1.me.stbEntry.schemaTag.pSchema,
sizeof(SSchema) * metaRsp.numOfTags); sizeof(SSchema) * metaRsp.numOfTags);
} else if (meReader1.me.type == TSDB_CHILD_TABLE) { } else if (meReader1.me.type == TSDB_CHILD_TABLE) {
strcpy(metaRsp.stbName, meReader2.me.name); strcpy(metaRsp.stbName, meReader2.me.name);
metaRsp.numOfTags = meReader2.me.stbEntry.nTags; metaRsp.numOfTags = meReader2.me.stbEntry.schemaTag.nCols;
metaRsp.numOfColumns = meReader2.me.stbEntry.nCols; metaRsp.numOfColumns = meReader2.me.stbEntry.schema.nCols;
metaRsp.suid = meReader2.me.uid; metaRsp.suid = meReader2.me.uid;
metaRsp.pSchemas = taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema)); metaRsp.pSchemas = taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
if (metaRsp.pSchemas == NULL) { if (metaRsp.pSchemas == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _exit; goto _exit;
} }
memcpy(metaRsp.pSchemas, meReader2.me.stbEntry.pSchema, sizeof(SSchema) * metaRsp.numOfColumns); memcpy(metaRsp.pSchemas, meReader2.me.stbEntry.schema.pSchema, sizeof(SSchema) * metaRsp.numOfColumns);
memcpy(metaRsp.pSchemas + metaRsp.numOfColumns, meReader2.me.stbEntry.pSchemaTg, memcpy(metaRsp.pSchemas + metaRsp.numOfColumns, meReader2.me.stbEntry.schemaTag.pSchema,
sizeof(SSchema) * metaRsp.numOfTags); sizeof(SSchema) * metaRsp.numOfTags);
} else if (meReader1.me.type == TSDB_NORMAL_TABLE) { } else if (meReader1.me.type == TSDB_NORMAL_TABLE) {
metaRsp.numOfTags = 0; metaRsp.numOfTags = 0;
metaRsp.numOfColumns = meReader1.me.ntbEntry.nCols; metaRsp.numOfColumns = meReader1.me.ntbEntry.schema.nCols;
metaRsp.suid = 0; metaRsp.suid = 0;
metaRsp.pSchemas = meReader1.me.ntbEntry.pSchema; metaRsp.pSchemas = meReader1.me.ntbEntry.schema.pSchema;
} else { } else {
ASSERT(0); ASSERT(0);
} }
......
...@@ -3158,7 +3158,7 @@ typedef struct SVgroupTablesBatch { ...@@ -3158,7 +3158,7 @@ typedef struct SVgroupTablesBatch {
static void destroyCreateTbReq(SVCreateTbReq* pReq) { static void destroyCreateTbReq(SVCreateTbReq* pReq) {
taosMemoryFreeClear(pReq->name); taosMemoryFreeClear(pReq->name);
taosMemoryFreeClear(pReq->ntb.pSchema); taosMemoryFreeClear(pReq->ntb.schema.pSchema);
} }
static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) { static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) {
...@@ -3196,17 +3196,17 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* ...@@ -3196,17 +3196,17 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
SVCreateTbReq req = {0}; SVCreateTbReq req = {0};
req.type = TD_NORMAL_TABLE; req.type = TD_NORMAL_TABLE;
req.name = strdup(pStmt->tableName); req.name = strdup(pStmt->tableName);
req.ntb.nCols = LIST_LENGTH(pStmt->pCols); req.ntb.schema.nCols = LIST_LENGTH(pStmt->pCols);
req.ntb.sver = 0; req.ntb.schema.sver = 0;
req.ntb.pSchema = taosMemoryCalloc(req.ntb.nCols, sizeof(SSchema)); req.ntb.schema.pSchema = taosMemoryCalloc(req.ntb.schema.nCols, sizeof(SSchema));
if (NULL == req.name || NULL == req.ntb.pSchema) { if (NULL == req.name || NULL == req.ntb.schema.pSchema) {
destroyCreateTbReq(&req); destroyCreateTbReq(&req);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SNode* pCol; SNode* pCol;
col_id_t index = 0; col_id_t index = 0;
FOREACH(pCol, pStmt->pCols) { FOREACH(pCol, pStmt->pCols) {
toSchema((SColumnDefNode*)pCol, index + 1, req.ntb.pSchema + index); toSchema((SColumnDefNode*)pCol, index + 1, req.ntb.schema.pSchema + index);
++index; ++index;
} }
if (TSDB_CODE_SUCCESS != buildSmaParam(pStmt->pOptions, &req)) { if (TSDB_CODE_SUCCESS != buildSmaParam(pStmt->pOptions, &req)) {
...@@ -3264,7 +3264,7 @@ static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { ...@@ -3264,7 +3264,7 @@ static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) {
taosMemoryFreeClear(pTableReq->name); taosMemoryFreeClear(pTableReq->name);
if (pTableReq->type == TSDB_NORMAL_TABLE) { if (pTableReq->type == TSDB_NORMAL_TABLE) {
taosMemoryFreeClear(pTableReq->ntb.pSchema); taosMemoryFreeClear(pTableReq->ntb.schema.pSchema);
} else if (pTableReq->type == TSDB_CHILD_TABLE) { } else if (pTableReq->type == TSDB_CHILD_TABLE) {
taosMemoryFreeClear(pTableReq->ctb.pTag); taosMemoryFreeClear(pTableReq->ctb.pTag);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册