diff --git a/src/inc/mnode.h b/src/inc/mnode.h index 307a7a252a5281371fa698643c2523b40eaf3654..597342d3cbe030a86eb41b33292514ae99de1c09 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -59,6 +59,7 @@ typedef struct { char mnodeName[TSDB_DNODE_NAME_LEN + 1]; int8_t reserved[15]; int8_t updateEnd[1]; + int32_t refCount; int syncFd; void *hbTimer; void *pSync; @@ -84,6 +85,7 @@ typedef struct { char dnodeName[TSDB_DNODE_NAME_LEN + 1]; int8_t reserved[15]; int8_t updateEnd[1]; + int32_t refCount; SVnodeLoad vload[TSDB_MAX_VNODES]; int32_t status; uint32_t lastReboot; // time stamp for last reboot @@ -151,6 +153,7 @@ typedef struct _vg_obj { int8_t lbStatus; int8_t reserved[14]; int8_t updateEnd[1]; + int32_t refCount; struct _vg_obj *prev, *next; struct _db_obj *pDb; int32_t numOfTables; @@ -216,6 +219,7 @@ typedef struct _acctObj { int8_t dirty; int8_t reserved[14]; int8_t updateEnd[1]; + int32_t refCount; SAcctInfo acctInfo; pthread_mutex_t mutex; } SAcctObj; @@ -248,6 +252,7 @@ typedef struct { void *pCont; SUserObj *pUser; SDbObj *pDb; + SVgObj *pVgroup; STableInfo *pTable; } SQueuedMsg; diff --git a/src/mnode/inc/mgmtAcct.h b/src/mnode/inc/mgmtAcct.h index 36758c19ebe441d16ce02443792edd556d57f013..1f8dc5c74ae11a3df081411829e46c1ecc34c82d 100644 --- a/src/mnode/inc/mgmtAcct.h +++ b/src/mnode/inc/mgmtAcct.h @@ -30,6 +30,8 @@ typedef enum { int32_t acctInit(); void acctCleanUp(); SAcctObj *acctGetAcct(char *acctName); +void acctIncRef(SAcctObj *pAcct); +void acctDecRef(SAcctObj *pAcct); int32_t acctCheck(SAcctObj *pAcct, EAcctGrantType type); void acctAddDb(SAcctObj *pAcct, SDbObj *pDb); diff --git a/src/mnode/inc/mgmtVgroup.h b/src/mnode/inc/mgmtVgroup.h index 7743f0451be94b658cd4dbbcae450be54d03e786..d0b1e0de971a0adea6f2aec65bb0eeb6da337438 100644 --- a/src/mnode/inc/mgmtVgroup.h +++ b/src/mnode/inc/mgmtVgroup.h @@ -27,6 +27,8 @@ extern "C" { int32_t mgmtInitVgroups(); void mgmtCleanUpVgroups(); SVgObj *mgmtGetVgroup(int32_t vgId); +void mgmtIncVgroupRef(SVgObj *pVgroup); +void mgmtDecVgroupRef(SVgObj *pVgroup); void mgmtDropAllVgroups(SDbObj *pDropDb); void mgmtCreateVgroup(SQueuedMsg *pMsg, SDbObj *pDb); diff --git a/src/mnode/src/mgmtAcct.c b/src/mnode/src/mgmtAcct.c index fab9e9a9ca24c15ba7f31e8f1dae7b297fdf9e8d..22690c4a44ebdf6bd17755f75bf3b2d405c3fa01 100644 --- a/src/mnode/src/mgmtAcct.c +++ b/src/mnode/src/mgmtAcct.c @@ -32,25 +32,31 @@ int32_t acctInit() { void acctCleanUp() {} SAcctObj *acctGetAcct(char *acctName) { return &tsAcctObj; } +void acctIncRef(SAcctObj *pAcct) {} +void acctDecRef(SAcctObj *pAcct) {} int32_t acctCheck(SAcctObj *pAcct, EAcctGrantType type) { return TSDB_CODE_SUCCESS; } #endif void acctAddDb(SAcctObj *pAcct, SDbObj *pDb) { atomic_add_fetch_32(&pAcct->acctInfo.numOfDbs, 1); pDb->pAcct = pAcct; + acctIncRef(pAcct); } void acctRemoveDb(SAcctObj *pAcct, SDbObj *pDb) { atomic_sub_fetch_32(&pAcct->acctInfo.numOfDbs, 1); pDb->pAcct = NULL; + acctIncRef(pAcct); } void acctAddUser(SAcctObj *pAcct, SUserObj *pUser) { atomic_add_fetch_32(&pAcct->acctInfo.numOfUsers, 1); pUser->pAcct = pAcct; + acctIncRef(pAcct); } void acctRemoveUser(SAcctObj *pAcct, SUserObj *pUser) { atomic_sub_fetch_32(&pAcct->acctInfo.numOfUsers, 1); pUser->pAcct = NULL; + acctIncRef(pAcct); } \ No newline at end of file diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 8c293865ab23e2305e213cf3c2c3085e313c91ba..4678247e69e18d38c5aa43694fa4ff2e17046e3d 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -33,7 +33,7 @@ #include "mgmtUser.h" #include "mgmtVgroup.h" -void * tsDbSdb = NULL; +static void * tsDbSdb = NULL; static int32_t tsDbUpdateSize; static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate); @@ -116,7 +116,7 @@ int32_t mgmtInitDbs() { .tableName = "dbs", .hashSessions = TSDB_MAX_DBS, .maxRowSize = tsDbUpdateSize, - .refCountPos = 0,//(int8_t *)(&tObj.refCount) - (int8_t *)&tObj, + .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_TYPE_STRING, .insertFp = mgmtDbActionInsert, .deleteFp = mgmtDbActionDelete, diff --git a/src/mnode/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c index 53f0a668b409702a39614a1bf99b5071becd7d11..65531bd36d6d638916884fcaf6c64a1ac1d9f641 100644 --- a/src/mnode/src/mgmtDnode.c +++ b/src/mnode/src/mgmtDnode.c @@ -215,6 +215,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { mPrint("dnode:%d, vgroup:%d not exist in mnode, drop it", pDnode->dnodeId, pDnode->vload[j].vgId); mgmtSendDropVnodeMsg(pDnode->vload[j].vgId, &ipSet, NULL); } + mgmtDecVgroupRef(pVgroup); } if (pDnode->status != TSDB_DN_STATUS_READY) { diff --git a/src/mnode/src/mgmtProfile.c b/src/mnode/src/mgmtProfile.c index 1549b5f37cca0941f25717e51f2ec416d411c195..ae921a0505f4f28e2545ee2b39ffb65b1db829ee 100644 --- a/src/mnode/src/mgmtProfile.c +++ b/src/mnode/src/mgmtProfile.c @@ -789,6 +789,7 @@ void mgmtFreeQueuedMsg(SQueuedMsg *pMsg) { rpcFreeCont(pMsg->pCont); if (pMsg->pUser) mgmtDecUserRef(pMsg->pUser); if (pMsg->pDb) mgmtDecDbRef(pMsg->pDb); + if (pMsg->pVgroup) mgmtDecVgroupRef(pMsg->pVgroup); if (pMsg->pTable) mgmtDecTableRef(pMsg->pTable); free(pMsg); } diff --git a/src/mnode/src/mgmtSdb.c b/src/mnode/src/mgmtSdb.c index b3b64ab6644a53335bc3aaab100ae289e563b7ee..d98ed623a4a5331cf75ad68387f9f8e75dbc24b3 100644 --- a/src/mnode/src/mgmtSdb.c +++ b/src/mnode/src/mgmtSdb.c @@ -433,25 +433,21 @@ static SRowMeta *sdbGetRowMeta(void *handle, void *key) { void sdbIncRef(void *handle, void *pRow) { if (pRow) { SSdbTable *pTable = handle; - if (pTable->refCountPos > 0) { - int32_t *pRefCount = (int32_t *)(pRow + pTable->refCountPos); - atomic_add_fetch_32(pRefCount, 1); - sdbTrace("add ref to record:%s:%s:%d", pTable->tableName, sdbGetkeyStr(pTable, pRow), *pRefCount); - } + int32_t *pRefCount = (int32_t *)(pRow + pTable->refCountPos); + atomic_add_fetch_32(pRefCount, 1); + sdbTrace("add ref to record:%s:%s:%d", pTable->tableName, sdbGetkeyStr(pTable, pRow), *pRefCount); } } void sdbDecRef(void *handle, void *pRow) { if (pRow) { SSdbTable *pTable = handle; - if (pTable->refCountPos > 0) { - int32_t *pRefCount = (int32_t *)(pRow + pTable->refCountPos); - int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); - sdbTrace("def ref of record:%s:%s:%d", pTable->tableName, sdbGetkeyStr(pTable, pRow), *pRefCount); - if (refCount <= 0) { - SSdbOperDesc oper = {.pObj = pRow}; - (*pTable->destroyFp)(&oper); - } + int32_t *pRefCount = (int32_t *)(pRow + pTable->refCountPos); + int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); + sdbTrace("def ref of record:%s:%s:%d", pTable->tableName, sdbGetkeyStr(pTable, pRow), *pRefCount); + if (refCount <= 0) { + SSdbOperDesc oper = {.pObj = pRow}; + (*pTable->destroyFp)(&oper); } } } diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index 6e296722ea5a32c16eeb8854c7dca23578d0a380..e2ed023fd24b4ca7b28cfecf9ae7efa1b45f0429 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -45,8 +45,8 @@ #include "mgmtUser.h" #include "mgmtVgroup.h" -void * tsChildTableSdb; -void * tsSuperTableSdb; +static void * tsChildTableSdb; +static void * tsSuperTableSdb; static int32_t tsChildTableUpdateSize; static int32_t tsSuperTableUpdateSize; @@ -239,7 +239,7 @@ static int32_t mgmtInitChildTables() { .tableName = "ctables", .hashSessions = tsMaxTables, .maxRowSize = sizeof(SChildTableObj) + sizeof(SSchema) * TSDB_MAX_COLUMNS, - .refCountPos = 0, //(int8_t *)(&tObj.refCount) - (int8_t *)&tObj, + .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_TYPE_STRING, .insertFp = mgmtChildTableActionInsert, .deleteFp = mgmtChildTableActionDelete, @@ -415,7 +415,7 @@ static int32_t mgmtInitSuperTables() { .tableName = "stables", .hashSessions = TSDB_MAX_SUPER_TABLES, .maxRowSize = tsSuperTableUpdateSize + sizeof(SSchema) * TSDB_MAX_COLUMNS, - .refCountPos = 0, //(int8_t *)(&tObj.refCount) - (int8_t *)&tObj, + .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_TYPE_STRING, .insertFp = mgmtSuperTableActionInsert, .deleteFp = mgmtSuperTableActionDelete, @@ -1355,7 +1355,7 @@ static void mgmtProcessCreateChildTableMsg(SQueuedMsg *pMsg) { return; } - SVgObj *pVgroup = mgmtGetAvailableVgroup(pMsg->pDb); + SVgObj *pVgroup = pMsg->pVgroup = mgmtGetAvailableVgroup(pMsg->pDb); if (pVgroup == NULL) { mTrace("table:%s, start to create a new vgroup", pCreate->tableId); mgmtCreateVgroup(mgmtCloneQueuedMsg(pMsg), pMsg->pDb); @@ -1397,7 +1397,7 @@ static void mgmtProcessCreateChildTableMsg(SQueuedMsg *pMsg) { void mgmtProcessDropChildTableMsg(SQueuedMsg *pMsg) { SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; - SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId); + SVgObj *pVgroup = pMsg->pVgroup = mgmtGetVgroup(pTable->vgId); if (pVgroup == NULL) { mError("table:%s, failed to drop ctable, vgroup not exist", pTable->info.tableId); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_OTHERS); @@ -1817,7 +1817,7 @@ static void mgmtProcessDropTableRsp(SRpcMsg *rpcMsg) { return; } - SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId); + SVgObj *pVgroup = pMsg->pVgroup = mgmtGetVgroup(pTable->vgId); if (pVgroup == NULL) { mError("table:%s, failed to get vgroup", pTable->info.tableId); mgmtSendSimpleResp(queueMsg->thandle, TSDB_CODE_INVALID_VGROUP_ID); diff --git a/src/mnode/src/mgmtUser.c b/src/mnode/src/mgmtUser.c index b5a88f42d0e7b70540c460b7ef38d961a126a139..04b2a9ad2b7d6b20df5f46bc2096027b2b311dfc 100644 --- a/src/mnode/src/mgmtUser.c +++ b/src/mnode/src/mgmtUser.c @@ -25,7 +25,7 @@ #include "mgmtShell.h" #include "mgmtUser.h" -void * tsUserSdb = NULL; +static void * tsUserSdb = NULL; static int32_t tsUserUpdateSize = 0; static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn); @@ -97,7 +97,7 @@ int32_t mgmtInitUsers() { .tableName = "users", .hashSessions = TSDB_MAX_USERS, .maxRowSize = tsUserUpdateSize, - .refCountPos = 0, //(int8_t *)(&tObj.refCount) - (int8_t *)&tObj, + .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_TYPE_STRING, .insertFp = mgmtUserActionInsert, .deleteFp = mgmtUserActionDelete, @@ -117,7 +117,8 @@ int32_t mgmtInitUsers() { mgmtCreateUser(pAcct, "root", "taosdata"); mgmtCreateUser(pAcct, "monitor", tsInternalPass); mgmtCreateUser(pAcct, "_root", tsInternalPass); - + acctDecRef(pAcct); + mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CREATE_USER, mgmtProcessCreateUserMsg); mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_ALTER_USER, mgmtProcessAlterUserMsg); mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_DROP_USER, mgmtProcessDropUserMsg); diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index 36e8431570a794a46fc0b0d9433dd4647467991d..fbaa0a376b458385e4819e6fc4f17526e995092b 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -149,6 +149,7 @@ int32_t mgmtInitVgroups() { .tableName = "vgroups", .hashSessions = TSDB_MAX_VGROUPS, .maxRowSize = tsVgUpdateSize, + .refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj, .keyType = SDB_KEY_TYPE_AUTO, .insertFp = mgmtVgroupActionInsert, .deleteFp = mgmtVgroupActionDelete, @@ -174,6 +175,14 @@ int32_t mgmtInitVgroups() { return 0; } +void mgmtIncVgroupRef(SVgObj *pVgroup) { + return sdbIncRef(tsVgroupSdb, pVgroup); +} + +void mgmtDecVgroupRef(SVgObj *pVgroup) { + return sdbDecRef(tsVgroupSdb, pVgroup); +} + SVgObj *mgmtGetVgroup(int32_t vgId) { return (SVgObj *)sdbGetRow(tsVgroupSdb, &vgId); } diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index d990adaf5f652729db0a377c996d752ca3f940da..0192b189796d303af88fc8d8f5dbccbb49297bfd 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -92,7 +92,7 @@ echo "internalIp $NODE_IP" >> $TAOS_CFG echo "privateIp $NODE_IP" >> $TAOS_CFG echo "dDebugFlag 135" >> $TAOS_CFG echo "mDebugFlag 199" >> $TAOS_CFG -echo "sdbDebugFlag 135" >> $TAOS_CFG +echo "sdbDebugFlag 199" >> $TAOS_CFG echo "rpcDebugFlag 135" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "cDebugFlag 135" >> $TAOS_CFG