Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
067a8334
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
067a8334
编写于
6月 30, 2023
作者:
K
kailixu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: code optimization
上级
387d6111
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
58 addition
and
59 deletion
+58
-59
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+1
-1
source/client/src/clientHb.c
source/client/src/clientHb.c
+53
-54
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+1
-1
tests/script/api/passwdTest.c
tests/script/api/passwdTest.c
+3
-3
未找到文件。
source/client/inc/clientInt.h
浏览文件 @
067a8334
...
@@ -64,7 +64,7 @@ typedef struct {
...
@@ -64,7 +64,7 @@ typedef struct {
// statistics
// statistics
int32_t
reportCnt
;
int32_t
reportCnt
;
int32_t
connKeyCnt
;
int32_t
connKeyCnt
;
int8_t
connHbFlag
;
int8_t
connHbFlag
;
// 0 init, 1 send req, 2 get resp
int64_t
reportBytes
;
// not implemented
int64_t
reportBytes
;
// not implemented
int64_t
startTime
;
int64_t
startTime
;
// ctl
// ctl
...
...
source/client/src/clientHb.c
浏览文件 @
067a8334
...
@@ -21,11 +21,10 @@
...
@@ -21,11 +21,10 @@
#include "tsimplehash.h"
#include "tsimplehash.h"
typedef
struct
{
typedef
struct
{
SAppHbMgr
*
pAppHbMgr
;
union
{
union
{
struct
{
struct
{
SAppHbMgr
*
pAppHbMgr
;
int64_t
clusterId
;
int64_t
clusterId
;
// int32_t authVer;
int32_t
reqCnt
;
int32_t
reqCnt
;
int8_t
connHbFlag
;
int8_t
connHbFlag
;
};
};
...
@@ -41,60 +40,36 @@ static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq
...
@@ -41,60 +40,36 @@ static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq
static
int32_t
hbMqHbRspHandle
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbRsp
*
pRsp
)
{
return
0
;
}
static
int32_t
hbMqHbRspHandle
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbRsp
*
pRsp
)
{
return
0
;
}
static
int32_t
hbProcessUserAuthInfoRsp
(
void
*
value
,
int32_t
valueLen
,
struct
SCatalog
*
pCatalog
,
static
int32_t
hbUpdateUserAuthInfo
(
SAppHbMgr
*
pAppHbMgr
,
SUserAuthBatchRsp
*
batchRsp
)
{
SAppHbMgr
*
pAppHbMgr
)
{
int32_t
code
=
0
;
SUserAuthBatchRsp
batchRsp
=
{
0
};
if
(
tDeserializeSUserAuthBatchRsp
(
value
,
valueLen
,
&
batchRsp
)
!=
0
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
return
-
1
;
}
atomic_val_compare_exchange_8
(
&
pAppHbMgr
->
connHbFlag
,
2
,
0
);
int32_t
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserAuthRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
tscDebug
(
"hb user auth rsp, user:%s, version:%d"
,
rsp
->
user
,
rsp
->
version
);
catalogUpdateUserAuthInfo
(
pCatalog
,
rsp
);
}
SClientHbReq
*
pReq
=
NULL
;
SClientHbReq
*
pReq
=
NULL
;
while
((
pReq
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pReq
)))
{
while
((
pReq
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pReq
)))
{
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
pReq
->
connKey
.
tscRid
);
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
pReq
->
connKey
.
tscRid
);
if
(
!
pTscObj
)
{
if
(
!
pTscObj
)
{
continue
;
continue
;
}
}
for
(
int32_t
i
=
0
;
i
<
TARRAY_SIZE
(
batchRsp
->
pArray
);
++
i
)
{
SGetUserAuthRsp
*
rsp
=
taosArrayGet
(
batchRsp
->
pArray
,
i
);
if
(
0
==
strncmp
(
rsp
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
))
{
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserAuthRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
pTscObj
->
authVer
=
rsp
->
version
;
pTscObj
->
authVer
=
rsp
->
version
;
if
(
0
==
strncmp
(
rsp
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
))
{
if
(
pTscObj
->
sysInfo
!=
rsp
->
sysInfo
)
{
if
(
pTscObj
->
sysInfo
!=
rsp
->
sysInfo
)
{
printf
(
"update sysInfo of user %s from %"
PRIi8
" to %"
PRIi8
", tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
tscDebug
(
"update sysInfo of user %s from %"
PRIi8
" to %"
PRIi8
", tscRid:%"
PRIi64
,
rsp
->
user
,
pTscObj
->
sysInfo
,
rsp
->
sysInfo
,
pTscObj
->
id
);
pTscObj
->
sysInfo
,
rsp
->
sysInfo
,
pTscObj
->
id
);
pTscObj
->
sysInfo
=
rsp
->
sysInfo
;
pTscObj
->
sysInfo
=
rsp
->
sysInfo
;
}
else
{
printf
(
"not update sysInfo of user %s since not change: %"
PRIi8
", tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
pTscObj
->
sysInfo
,
pTscObj
->
id
);
}
}
if
(
pTscObj
->
passInfo
.
fp
)
{
SPassInfo
*
passInfo
=
&
pTscObj
->
passInfo
;
SPassInfo
*
passInfo
=
&
pTscObj
->
passInfo
;
if
(
passInfo
->
fp
)
{
int32_t
oldVer
=
atomic_load_32
(
&
passInfo
->
ver
);
int32_t
oldVer
=
atomic_load_32
(
&
passInfo
->
ver
);
if
(
oldVer
<
rsp
->
passVer
)
{
if
(
oldVer
<
rsp
->
passVer
)
{
atomic_store_32
(
&
passInfo
->
ver
,
rsp
->
passVer
);
atomic_store_32
(
&
passInfo
->
ver
,
rsp
->
passVer
);
if
(
passInfo
->
fp
)
{
if
(
passInfo
->
fp
)
{
(
*
passInfo
->
fp
)(
passInfo
->
param
,
&
passInfo
->
v
er
,
TAOS_NOTIFY_PASSVER
);
(
*
passInfo
->
fp
)(
passInfo
->
param
,
&
rsp
->
passV
er
,
TAOS_NOTIFY_PASSVER
);
}
}
printf
(
"update passVer of user %s from %d to %d, tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
oldVer
,
tscDebug
(
"update passVer of user %s from %d to %d, tscRid:%"
PRIi64
,
rsp
->
user
,
oldVer
,
atomic_load_32
(
&
passInfo
->
ver
),
pTscObj
->
id
);
atomic_load_32
(
&
passInfo
->
ver
),
pTscObj
->
id
);
}
else
{
printf
(
"not update passVer of user %s since not changed: %d, tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
oldVer
,
pTscObj
->
id
);
}
}
}
}
...
@@ -103,6 +78,30 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
...
@@ -103,6 +78,30 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
}
}
releaseTscObj
(
pReq
->
connKey
.
tscRid
);
releaseTscObj
(
pReq
->
connKey
.
tscRid
);
}
}
return
0
;
}
static
int32_t
hbProcessUserAuthInfoRsp
(
void
*
value
,
int32_t
valueLen
,
struct
SCatalog
*
pCatalog
,
SAppHbMgr
*
pAppHbMgr
)
{
int32_t
code
=
0
;
SUserAuthBatchRsp
batchRsp
=
{
0
};
if
(
tDeserializeSUserAuthBatchRsp
(
value
,
valueLen
,
&
batchRsp
)
!=
0
)
{
terrno
=
TSDB_CODE_INVALID_MSG
;
return
-
1
;
}
int32_t
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserAuthRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
tscDebug
(
"hb user auth rsp, user:%s, version:%d"
,
rsp
->
user
,
rsp
->
version
);
catalogUpdateUserAuthInfo
(
pCatalog
,
rsp
);
}
if
(
numOfBatchs
>
0
)
hbUpdateUserAuthInfo
(
pAppHbMgr
,
&
batchRsp
);
atomic_val_compare_exchange_8
(
&
pAppHbMgr
->
connHbFlag
,
1
,
2
);
taosArrayDestroy
(
batchRsp
.
pArray
);
taosArrayDestroy
(
batchRsp
.
pArray
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -548,16 +547,16 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
...
@@ -548,16 +547,16 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
SKv
*
pKv
=
NULL
;
SKv
*
pKv
=
NULL
;
if
((
pKv
=
taosHashGet
(
req
->
info
,
&
kv
.
key
,
sizeof
(
kv
.
key
))))
{
if
((
pKv
=
taosHashGet
(
req
->
info
,
&
kv
.
key
,
sizeof
(
kv
.
key
))))
{
int32_t
userNum
=
pKv
->
valueLen
/
sizeof
(
SUserAuthVersion
);
int32_t
userNum
=
pKv
->
valueLen
/
sizeof
(
SUserAuthVersion
);
SUserAuthVersion
*
pU
serAuths
=
(
SUserAuthVersion
*
)
pKv
->
value
;
SUserAuthVersion
*
u
serAuths
=
(
SUserAuthVersion
*
)
pKv
->
value
;
for
(
int32_t
i
=
0
;
i
<
userNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
userNum
;
++
i
)
{
SUserAuthVersion
*
pUserAuth
=
pU
serAuths
+
i
;
SUserAuthVersion
*
pUserAuth
=
u
serAuths
+
i
;
// both key and user exist
// both key and user exist
, update version
if
(
strncmp
(
pUserAuth
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
)
==
0
)
{
if
(
strncmp
(
pUserAuth
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
)
==
0
)
{
pUserAuth
->
version
=
htonl
(
-
1
);
// force get userAuthInfo
pUserAuth
->
version
=
htonl
(
-
1
);
// force get userAuthInfo
goto
_return
;
goto
_return
;
}
}
}
}
// key exists, user not exist
// key exists, user not exist
, append user
SUserAuthVersion
*
qUserAuth
=
SUserAuthVersion
*
qUserAuth
=
(
SUserAuthVersion
*
)
taosMemoryRealloc
(
pKv
->
value
,
(
userNum
+
1
)
*
sizeof
(
SUserAuthVersion
));
(
SUserAuthVersion
*
)
taosMemoryRealloc
(
pKv
->
value
,
(
userNum
+
1
)
*
sizeof
(
SUserAuthVersion
));
if
(
qUserAuth
)
{
if
(
qUserAuth
)
{
...
@@ -571,6 +570,7 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
...
@@ -571,6 +570,7 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
goto
_return
;
goto
_return
;
}
}
// key/user not exist, add user
SUserAuthVersion
*
user
=
taosMemoryMalloc
(
sizeof
(
SUserAuthVersion
));
SUserAuthVersion
*
user
=
taosMemoryMalloc
(
sizeof
(
SUserAuthVersion
));
if
(
!
user
)
{
if
(
!
user
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -774,12 +774,12 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
...
@@ -774,12 +774,12 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
}
}
// invoke after hbGetExpiredUserInfo
// invoke after hbGetExpiredUserInfo
if
(
atomic_load_8
(
&
hbParam
->
pAppHbMgr
->
connHbFlag
))
{
if
(
2
!=
atomic_load_8
(
&
hbParam
->
pAppHbMgr
->
connHbFlag
))
{
code
=
hbGetUserAuthInfo
(
connKey
,
hbParam
,
req
);
code
=
hbGetUserAuthInfo
(
connKey
,
hbParam
,
req
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
return
code
;
}
}
atomic_store_8
(
&
hbParam
->
pAppHbMgr
->
connHbFlag
,
2
);
atomic_store_8
(
&
hbParam
->
pAppHbMgr
->
connHbFlag
,
1
);
}
}
code
=
hbGetExpiredDBInfo
(
connKey
,
pCatalog
,
req
);
code
=
hbGetExpiredDBInfo
(
connKey
,
pCatalog
,
req
);
...
@@ -923,11 +923,10 @@ static void *hbThreadFunc(void *param) {
...
@@ -923,11 +923,10 @@ static void *hbThreadFunc(void *param) {
if
(
sz
>
0
)
{
if
(
sz
>
0
)
{
hbGatherAppInfo
();
hbGatherAppInfo
();
if
(
sz
>
1
&&
!
clientHbMgr
.
appHbHash
)
{
if
(
sz
>
1
&&
!
clientHbMgr
.
appHbHash
)
{
clientHbMgr
.
appHbHash
=
tSimpleHashInit
(
0
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
));
clientHbMgr
.
appHbHash
=
tSimpleHashInit
(
0
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_
U
BIGINT
));
}
}
}
tSimpleHashClear
(
clientHbMgr
.
appHbHash
);
tSimpleHashClear
(
clientHbMgr
.
appHbHash
);
}
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SAppHbMgr
*
pAppHbMgr
=
taosArrayGetP
(
clientHbMgr
.
appHbMgrs
,
i
);
SAppHbMgr
*
pAppHbMgr
=
taosArrayGetP
(
clientHbMgr
.
appHbMgrs
,
i
);
...
@@ -979,7 +978,7 @@ static void *hbThreadFunc(void *param) {
...
@@ -979,7 +978,7 @@ static void *hbThreadFunc(void *param) {
asyncSendMsgToServer
(
pAppInstInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
pInfo
);
asyncSendMsgToServer
(
pAppInstInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
pInfo
);
tFreeClientHbBatchReq
(
pReq
);
tFreeClientHbBatchReq
(
pReq
);
// hbClearReqInfo(pAppHbMgr);
// hbClearReqInfo(pAppHbMgr);
tSimpleHashPut
(
clientHbMgr
.
appHbHash
,
&
pAppHbMgr
->
pAppInstInfo
->
clusterId
,
sizeof
(
int64_t
),
NULL
,
0
);
tSimpleHashPut
(
clientHbMgr
.
appHbHash
,
&
pAppHbMgr
->
pAppInstInfo
->
clusterId
,
sizeof
(
u
int64_t
),
NULL
,
0
);
atomic_add_fetch_32
(
&
pAppHbMgr
->
reportCnt
,
1
);
atomic_add_fetch_32
(
&
pAppHbMgr
->
reportCnt
,
1
);
}
}
...
@@ -1036,7 +1035,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
...
@@ -1036,7 +1035,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
// init stat
// init stat
pAppHbMgr
->
startTime
=
taosGetTimestampMs
();
pAppHbMgr
->
startTime
=
taosGetTimestampMs
();
pAppHbMgr
->
connKeyCnt
=
0
;
pAppHbMgr
->
connKeyCnt
=
0
;
pAppHbMgr
->
connHbFlag
=
1
;
pAppHbMgr
->
connHbFlag
=
0
;
pAppHbMgr
->
reportCnt
=
0
;
pAppHbMgr
->
reportCnt
=
0
;
pAppHbMgr
->
reportBytes
=
0
;
pAppHbMgr
->
reportBytes
=
0
;
pAppHbMgr
->
key
=
taosStrdup
(
key
);
pAppHbMgr
->
key
=
taosStrdup
(
key
);
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
067a8334
...
@@ -1382,7 +1382,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
...
@@ -1382,7 +1382,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_
pUsers
[
i
].
version
=
ntohl
(
pUsers
[
i
].
version
);
pUsers
[
i
].
version
=
ntohl
(
pUsers
[
i
].
version
);
if
(
pUser
->
authVersion
<=
pUsers
[
i
].
version
)
{
if
(
pUser
->
authVersion
<=
pUsers
[
i
].
version
)
{
mTrace
(
"pUser->authVersion:%d <= pUsers[i].version:%d
"
,
pUser
->
authVersion
,
pUsers
[
i
].
version
);
printf
(
"pUser->authVersion:%d <= pUsers[i].version:%d
\n
"
,
pUser
->
authVersion
,
pUsers
[
i
].
version
);
mndReleaseUser
(
pMnode
,
pUser
);
mndReleaseUser
(
pMnode
,
pUser
);
continue
;
continue
;
}
}
...
...
tests/script/api/passwdTest.c
浏览文件 @
067a8334
...
@@ -166,11 +166,11 @@ void passVerTestMulti(const char *host, char *qstr) {
...
@@ -166,11 +166,11 @@ void passVerTestMulti(const char *host, char *qstr) {
// calculate the nPassVerNotified for root and users
// calculate the nPassVerNotified for root and users
int
nConn
=
nRoot
+
nUser
;
int
nConn
=
nRoot
+
nUser
;
for
(
int
i
=
1
;
i
<
15
;
++
i
)
{
for
(
int
i
=
0
;
i
<
15
;
++
i
)
{
printf
(
"%s:%d [%d] second(s) elasped, passVer notification received:%d, total:%d
\n
"
,
__func__
,
__LINE__
,
i
,
nPassVerNotified
,
nConn
);
if
(
nPassVerNotified
>=
nConn
)
break
;
if
(
nPassVerNotified
>=
nConn
)
break
;
sleep
(
1
);
sleep
(
1
);
printf
(
"%s:%d %d second(s) elasped, passVer notification received:%d, total:%d
\n
"
,
__func__
,
__LINE__
,
i
,
nPassVerNotified
,
nConn
);
}
}
// close the taos_conn
// close the taos_conn
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录