提交 fded16d1 编写于 作者: S Shengliang Guan

fix memory leak while drop user

上级 1b9b49c9
...@@ -75,7 +75,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char ...@@ -75,7 +75,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
if (pRaw == NULL) return -1; if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY); sdbSetRawStatus(pRaw, SDB_STATUS_READY);
mDebug("user:%s, will be created while deploy sdb", userObj.user); mDebug("user:%s, will be created while deploy sdb, raw:%p", userObj.user, pRaw);
return sdbWrite(pMnode->pSdb, pRaw); return sdbWrite(pMnode->pSdb, pRaw);
} }
...@@ -107,6 +107,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { ...@@ -107,6 +107,7 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE) SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE)
SDB_SET_DATALEN(pRaw, dataPos); SDB_SET_DATALEN(pRaw, dataPos);
mTrace("user:%s, encode to raw:%p, row:%p", pUser->user, pRaw, pUser);
return pRaw; return pRaw;
} }
...@@ -133,11 +134,12 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { ...@@ -133,11 +134,12 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser) SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser)
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE) SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE)
mTrace("user:%s, decode from raw:%p, row:%p", pUser->user, pRaw, pUser);
return pRow; return pRow;
} }
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
mTrace("user:%s, perform insert action", pUser->user); mTrace("user:%s, perform insert action, row:%p", pUser->user, pUser);
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pUser->prohibitDbHash == NULL) { if (pUser->prohibitDbHash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -158,7 +160,7 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { ...@@ -158,7 +160,7 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
} }
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
mTrace("user:%s, perform delete action", pUser->user); mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
if (pUser->prohibitDbHash) { if (pUser->prohibitDbHash) {
taosHashCleanup(pUser->prohibitDbHash); taosHashCleanup(pUser->prohibitDbHash);
pUser->prohibitDbHash = NULL; pUser->prohibitDbHash = NULL;
...@@ -168,7 +170,7 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { ...@@ -168,7 +170,7 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
} }
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) { static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) {
mTrace("user:%s, perform update action", pOldUser->user); mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOldUser->user, pOldUser, pNewUser);
memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN); memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN);
pOldUser->updateTime = pNewUser->updateTime; pOldUser->updateTime = pNewUser->updateTime;
return 0; return 0;
...@@ -242,7 +244,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { ...@@ -242,7 +244,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user); SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user);
if (pUser != NULL) { if (pUser != NULL) {
sdbRelease(pMnode->pSdb, pUser); mndReleaseUser(pMnode, pUser);
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST; terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
mError("user:%s, failed to create since %s", pCreate->user, terrstr()); mError("user:%s, failed to create since %s", pCreate->user, terrstr());
return -1; return -1;
...@@ -256,7 +258,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { ...@@ -256,7 +258,7 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
} }
int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg); int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
sdbRelease(pMnode->pSdb, pOperUser); mndReleaseUser(pMnode, pOperUser);
if (code != 0) { if (code != 0) {
mError("user:%s, failed to create since %s", pCreate->user, terrstr()); mError("user:%s, failed to create since %s", pCreate->user, terrstr());
...@@ -319,6 +321,7 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { ...@@ -319,6 +321,7 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
if (pOperUser == NULL) { if (pOperUser == NULL) {
mndReleaseUser(pMnode, pUser);
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
return -1; return -1;
...@@ -331,7 +334,8 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { ...@@ -331,7 +334,8 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
newUser.updateTime = taosGetTimestampMs(); newUser.updateTime = taosGetTimestampMs();
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg); int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg);
sdbRelease(pMnode->pSdb, pOperUser); mndReleaseUser(pMnode, pOperUser);
mndReleaseUser(pMnode, pUser);
if (code != 0) { if (code != 0) {
mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
...@@ -388,13 +392,15 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { ...@@ -388,13 +392,15 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) {
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
if (pOperUser == NULL) { if (pOperUser == NULL) {
mndReleaseUser(pMnode, pUser);
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
return -1; return -1;
} }
int32_t code = mndDropUser(pMnode, pMsg, pUser); int32_t code = mndDropUser(pMnode, pMsg, pUser);
sdbRelease(pMnode->pSdb, pOperUser); mndReleaseUser(pMnode, pOperUser);
mndReleaseUser(pMnode, pUser);
if (code != 0) { if (code != 0) {
mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
......
...@@ -57,12 +57,14 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { ...@@ -57,12 +57,14 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
EKeyType keyType = pSdb->keyTypes[pRow->type]; EKeyType keyType = pSdb->keyTypes[pRow->type];
if (keyType == SDB_KEY_BINARY) { if (keyType == SDB_KEY_BINARY) {
mTrace("%s:%s, refCount:%d oper:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper); mTrace("%s:%s, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper,
pRow->pObj);
} else if (keyType == SDB_KEY_INT32) { } else if (keyType == SDB_KEY_INT32) {
mTrace("%s:%d, refCount:%d oper:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper); mTrace("%s:%d, refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper,
pRow->pObj);
} else if (keyType == SDB_KEY_INT64) { } else if (keyType == SDB_KEY_INT64) {
mTrace("%s:%" PRId64 ", refCount:%d oper:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, pRow->refCount, mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p", sdbTableName(pRow->type), *(int64_t *)pRow->pObj,
oper); pRow->refCount, oper, pRow->pObj);
} else { } else {
} }
} }
......
...@@ -23,6 +23,7 @@ SSdbRow *sdbAllocRow(int32_t objSize) { ...@@ -23,6 +23,7 @@ SSdbRow *sdbAllocRow(int32_t objSize) {
return NULL; return NULL;
} }
mTrace("row:%p, is created, len:%d", pRow->pObj, objSize);
return pRow; return pRow;
} }
...@@ -43,5 +44,7 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) { ...@@ -43,5 +44,7 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) {
} }
sdbPrintOper(pSdb, pRow, "freeRow"); sdbPrintOper(pSdb, pRow, "freeRow");
mTrace("row:%p, is freed", pRow->pObj);
tfree(pRow); tfree(pRow);
} }
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start -v
sql connect sql connect
print =============== show users print =============== show users
sql show users
if $rows != 1 then
return -1
endi
print $data00 $data01 $data02
print $data10 $data11 $data22
print $data20 $data11 $data22
sql_error show accounts;
sql_error create account a pass "a"
sql_error drop account a
sql_error drop account root
print =============== create user1 print =============== create user1
sql create user user1 PASS 'user1' sql create user user1 PASS 'user1'
...@@ -30,23 +17,10 @@ print $data10 $data11 $data12 ...@@ -30,23 +17,10 @@ print $data10 $data11 $data12
print $data20 $data11 $data22 print $data20 $data11 $data22
print $data30 $data31 $data32 print $data30 $data31 $data32
print =============== create user2
sql create user user2 PASS 'user2'
sql show users
if $rows != 3 then
return -1
endi
print $data00 $data01 $data02
print $data10 $data11 $data12
print $data20 $data11 $data22
print $data30 $data31 $data32
print $data40 $data41 $data42
print =============== drop user1 print =============== drop user1
sql drop user user1 sql drop user user1
sql show users sql show users
if $rows != 2 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -57,18 +31,4 @@ print $data30 $data31 $data32 ...@@ -57,18 +31,4 @@ print $data30 $data31 $data32
print =============== restart taosd print =============== restart taosd
system sh/exec.sh -n dnode1 -s stop system sh/exec.sh -n dnode1 -s stop
sleep 1000
system sh/exec.sh -n dnode1 -s start
print =============== show users
sql show users
if $rows != 2 then
return -1
endi
print $data00 $data01 $data02
print $data10 $data11 $data22
print $data20 $data11 $data22
print $data30 $data31 $data32
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册