Skip to content

Commit

Permalink
Merge pull request #1647 from taosdata/feature/add_tbname_in_tsdb
Browse files Browse the repository at this point in the history
add tbname in tsdb
  • Loading branch information
guanshengliang committed Apr 18, 2020
2 parents 3330d8d + 43a0747 commit 57f473e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/inc/tsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/tsdb/inc/tsdbMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions src/tsdb/src/tsdbMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 16 additions & 1 deletion src/tsdb/src/tsdbMeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -374,6 +387,7 @@ static int tsdbFreeTable(STable *pTable) {
tsdbFreeMemTable(pTable->mem);
tsdbFreeMemTable(pTable->imem);

tfree(pTable->name);
free(pTable);
return 0;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/vnode/src/vnodeWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ 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);
for (int i = numOfColumns; i < totalCols; i++) {
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;
Expand Down

0 comments on commit 57f473e

Please sign in to comment.