diff --git a/src/inc/mnode.h b/src/inc/mnode.h index bbb6fc53851700c70e192d4e368183acd833ea28..01358fdb447d93e9f68cb30376e753ed112fab25 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -48,6 +48,7 @@ typedef struct SMnodeMsg { struct SDbObj * pDb; struct SVgObj * pVgroup; struct STableObj *pTable; + struct SSuperTableObj *pSTable; } SMnodeMsg; void mnodeCreateMsg(SMnodeMsg *pMsg, SRpcMsg *rpcMsg); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 01f56f8902c09057f83b8b8ff67c9ceea6fa652c..5ec5aebf144d6d576824e907617572dd0950c5bc 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -311,6 +311,15 @@ static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->replications < 0) pCfg->replications = tsReplications; } +static int32_t mnodeCreateDbCb(SMnodeMsg *pMsg, int32_t code) { + SDbObj *pDb = pMsg->pDb; + if (pDb != NULL) { + mLPrint("db:%s, is created by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); + } + + return code; +} + static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMsg) { int32_t code = acctCheck(pAcct, ACCT_GRANT_DB); if (code != 0) return code; @@ -364,18 +373,18 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs .table = tsDbSdb, .pObj = pDb, .rowSize = sizeof(SDbObj), - .pMsg = pMsg + .pMsg = pMsg, + .cb = mnodeCreateDbCb }; code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { tfree(pDb); + mLPrint("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code)); + return code; } else { - mLPrint("db:%s, is created by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); - if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } - - return code; } bool mnodeCheckIsMonitorDB(char *db, char *monitordb) { diff --git a/src/mnode/src/mnodeInt.c b/src/mnode/src/mnodeInt.c index c2dd46d981a52040a0e961eda3a43496dbafdbd9..91c8dcb6e52e86ef009c18e69b00252c66346b1b 100644 --- a/src/mnode/src/mnodeInt.c +++ b/src/mnode/src/mnodeInt.c @@ -54,6 +54,7 @@ void mnodeCleanupMsg(SMnodeMsg *pMsg) { if (pMsg->pDb) mnodeDecDbRef(pMsg->pDb); if (pMsg->pVgroup) mnodeDecVgroupRef(pMsg->pVgroup); if (pMsg->pTable) mnodeDecTableRef(pMsg->pTable); + if (pMsg->pSTable) mnodeDecTableRef(pMsg->pSTable); if (pMsg->pAcct) mnodeDecAcctRef(pMsg->pAcct); if (pMsg->pDnode) mnodeDecDnodeRef(pMsg->pDnode); } diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 346c33f80de78d361c159aa5d192b31a2e474047..4906aeaeb09ae8fd3fca84747ab6cf925aa88c20 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -783,7 +783,7 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) { static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; if (pTable != NULL) { - mLPrint("app:%p:%p, stable:%s, create result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, + mLPrint("app:%p:%p, stable:%s, is created in sdb, result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); } @@ -852,6 +852,15 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { } } +static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) { + SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; + if (pTable != NULL) { + mLPrint("app:%p:%p, stable:%s, is dropped from sdb, result:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, + tstrerror(code)); + } + + return code; +} static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; @@ -882,19 +891,20 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { } SSdbOper oper = { - .type = SDB_OPER_GLOBAL, + .type = SDB_OPER_GLOBAL, .table = tsSuperTableSdb, - .pObj = pStable, - .pMsg = pMsg + .pObj = pStable, + .pMsg = pMsg, + .cb = mnodeDropSuperTableCb }; - + int32_t code = sdbDeleteRow(&oper); - if (code == TSDB_CODE_SUCCESS) { - mLPrint("stable:%s, is dropped from sdb, result:%s", pStable->info.tableId, tstrerror(code)); - code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + if (code != TSDB_CODE_SUCCESS) { + mError("app:%p:%p, table:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId); + return code; + } else { + return TSDB_CODE_MND_ACTION_IN_PROGRESS; } - - return code; } static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char *tagName) { @@ -1596,19 +1606,18 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { if (pTable->info.type == TSDB_CHILD_TABLE) { STagData *pTagData = (STagData *) pCreate->schema; // it is a tag key - SSuperTableObj *pSuperTable = mnodeGetSuperTable(pTagData->name); - if (pSuperTable == NULL) { + if (pMsg->pSTable == NULL) pMsg->pSTable = mnodeGetSuperTable(pTagData->name); + if (pMsg->pSTable == NULL) { mError("app:%p:%p, table:%s, corresponding super table:%s does not exist", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, pTagData->name); mnodeDestroyChildTable(pTable); return TSDB_CODE_MND_INVALID_TABLE_NAME; } - mnodeDecTableRef(pSuperTable); - - pTable->suid = pSuperTable->uid; + + pTable->suid = pMsg->pSTable->uid; pTable->uid = (((uint64_t)pTable->vgId) << 40) + ((((uint64_t)pTable->sid) & ((1ul << 24) - 1ul)) << 16) + (sdbGetVersion() & ((1ul << 16) - 1ul)); - pTable->superTable = pSuperTable; + pTable->superTable = pMsg->pSTable; } else { pTable->uid = (((uint64_t) pTable->createdTime) << 16) + (sdbGetVersion() & ((1ul << 16) - 1ul)); pTable->sversion = 0; @@ -1661,9 +1670,10 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) { pMsg->pTable = NULL; mError("app:%p:%p, table:%s, update sdb error, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, tstrerror(code)); - } - - return code; + return code; + } else { + return TSDB_CODE_MND_ACTION_IN_PROGRESS; + } } static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { @@ -1698,12 +1708,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { mTrace("app:%p:%p, table:%s, create table in vgroup, vgId:%d sid:%d", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, pVgroup->vgId, sid); - code = mnodeDoCreateChildTable(pMsg, sid); - if (code != TSDB_CODE_SUCCESS) { - return code; - } else { - return TSDB_CODE_MND_ACTION_IN_PROGRESS; - } + return mnodeDoCreateChildTable(pMsg, sid); } } else { if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pCreate->tableId); diff --git a/tests/script/loop.sh b/tests/script/loop.sh index adafe2ed605ffeacbd7dba4e8e13672323fc5bb6..3e6306d624fdc53cd8f688ef27c33c46b8159a89 100755 --- a/tests/script/loop.sh +++ b/tests/script/loop.sh @@ -30,10 +30,15 @@ done echo LOOP_TIMES ${LOOP_TIMES} echo CMD_NAME ${CMD_NAME} +GREEN='\033[1;32m' +GREEN_DARK='\033[0;32m' +GREEN_UNDERLINE='\033[4;32m' +NC='\033[0m' + for ((i=0; i<$LOOP_TIMES; i++ )) do - echo loop $i - echo cmd $CMD_NAME + echo -e $GREEN loop $i $NC + echo -e $GREEN cmd $CMD_NAME $NC $CMD_NAME sleep 2 done