diff --git a/src/mnode/inc/mgmtDef.h b/src/mnode/inc/mgmtDef.h index 34249d3f00cddfca1c73df0732386ba08c6a832f..f6a85ec237751dda77a46a97abc9edb9c3861c7e 100644 --- a/src/mnode/inc/mgmtDef.h +++ b/src/mnode/inc/mgmtDef.h @@ -32,8 +32,8 @@ struct SMnodeObj; typedef struct SDnodeObj { int32_t dnodeId; uint16_t dnodePort; - char dnodeFqdn[TSDB_FQDN_LEN]; - char dnodeEp[TSDB_FQDN_LEN]; + char dnodeFqdn[TSDB_FQDN_LEN + 1]; + char dnodeEp[TSDB_FQDN_LEN + 1]; int64_t createdTime; uint32_t lastAccess; int32_t openVnodes; @@ -96,7 +96,7 @@ typedef struct { int32_t numOfColumns; //used by normal table int32_t sid; int32_t vgId; - char superTableId[TSDB_TABLE_ID_LEN + 1]; + uint64_t suid; int32_t sqlLen; int8_t reserved[1]; int8_t updateEnd[1]; diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index a1d260d1cf1d86d2e92ebefe8ce5dd331c9e9d1f..6ed19b3d1146e8478ff7cc2f84121b55e5396433 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -47,6 +47,7 @@ static int32_t tsChildTableUpdateSize; static int32_t tsSuperTableUpdateSize; static void * mgmtGetChildTable(char *tableId); static void * mgmtGetSuperTable(char *tableId); +static void * mgmtGetSuperTableByUid(uint64_t uid); static void mgmtDropAllChildTablesInStable(SSuperTableObj *pStable); static void mgmtAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable); static void mgmtRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable); @@ -118,7 +119,7 @@ static int32_t mgmtChildTableActionInsert(SSdbOper *pOper) { if (pTable->info.type == TSDB_CHILD_TABLE) { // add ref - pTable->superTable = mgmtGetSuperTable(pTable->superTableId); + pTable->superTable = mgmtGetSuperTableByUid(pTable->suid); mgmtAddTableIntoStable(pTable->superTable, pTable); grantAdd(TSDB_GRANT_TIMESERIES, pTable->superTable->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries += (pTable->superTable->numOfColumns - 1); @@ -308,9 +309,9 @@ static int32_t mgmtChildTableActionRestored() { } if (pTable->info.type == TSDB_CHILD_TABLE) { - SSuperTableObj *pSuperTable = mgmtGetSuperTable(pTable->superTableId); + SSuperTableObj *pSuperTable = mgmtGetSuperTableByUid(pTable->suid); if (pSuperTable == NULL) { - mError("ctable:%s, stable:%s not exist", pTable->info.tableId, pTable->superTableId); + mError("ctable:%s, stable:%" PRIu64 " not exist", pTable->info.tableId, pTable->suid); pTable->vgId = 0; SSdbOper desc = {0}; desc.type = SDB_OPER_LOCAL; @@ -560,6 +561,22 @@ static void *mgmtGetSuperTable(char *tableId) { return sdbGetRow(tsSuperTableSdb, tableId); } +static void *mgmtGetSuperTableByUid(uint64_t uid) { + SSuperTableObj *pStable = NULL; + void * pNode = NULL; + + while (1) { + pNode = mgmtGetNextSuperTable(pNode, &pStable); + if (pStable == NULL) break; + if (pStable->uid == uid) { + return pStable; + } + mgmtDecTableRef(pStable); + } + + return NULL; +} + void *mgmtGetTable(char *tableId) { void *pTable = mgmtGetSuperTable(tableId); if (pTable != NULL) { @@ -1358,10 +1375,10 @@ static SChildTableObj* mgmtDoCreateChildTable(SCMCreateTableMsg *pCreate, SVgObj } mgmtDecTableRef(pSuperTable); - strcpy(pTable->superTableId, pSuperTable->info.tableId); - pTable->uid = (((uint64_t) pTable->vgId) << 40) + ((((uint64_t) pTable->sid) & ((1ul << 24) - 1ul)) << 16) + - (sdbGetVersion() & ((1ul << 16) - 1ul)); - pTable->superTable = pSuperTable; + pTable->suid = pSuperTable->uid; + pTable->uid = (((uint64_t)pTable->vgId) << 40) + ((((uint64_t)pTable->sid) & ((1ul << 24) - 1ul)) << 16) + + (sdbGetVersion() & ((1ul << 16) - 1ul)); + pTable->superTable = pSuperTable; } else { pTable->uid = (((uint64_t) pTable->createdTime) << 16) + (sdbGetVersion() & ((1ul << 16) - 1ul)); pTable->sversion = 0; @@ -2073,7 +2090,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; if (pTable->info.type == TSDB_CHILD_TABLE) { - mgmtExtractTableName(pTable->superTableId, pWrite); + mgmtExtractTableName(pTable->superTable->info.tableId, pWrite); } cols++;