Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6a85467d
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6a85467d
编写于
8月 12, 2022
作者:
D
dapan1121
提交者:
GitHub
8月 12, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16031 from taosdata/fix/TD-18351
fix: fix task sched crash issue
上级
f0a60614
d5072a8f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
49 addition
and
34 deletion
+49
-34
include/util/tsched.h
include/util/tsched.h
+20
-1
source/libs/index/src/index.c
source/libs/index/src/index.c
+2
-1
source/libs/qcom/src/queryUtil.c
source/libs/qcom/src/queryUtil.c
+5
-5
source/util/src/tsched.c
source/util/src/tsched.c
+20
-26
source/util/src/ttimer.c
source/util/src/ttimer.c
+2
-1
未找到文件。
include/util/tsched.h
浏览文件 @
6a85467d
...
...
@@ -17,6 +17,7 @@
#define _TD_UTIL_SCHED_H_
#include "os.h"
#include "tdef.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -30,6 +31,24 @@ typedef struct SSchedMsg {
void
*
thandle
;
}
SSchedMsg
;
typedef
struct
{
char
label
[
TSDB_LABEL_LEN
];
tsem_t
emptySem
;
tsem_t
fullSem
;
TdThreadMutex
queueMutex
;
int32_t
fullSlot
;
int32_t
emptySlot
;
int32_t
queueSize
;
int32_t
numOfThreads
;
TdThread
*
qthread
;
SSchedMsg
*
queue
;
int8_t
stop
;
void
*
pTmrCtrl
;
void
*
pTimer
;
}
SSchedQueue
;
/**
* Create a thread-safe ring-buffer based task queue and return the instance. A thread
* pool will be created to consume the messages in the queue.
...
...
@@ -38,7 +57,7 @@ typedef struct SSchedMsg {
* @param label the label of the queue
* @return the created queue scheduler
*/
void
*
taosInitScheduler
(
int32_t
capacity
,
int32_t
numOfThreads
,
const
char
*
label
);
void
*
taosInitScheduler
(
int32_t
capacity
,
int32_t
numOfThreads
,
const
char
*
label
,
SSchedQueue
*
pSched
);
/**
* Create a thread-safe ring-buffer based task queue and return the instance.
...
...
source/libs/index/src/index.c
浏览文件 @
6a85467d
...
...
@@ -62,12 +62,13 @@ static void indexDestroy(void* sIdx);
void
indexInit
()
{
// refactor later
indexQhandle
=
taosInitScheduler
(
INDEX_QUEUE_SIZE
,
INDEX_NUM_OF_THREADS
,
"index"
);
indexQhandle
=
taosInitScheduler
(
INDEX_QUEUE_SIZE
,
INDEX_NUM_OF_THREADS
,
"index"
,
NULL
);
indexRefMgt
=
taosOpenRef
(
1000
,
indexDestroy
);
}
void
indexCleanup
()
{
// refacto later
taosCleanUpScheduler
(
indexQhandle
);
taosMemoryFreeClear
(
indexQhandle
);
taosCloseRef
(
indexRefMgt
);
}
...
...
source/libs/qcom/src/queryUtil.c
浏览文件 @
6a85467d
...
...
@@ -96,12 +96,12 @@ bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTag
return
true
;
}
static
void
*
pTaskQueue
=
NULL
;
static
SSchedQueue
pTaskQueue
=
{
0
}
;
int32_t
initTaskQueue
()
{
int32_t
queueSize
=
tsMaxShellConns
*
2
;
pTaskQueue
=
taosInitScheduler
(
queueSize
,
tsNumOfTaskQueueThreads
,
"tsc"
);
if
(
NULL
==
p
TaskQueue
)
{
void
*
p
=
taosInitScheduler
(
queueSize
,
tsNumOfTaskQueueThreads
,
"tsc"
,
&
pTaskQueue
);
if
(
NULL
==
p
)
{
qError
(
"failed to init task queue"
);
return
-
1
;
}
...
...
@@ -111,7 +111,7 @@ int32_t initTaskQueue() {
}
int32_t
cleanupTaskQueue
()
{
taosCleanUpScheduler
(
pTaskQueue
);
taosCleanUpScheduler
(
&
pTaskQueue
);
return
0
;
}
...
...
@@ -134,7 +134,7 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code)
schedMsg
.
thandle
=
execParam
;
schedMsg
.
msg
=
code
;
taosScheduleTask
(
pTaskQueue
,
&
schedMsg
);
taosScheduleTask
(
&
pTaskQueue
,
&
schedMsg
);
return
0
;
}
...
...
source/util/src/tsched.c
浏览文件 @
6a85467d
...
...
@@ -22,30 +22,16 @@
#define DUMP_SCHEDULER_TIME_WINDOW 30000 // every 30sec, take a snap shot of task queue.
typedef
struct
{
char
label
[
TSDB_LABEL_LEN
];
tsem_t
emptySem
;
tsem_t
fullSem
;
TdThreadMutex
queueMutex
;
int32_t
fullSlot
;
int32_t
emptySlot
;
int32_t
queueSize
;
int32_t
numOfThreads
;
TdThread
*
qthread
;
SSchedMsg
*
queue
;
bool
stop
;
void
*
pTmrCtrl
;
void
*
pTimer
;
}
SSchedQueue
;
static
void
*
taosProcessSchedQueue
(
void
*
param
);
static
void
taosDumpSchedulerStatus
(
void
*
qhandle
,
void
*
tmrId
);
void
*
taosInitScheduler
(
int32_t
queueSize
,
int32_t
numOfThreads
,
const
char
*
label
)
{
SSchedQueue
*
pSched
=
(
SSchedQueue
*
)
taosMemoryCalloc
(
sizeof
(
SSchedQueue
),
1
);
if
(
pSched
==
NULL
)
{
uError
(
"%s: no enough memory for pSched"
,
label
);
return
NULL
;
void
*
taosInitScheduler
(
int32_t
queueSize
,
int32_t
numOfThreads
,
const
char
*
label
,
SSchedQueue
*
pSched
)
{
if
(
NULL
==
pSched
)
{
pSched
=
(
SSchedQueue
*
)
taosMemoryCalloc
(
sizeof
(
SSchedQueue
),
1
);
if
(
pSched
==
NULL
)
{
uError
(
"%s: no enough memory for pSched"
,
label
);
return
NULL
;
}
}
pSched
->
queue
=
(
SSchedMsg
*
)
taosMemoryCalloc
(
sizeof
(
SSchedMsg
),
queueSize
);
...
...
@@ -86,7 +72,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
return
NULL
;
}
pSched
->
stop
=
false
;
atomic_store_8
(
&
pSched
->
stop
,
0
)
;
for
(
int32_t
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
TdThreadAttr
attr
;
taosThreadAttrInit
(
&
attr
);
...
...
@@ -107,7 +93,7 @@ void *taosInitScheduler(int32_t queueSize, int32_t numOfThreads, const char *lab
}
void
*
taosInitSchedulerWithInfo
(
int32_t
queueSize
,
int32_t
numOfThreads
,
const
char
*
label
,
void
*
tmrCtrl
)
{
SSchedQueue
*
pSched
=
taosInitScheduler
(
queueSize
,
numOfThreads
,
label
);
SSchedQueue
*
pSched
=
taosInitScheduler
(
queueSize
,
numOfThreads
,
label
,
NULL
);
if
(
tmrCtrl
!=
NULL
&&
pSched
!=
NULL
)
{
pSched
->
pTmrCtrl
=
tmrCtrl
;
...
...
@@ -131,7 +117,7 @@ void *taosProcessSchedQueue(void *scheduler) {
uFatal
(
"wait %s fullSem failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
ASSERT
(
0
);
}
if
(
pSched
->
stop
)
{
if
(
atomic_load_8
(
&
pSched
->
stop
)
)
{
break
;
}
...
...
@@ -172,6 +158,11 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
return
;
}
if
(
atomic_load_8
(
&
pSched
->
stop
))
{
uError
(
"sched is already stopped, msg:%p is dropped"
,
pMsg
);
return
;
}
if
((
ret
=
tsem_wait
(
&
pSched
->
emptySem
))
!=
0
)
{
uFatal
(
"wait %s emptySem failed(%s)"
,
pSched
->
label
,
strerror
(
errno
));
ASSERT
(
0
);
...
...
@@ -202,7 +193,10 @@ void taosCleanUpScheduler(void *param) {
uDebug
(
"start to cleanup %s schedQsueue"
,
pSched
->
label
);
pSched
->
stop
=
true
;
atomic_store_8
(
&
pSched
->
stop
,
1
);
taosMsleep
(
200
);
for
(
int32_t
i
=
0
;
i
<
pSched
->
numOfThreads
;
++
i
)
{
if
(
taosCheckPthreadValid
(
pSched
->
qthread
[
i
]))
{
tsem_post
(
&
pSched
->
fullSem
);
...
...
@@ -226,7 +220,7 @@ void taosCleanUpScheduler(void *param) {
if
(
pSched
->
queue
)
taosMemoryFree
(
pSched
->
queue
);
if
(
pSched
->
qthread
)
taosMemoryFree
(
pSched
->
qthread
);
taosMemoryFree
(
pSched
);
// fix memory leak
//taosMemoryFree(pSched);
}
// for debug purpose, dump the scheduler status every 1min.
...
...
source/util/src/ttimer.c
浏览文件 @
6a85467d
...
...
@@ -555,7 +555,7 @@ static void taosTmrModuleInit(void) {
return
;
}
tmrQhandle
=
taosInitScheduler
(
10000
,
taosTmrThreads
,
"tmr"
);
tmrQhandle
=
taosInitScheduler
(
10000
,
taosTmrThreads
,
"tmr"
,
NULL
);
taosInitTimer
(
taosTimerLoopFunc
,
MSECONDS_PER_TICK
);
tmrDebug
(
"timer module is initialized, number of threads: %d"
,
taosTmrThreads
);
...
...
@@ -606,6 +606,7 @@ void taosTmrCleanUp(void* handle) {
taosUninitTimer
();
taosCleanUpScheduler
(
tmrQhandle
);
taosMemoryFreeClear
(
tmrQhandle
);
for
(
int32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
time_wheel_t
*
wheel
=
wheels
+
i
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录