未验证 提交 57f473e2 编写于 作者: S slguan 提交者: GitHub

Merge pull request #1647 from taosdata/feature/add_tbname_in_tsdb

add tbname in tsdb
......@@ -77,8 +77,10 @@ typedef struct {
// --------- TSDB TABLE configuration
typedef struct {
ETableType type;
char * name;
STableId tableId;
int32_t sversion;
char * sname; // super table name
int64_t superUid;
STSchema * schema;
STSchema * tagSchema;
......@@ -90,6 +92,8 @@ int tsdbTableSetSuperUid(STableCfg *config, int64_t uid);
int tsdbTableSetSchema(STableCfg *config, STSchema *pSchema, bool dup);
int tsdbTableSetTagSchema(STableCfg *config, STSchema *pSchema, bool dup);
int tsdbTableSetTagValue(STableCfg *config, SDataRow row, bool dup);
int tsdbTableSetName(STableCfg *config, char *name, bool dup);
int tsdbTableSetSName(STableCfg *config, char *sname, bool dup);
void tsdbClearTableCfg(STableCfg *config);
int32_t tsdbGetTableTagVal(tsdb_repo_t *repo, STableId id, int32_t col, int16_t* type, int16_t* bytes, char** val);
......
......@@ -62,6 +62,7 @@ typedef struct {
// ---------- TSDB TABLE DEFINITION
typedef struct STable {
int8_t type;
char * name;
STableId tableId;
int64_t superUid; // Super table UID
int32_t sversion;
......
......@@ -459,10 +459,35 @@ int tsdbTableSetTagValue(STableCfg *config, SDataRow row, bool dup) {
return 0;
}
int tsdbTableSetName(STableCfg *config, char *name, bool dup) {
if (dup) {
config->name = strdup(name);
if (config->name == NULL) return -1;
} else {
config->name = name;
}
return 0;
}
int tsdbTableSetSName(STableCfg *config, char *sname, bool dup) {
if (config->type != TSDB_CHILD_TABLE) return -1;
if (dup) {
config->sname = strdup(sname);
if (config->sname == NULL) return -1;
} else {
config->sname = sname;
}
return 0;
}
void tsdbClearTableCfg(STableCfg *config) {
if (config->schema) tdFreeSchema(config->schema);
if (config->tagSchema) tdFreeSchema(config->tagSchema);
if (config->tagValues) tdFreeDataRow(config->tagValues);
tfree(config->name);
tfree(config->sname);
}
int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
......
......@@ -39,6 +39,11 @@ void *tsdbEncodeTable(STable *pTable, int *contLen) {
void *ptr = ret;
T_APPEND_MEMBER(ptr, pTable, STable, type);
// Encode name
*(int *)ptr = strlen(pTable->name);
ptr = (char *)ptr + sizeof(int);
memcpy(ptr, pTable->name, strlen(pTable->name));
ptr = (char *)ptr + strlen(pTable->name);
T_APPEND_MEMBER(ptr, &(pTable->tableId), STableId, uid);
T_APPEND_MEMBER(ptr, &(pTable->tableId), STableId, tid);
T_APPEND_MEMBER(ptr, pTable, STable, superUid);
......@@ -72,6 +77,12 @@ STable *tsdbDecodeTable(void *cont, int contLen) {
void *ptr = cont;
T_READ_MEMBER(ptr, int8_t, pTable->type);
int len = *(int *)ptr;
ptr = (char *)ptr + sizeof(int);
pTable->name = calloc(1, len + 1);
if (pTable->name == NULL) return NULL;
memcpy(pTable->name, ptr, len);
ptr = (char *)ptr + len;
T_READ_MEMBER(ptr, int64_t, pTable->tableId.uid);
T_READ_MEMBER(ptr, int32_t, pTable->tableId.tid);
T_READ_MEMBER(ptr, int64_t, pTable->superUid);
......@@ -252,7 +263,8 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
super->schema = tdDupSchema(pCfg->schema);
super->tagSchema = tdDupSchema(pCfg->tagSchema);
super->tagVal = tdDataRowDup(pCfg->tagValues);
super->name = strdup(pCfg->sname);
// index the first tag column
STColumn* pColSchema = schemaColAt(super->tagSchema, 0);
super->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, pColSchema->type, pColSchema->bytes,
......@@ -277,6 +289,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
}
table->tableId = pCfg->tableId;
table->name = strdup(pCfg->name);
if (IS_CREATE_STABLE(pCfg)) { // TSDB_CHILD_TABLE
table->type = TSDB_CHILD_TABLE;
table->superUid = pCfg->superUid;
......@@ -374,6 +387,7 @@ static int tsdbFreeTable(STable *pTable) {
tsdbFreeMemTable(pTable->mem);
tsdbFreeMemTable(pTable->imem);
tfree(pTable->name);
free(pTable);
return 0;
}
......@@ -468,6 +482,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
static int tsdbEstimateTableEncodeSize(STable *pTable) {
int size = 0;
size += T_MEMBER_SIZE(STable, type);
size += sizeof(int) + strlen(pTable->name);
size += T_MEMBER_SIZE(STable, tableId);
size += T_MEMBER_SIZE(STable, superUid);
size += T_MEMBER_SIZE(STable, sversion);
......
......@@ -126,6 +126,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
tdSchemaAppendCol(pDestSchema, pSchema[i].type, htons(pSchema[i].colId), htons(pSchema[i].bytes));
}
tsdbTableSetSchema(&tCfg, pDestSchema, false);
tsdbTableSetName(&tCfg, pTable->tableId, false);
if (numOfTags != 0) {
STSchema *pDestTagSchema = tdNewSchema(numOfTags);
......@@ -133,6 +134,7 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe
tdSchemaAppendCol(pDestTagSchema, pSchema[i].type, htons(pSchema[i].colId), htons(pSchema[i].bytes));
}
tsdbTableSetTagSchema(&tCfg, pDestTagSchema, false);
tsdbTableSetSName(&tCfg, pTable->superTableId, false);
char *pTagData = pTable->data + totalCols * sizeof(SSchema);
int accumBytes = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册