Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0256b44b
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看板
提交
0256b44b
编写于
4月 23, 2023
作者:
K
kailixu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: code optimization
上级
3b3732c3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
125 addition
and
56 deletion
+125
-56
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+3
-2
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+1
-1
source/client/src/clientHb.c
source/client/src/clientHb.c
+50
-35
source/client/src/clientMain.c
source/client/src/clientMain.c
+3
-0
tests/script/api/passwdTest.c
tests/script/api/passwdTest.c
+68
-18
未找到文件。
source/client/inc/clientInt.h
浏览文件 @
0256b44b
...
...
@@ -63,6 +63,7 @@ typedef struct {
// statistics
int32_t
reportCnt
;
int32_t
connKeyCnt
;
int32_t
nPassVerCb
;
int64_t
reportBytes
;
// not implemented
int64_t
startTime
;
// ctl
...
...
@@ -73,7 +74,7 @@ typedef struct {
typedef
int32_t
(
*
FHbRspHandle
)(
SAppHbMgr
*
pAppHbMgr
,
SClientHbRsp
*
pRsp
);
typedef
int32_t
(
*
FHbReqHandle
)(
SClientHbKey
*
connKey
,
void
*
param
,
SClientHbReq
*
req
);
typedef
int32_t
(
*
FHbReqHandle
)(
SClientHbKey
*
connKey
,
void
*
param
,
SClientHbReq
*
req
,
int32_t
cb
);
typedef
struct
{
int8_t
inited
;
...
...
@@ -360,7 +361,7 @@ void stopAllRequests(SHashObj* pRequests);
// conn level
int
hbRegisterConn
(
SAppHbMgr
*
pAppHbMgr
,
int64_t
tscRefId
,
int64_t
clusterId
,
int8_t
connType
);
void
hbDeregisterConn
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
);
void
hbDeregisterConn
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
,
void
*
cb
);
typedef
struct
SSqlCallbackWrapper
{
SParseContext
*
pParseCtx
;
...
...
source/client/src/clientEnv.c
浏览文件 @
0256b44b
...
...
@@ -239,7 +239,7 @@ void destroyTscObj(void *pObj) {
tscTrace
(
"begin to destroy tscObj %"
PRIx64
" p:%p"
,
tscId
,
pTscObj
);
SClientHbKey
connKey
=
{.
tscRid
=
pTscObj
->
id
,
.
connType
=
pTscObj
->
connType
};
hbDeregisterConn
(
pTscObj
->
pAppInfo
->
pAppHbMgr
,
connKey
);
hbDeregisterConn
(
pTscObj
->
pAppInfo
->
pAppHbMgr
,
connKey
,
pTscObj
->
passInfo
.
fp
);
destroyAllRequests
(
pTscObj
->
pRequests
);
taosHashCleanup
(
pTscObj
->
pRequests
);
...
...
source/client/src/clientHb.c
浏览文件 @
0256b44b
...
...
@@ -24,7 +24,7 @@ static SClientHbMgr clientHbMgr = {0};
static
int32_t
hbCreateThread
();
static
void
hbStopThread
();
static
int32_t
hbMqHbReqHandle
(
SClientHbKey
*
connKey
,
void
*
param
,
SClientHbReq
*
req
)
{
return
0
;
}
static
int32_t
hbMqHbReqHandle
(
SClientHbKey
*
connKey
,
void
*
param
,
SClientHbReq
*
req
,
int32_t
cb
)
{
return
0
;
}
static
int32_t
hbMqHbRspHandle
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbRsp
*
pRsp
)
{
return
0
;
}
...
...
@@ -49,38 +49,48 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
hbProcessUserPassInfoRsp
(
void
*
value
,
int32_t
valueLen
,
SClientHbKey
*
connKey
)
{
int32_t
code
=
0
;
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
connKey
->
tscRid
);
if
(
NULL
==
pTscObj
)
{
tscWarn
(
"tscObj rid %"
PRIx64
" not exist"
,
connKey
->
tscRid
);
return
code
;
}
static
int32_t
hbProcessUserPassInfoRsp
(
void
*
value
,
int32_t
valueLen
,
SClientHbKey
*
connKey
,
SAppHbMgr
*
pAppHbMgr
)
{
int32_t
code
=
0
;
int32_t
numOfBatchs
=
0
;
SUserPassBatchRsp
batchRsp
=
{
0
};
if
(
tDeserializeSUserPassBatchRsp
(
value
,
valueLen
,
&
batchRsp
)
!=
0
)
{
code
=
TSDB_CODE_INVALID_MSG
;
releaseTscObj
(
connKey
->
tscRid
);
return
code
;
}
SPassInfo
*
passInfo
=
&
pTscObj
->
passInfo
;
int32_t
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserPassRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
if
(
0
==
strncmp
(
rsp
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
))
{
tscDebug
(
"update passVer of user %s from %d to %d"
,
rsp
->
user
,
passInfo
->
ver
,
rsp
->
version
);
if
(
atomic_load_32
(
&
passInfo
->
ver
)
<
rsp
->
version
)
{
atomic_store_32
(
&
passInfo
->
ver
,
rsp
->
version
);
if
(
passInfo
->
fp
)
{
(
*
passInfo
->
fp
)(
passInfo
->
param
,
&
passInfo
->
ver
,
TAOS_NOTIFY_PASSVER
);
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
SClientHbReq
*
pReq
=
NULL
;
while
((
pReq
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pReq
)))
{
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
pReq
->
connKey
.
tscRid
);
if
(
!
pTscObj
)
{
continue
;
}
SPassInfo
*
passInfo
=
&
pTscObj
->
passInfo
;
if
(
!
passInfo
->
fp
)
{
continue
;
}
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserPassRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
if
(
0
==
strncmp
(
rsp
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
))
{
int32_t
oldVer
=
atomic_load_32
(
&
passInfo
->
ver
);
if
(
oldVer
<
rsp
->
version
)
{
atomic_store_32
(
&
passInfo
->
ver
,
rsp
->
version
);
tscDebug
(
"update passVer of user %s from %d to %d, tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
oldVer
,
atomic_load_32
(
&
passInfo
->
ver
),
pTscObj
->
id
);
if
(
passInfo
->
fp
)
{
(
*
passInfo
->
fp
)(
passInfo
->
param
,
&
passInfo
->
ver
,
TAOS_NOTIFY_PASSVER
);
}
}
break
;
}
}
releaseTscObj
(
pReq
->
connKey
.
tscRid
);
}
taosArrayDestroy
(
batchRsp
.
pArray
);
releaseTscObj
(
connKey
->
tscRid
);
return
code
;
}
...
...
@@ -91,7 +101,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) {
code
=
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
vgInfo
->
vgVersion
=
rsp
->
vgVersion
;
vgInfo
->
stateTs
=
rsp
->
stateTs
;
vgInfo
->
hashMethod
=
rsp
->
hashMethod
;
...
...
@@ -104,7 +114,7 @@ static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) {
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_return
;
}
for
(
int32_t
j
=
0
;
j
<
rsp
->
vgNum
;
++
j
)
{
SVgroupInfo
*
pInfo
=
taosArrayGet
(
rsp
->
pVgroupInfos
,
j
);
if
(
taosHashPut
(
vgInfo
->
vgHash
,
&
pInfo
->
vgId
,
sizeof
(
int32_t
),
pInfo
,
sizeof
(
SVgroupInfo
))
!=
0
)
{
...
...
@@ -332,7 +342,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
break
;
}
hbProcessUserPassInfoRsp
(
kv
->
value
,
kv
->
valueLen
,
&
pRsp
->
connKey
);
hbProcessUserPassInfoRsp
(
kv
->
value
,
kv
->
valueLen
,
&
pRsp
->
connKey
,
pAppHbMgr
);
break
;
}
default:
...
...
@@ -523,12 +533,7 @@ static int32_t hbGetUserBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
return
TSDB_CODE_APP_ERROR
;
}
int32_t
code
=
0
;
if
(
!
pTscObj
->
passInfo
.
fp
)
{
goto
_return
;
}
int32_t
code
=
0
;
SUserPassVersion
*
user
=
taosMemoryMalloc
(
sizeof
(
SUserPassVersion
));
if
(
!
user
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -543,7 +548,8 @@ static int32_t hbGetUserBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
.
value
=
user
,
};
tscDebug
(
"hb got user basic info, valueLen:%d"
,
kv
.
valueLen
);
tscDebug
(
"hb got user basic info, valueLen:%d, user:%s, passVer:%d, tscRid:%"
PRIi64
,
kv
.
valueLen
,
user
->
user
,
pTscObj
->
passInfo
.
ver
,
connKey
->
tscRid
);
if
(
!
req
->
info
)
{
req
->
info
=
taosHashInit
(
64
,
hbKeyHashFunc
,
1
,
HASH_ENTRY_LOCK
);
...
...
@@ -697,7 +703,7 @@ int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
hbQueryHbReqHandle
(
SClientHbKey
*
connKey
,
void
*
param
,
SClientHbReq
*
req
)
{
int32_t
hbQueryHbReqHandle
(
SClientHbKey
*
connKey
,
void
*
param
,
SClientHbReq
*
req
,
int32_t
cb
)
{
int64_t
*
clusterId
=
(
int64_t
*
)
param
;
struct
SCatalog
*
pCatalog
=
NULL
;
...
...
@@ -711,7 +717,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
hbGetQueryBasicInfo
(
connKey
,
req
);
hbGetUserBasicInfo
(
connKey
,
req
);
if
(
cb
)
hbGetUserBasicInfo
(
connKey
,
req
);
code
=
hbGetExpiredUserInfo
(
connKey
,
pCatalog
,
req
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
...
...
@@ -764,9 +770,14 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
return
NULL
;
}
int32_t
nPassVerCb
=
atomic_load_32
(
&
pAppHbMgr
->
nPassVerCb
);
while
(
pIter
!=
NULL
)
{
pOneReq
=
taosArrayPush
(
pBatchReq
->
reqs
,
pOneReq
);
code
=
(
*
clientHbMgr
.
reqHandle
[
pOneReq
->
connKey
.
connType
])(
&
pOneReq
->
connKey
,
&
pOneReq
->
clusterId
,
pOneReq
);
code
=
(
*
clientHbMgr
.
reqHandle
[
pOneReq
->
connKey
.
connType
])(
&
pOneReq
->
connKey
,
&
pOneReq
->
clusterId
,
pOneReq
,
nPassVerCb
);
break
;
#if 0
if (code) {
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
pOneReq = pIter;
...
...
@@ -775,6 +786,7 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
pOneReq = pIter;
#endif
}
releaseTscObj
(
rid
);
...
...
@@ -1116,7 +1128,7 @@ int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, in
}
}
void
hbDeregisterConn
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
)
{
void
hbDeregisterConn
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
,
void
*
cb
)
{
SClientHbReq
*
pReq
=
taosHashAcquire
(
pAppHbMgr
->
activeInfo
,
&
connKey
,
sizeof
(
SClientHbKey
));
if
(
pReq
)
{
tFreeClientHbReq
(
pReq
);
...
...
@@ -1129,4 +1141,7 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) {
}
atomic_sub_fetch_32
(
&
pAppHbMgr
->
connKeyCnt
,
1
);
if
(
cb
)
{
atomic_sub_fetch_32
(
&
pAppHbMgr
->
nPassVerCb
,
1
);
}
}
source/client/src/clientMain.c
浏览文件 @
0256b44b
...
...
@@ -136,6 +136,9 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)
case
TAOS_NOTIFY_PASSVER
:
{
pObj
->
passInfo
.
fp
=
fp
;
pObj
->
passInfo
.
param
=
param
;
if
(
fp
)
{
atomic_add_fetch_32
(
&
pObj
->
pAppInfo
->
pAppHbMgr
->
nPassVerCb
,
1
);
}
break
;
}
default:
{
...
...
tests/script/api/passwdTest.c
浏览文件 @
0256b44b
...
...
@@ -16,6 +16,11 @@
// TAOS standard API example. The same syntax as MySQL, but only a subset
// to compile: gcc -o demo demo.c -ltaos
/**
* passwdTest.c
* - Run the test case in clear TDengine environment with default root passwd 'taosdata'
*/
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -23,18 +28,23 @@
#include <unistd.h>
#include "taos.h" // TAOS header file
#define nRepetition 1
#define nTaos 10
#define nDup 1
#define nRoot 10
#define nUser 10
#define USER_LEN 30
void
Test
(
TAOS
*
taos
,
char
*
qstr
);
void
createUers
(
TAOS
*
taos
,
const
char
*
host
,
char
*
qstr
);
void
passVerTestMulti
(
const
char
*
host
,
char
*
qstr
);
int
nPassVerNotifiedMulti
=
0
;
int
nPassVerNotified
=
0
;
TAOS
*
taosu
[
nRoot
]
=
{
0
};
char
users
[
nUser
][
USER_LEN
]
=
{
0
};
void
__taos_notify_cb
(
void
*
param
,
void
*
ext
,
int
type
)
{
switch
(
type
)
{
case
TAOS_NOTIFY_PASSVER
:
{
++
nPassVerNotified
Multi
;
++
nPassVerNotified
;
printf
(
"%s:%d type:%d user:%s ver:%d
\n
"
,
__func__
,
__LINE__
,
type
,
param
?
(
char
*
)
param
:
"NULL"
,
*
(
int
*
)
ext
);
break
;
}
...
...
@@ -49,7 +59,7 @@ static void queryDB(TAOS *taos, char *command) {
TAOS_RES
*
pSql
=
NULL
;
int32_t
code
=
-
1
;
for
(
i
=
0
;
i
<
n
Repetition
;
++
i
)
{
for
(
i
=
0
;
i
<
n
Dup
;
++
i
)
{
if
(
NULL
!=
pSql
)
{
taos_free_result
(
pSql
);
pSql
=
NULL
;
...
...
@@ -88,19 +98,46 @@ int main(int argc, char *argv[]) {
printf
(
"failed to connect to server, reason:%s
\n
"
,
"null taos"
/*taos_errstr(taos)*/
);
exit
(
1
);
}
createUers
(
taos
,
argv
[
1
],
qstr
);
passVerTestMulti
(
argv
[
1
],
qstr
);
taos_close
(
taos
);
taos_cleanup
();
}
void
createUers
(
TAOS
*
taos
,
const
char
*
host
,
char
*
qstr
)
{
// users
for
(
int
i
=
0
;
i
<
nUser
;
++
i
)
{
sprintf
(
users
[
i
],
"user%d"
,
i
);
sprintf
(
qstr
,
"CREATE USER %s PASS 'taosdata'"
,
users
[
i
]);
queryDB
(
taos
,
qstr
);
taosu
[
i
]
=
taos_connect
(
host
,
users
[
i
],
"taosdata"
,
NULL
,
0
);
if
(
taosu
[
i
]
==
NULL
)
{
printf
(
"failed to connect to server, user:%s, reason:%s
\n
"
,
users
[
i
],
"null taos"
/*taos_errstr(taos)*/
);
exit
(
1
);
}
int
code
=
taos_set_notify_cb
(
taosu
[
i
],
__taos_notify_cb
,
users
[
i
],
TAOS_NOTIFY_PASSVER
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run: taos_set_notify_cb for user:%s since %d
\n
"
,
users
[
i
],
code
);
}
else
{
fprintf
(
stderr
,
"success to run: taos_set_notify_cb for user:%s
\n
"
,
users
[
i
]);
}
// alter pass for users
sprintf
(
qstr
,
"alter user %s pass 'taos'"
,
users
[
i
]);
queryDB
(
taos
,
qstr
);
}
}
void
passVerTestMulti
(
const
char
*
host
,
char
*
qstr
)
{
TAOS
*
taos
[
nTaos
]
=
{
0
};
char
*
userName
=
calloc
(
1
,
24
)
;
strcpy
(
userName
,
"root"
)
;
// root
TAOS
*
taos
[
nRoot
]
=
{
0
}
;
char
userName
[
USER_LEN
]
=
"root"
;
for
(
int
i
=
0
;
i
<
n
Taos
;
++
i
)
{
for
(
int
i
=
0
;
i
<
n
Root
;
++
i
)
{
taos
[
i
]
=
taos_connect
(
host
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
[
i
]
==
NULL
)
{
printf
(
"failed to connect to server, reason:%s
\n
"
,
"null taos"
/*taos_errstr(taos)*/
);
...
...
@@ -127,18 +164,31 @@ void passVerTestMulti(const char *host, char *qstr) {
strcpy
(
qstr
,
"alter user root pass 'taos'"
);
queryDB
(
taos
[
0
],
qstr
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
if
(
nPassVerNotifiedMulti
>=
nTaos
)
break
;
// calculate the nPassVerNotified for root and users
int
nConn
=
nRoot
+
nUser
;
for
(
int
i
=
0
;
i
<
15
;
++
i
)
{
if
(
nPassVerNotified
>=
nConn
)
break
;
sleep
(
1
);
}
if
(
nPassVerNotifiedMulti
>=
nTaos
)
{
fprintf
(
stderr
,
"success to get passVer notification
\n
"
);
}
else
{
fprintf
(
stderr
,
"failed to get passVer notification
\n
"
);
// close the taos_conn
for
(
int
i
=
0
;
i
<
nRoot
;
++
i
)
{
taos_close
(
taos
[
i
]);
printf
(
"%s:%d close taos[%d]
\n
"
,
__func__
,
__LINE__
,
i
);
sleep
(
1
);
}
// sleep(1000);
for
(
int
i
=
0
;
i
<
nUser
;
++
i
)
{
taos_close
(
taosu
[
i
]);
printf
(
"%s:%d close taosu[%d]
\n
"
,
__func__
,
__LINE__
,
i
);
sleep
(
1
);
}
free
(
userName
);
if
(
nPassVerNotified
>=
nConn
)
{
fprintf
(
stderr
,
"succeed to get passVer notification since nNotify %d >= nConn %d
\n
"
,
nPassVerNotified
,
nConn
);
}
else
{
fprintf
(
stderr
,
"failed to get passVer notification since nNotify %d < nConn %d
\n
"
,
nPassVerNotified
,
nConn
);
}
// sleep(300);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录