TD-90
This commit is contained in:
parent
4de11d8312
commit
f81120e352
|
@ -69,11 +69,13 @@ typedef struct {
|
||||||
} SMemTable;
|
} SMemTable;
|
||||||
|
|
||||||
// ---------- TSDB TABLE DEFINITION
|
// ---------- TSDB TABLE DEFINITION
|
||||||
|
#define TSDB_MAX_TABLE_SCHEMAS 16
|
||||||
typedef struct STable {
|
typedef struct STable {
|
||||||
int8_t type;
|
int8_t type;
|
||||||
STableId tableId;
|
STableId tableId;
|
||||||
uint64_t superUid; // Super table UID
|
uint64_t superUid; // Super table UID
|
||||||
STSchema * schema;
|
int16_t numOfSchemas;
|
||||||
|
STSchema ** schema;
|
||||||
STSchema * tagSchema;
|
STSchema * tagSchema;
|
||||||
SKVRow tagVal;
|
SKVRow tagVal;
|
||||||
SMemTable * mem;
|
SMemTable * mem;
|
||||||
|
|
|
@ -43,12 +43,18 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) {
|
||||||
T_APPEND_MEMBER(ptr, pTable, STable, superUid);
|
T_APPEND_MEMBER(ptr, pTable, STable, superUid);
|
||||||
|
|
||||||
if (pTable->type == TSDB_SUPER_TABLE) {
|
if (pTable->type == TSDB_SUPER_TABLE) {
|
||||||
ptr = tdEncodeSchema(ptr, pTable->schema);
|
T_APPEND_MEMBER(ptr, pTable, STable, numOfSchemas);
|
||||||
|
for (int i = 0; i < pTable->numOfSchemas; i++) {
|
||||||
|
ptr = tdEncodeSchema(ptr, pTable->schema[i]);
|
||||||
|
}
|
||||||
ptr = tdEncodeSchema(ptr, pTable->tagSchema);
|
ptr = tdEncodeSchema(ptr, pTable->tagSchema);
|
||||||
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
||||||
ptr = tdEncodeKVRow(ptr, pTable->tagVal);
|
ptr = tdEncodeKVRow(ptr, pTable->tagVal);
|
||||||
} else {
|
} else {
|
||||||
ptr = tdEncodeSchema(ptr, pTable->schema);
|
T_APPEND_MEMBER(ptr, pTable, STable, numOfSchemas);
|
||||||
|
for (int i = 0; i < pTable->numOfSchemas; i++) {
|
||||||
|
ptr = tdEncodeSchema(ptr, pTable->schema[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTable->type == TSDB_STREAM_TABLE) {
|
if (pTable->type == TSDB_STREAM_TABLE) {
|
||||||
|
@ -71,6 +77,11 @@ void tsdbEncodeTable(STable *pTable, char *buf, int *contLen) {
|
||||||
STable *tsdbDecodeTable(void *cont, int contLen) {
|
STable *tsdbDecodeTable(void *cont, int contLen) {
|
||||||
STable *pTable = (STable *)calloc(1, sizeof(STable));
|
STable *pTable = (STable *)calloc(1, sizeof(STable));
|
||||||
if (pTable == NULL) return NULL;
|
if (pTable == NULL) return NULL;
|
||||||
|
pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS);
|
||||||
|
if (pTable->schema == NULL) {
|
||||||
|
free(pTable);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void *ptr = cont;
|
void *ptr = cont;
|
||||||
T_READ_MEMBER(ptr, int8_t, pTable->type);
|
T_READ_MEMBER(ptr, int8_t, pTable->type);
|
||||||
|
@ -88,12 +99,18 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
|
||||||
T_READ_MEMBER(ptr, uint64_t, pTable->superUid);
|
T_READ_MEMBER(ptr, uint64_t, pTable->superUid);
|
||||||
|
|
||||||
if (pTable->type == TSDB_SUPER_TABLE) {
|
if (pTable->type == TSDB_SUPER_TABLE) {
|
||||||
pTable->schema = tdDecodeSchema(&ptr);
|
T_READ_MEMBER(ptr, int16_t, pTable->numOfSchemas);
|
||||||
|
for (int i = 0; i < pTable->numOfSchemas; i++) {
|
||||||
|
pTable->schema[i] = tdDecodeSchema(&ptr);
|
||||||
|
}
|
||||||
pTable->tagSchema = tdDecodeSchema(&ptr);
|
pTable->tagSchema = tdDecodeSchema(&ptr);
|
||||||
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
||||||
ptr = tdDecodeKVRow(ptr, &pTable->tagVal);
|
ptr = tdDecodeKVRow(ptr, &pTable->tagVal);
|
||||||
} else {
|
} else {
|
||||||
pTable->schema = tdDecodeSchema(&ptr);
|
T_READ_MEMBER(ptr, int16_t, pTable->numOfSchemas);
|
||||||
|
for (int i = 0; i < pTable->numOfSchemas; i++) {
|
||||||
|
pTable->schema[i] = tdDecodeSchema(&ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTable->type == TSDB_STREAM_TABLE) {
|
if (pTable->type == TSDB_STREAM_TABLE) {
|
||||||
|
@ -221,13 +238,14 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the newest table schema
|
||||||
STSchema *tsdbGetTableSchema(STsdbMeta *pMeta, STable *pTable) {
|
STSchema *tsdbGetTableSchema(STsdbMeta *pMeta, STable *pTable) {
|
||||||
if (pTable->type == TSDB_NORMAL_TABLE || pTable->type == TSDB_SUPER_TABLE || pTable->type == TSDB_STREAM_TABLE) {
|
if (pTable->type == TSDB_NORMAL_TABLE || pTable->type == TSDB_SUPER_TABLE || pTable->type == TSDB_STREAM_TABLE) {
|
||||||
return pTable->schema;
|
return pTable->schema[pTable->numOfSchemas - 1];
|
||||||
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
} else if (pTable->type == TSDB_CHILD_TABLE) {
|
||||||
STable *pSuper = tsdbGetTableByUid(pMeta, pTable->superUid);
|
STable *pSuper = tsdbGetTableByUid(pMeta, pTable->superUid);
|
||||||
if (pSuper == NULL) return NULL;
|
if (pSuper == NULL) return NULL;
|
||||||
return pSuper->schema;
|
return pSuper->schema[pSuper->numOfSchemas-1];
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -299,13 +317,16 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pTable->type = pCfg->type;
|
pTable->type = pCfg->type;
|
||||||
|
pTable->numOfSchemas = 0;
|
||||||
|
|
||||||
if (isSuper) {
|
if (isSuper) {
|
||||||
pTable->type = TSDB_SUPER_TABLE;
|
pTable->type = TSDB_SUPER_TABLE;
|
||||||
pTable->tableId.uid = pCfg->superUid;
|
pTable->tableId.uid = pCfg->superUid;
|
||||||
pTable->tableId.tid = -1;
|
pTable->tableId.tid = -1;
|
||||||
pTable->superUid = TSDB_INVALID_SUPER_TABLE_ID;
|
pTable->superUid = TSDB_INVALID_SUPER_TABLE_ID;
|
||||||
pTable->schema = tdDupSchema(pCfg->schema);
|
pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS);
|
||||||
|
pTable->numOfSchemas = 1;
|
||||||
|
pTable->schema[0] = tdDupSchema(pCfg->schema);
|
||||||
pTable->tagSchema = tdDupSchema(pCfg->tagSchema);
|
pTable->tagSchema = tdDupSchema(pCfg->tagSchema);
|
||||||
|
|
||||||
tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN);
|
tsize = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN);
|
||||||
|
@ -340,16 +361,20 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
|
||||||
if (pCfg->type == TSDB_CHILD_TABLE) {
|
if (pCfg->type == TSDB_CHILD_TABLE) {
|
||||||
pTable->superUid = pCfg->superUid;
|
pTable->superUid = pCfg->superUid;
|
||||||
pTable->tagVal = tdKVRowDup(pCfg->tagValues);
|
pTable->tagVal = tdKVRowDup(pCfg->tagValues);
|
||||||
} else if (pCfg->type == TSDB_NORMAL_TABLE) {
|
} else {
|
||||||
|
pTable->schema = (STSchema **)malloc(sizeof(STSchema *) * TSDB_MAX_TABLE_SCHEMAS);
|
||||||
|
pTable->numOfSchemas = 1;
|
||||||
|
pTable->schema[0] = tdDupSchema(pCfg->schema);
|
||||||
|
|
||||||
|
if (pCfg->type == TSDB_NORMAL_TABLE) {
|
||||||
pTable->superUid = -1;
|
pTable->superUid = -1;
|
||||||
pTable->schema = tdDupSchema(pCfg->schema);
|
|
||||||
} else {
|
} else {
|
||||||
ASSERT(pCfg->type == TSDB_STREAM_TABLE);
|
ASSERT(pCfg->type == TSDB_STREAM_TABLE);
|
||||||
pTable->superUid = -1;
|
pTable->superUid = -1;
|
||||||
pTable->schema = tdDupSchema(pCfg->schema);
|
|
||||||
pTable->sql = strdup(pCfg->sql);
|
pTable->sql = strdup(pCfg->sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return pTable;
|
return pTable;
|
||||||
|
|
||||||
|
@ -580,7 +605,7 @@ static int tsdbFreeTable(STable *pTable) {
|
||||||
if (pTable->type == TSDB_CHILD_TABLE) {
|
if (pTable->type == TSDB_CHILD_TABLE) {
|
||||||
kvRowFree(pTable->tagVal);
|
kvRowFree(pTable->tagVal);
|
||||||
} else {
|
} else {
|
||||||
tdFreeSchema(pTable->schema);
|
for (int i = 0; i < pTable->numOfSchemas; i++) tdFreeSchema(pTable->schema[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTable->type == TSDB_STREAM_TABLE) {
|
if (pTable->type == TSDB_STREAM_TABLE) {
|
||||||
|
@ -642,9 +667,10 @@ static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the pMeta->maxCols and pMeta->maxRowBytes
|
// Update the pMeta->maxCols and pMeta->maxRowBytes
|
||||||
if (pTable->type == TSDB_SUPER_TABLE || pTable->type == TSDB_NORMAL_TABLE) {
|
if (pTable->type == TSDB_SUPER_TABLE || pTable->type == TSDB_NORMAL_TABLE || pTable->type == TSDB_STREAM_TABLE) {
|
||||||
if (schemaNCols(pTable->schema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(pTable->schema);
|
if (schemaNCols(pTable->schema[pTable->numOfSchemas - 1]) > pMeta->maxCols)
|
||||||
int bytes = dataRowMaxBytesFromSchema(pTable->schema);
|
pMeta->maxCols = schemaNCols(pTable->schema[pTable->numOfSchemas - 1]);
|
||||||
|
int bytes = dataRowMaxBytesFromSchema(pTable->schema[pTable->numOfSchemas - 1]);
|
||||||
if (bytes > pMeta->maxRowBytes) pMeta->maxRowBytes = bytes;
|
if (bytes > pMeta->maxRowBytes) pMeta->maxRowBytes = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue