Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
40917712
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看板
提交
40917712
编写于
3月 22, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact queue
上级
fe8714fe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
108 addition
and
18 deletion
+108
-18
include/util/tworker.h
include/util/tworker.h
+32
-0
source/dnode/mgmt/mnode/inc/mmInt.h
source/dnode/mgmt/mnode/inc/mmInt.h
+3
-3
source/dnode/mgmt/mnode/src/mmWorker.c
source/dnode/mgmt/mnode/src/mmWorker.c
+15
-13
source/util/src/tqueue.c
source/util/src/tqueue.c
+0
-1
source/util/src/tworker.c
source/util/src/tworker.c
+58
-1
未找到文件。
include/util/tworker.h
浏览文件 @
40917712
...
...
@@ -67,6 +67,38 @@ void tWWorkerCleanup(SWWorkerPool *pool);
STaosQueue
*
tWWorkerAllocQueue
(
SWWorkerPool
*
pool
,
void
*
ahandle
,
FItems
fp
);
void
tWWorkerFreeQueue
(
SWWorkerPool
*
pool
,
STaosQueue
*
queue
);
typedef
struct
{
const
char
*
name
;
int32_t
minNum
;
int32_t
maxNum
;
FItem
fp
;
void
*
param
;
}
SQWorkerAllCfg
;
typedef
struct
{
const
char
*
name
;
STaosQueue
*
queue
;
SQWorkerPool
pool
;
}
SQWorkerAll
;
typedef
struct
{
const
char
*
name
;
int32_t
maxNum
;
FItems
fp
;
void
*
param
;
}
SWWorkerAllCfg
;
typedef
struct
{
const
char
*
name
;
STaosQueue
*
queue
;
SWWorkerPool
pool
;
}
SWWorkerAll
;
int32_t
tQWorkerAllInit
(
SQWorkerAll
*
pWorker
,
const
SQWorkerAllCfg
*
pCfg
);
void
tQWorkerAllCleanup
(
SQWorkerAll
*
pWorker
);
int32_t
tWWorkerAllInit
(
SWWorkerAll
*
pWorker
,
const
SWWorkerAllCfg
*
pCfg
);
void
tWWorkerAllCleanup
(
SWWorkerAll
*
pWorker
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mgmt/mnode/inc/mmInt.h
浏览文件 @
40917712
...
...
@@ -28,9 +28,9 @@ typedef struct SMnodeMgmt {
SDnode
*
pDnode
;
SMgmtWrapper
*
pWrapper
;
const
char
*
path
;
S
DnodeWorker
readWorker
;
S
DnodeWorker
writeWorker
;
S
DnodeWorker
syncWorker
;
S
QWorkerAll
readWorker
;
S
QWorkerAll
writeWorker
;
S
QWorkerAll
syncWorker
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
int8_t
replica
;
int8_t
selfIndex
;
...
...
source/dnode/mgmt/mnode/src/mmWorker.c
浏览文件 @
40917712
...
...
@@ -42,9 +42,9 @@ static void mmProcessQueue(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
taosFreeQitem
(
pMsg
);
}
static
int32_t
mmPutMsgToWorker
(
SMnodeMgmt
*
pMgmt
,
S
DnodeWorker
*
pWorker
,
SNodeMsg
*
pMsg
)
{
static
int32_t
mmPutMsgToWorker
(
SMnodeMgmt
*
pMgmt
,
S
QWorkerAll
*
pWorker
,
SNodeMsg
*
pMsg
)
{
dTrace
(
"msg:%p, put into worker %s"
,
pMsg
,
pWorker
->
name
);
return
dndWriteMsgToWorker
(
pWorker
,
pMsg
);
return
taosWriteQitem
(
pWorker
->
queue
,
pMsg
);
}
int32_t
mmProcessWriteMsg
(
SMnodeMgmt
*
pMgmt
,
SNodeMsg
*
pMsg
)
{
...
...
@@ -59,7 +59,7 @@ int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
return
mmPutMsgToWorker
(
pMgmt
,
&
pMgmt
->
readWorker
,
pMsg
);
}
static
int32_t
mmPutRpcMsgToWorker
(
SMnodeMgmt
*
pMgmt
,
S
DnodeWorker
*
pWorker
,
SRpcMsg
*
pRpc
)
{
static
int32_t
mmPutRpcMsgToWorker
(
SMnodeMgmt
*
pMgmt
,
S
QWorkerAll
*
pWorker
,
SRpcMsg
*
pRpc
)
{
SNodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SNodeMsg
));
if
(
pMsg
==
NULL
)
{
return
-
1
;
...
...
@@ -68,7 +68,7 @@ static int32_t mmPutRpcMsgToWorker(SMnodeMgmt *pMgmt, SDnodeWorker *pWorker, SRp
dTrace
(
"msg:%p, is created and put into worker:%s, type:%s"
,
pMsg
,
pWorker
->
name
,
TMSG_INFO
(
pRpc
->
msgType
));
pMsg
->
rpcMsg
=
*
pRpc
;
int32_t
code
=
dndWriteMsgToWorker
(
pWorker
,
pMsg
);
int32_t
code
=
taosWriteQitem
(
pWorker
->
queue
,
pMsg
);
if
(
code
!=
0
)
{
dTrace
(
"msg:%p, is freed"
,
pMsg
);
taosFreeQitem
(
pMsg
);
...
...
@@ -89,18 +89,20 @@ int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
}
int32_t
mmStartWorker
(
SMnodeMgmt
*
pMgmt
)
{
if
(
dndInitWorker
(
pMgmt
,
&
pMgmt
->
readWorker
,
DND_WORKER_SINGLE
,
"mnode-read"
,
0
,
1
,
mmProcessQueue
)
!=
0
)
{
dError
(
"failed to start mnode read worker since %s"
,
terrstr
());
SQWorkerAllCfg
cfg
=
{.
minNum
=
0
,
.
maxNum
=
1
,
.
name
=
"mnode-read"
,
.
fp
=
(
FItem
)
mmProcessQueue
,
.
param
=
pMgmt
};
if
(
tQWorkerAllInit
(
&
pMgmt
->
readWorker
,
&
cfg
)
!=
0
)
{
dError
(
"failed to start mnode-read worker since %s"
,
terrstr
());
return
-
1
;
}
if
(
dndInitWorker
(
pMgmt
,
&
pMgmt
->
writeWorker
,
DND_WORKER_SINGLE
,
"mnode-write"
,
0
,
1
,
mmProcessQueue
)
!=
0
)
{
dError
(
"failed to start mnode
write worker since %s"
,
terrstr
());
if
(
tQWorkerAllInit
(
&
pMgmt
->
writeWorker
,
&
cfg
)
!=
0
)
{
dError
(
"failed to start mnode
-
write worker since %s"
,
terrstr
());
return
-
1
;
}
if
(
dndInitWorker
(
pMgmt
,
&
pMgmt
->
syncWorker
,
DND_WORKER_SINGLE
,
"mnode-sync"
,
0
,
1
,
mmProcessQueue
)
!=
0
)
{
dError
(
"failed to start mnode sync
worker since %s"
,
terrstr
());
if
(
tQWorkerAllInit
(
&
pMgmt
->
syncWorker
,
&
cfg
)
!=
0
)
{
dError
(
"failed to start mnode sync
-
worker since %s"
,
terrstr
());
return
-
1
;
}
...
...
@@ -108,7 +110,7 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
}
void
mmStopWorker
(
SMnodeMgmt
*
pMgmt
)
{
dndCleanupWorker
(
&
pMgmt
->
readWorker
);
dndCleanupWorker
(
&
pMgmt
->
writeWorker
);
dndCleanupWorker
(
&
pMgmt
->
syncWorker
);
tQWorkerAllCleanup
(
&
pMgmt
->
readWorker
);
tQWorkerAllCleanup
(
&
pMgmt
->
writeWorker
);
tQWorkerAllCleanup
(
&
pMgmt
->
syncWorker
);
}
source/util/src/tqueue.c
浏览文件 @
40917712
...
...
@@ -441,7 +441,6 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) {
STaosQnode
*
pNode
=
(
STaosQnode
*
)((
char
*
)
pItem
-
sizeof
(
STaosQnode
));
taosThreadMutexLock
(
&
qset
->
mutex
);
pNode
->
queue
->
threadId
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pNode
->
queue
->
numOfItems
;
++
i
)
{
tsem_post
(
&
qset
->
sem
);
}
...
...
source/util/src/tworker.c
浏览文件 @
40917712
...
...
@@ -22,7 +22,7 @@ typedef void *(*ThreadFp)(void *param);
int32_t
tQWorkerInit
(
SQWorkerPool
*
pool
)
{
pool
->
qset
=
taosOpenQset
();
pool
->
workers
=
calloc
(
sizeof
(
SQWorker
),
pool
->
max
);
pool
->
workers
=
calloc
(
pool
->
max
,
sizeof
(
SQWorker
)
);
if
(
pool
->
workers
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -279,3 +279,60 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue) {
taosCloseQueue
(
queue
);
uDebug
(
"worker:%s, queue:%p is freed"
,
pool
->
name
,
queue
);
}
int32_t
tQWorkerAllInit
(
SQWorkerAll
*
pWorker
,
const
SQWorkerAllCfg
*
pCfg
)
{
SQWorkerPool
*
pPool
=
&
pWorker
->
pool
;
pPool
->
name
=
pCfg
->
name
;
pPool
->
min
=
pCfg
->
minNum
;
pPool
->
max
=
pCfg
->
maxNum
;
if
(
tQWorkerInit
(
pPool
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pWorker
->
queue
=
tQWorkerAllocQueue
(
pPool
,
pCfg
->
param
,
pCfg
->
fp
);
if
(
pWorker
->
queue
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pWorker
->
name
=
pCfg
->
name
;
return
0
;
}
void
tQWorkerAllCleanup
(
SQWorkerAll
*
pWorker
)
{
if
(
pWorker
->
queue
==
NULL
)
return
;
while
(
!
taosQueueEmpty
(
pWorker
->
queue
))
{
taosMsleep
(
10
);
}
tQWorkerCleanup
(
&
pWorker
->
pool
);
tQWorkerFreeQueue
(
&
pWorker
->
pool
,
pWorker
->
queue
);
}
int32_t
tWWorkerAllInit
(
SWWorkerAll
*
pWorker
,
const
SWWorkerAllCfg
*
pCfg
)
{
SWWorkerPool
*
pPool
=
&
pWorker
->
pool
;
pPool
->
name
=
pCfg
->
name
;
pPool
->
max
=
pCfg
->
maxNum
;
if
(
tWWorkerInit
(
pPool
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pWorker
->
queue
=
tWWorkerAllocQueue
(
pPool
,
pCfg
->
param
,
pCfg
->
fp
);
if
(
pWorker
->
queue
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pWorker
->
name
=
pCfg
->
name
;
return
0
;
}
void
tWWorkerAllCleanup
(
SWWorkerAll
*
pWorker
)
{
if
(
pWorker
->
queue
==
NULL
)
return
;
while
(
!
taosQueueEmpty
(
pWorker
->
queue
))
{
taosMsleep
(
10
);
}
tWWorkerCleanup
(
&
pWorker
->
pool
);
tWWorkerFreeQueue
(
&
pWorker
->
pool
,
pWorker
->
queue
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录