diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 89acf66f21a2d7fa6d622da07f735307e38413a2..62f9605b6aa81623052bd2de59c6ef2dafe73f77 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -78,8 +78,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; @@ -91,6 +93,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); diff --git a/src/mnode/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c index 3c66ff6c57a61a56c361d1d125cedca152f2e2e0..8b5969cfd019c18a7eda4d32d6da82e1eeb3c230 100644 --- a/src/mnode/src/mgmtDnode.c +++ b/src/mnode/src/mgmtDnode.c @@ -402,8 +402,10 @@ static int32_t mgmtCreateDnode(uint32_t ip) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { + int dnodeId = pDnode->dnodeId; tfree(pDnode); - code = TSDB_CODE_SDB_ERROR; + mError("failed to create dnode:%d, result:%s", dnodeId, tstrerror(code)); + return TSDB_CODE_SDB_ERROR; } mPrint("dnode:%d is created, result:%s", pDnode->dnodeId, tstrerror(code)); diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index 8af20269771573ca4ea1bb1c5551d02fccb90d2c..48181c078b07d8f91fc17a3acce489b01c2556fd 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -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; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 75a0c4d2a8ec49e9ec283736b3e7dcc824302726..9816dbf135e3e0d277faa03d584c35c7029664be 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -462,10 +462,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) { diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 5d443d2290d70f01bf10e1081a9c1b547ade40dd..8bbac11dc10dbaa33152a1f3e625523a51a0adf3 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -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); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 1692bc14eb717d5284aa23bb42fdc31698c105f8..8e66a427de250ef4139f89845de8e75f09beaf0c 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -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; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index 7ec55bbf1f1e44cf319d60e75f5da7753ef762d3..ab324bcfad10b131238b911e895c99d0a343e5f1 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -208,7 +208,10 @@ int walRestore(void *handle, void *pVnode, int (*writeFp)(void *, void *, int)) } } - if (count == 0) return 0; + if (count == 0) { + if (pWal->keep) code = walRenew(pWal); + return code; + } if ( count != (maxId-minId+1) ) { wError("wal:%s, messed up, count:%d max:%d min:%d", opath, count, maxId, minId); diff --git a/tests/script/unique/mnode/basic1.sim b/tests/script/unique/mnode/basic1.sim new file mode 100644 index 0000000000000000000000000000000000000000..98d4bf02bf463a7a306c3a55063578ebd42273f4 --- /dev/null +++ b/tests/script/unique/mnode/basic1.sim @@ -0,0 +1,15 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1 +system sh/deploy.sh -n dnode2 -m 192.168.0.1 -i 192.168.0.2 +system sh/deploy.sh -n dnode3 -m 192.168.0.1 -i 192.168.0.3 +system sh/cfg.sh -n dnode1 -c numOfMPeers -v 3 +system sh/cfg.sh -n dnode2 -c numOfMPeers -v 3 +system sh/cfg.sh -n dnode3 -c numOfMPeers -v 3 + +system sh/exec_up.sh -n dnode1 -s start +system sh/exec_up.sh -n dnode2 -s start + +sql connect + +sleep 2000 +sql create dnode 192.168.0.2