Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fe8714fe
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
fe8714fe
编写于
3月 22, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact worker
上级
5f9f8ac7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
22 addition
and
125 deletion
+22
-125
include/util/tqueue.h
include/util/tqueue.h
+0
-3
include/util/tworker.h
include/util/tworker.h
+14
-19
source/dnode/mgmt/vnode/inc/vmInt.h
source/dnode/mgmt/vnode/inc/vmInt.h
+1
-1
source/dnode/mgmt/vnode/src/vmWorker.c
source/dnode/mgmt/vnode/src/vmWorker.c
+5
-5
source/util/src/tqueue.c
source/util/src/tqueue.c
+0
-48
source/util/src/tworker.c
source/util/src/tworker.c
+2
-49
未找到文件。
include/util/tqueue.h
浏览文件 @
fe8714fe
...
...
@@ -70,10 +70,7 @@ int32_t taosGetQueueNumber(STaosQset *qset);
int32_t
taosReadQitemFromQset
(
STaosQset
*
qset
,
void
**
ppItem
,
void
**
ahandle
,
FItem
*
itemFp
);
int32_t
taosReadAllQitemsFromQset
(
STaosQset
*
qset
,
STaosQall
*
qall
,
void
**
ahandle
,
FItems
*
itemsFp
);
int32_t
taosReadQitemFromQsetByThread
(
STaosQset
*
qset
,
void
**
ppItem
,
void
**
ahandle
,
FItem
*
itemFp
,
int32_t
threadId
);
void
taosResetQsetThread
(
STaosQset
*
qset
,
void
*
pItem
);
int32_t
taosGetQueueItemsNumber
(
STaosQueue
*
queue
);
int32_t
taosGetQsetItemsNumber
(
STaosQset
*
qset
);
...
...
include/util/tworker.h
浏览文件 @
fe8714fe
...
...
@@ -27,33 +27,33 @@ typedef struct SWWorkerPool SWWorkerPool;
typedef
struct
SQWorker
{
int32_t
id
;
// worker ID
TdThread
thread
;
// thread
TdThread
thread
;
// thread
SQWorkerPool
*
pool
;
}
SQWorker
,
SFWorker
;
}
SQWorker
;
typedef
struct
SQWorkerPool
{
int32_t
max
;
// max number of workers
int32_t
min
;
// min number of workers
int32_t
num
;
// current number of workers
STaosQset
*
qset
;
const
char
*
name
;
SQWorker
*
workers
;
int32_t
max
;
// max number of workers
int32_t
min
;
// min number of workers
int32_t
num
;
// current number of workers
STaosQset
*
qset
;
const
char
*
name
;
SQWorker
*
workers
;
TdThreadMutex
mutex
;
}
SQWorkerPool
,
SFWorkerPool
;
}
SQWorkerPool
;
typedef
struct
SWWorker
{
int32_t
id
;
// worker id
TdThread
thread
;
// thread
TdThread
thread
;
// thread
STaosQall
*
qall
;
STaosQset
*
qset
;
// queue set
SWWorkerPool
*
pool
;
}
SWWorker
;
typedef
struct
SWWorkerPool
{
int32_t
max
;
// max number of workers
int32_t
nextId
;
// from 0 to max-1, cyclic
const
char
*
name
;
SWWorker
*
workers
;
int32_t
max
;
// max number of workers
int32_t
nextId
;
// from 0 to max-1, cyclic
const
char
*
name
;
SWWorker
*
workers
;
TdThreadMutex
mutex
;
}
SWWorkerPool
;
...
...
@@ -62,11 +62,6 @@ void tQWorkerCleanup(SQWorkerPool *pool);
STaosQueue
*
tQWorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
);
void
tQWorkerFreeQueue
(
SQWorkerPool
*
pool
,
STaosQueue
*
queue
);
int32_t
tFWorkerInit
(
SFWorkerPool
*
pool
);
void
tFWorkerCleanup
(
SFWorkerPool
*
pool
);
STaosQueue
*
tFWorkerAllocQueue
(
SFWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
);
void
tFWorkerFreeQueue
(
SFWorkerPool
*
pool
,
STaosQueue
*
queue
);
int32_t
tWWorkerInit
(
SWWorkerPool
*
pool
);
void
tWWorkerCleanup
(
SWWorkerPool
*
pool
);
STaosQueue
*
tWWorkerAllocQueue
(
SWWorkerPool
*
pool
,
void
*
ahandle
,
FItems
fp
);
...
...
source/dnode/mgmt/vnode/inc/vmInt.h
浏览文件 @
fe8714fe
...
...
@@ -30,7 +30,7 @@ typedef struct SVnodesMgmt {
SVnodesStat
state
;
STfs
*
pTfs
;
SQWorkerPool
queryPool
;
S
F
WorkerPool
fetchPool
;
S
Q
WorkerPool
fetchPool
;
SWWorkerPool
syncPool
;
SWWorkerPool
writePool
;
const
char
*
path
;
...
...
source/dnode/mgmt/vnode/src/vmWorker.c
浏览文件 @
fe8714fe
...
...
@@ -262,7 +262,7 @@ int32_t vmAllocQueue(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) {
pVnode
->
pWriteQ
=
tWWorkerAllocQueue
(
&
pMgmt
->
writePool
,
pVnode
,
(
FItems
)
vmProcessWriteQueue
);
pVnode
->
pApplyQ
=
tWWorkerAllocQueue
(
&
pMgmt
->
writePool
,
pVnode
,
(
FItems
)
vmProcessApplyQueue
);
pVnode
->
pSyncQ
=
tWWorkerAllocQueue
(
&
pMgmt
->
syncPool
,
pVnode
,
(
FItems
)
vmProcessSyncQueue
);
pVnode
->
pFetchQ
=
t
F
WorkerAllocQueue
(
&
pMgmt
->
fetchPool
,
pVnode
,
(
FItem
)
vmProcessFetchQueue
);
pVnode
->
pFetchQ
=
t
Q
WorkerAllocQueue
(
&
pMgmt
->
fetchPool
,
pVnode
,
(
FItem
)
vmProcessFetchQueue
);
pVnode
->
pQueryQ
=
tQWorkerAllocQueue
(
&
pMgmt
->
queryPool
,
pVnode
,
(
FItem
)
vmProcessQueryQueue
);
if
(
pVnode
->
pApplyQ
==
NULL
||
pVnode
->
pWriteQ
==
NULL
||
pVnode
->
pSyncQ
==
NULL
||
pVnode
->
pFetchQ
==
NULL
||
...
...
@@ -277,7 +277,7 @@ int32_t vmAllocQueue(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) {
void
vmFreeQueue
(
SVnodesMgmt
*
pMgmt
,
SVnodeObj
*
pVnode
)
{
tQWorkerFreeQueue
(
&
pMgmt
->
queryPool
,
pVnode
->
pQueryQ
);
t
F
WorkerFreeQueue
(
&
pMgmt
->
fetchPool
,
pVnode
->
pFetchQ
);
t
Q
WorkerFreeQueue
(
&
pMgmt
->
fetchPool
,
pVnode
->
pFetchQ
);
tWWorkerFreeQueue
(
&
pMgmt
->
writePool
,
pVnode
->
pWriteQ
);
tWWorkerFreeQueue
(
&
pMgmt
->
writePool
,
pVnode
->
pApplyQ
);
tWWorkerFreeQueue
(
&
pMgmt
->
syncPool
,
pVnode
->
pSyncQ
);
...
...
@@ -303,11 +303,11 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) {
pQPool
->
max
=
maxQueryThreads
;
if
(
tQWorkerInit
(
pQPool
)
!=
0
)
return
-
1
;
S
F
WorkerPool
*
pFPool
=
&
pMgmt
->
fetchPool
;
S
Q
WorkerPool
*
pFPool
=
&
pMgmt
->
fetchPool
;
pFPool
->
name
=
"vnode-fetch"
;
pFPool
->
min
=
minFetchThreads
;
pFPool
->
max
=
maxFetchThreads
;
if
(
t
F
WorkerInit
(
pFPool
)
!=
0
)
return
-
1
;
if
(
t
Q
WorkerInit
(
pFPool
)
!=
0
)
return
-
1
;
SWWorkerPool
*
pWPool
=
&
pMgmt
->
writePool
;
pWPool
->
name
=
"vnode-write"
;
...
...
@@ -330,7 +330,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) {
void
vmStopWorker
(
SVnodesMgmt
*
pMgmt
)
{
dndCleanupWorker
(
&
pMgmt
->
mgmtWorker
);
t
F
WorkerCleanup
(
&
pMgmt
->
fetchPool
);
t
Q
WorkerCleanup
(
&
pMgmt
->
fetchPool
);
tQWorkerCleanup
(
&
pMgmt
->
queryPool
);
tWWorkerCleanup
(
&
pMgmt
->
writePool
);
tWWorkerCleanup
(
&
pMgmt
->
syncPool
);
...
...
source/util/src/tqueue.c
浏览文件 @
fe8714fe
...
...
@@ -68,7 +68,6 @@ STaosQueue *taosOpenQueue() {
return
NULL
;
}
queue
->
threadId
=
-
1
;
uDebug
(
"queue:%p is opened"
,
queue
);
return
queue
;
}
...
...
@@ -437,53 +436,6 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
return
code
;
}
int32_t
taosReadQitemFromQsetByThread
(
STaosQset
*
qset
,
void
**
ppItem
,
void
**
ahandle
,
FItem
*
itemFp
,
int32_t
threadId
)
{
STaosQnode
*
pNode
=
NULL
;
int32_t
code
=
-
1
;
tsem_wait
(
&
qset
->
sem
);
taosThreadMutexLock
(
&
qset
->
mutex
);
for
(
int32_t
i
=
0
;
i
<
qset
->
numOfQueues
;
++
i
)
{
if
(
qset
->
current
==
NULL
)
qset
->
current
=
qset
->
head
;
STaosQueue
*
queue
=
qset
->
current
;
if
(
queue
)
qset
->
current
=
queue
->
next
;
if
(
queue
==
NULL
)
break
;
if
(
queue
->
head
==
NULL
)
continue
;
if
(
queue
->
threadId
!=
-
1
&&
queue
->
threadId
!=
threadId
)
{
code
=
0
;
continue
;
}
taosThreadMutexLock
(
&
queue
->
mutex
);
if
(
queue
->
head
)
{
pNode
=
queue
->
head
;
pNode
->
queue
=
queue
;
queue
->
threadId
=
threadId
;
*
ppItem
=
pNode
->
item
;
if
(
ahandle
)
*
ahandle
=
queue
->
ahandle
;
if
(
itemFp
)
*
itemFp
=
queue
->
itemFp
;
queue
->
head
=
pNode
->
next
;
if
(
queue
->
head
==
NULL
)
queue
->
tail
=
NULL
;
queue
->
numOfItems
--
;
atomic_sub_fetch_32
(
&
qset
->
numOfItems
,
1
);
code
=
1
;
uTrace
(
"item:%p is read out from queue:%p, items:%d"
,
*
ppItem
,
queue
,
queue
->
numOfItems
);
}
taosThreadMutexUnlock
(
&
queue
->
mutex
);
if
(
pNode
)
break
;
}
taosThreadMutexUnlock
(
&
qset
->
mutex
);
return
code
;
}
void
taosResetQsetThread
(
STaosQset
*
qset
,
void
*
pItem
)
{
if
(
pItem
==
NULL
)
return
;
STaosQnode
*
pNode
=
(
STaosQnode
*
)((
char
*
)
pItem
-
sizeof
(
STaosQnode
));
...
...
source/util/src/tworker.c
浏览文件 @
fe8714fe
...
...
@@ -93,7 +93,7 @@ static void *tQWorkerThreadFp(SQWorker *worker) {
return
NULL
;
}
STaosQueue
*
t
WorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
,
ThreadFp
threadF
p
)
{
STaosQueue
*
t
QWorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
f
p
)
{
taosThreadMutexLock
(
&
pool
->
mutex
);
STaosQueue
*
queue
=
taosOpenQueue
();
if
(
queue
==
NULL
)
{
...
...
@@ -114,7 +114,7 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
taosThreadAttrInit
(
&
thAttr
);
taosThreadAttrSetDetachState
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
taosThreadCreate
(
&
worker
->
thread
,
&
thAttr
,
t
hreadFp
,
worker
)
!=
0
)
{
if
(
taosThreadCreate
(
&
worker
->
thread
,
&
thAttr
,
(
ThreadFp
)
tQWorkerT
hreadFp
,
worker
)
!=
0
)
{
uError
(
"worker:%s:%d failed to create thread to process since %s"
,
pool
->
name
,
worker
->
id
,
strerror
(
errno
));
taosCloseQueue
(
queue
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -134,58 +134,11 @@ STaosQueue *tWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp, Threa
return
queue
;
}
STaosQueue
*
tQWorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
)
{
return
tWorkerAllocQueue
(
pool
,
ahandle
,
fp
,
(
ThreadFp
)
tQWorkerThreadFp
);
}
void
tQWorkerFreeQueue
(
SQWorkerPool
*
pool
,
STaosQueue
*
queue
)
{
taosCloseQueue
(
queue
);
uDebug
(
"worker:%s, queue:%p is freed"
,
pool
->
name
,
queue
);
}
int32_t
tFWorkerInit
(
SFWorkerPool
*
pool
)
{
return
tQWorkerInit
((
SQWorkerPool
*
)
pool
);
}
void
tFWorkerCleanup
(
SFWorkerPool
*
pool
)
{
tQWorkerCleanup
(
pool
);
}
static
void
*
tFWorkerThreadFp
(
SQWorker
*
worker
)
{
SQWorkerPool
*
pool
=
worker
->
pool
;
FItem
fp
=
NULL
;
void
*
msg
=
NULL
;
void
*
ahandle
=
NULL
;
int32_t
code
=
0
;
taosBlockSIGPIPE
();
setThreadName
(
pool
->
name
);
uDebug
(
"worker:%s:%d is running"
,
pool
->
name
,
worker
->
id
);
while
(
1
)
{
code
=
taosReadQitemFromQsetByThread
(
pool
->
qset
,
(
void
**
)
&
msg
,
&
ahandle
,
&
fp
,
worker
->
id
);
if
(
code
<
0
)
{
uDebug
(
"worker:%s:%d qset:%p, got no message and exiting"
,
pool
->
name
,
worker
->
id
,
pool
->
qset
);
break
;
}
else
if
(
code
==
0
)
{
// uTrace("worker:%s:%d qset:%p, got no message and continue", pool->name, worker->id, pool->qset);
continue
;
}
if
(
fp
!=
NULL
)
{
(
*
fp
)(
ahandle
,
msg
);
}
taosResetQsetThread
(
pool
->
qset
,
msg
);
}
return
NULL
;
}
STaosQueue
*
tFWorkerAllocQueue
(
SQWorkerPool
*
pool
,
void
*
ahandle
,
FItem
fp
)
{
return
tWorkerAllocQueue
(
pool
,
ahandle
,
fp
,
(
ThreadFp
)
tQWorkerThreadFp
);
}
void
tFWorkerFreeQueue
(
SFWorkerPool
*
pool
,
STaosQueue
*
queue
)
{
tQWorkerFreeQueue
(
pool
,
queue
);
}
int32_t
tWWorkerInit
(
SWWorkerPool
*
pool
)
{
pool
->
nextId
=
0
;
pool
->
workers
=
calloc
(
pool
->
max
,
sizeof
(
SWWorker
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录