Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
661cfc71
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
661cfc71
编写于
11月 09, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
11月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4156 from taosdata/feature/wal
Feature/wal
上级
f5ce39b3
13e35660
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
51 deletion
+54
-51
src/sync/src/taosTcpPool.c
src/sync/src/taosTcpPool.c
+53
-50
tests/tsim/src/simSystem.c
tests/tsim/src/simSystem.c
+1
-1
未找到文件。
src/sync/src/taosTcpPool.c
浏览文件 @
661cfc71
...
...
@@ -13,18 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tulog.h"
#include "tutil.h"
#include "tsocket.h"
#include "taoserror.h"
#include "taosTcpPool.h"
#include "twal.h"
#include "tsync.h"
#include "syncInt.h"
typedef
struct
SThreadObj
{
pthread_t
thread
;
bool
stop
;
int
pollFd
;
int
numOfFds
;
int
32_t
pollFd
;
int
32_t
numOfFds
;
struct
SPoolObj
*
pPool
;
}
SThreadObj
;
...
...
@@ -32,15 +36,15 @@ typedef struct SPoolObj {
SPoolInfo
info
;
SThreadObj
**
pThread
;
pthread_t
thread
;
int
nextId
;
int
acceptFd
;
// FD for accept new connection
int
32_t
nextId
;
int
32_t
acceptFd
;
// FD for accept new connection
}
SPoolObj
;
typedef
struct
{
SThreadObj
*
pThread
;
void
*
ahandle
;
int
fd
;
int
closedByApp
;
void
*
ahandle
;
int
32_t
fd
;
int
32_t
closedByApp
;
}
SConnObj
;
static
void
*
taosAcceptPeerTcpConnection
(
void
*
argv
);
...
...
@@ -53,66 +57,66 @@ void *taosOpenTcpThreadPool(SPoolInfo *pInfo) {
SPoolObj
*
pPool
=
calloc
(
sizeof
(
SPoolObj
),
1
);
if
(
pPool
==
NULL
)
{
uError
(
"TCP server,
no enough memory"
);
sError
(
"failed to alloc pool for TCP server since
no enough memory"
);
return
NULL
;
}
pPool
->
info
=
*
pInfo
;
pPool
->
pThread
=
(
SThreadObj
**
)
calloc
(
sizeof
(
SThreadObj
*
),
pInfo
->
numOfThreads
);
pPool
->
pThread
=
calloc
(
sizeof
(
SThreadObj
*
),
pInfo
->
numOfThreads
);
if
(
pPool
->
pThread
==
NULL
)
{
uError
(
"TCP server,
no enough memory"
);
free
(
pPool
);
sError
(
"failed to alloc pool thread for TCP server since
no enough memory"
);
t
free
(
pPool
);
return
NULL
;
}
pPool
->
acceptFd
=
taosOpenTcpServerSocket
(
pInfo
->
serverIp
,
pInfo
->
port
);
if
(
pPool
->
acceptFd
<
0
)
{
free
(
pPool
->
pThread
);
free
(
pPool
);
u
Error
(
"failed to create TCP server socket, port:%d (%s)"
,
pInfo
->
port
,
strerror
(
errno
));
t
free
(
pPool
->
pThread
);
t
free
(
pPool
);
s
Error
(
"failed to create TCP server socket, port:%d (%s)"
,
pInfo
->
port
,
strerror
(
errno
));
return
NULL
;
}
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pPool
->
thread
),
&
thattr
,
(
void
*
)
taosAcceptPeerTcpConnection
,
pPool
)
!=
0
)
{
uError
(
"TCP server, failed to create accept thread, reason:
%s"
,
strerror
(
errno
));
sError
(
"failed to create accept thread for TCP server since
%s"
,
strerror
(
errno
));
close
(
pPool
->
acceptFd
);
free
(
pPool
->
pThread
);
free
(
pPool
);
t
free
(
pPool
->
pThread
);
t
free
(
pPool
);
return
NULL
;
}
pthread_attr_destroy
(
&
thattr
);
u
Debug
(
"%p TCP pool is created"
,
pPool
);
s
Debug
(
"%p TCP pool is created"
,
pPool
);
return
pPool
;
}
void
taosCloseTcpThreadPool
(
void
*
param
)
{
SPoolObj
*
pPool
=
(
SPoolObj
*
)
param
;
SPoolObj
*
pPool
=
param
;
SThreadObj
*
pThread
;
shutdown
(
pPool
->
acceptFd
,
SHUT_RD
);
pthread_join
(
pPool
->
thread
,
NULL
);
for
(
int
i
=
0
;
i
<
pPool
->
info
.
numOfThreads
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
pPool
->
info
.
numOfThreads
;
++
i
)
{
pThread
=
pPool
->
pThread
[
i
];
if
(
pThread
)
taosStopPoolThread
(
pThread
);
}
u
Debug
(
"%p TCP pool is closed"
,
pPool
);
s
Debug
(
"%p TCP pool is closed"
,
pPool
);
taosTFree
(
pPool
->
pThread
);
free
(
pPool
);
t
free
(
pPool
);
}
void
*
taosAllocateTcpConn
(
void
*
param
,
void
*
pPeer
,
int
connFd
)
{
void
*
taosAllocateTcpConn
(
void
*
param
,
void
*
pPeer
,
int
32_t
connFd
)
{
struct
epoll_event
event
;
SPoolObj
*
pPool
=
(
SPoolObj
*
)
param
;
SPoolObj
*
pPool
=
param
;
SConnObj
*
pConn
=
(
SConnObj
*
)
calloc
(
sizeof
(
SConnObj
),
1
);
SConnObj
*
pConn
=
calloc
(
sizeof
(
SConnObj
),
1
);
if
(
pConn
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
...
...
@@ -120,7 +124,7 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int connFd) {
SThreadObj
*
pThread
=
taosGetTcpThread
(
pPool
);
if
(
pThread
==
NULL
)
{
free
(
pConn
);
t
free
(
pConn
);
return
NULL
;
}
...
...
@@ -133,13 +137,13 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int connFd) {
event
.
data
.
ptr
=
pConn
;
if
(
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_ADD
,
connFd
,
&
event
)
<
0
)
{
uError
(
"failed to add fd:%d(%s)
"
,
connFd
,
strerror
(
errno
));
sError
(
"failed to add fd:%d since %s
"
,
connFd
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
free
(
pConn
);
t
free
(
pConn
);
pConn
=
NULL
;
}
else
{
pThread
->
numOfFds
++
;
u
Debug
(
"%p fd:%d is added to epoll thread, num:%d"
,
pThread
,
connFd
,
pThread
->
numOfFds
);
s
Debug
(
"%p fd:%d is added to epoll thread, num:%d"
,
pThread
,
connFd
,
pThread
->
numOfFds
);
}
return
pConn
;
...
...
@@ -149,7 +153,7 @@ void taosFreeTcpConn(void *param) {
SConnObj
*
pConn
=
(
SConnObj
*
)
param
;
SThreadObj
*
pThread
=
pConn
->
pThread
;
u
Debug
(
"%p TCP connection will be closed, fd:%d"
,
pThread
,
pConn
->
fd
);
s
Debug
(
"%p TCP connection will be closed, fd:%d"
,
pThread
,
pConn
->
fd
);
pConn
->
closedByApp
=
1
;
shutdown
(
pConn
->
fd
,
SHUT_WR
);
}
...
...
@@ -164,9 +168,9 @@ static void taosProcessBrokenLink(SConnObj *pConn) {
pThread
->
numOfFds
--
;
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_DEL
,
pConn
->
fd
,
NULL
);
u
Debug
(
"%p fd:%d is removed from epoll thread, num:%d"
,
pThread
,
pConn
->
fd
,
pThread
->
numOfFds
);
s
Debug
(
"%p fd:%d is removed from epoll thread, num:%d"
,
pThread
,
pConn
->
fd
,
pThread
->
numOfFds
);
taosClose
(
pConn
->
fd
);
free
(
pConn
);
t
free
(
pConn
);
}
#define maxEvents 10
...
...
@@ -183,18 +187,18 @@ static void *taosProcessTcpData(void *param) {
while
(
1
)
{
if
(
pThread
->
stop
)
break
;
int
fdNum
=
epoll_wait
(
pThread
->
pollFd
,
events
,
maxEvents
,
TAOS_EPOLL_WAIT_TIME
);
int
32_t
fdNum
=
epoll_wait
(
pThread
->
pollFd
,
events
,
maxEvents
,
TAOS_EPOLL_WAIT_TIME
);
if
(
pThread
->
stop
)
{
u
Debug
(
"%p TCP epoll thread is exiting..."
,
pThread
);
s
Debug
(
"%p TCP epoll thread is exiting..."
,
pThread
);
break
;
}
if
(
fdNum
<
0
)
{
uError
(
"epoll_wait failed (%s)
"
,
strerror
(
errno
));
sError
(
"epoll_wait failed since %s
"
,
strerror
(
errno
));
continue
;
}
for
(
int
i
=
0
;
i
<
fdNum
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
fdNum
;
++
i
)
{
pConn
=
events
[
i
].
data
.
ptr
;
assert
(
pConn
);
...
...
@@ -219,17 +223,16 @@ static void *taosProcessTcpData(void *param) {
continue
;
}
}
}
if
(
pThread
->
stop
)
break
;
}
u
Debug
(
"%p TCP epoll thread exits"
,
pThread
);
s
Debug
(
"%p TCP epoll thread exits"
,
pThread
);
close
(
pThread
->
pollFd
);
free
(
pThread
);
free
(
buffer
);
t
free
(
pThread
);
t
free
(
buffer
);
return
NULL
;
}
...
...
@@ -242,18 +245,18 @@ static void *taosAcceptPeerTcpConnection(void *argv) {
while
(
1
)
{
struct
sockaddr_in
clientAddr
;
socklen_t
addrlen
=
sizeof
(
clientAddr
);
int
connFd
=
accept
(
pPool
->
acceptFd
,
(
struct
sockaddr
*
)
&
clientAddr
,
&
addrlen
);
int
32_t
connFd
=
accept
(
pPool
->
acceptFd
,
(
struct
sockaddr
*
)
&
clientAddr
,
&
addrlen
);
if
(
connFd
<
0
)
{
if
(
errno
==
EINVAL
)
{
u
Debug
(
"%p TCP server accept is exiting..."
,
pPool
);
s
Debug
(
"%p TCP server accept is exiting..."
,
pPool
);
break
;
}
else
{
uError
(
"TCP accept failure, reason:
%s"
,
strerror
(
errno
));
sError
(
"TCP accept failure since
%s"
,
strerror
(
errno
));
continue
;
}
}
//
u
Debug("TCP connection from: 0x%x:%d", clientAddr.sin_addr.s_addr, clientAddr.sin_port);
//
s
Debug("TCP connection from: 0x%x:%d", clientAddr.sin_addr.s_addr, clientAddr.sin_port);
taosKeepTcpAlive
(
connFd
);
(
*
pInfo
->
processIncomingConn
)(
connFd
,
clientAddr
.
sin_addr
.
s_addr
);
}
...
...
@@ -273,23 +276,23 @@ static SThreadObj *taosGetTcpThread(SPoolObj *pPool) {
pThread
->
pPool
=
pPool
;
pThread
->
pollFd
=
epoll_create
(
10
);
// size does not matter
if
(
pThread
->
pollFd
<
0
)
{
free
(
pThread
);
t
free
(
pThread
);
return
NULL
;
}
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
int
ret
=
pthread_create
(
&
(
pThread
->
thread
),
&
thattr
,
(
void
*
)
taosProcessTcpData
,
pThread
);
int
32_t
ret
=
pthread_create
(
&
(
pThread
->
thread
),
&
thattr
,
(
void
*
)
taosProcessTcpData
,
pThread
);
pthread_attr_destroy
(
&
thattr
);
if
(
ret
!=
0
)
{
close
(
pThread
->
pollFd
);
free
(
pThread
);
t
free
(
pThread
);
return
NULL
;
}
u
Debug
(
"%p TCP epoll thread is created"
,
pThread
);
s
Debug
(
"%p TCP epoll thread is created"
,
pThread
);
pPool
->
pThread
[
pPool
->
nextId
]
=
pThread
;
pPool
->
nextId
++
;
pPool
->
nextId
=
pPool
->
nextId
%
pPool
->
info
.
numOfThreads
;
...
...
@@ -314,12 +317,12 @@ static void taosStopPoolThread(SThreadObj *pThread) {
eventfd_t
fd
=
eventfd
(
1
,
0
);
if
(
fd
==
-
1
)
{
// failed to create eventfd, call pthread_cancel instead, which may result in data corruption
uError
(
"failed to create eventfd(%s)
"
,
strerror
(
errno
));
sError
(
"failed to create eventfd since %s
"
,
strerror
(
errno
));
pthread_cancel
(
pThread
->
thread
);
pThread
->
stop
=
true
;
}
else
if
(
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_ADD
,
fd
,
&
event
)
<
0
)
{
// failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption
uError
(
"failed to call epoll_ctl(%s)
"
,
strerror
(
errno
));
sError
(
"failed to call epoll_ctl since %s
"
,
strerror
(
errno
));
pthread_cancel
(
pThread
->
thread
);
}
...
...
tests/tsim/src/simSystem.c
浏览文件 @
661cfc71
...
...
@@ -128,7 +128,7 @@ SScript *simProcessCallOver(SScript *script) {
exit
(
0
);
}
return
NULL
;
return
simScriptList
[
simScriptPos
]
;
}
}
else
{
simInfo
(
"script:%s, is stopped by main script"
,
script
->
fileName
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录