Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bcd6df15
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bcd6df15
编写于
1月 20, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor rpc
上级
906e0e78
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
16 deletion
+67
-16
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+54
-9
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+11
-7
source/libs/transport/test/rclient.c
source/libs/transport/test/rclient.c
+2
-0
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
bcd6df15
...
@@ -52,7 +52,14 @@ typedef struct SClientObj {
...
@@ -52,7 +52,14 @@ typedef struct SClientObj {
SCliThrdObj
**
pThreadObj
;
SCliThrdObj
**
pThreadObj
;
}
SClientObj
;
}
SClientObj
;
typedef
struct
SConnList
{
queue
conn
;
}
SConnList
;
// conn pool
// conn pool
// add expire timeout and capacity limit
static
void
*
connCacheCreate
(
int
size
);
static
void
*
connCacheDestroy
(
void
*
cache
);
static
SCliConn
*
getConnFromCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
);
static
SCliConn
*
getConnFromCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
);
static
void
addConnToCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
,
SCliConn
*
conn
);
static
void
addConnToCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
,
SCliConn
*
conn
);
...
@@ -81,6 +88,53 @@ static void clientProcessData(SCliConn* conn) {
...
@@ -81,6 +88,53 @@ static void clientProcessData(SCliConn* conn) {
}
}
static
void
clientHandleReq
(
SCliMsg
*
pMsg
,
SCliThrdObj
*
pThrd
);
static
void
clientHandleReq
(
SCliMsg
*
pMsg
,
SCliThrdObj
*
pThrd
);
static
void
*
connCacheCreate
(
int
size
)
{
SHashObj
*
cache
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
return
false
;
}
static
void
*
connCacheDestroy
(
void
*
cache
)
{
SConnList
*
connList
=
taosHashIterate
((
SHashObj
*
)
cache
,
NULL
);
while
(
!
QUEUE_IS_EMPTY
(
&
connList
->
conn
))
{
queue
*
h
=
QUEUE_HEAD
(
&
connList
->
conn
);
QUEUE_REMOVE
(
h
);
SCliConn
*
c
=
QUEUE_DATA
(
h
,
SCliConn
,
conn
);
clientConnDestroy
(
c
);
}
taosHashClear
(
cache
);
}
static
SCliConn
*
getConnFromCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
)
{
char
key
[
128
]
=
{
0
};
tstrncpy
(
key
,
ip
,
strlen
(
ip
));
tstrncpy
(
key
+
strlen
(
key
),
(
char
*
)(
&
port
),
sizeof
(
port
));
SHashObj
*
pCache
=
cache
;
SConnList
*
plist
=
taosHashGet
(
pCache
,
key
,
strlen
(
key
));
if
(
plist
==
NULL
)
{
SConnList
list
;
plist
=
&
list
;
QUEUE_INIT
(
&
plist
->
conn
);
taosHashPut
(
pCache
,
key
,
strlen
(
key
),
plist
,
sizeof
(
*
plist
));
}
if
(
QUEUE_IS_EMPTY
(
&
plist
->
conn
))
{
return
NULL
;
}
queue
*
h
=
QUEUE_HEAD
(
&
plist
->
conn
);
QUEUE_REMOVE
(
h
);
return
QUEUE_DATA
(
h
,
SCliConn
,
conn
);
}
static
void
addConnToCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
,
SCliConn
*
conn
)
{
char
key
[
128
]
=
{
0
};
tstrncpy
(
key
,
ip
,
strlen
(
ip
));
tstrncpy
(
key
+
strlen
(
key
),
(
char
*
)(
&
port
),
sizeof
(
port
));
SHashObj
*
pCache
=
cache
;
SConnList
*
plist
=
taosHashGet
(
pCache
,
key
,
strlen
(
key
));
// list already create before
assert
(
plist
!=
NULL
);
QUEUE_PUSH
(
&
plist
->
conn
,
&
conn
->
conn
);
}
static
bool
clientReadComplete
(
SConnBuffer
*
data
)
{
static
bool
clientReadComplete
(
SConnBuffer
*
data
)
{
STransMsgHead
head
;
STransMsgHead
head
;
int32_t
headLen
=
sizeof
(
head
);
int32_t
headLen
=
sizeof
(
head
);
...
@@ -206,15 +260,6 @@ static void clientConnCb(uv_connect_t* req, int status) {
...
@@ -206,15 +260,6 @@ static void clientConnCb(uv_connect_t* req, int status) {
clientWrite
(
pConn
);
clientWrite
(
pConn
);
}
}
static
SCliConn
*
getConnFromCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
)
{
// impl later
return
NULL
;
}
static
void
addConnToCache
(
void
*
cache
,
char
*
ip
,
uint32_t
port
,
SCliConn
*
conn
)
{
// impl later
}
static
void
clientHandleReq
(
SCliMsg
*
pMsg
,
SCliThrdObj
*
pThrd
)
{
static
void
clientHandleReq
(
SCliMsg
*
pMsg
,
SCliThrdObj
*
pThrd
)
{
uint64_t
et
=
taosGetTimestampUs
();
uint64_t
et
=
taosGetTimestampUs
();
uint64_t
el
=
et
-
pMsg
->
st
;
uint64_t
el
=
et
-
pMsg
->
st
;
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
bcd6df15
...
@@ -210,8 +210,8 @@ static int uvAuthMsg(SConn* pConn, char* msg, int len) {
...
@@ -210,8 +210,8 @@ static int uvAuthMsg(SConn* pConn, char* msg, int len) {
// refers specifically to query or insert timeout
// refers specifically to query or insert timeout
static
void
uvHandleActivityTimeout
(
uv_timer_t
*
handle
)
{
static
void
uvHandleActivityTimeout
(
uv_timer_t
*
handle
)
{
// impl later
SConn
*
conn
=
handle
->
data
;
SConn
*
conn
=
handle
->
data
;
tDebug
(
"%p timeout since no activity"
,
conn
);
}
}
static
void
uvProcessData
(
SConn
*
pConn
)
{
static
void
uvProcessData
(
SConn
*
pConn
)
{
...
@@ -232,12 +232,13 @@ static void uvProcessData(SConn* pConn) {
...
@@ -232,12 +232,13 @@ static void uvProcessData(SConn* pConn) {
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
p
->
shandle
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
p
->
shandle
;
// auth here
// auth here
// auth should not do in rpc thread
int8_t
code
=
uvAuthMsg
(
pConn
,
(
char
*
)
pHead
,
p
->
msgLen
);
//
int8_t code = uvAuthMsg(pConn, (char*)pHead, p->msgLen);
if
(
code
!=
0
)
{
//
if (code != 0) {
terrno
=
code
;
//
terrno = code;
return
;
//
return;
}
//
}
pHead
->
code
=
htonl
(
pHead
->
code
);
pHead
->
code
=
htonl
(
pHead
->
code
);
int32_t
dlen
=
0
;
int32_t
dlen
=
0
;
...
@@ -248,7 +249,7 @@ static void uvProcessData(SConn* pConn) {
...
@@ -248,7 +249,7 @@ static void uvProcessData(SConn* pConn) {
}
else
{
}
else
{
// impl later
// impl later
}
}
rpcMsg
.
contLen
=
rpc
ContLenFromMsg
(
pHead
->
msgLen
);
rpcMsg
.
contLen
=
trans
ContLenFromMsg
(
pHead
->
msgLen
);
rpcMsg
.
pCont
=
pHead
->
content
;
rpcMsg
.
pCont
=
pHead
->
content
;
rpcMsg
.
msgType
=
pHead
->
msgType
;
rpcMsg
.
msgType
=
pHead
->
msgType
;
rpcMsg
.
code
=
pHead
->
code
;
rpcMsg
.
code
=
pHead
->
code
;
...
@@ -318,6 +319,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
...
@@ -318,6 +319,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
return
;
return
;
}
}
uv_buf_t
wb
=
uv_buf_init
(
conn
->
writeBuf
.
buf
,
conn
->
writeBuf
.
len
);
uv_buf_t
wb
=
uv_buf_init
(
conn
->
writeBuf
.
buf
,
conn
->
writeBuf
.
len
);
uv_timer_stop
(
conn
->
pTimer
);
uv_write
(
conn
->
pWriter
,
(
uv_stream_t
*
)
conn
->
pTcp
,
&
wb
,
1
,
uvOnWriteCb
);
uv_write
(
conn
->
pWriter
,
(
uv_stream_t
*
)
conn
->
pTcp
,
&
wb
,
1
,
uvOnWriteCb
);
}
}
}
}
...
...
source/libs/transport/test/rclient.c
浏览文件 @
bcd6df15
...
@@ -40,6 +40,7 @@ static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
...
@@ -40,6 +40,7 @@ static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
if
(
pEpSet
)
pInfo
->
epSet
=
*
pEpSet
;
if
(
pEpSet
)
pInfo
->
epSet
=
*
pEpSet
;
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
// tsem_post(&pInfo->rspSem);
tsem_post
(
&
pInfo
->
rspSem
);
tsem_post
(
&
pInfo
->
rspSem
);
}
}
...
@@ -60,6 +61,7 @@ static void *sendRequest(void *param) {
...
@@ -60,6 +61,7 @@ static void *sendRequest(void *param) {
// tDebug("thread:%d, send request, contLen:%d num:%d", pInfo->index, pInfo->msgSize, pInfo->num);
// tDebug("thread:%d, send request, contLen:%d num:%d", pInfo->index, pInfo->msgSize, pInfo->num);
rpcSendRequest
(
pInfo
->
pRpc
,
&
pInfo
->
epSet
,
&
rpcMsg
,
NULL
);
rpcSendRequest
(
pInfo
->
pRpc
,
&
pInfo
->
epSet
,
&
rpcMsg
,
NULL
);
if
(
pInfo
->
num
%
20000
==
0
)
tInfo
(
"thread:%d, %d requests have been sent"
,
pInfo
->
index
,
pInfo
->
num
);
if
(
pInfo
->
num
%
20000
==
0
)
tInfo
(
"thread:%d, %d requests have been sent"
,
pInfo
->
index
,
pInfo
->
num
);
// tsem_wait(&pInfo->rspSem);
tsem_wait
(
&
pInfo
->
rspSem
);
tsem_wait
(
&
pInfo
->
rspSem
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录