Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dgr6878
TDengine
提交
54cd817f
T
TDengine
项目概览
dgr6878
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
54cd817f
编写于
2月 19, 2020
作者:
陶建辉(Jeff)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix many bugs
上级
e9470f0a
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
306 addition
and
291 deletion
+306
-291
src/rpc/inc/tconncache.h
src/rpc/inc/tconncache.h
+4
-4
src/rpc/src/tconncache.c
src/rpc/src/tconncache.c
+87
-87
src/rpc/src/trpc.c
src/rpc/src/trpc.c
+198
-194
src/rpc/test/rclient.c
src/rpc/test/rclient.c
+9
-3
src/rpc/test/rserver.c
src/rpc/test/rserver.c
+7
-2
src/util/src/tglobalcfg.c
src/util/src/tglobalcfg.c
+1
-1
未找到文件。
src/rpc/inc/tconncache.h
浏览文件 @
54cd817f
...
...
@@ -20,10 +20,10 @@
extern
"C"
{
#endif
void
*
taos
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
);
void
taos
CloseConnCache
(
void
*
handle
);
void
taos
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
void
*
taos
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
void
*
rpc
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
);
void
rpc
CloseConnCache
(
void
*
handle
);
void
rpc
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
void
*
rpc
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
#ifdef __cplusplus
}
...
...
src/rpc/src/tconncache.c
浏览文件 @
54cd817f
...
...
@@ -40,13 +40,13 @@ typedef struct {
int
*
count
;
int64_t
keepTimer
;
pthread_mutex_t
mutex
;
void
(
*
cleanFp
)(
void
*
);
void
*
tmrCtrl
;
void
*
pTimer
;
void
(
*
cleanFp
)(
void
*
);
void
*
tmrCtrl
;
void
*
pTimer
;
}
SConnCache
;
int
taos
HashConn
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
SConnCache
*
p
Obj
=
(
SConnCache
*
)
handle
;
int
rpc
HashConn
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
SConnCache
*
p
Cache
=
(
SConnCache
*
)
handle
;
int
hash
=
0
;
// size_t user_len = strlen(user);
...
...
@@ -58,109 +58,109 @@ int taosHashConn(void *handle, uint32_t ip, uint16_t port, char *user) {
user
++
;
}
hash
=
hash
%
p
Obj
->
maxSessions
;
hash
=
hash
%
p
Cache
->
maxSessions
;
return
hash
;
}
void
taosRemoveExpiredNodes
(
SConnCache
*
pObj
,
SConnHash
*
pNode
,
int
hash
,
uint64_t
time
)
{
if
(
time
<
pObj
->
keepTimer
+
pNode
->
time
)
return
;
void
rpcRemoveExpiredNodes
(
SConnCache
*
pCache
,
SConnHash
*
pNode
,
int
hash
,
uint64_t
time
)
{
if
(
pNode
==
NULL
||
(
time
<
pCache
->
keepTimer
+
pNode
->
time
)
)
return
;
SConnHash
*
pPrev
=
pNode
->
prev
,
*
pNext
;
while
(
pNode
)
{
(
*
p
Obj
->
cleanFp
)(
pNode
->
data
);
(
*
p
Cache
->
cleanFp
)(
pNode
->
data
);
pNext
=
pNode
->
next
;
p
Obj
->
total
--
;
p
Obj
->
count
[
hash
]
--
;
t
sc
Trace
(
"%p ip:0x%x:%hu:%d:%p removed, connections in cache:%d"
,
pNode
->
data
,
pNode
->
ip
,
pNode
->
port
,
hash
,
pNode
,
p
Obj
->
count
[
hash
]);
taosMemPoolFree
(
p
Obj
->
connHashMemPool
,
(
char
*
)
pNode
);
p
Cache
->
total
--
;
p
Cache
->
count
[
hash
]
--
;
tTrace
(
"%p ip:0x%x:%hu:%d:%p removed, connections in cache:%d"
,
pNode
->
data
,
pNode
->
ip
,
pNode
->
port
,
hash
,
pNode
,
p
Cache
->
count
[
hash
]);
taosMemPoolFree
(
p
Cache
->
connHashMemPool
,
(
char
*
)
pNode
);
pNode
=
pNext
;
}
if
(
pPrev
)
pPrev
->
next
=
NULL
;
else
p
Obj
->
connHashList
[
hash
]
=
NULL
;
p
Cache
->
connHashList
[
hash
]
=
NULL
;
}
void
taos
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
void
rpc
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
int
hash
;
SConnHash
*
pNode
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
uint64_t
time
=
taosGetTimestampMs
();
p
Obj
=
(
SConnCache
*
)
handle
;
assert
(
p
Obj
);
p
Cache
=
(
SConnCache
*
)
handle
;
assert
(
p
Cache
);
assert
(
data
);
hash
=
taosHashConn
(
pObj
,
ip
,
port
,
user
);
pNode
=
(
SConnHash
*
)
taosMemPoolMalloc
(
p
Obj
->
connHashMemPool
);
hash
=
rpcHashConn
(
pCache
,
ip
,
port
,
user
);
pNode
=
(
SConnHash
*
)
taosMemPoolMalloc
(
p
Cache
->
connHashMemPool
);
pNode
->
ip
=
ip
;
pNode
->
port
=
port
;
pNode
->
data
=
data
;
pNode
->
prev
=
NULL
;
pNode
->
time
=
time
;
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
pNode
->
next
=
p
Obj
->
connHashList
[
hash
];
if
(
p
Obj
->
connHashList
[
hash
]
!=
NULL
)
(
pObj
->
connHashList
[
hash
])
->
prev
=
pNode
;
p
Obj
->
connHashList
[
hash
]
=
pNode
;
pNode
->
next
=
p
Cache
->
connHashList
[
hash
];
if
(
p
Cache
->
connHashList
[
hash
]
!=
NULL
)
(
pCache
->
connHashList
[
hash
])
->
prev
=
pNode
;
p
Cache
->
connHashList
[
hash
]
=
pNode
;
p
Obj
->
total
++
;
p
Obj
->
count
[
hash
]
++
;
taosRemoveExpiredNodes
(
pObj
,
pNode
->
next
,
hash
,
time
);
p
Cache
->
total
++
;
p
Cache
->
count
[
hash
]
++
;
rpcRemoveExpiredNodes
(
pCache
,
pNode
->
next
,
hash
,
time
);
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
t
scTrace
(
"%p ip:0x%x:%hu:%d:%p added, connections in cache:%d"
,
data
,
ip
,
port
,
hash
,
pNode
,
pObj
->
count
[
hash
]);
t
Trace
(
"%p ip:0x%x:%hu:%d:%p added, connections in cache:%d"
,
data
,
ip
,
port
,
hash
,
pNode
,
pCache
->
count
[
hash
]);
return
;
}
void
taos
CleanConnCache
(
void
*
handle
,
void
*
tmrId
)
{
void
rpc
CleanConnCache
(
void
*
handle
,
void
*
tmrId
)
{
int
hash
;
SConnHash
*
pNode
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
p
Obj
=
(
SConnCache
*
)
handle
;
if
(
p
Obj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
;
if
(
p
Obj
->
pTimer
!=
tmrId
)
return
;
p
Cache
=
(
SConnCache
*
)
handle
;
if
(
p
Cache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
if
(
p
Cache
->
pTimer
!=
tmrId
)
return
;
uint64_t
time
=
taosGetTimestampMs
();
for
(
hash
=
0
;
hash
<
p
Obj
->
maxSessions
;
++
hash
)
{
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
pNode
=
p
Obj
->
connHashList
[
hash
];
taosRemoveExpiredNodes
(
pObj
,
pNode
,
hash
,
time
);
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
for
(
hash
=
0
;
hash
<
p
Cache
->
maxSessions
;
++
hash
)
{
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
pNode
=
p
Cache
->
connHashList
[
hash
];
rpcRemoveExpiredNodes
(
pCache
,
pNode
,
hash
,
time
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
}
// t
scTrace("timer, total connections in cache:%d", pObj
->total);
taosTmrReset
(
taosCleanConnCache
,
pObj
->
keepTimer
*
2
,
pObj
,
pObj
->
tmrCtrl
,
&
pObj
->
pTimer
);
// t
Trace("timer, total connections in cache:%d", pCache
->total);
taosTmrReset
(
rpcCleanConnCache
,
pCache
->
keepTimer
*
2
,
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
}
void
*
taos
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
void
*
rpc
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
int
hash
;
SConnHash
*
pNode
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
void
*
pData
=
NULL
;
p
Obj
=
(
SConnCache
*
)
handle
;
assert
(
p
Obj
);
p
Cache
=
(
SConnCache
*
)
handle
;
assert
(
p
Cache
);
uint64_t
time
=
taosGetTimestampMs
();
hash
=
taosHashConn
(
pObj
,
ip
,
port
,
user
);
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
hash
=
rpcHashConn
(
pCache
,
ip
,
port
,
user
);
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
pNode
=
p
Obj
->
connHashList
[
hash
];
pNode
=
p
Cache
->
connHashList
[
hash
];
while
(
pNode
)
{
if
(
time
>=
p
Obj
->
keepTimer
+
pNode
->
time
)
{
taosRemoveExpiredNodes
(
pObj
,
pNode
,
hash
,
time
);
if
(
time
>=
p
Cache
->
keepTimer
+
pNode
->
time
)
{
rpcRemoveExpiredNodes
(
pCache
,
pNode
,
hash
,
time
);
pNode
=
NULL
;
break
;
}
...
...
@@ -171,12 +171,12 @@ void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user)
}
if
(
pNode
)
{
taosRemoveExpiredNodes
(
pObj
,
pNode
->
next
,
hash
,
time
);
rpcRemoveExpiredNodes
(
pCache
,
pNode
->
next
,
hash
,
time
);
if
(
pNode
->
prev
)
{
pNode
->
prev
->
next
=
pNode
->
next
;
}
else
{
p
Obj
->
connHashList
[
hash
]
=
pNode
->
next
;
p
Cache
->
connHashList
[
hash
]
=
pNode
->
next
;
}
if
(
pNode
->
next
)
{
...
...
@@ -184,24 +184,24 @@ void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user)
}
pData
=
pNode
->
data
;
taosMemPoolFree
(
p
Obj
->
connHashMemPool
,
(
char
*
)
pNode
);
p
Obj
->
total
--
;
p
Obj
->
count
[
hash
]
--
;
taosMemPoolFree
(
p
Cache
->
connHashMemPool
,
(
char
*
)
pNode
);
p
Cache
->
total
--
;
p
Cache
->
count
[
hash
]
--
;
}
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
if
(
pData
)
{
t
scTrace
(
"%p ip:0x%x:%hu:%d:%p retrieved, connections in cache:%d"
,
pData
,
ip
,
port
,
hash
,
pNode
,
pObj
->
count
[
hash
]);
t
Trace
(
"%p ip:0x%x:%hu:%d:%p retrieved, connections in cache:%d"
,
pData
,
ip
,
port
,
hash
,
pNode
,
pCache
->
count
[
hash
]);
}
return
pData
;
}
void
*
taos
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
)
{
void
*
rpc
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
)
{
SConnHash
**
connHashList
;
mpool_h
connHashMemPool
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
connHashMemPool
=
taosMemPoolInit
(
maxSessions
,
sizeof
(
SConnHash
));
if
(
connHashMemPool
==
0
)
return
NULL
;
...
...
@@ -212,48 +212,48 @@ void *taosOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl,
return
NULL
;
}
p
Obj
=
malloc
(
sizeof
(
SConnCache
));
if
(
p
Obj
==
NULL
)
{
p
Cache
=
malloc
(
sizeof
(
SConnCache
));
if
(
p
Cache
==
NULL
)
{
taosMemPoolCleanUp
(
connHashMemPool
);
free
(
connHashList
);
return
NULL
;
}
memset
(
p
Obj
,
0
,
sizeof
(
SConnCache
));
memset
(
p
Cache
,
0
,
sizeof
(
SConnCache
));
p
Obj
->
count
=
calloc
(
sizeof
(
int
),
maxSessions
);
p
Obj
->
total
=
0
;
p
Obj
->
keepTimer
=
keepTimer
;
p
Obj
->
maxSessions
=
maxSessions
;
p
Obj
->
connHashMemPool
=
connHashMemPool
;
p
Obj
->
connHashList
=
connHashList
;
p
Obj
->
cleanFp
=
cleanFp
;
p
Obj
->
tmrCtrl
=
tmrCtrl
;
taosTmrReset
(
taosCleanConnCache
,
pObj
->
keepTimer
*
2
,
pObj
,
pObj
->
tmrCtrl
,
&
pObj
->
pTimer
);
p
Cache
->
count
=
calloc
(
sizeof
(
int
),
maxSessions
);
p
Cache
->
total
=
0
;
p
Cache
->
keepTimer
=
keepTimer
;
p
Cache
->
maxSessions
=
maxSessions
;
p
Cache
->
connHashMemPool
=
connHashMemPool
;
p
Cache
->
connHashList
=
connHashList
;
p
Cache
->
cleanFp
=
cleanFp
;
p
Cache
->
tmrCtrl
=
tmrCtrl
;
taosTmrReset
(
rpcCleanConnCache
,
pCache
->
keepTimer
*
2
,
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
pthread_mutex_init
(
&
p
Obj
->
mutex
,
NULL
);
pthread_mutex_init
(
&
p
Cache
->
mutex
,
NULL
);
return
p
Obj
;
return
p
Cache
;
}
void
taos
CloseConnCache
(
void
*
handle
)
{
SConnCache
*
p
Obj
;
void
rpc
CloseConnCache
(
void
*
handle
)
{
SConnCache
*
p
Cache
;
p
Obj
=
(
SConnCache
*
)
handle
;
if
(
p
Obj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
;
p
Cache
=
(
SConnCache
*
)
handle
;
if
(
p
Cache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
taosTmrStopA
(
&
(
p
Obj
->
pTimer
));
taosTmrStopA
(
&
(
p
Cache
->
pTimer
));
if
(
p
Obj
->
connHashMemPool
)
taosMemPoolCleanUp
(
pObj
->
connHashMemPool
);
if
(
p
Cache
->
connHashMemPool
)
taosMemPoolCleanUp
(
pCache
->
connHashMemPool
);
tfree
(
p
Obj
->
connHashList
);
tfree
(
p
Obj
->
count
)
tfree
(
p
Cache
->
connHashList
);
tfree
(
p
Cache
->
count
)
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
pthread_mutex_destroy
(
&
p
Obj
->
mutex
);
pthread_mutex_destroy
(
&
p
Cache
->
mutex
);
memset
(
p
Obj
,
0
,
sizeof
(
SConnCache
));
free
(
p
Obj
);
memset
(
p
Cache
,
0
,
sizeof
(
SConnCache
));
free
(
p
Cache
);
}
src/rpc/src/trpc.c
浏览文件 @
54cd817f
此差异已折叠。
点击以展开。
src/rpc/test/rclient.c
浏览文件 @
54cd817f
...
...
@@ -24,18 +24,23 @@ void processMsg(char type, void *pCont, int contLen, void *ahandle, int32_t code
}
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
taosInitLog
(
"client.log"
,
100000
,
10
);
dPrint
(
"unit test for rpc module"
);
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
"0.0.0.0"
;
rpcInit
.
localPort
=
700
0
;
rpcInit
.
label
=
"
unittest
"
;
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"
APP
"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
sessions
=
1000
;
rpcInit
.
connType
=
TAOS_CONN_UDPC
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
meterId
=
"jefftao"
;
rpcInit
.
secret
=
"password"
;
rpcInit
.
ckey
=
"key"
;
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
if
(
pRpc
==
NULL
)
{
...
...
@@ -46,6 +51,7 @@ int32_t main(int32_t argc, char *argv[]) {
SRpcIpSet
ipSet
;
ipSet
.
numOfIps
=
2
;
ipSet
.
index
=
0
;
ipSet
.
port
=
7000
;
ipSet
.
ip
[
0
]
=
inet_addr
(
"127.0.0.1"
);
ipSet
.
ip
[
1
]
=
inet_addr
(
"192.168.0.1"
);
...
...
src/rpc/test/rserver.c
浏览文件 @
54cd817f
...
...
@@ -27,18 +27,23 @@ void processMsg(char type, void *pCont, int contLen, void *ahandle, int32_t code
}
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
taosInitLog
(
"server.log"
,
100000
,
10
);
dPrint
(
"unit test for rpc module"
);
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
"0.0.0.0"
;
rpcInit
.
localPort
=
7000
;
rpcInit
.
label
=
"
unittest
"
;
rpcInit
.
label
=
"
APP
"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
sessions
=
1000
;
rpcInit
.
connType
=
TAOS_CONN_UDPS
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
meterId
=
"jefftao"
;
rpcInit
.
secret
=
"password"
;
rpcInit
.
ckey
=
"key"
;
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
if
(
pRpc
==
NULL
)
{
...
...
src/util/src/tglobalcfg.c
浏览文件 @
54cd817f
...
...
@@ -209,7 +209,7 @@ char tsLocale[TSDB_LOCALE_LEN] = {0};
char
tsCharset
[
TSDB_LOCALE_LEN
]
=
{
0
};
// default encode string
int
tsNumOfLogLines
=
10000000
;
uint32_t
rpcDebugFlag
=
13
1
;
uint32_t
rpcDebugFlag
=
13
5
;
uint32_t
ddebugFlag
=
131
;
uint32_t
mdebugFlag
=
135
;
uint32_t
sdbDebugFlag
=
135
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录