Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e01d598d
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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,发现更多精彩内容 >>
提交
e01d598d
编写于
6月 13, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
42a09cc9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
54 deletion
+61
-54
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+2
-1
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
+2
-1
source/dnode/vnode/src/vnd/vnodeModule.c
source/dnode/vnode/src/vnd/vnodeModule.c
+57
-52
未找到文件。
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
e01d598d
...
...
@@ -49,7 +49,8 @@ int32_t vnodeEncodeConfig(const void* pObj, SJson* pJson);
int32_t
vnodeDecodeConfig
(
const
SJson
*
pJson
,
void
*
pObj
);
// vnodeModule.c
int32_t
vnodeScheduleTask
(
int32_t
(
*
execute
)(
void
*
),
void
*
arg
);
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
);
int
vnodeScheduleTaskEx
(
int
tpid
,
int
(
*
execute
)(
void
*
),
void
*
arg
);
// vnodeBufPool.c
typedef
struct
SVBufPoolNode
SVBufPoolNode
;
...
...
source/dnode/vnode/src/tsdb/dev/tsdbFS.c
浏览文件 @
e01d598d
...
...
@@ -16,6 +16,7 @@
#include "inc/tsdbFS.h"
extern
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
);
extern
int
vnodeScheduleTaskEx
(
int
tpid
,
int
(
*
execute
)(
void
*
),
void
*
arg
);
#define TSDB_FS_EDIT_MIN TSDB_FEDIT_COMMIT
#define TSDB_FS_EDIT_MAX (TSDB_FEDIT_MERGE + 1)
...
...
@@ -612,7 +613,7 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) {
if
(
fobj
->
f
->
stt
->
nseg
<
fs
->
tsdb
->
pVnode
->
config
.
sttTrigger
)
continue
;
code
=
vnodeScheduleTask
(
tsdbMerge
,
fs
->
tsdb
);
code
=
vnodeScheduleTask
Ex
(
1
,
tsdbMerge
,
fs
->
tsdb
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
fs
->
mergeTaskOn
=
true
;
...
...
source/dnode/vnode/src/vnd/vnodeModule.c
浏览文件 @
e01d598d
...
...
@@ -23,26 +23,24 @@ struct SVnodeTask {
void
*
arg
;
};
struct
SVnodeGlobal
{
int8_t
init
;
int8_t
stop
;
typedef
struct
{
int
nthreads
;
TdThread
*
threads
;
TdThreadMutex
mutex
;
TdThreadCond
hasTask
;
SVnodeTask
queue
;
}
SVnodeThreadPool
;
struct
SVnodeGlobal
{
int8_t
init
;
int8_t
stop
;
SVnodeThreadPool
tp
[
2
];
};
struct
SVnodeGlobal
vnodeGlobal
;
static
void
*
loop
(
void
*
arg
);
static
tsem_t
canCommit
=
{
0
};
static
void
vnodeInitCommit
()
{
tsem_init
(
&
canCommit
,
0
,
4
);
};
void
vnode_wait_commit
()
{
tsem_wait
(
&
canCommit
);
}
void
vnode_done_commit
()
{
tsem_wait
(
&
canCommit
);
}
int
vnodeInit
(
int
nthreads
)
{
int8_t
init
;
int
ret
;
...
...
@@ -51,28 +49,30 @@ int vnodeInit(int nthreads) {
if
(
init
)
{
return
0
;
}
vnodeGlobal
.
stop
=
0
;
taosThreadMutexInit
(
&
vnodeGlobal
.
mutex
,
NULL
);
taosThreadCondInit
(
&
vnodeGlobal
.
hasTask
,
NULL
);
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
vnodeGlobal
.
tp
);
i
++
)
{
taosThreadMutexInit
(
&
vnodeGlobal
.
tp
[
i
].
mutex
,
NULL
);
taosThreadCondInit
(
&
vnodeGlobal
.
tp
[
i
].
hasTask
,
NULL
);
taosThreadMutexLock
(
&
vnodeGlobal
.
mutex
);
taosThreadMutexLock
(
&
vnodeGlobal
.
tp
[
i
]
.
mutex
);
vnodeGlobal
.
stop
=
0
;
vnodeGlobal
.
queue
.
next
=
&
vnodeGlobal
.
queue
;
vnodeGlobal
.
queue
.
prev
=
&
vnodeGlobal
.
queue
;
vnodeGlobal
.
tp
[
i
].
queue
.
next
=
&
vnodeGlobal
.
tp
[
i
].
queue
;
vnodeGlobal
.
tp
[
i
].
queue
.
prev
=
&
vnodeGlobal
.
tp
[
i
].
queue
;
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
mutex
));
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
tp
[
i
]
.
mutex
));
vnodeGlobal
.
nthreads
=
nthreads
;
vnodeGlobal
.
threads
=
taosMemoryCalloc
(
nthreads
,
sizeof
(
TdThread
));
if
(
vnodeGlobal
.
threads
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
vError
(
"failed to init vnode module since:%s"
,
tstrerror
(
terrno
));
return
-
1
;
}
vnodeGlobal
.
tp
[
i
]
.
nthreads
=
nthreads
;
vnodeGlobal
.
tp
[
i
]
.
threads
=
taosMemoryCalloc
(
nthreads
,
sizeof
(
TdThread
));
if
(
vnodeGlobal
.
tp
[
i
]
.
threads
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
vError
(
"failed to init vnode module since:%s"
,
tstrerror
(
terrno
));
return
-
1
;
}
for
(
int
i
=
0
;
i
<
nthreads
;
i
++
)
{
taosThreadCreate
(
&
(
vnodeGlobal
.
threads
[
i
]),
NULL
,
loop
,
NULL
);
for
(
int
j
=
0
;
j
<
nthreads
;
j
++
)
{
taosThreadCreate
(
&
(
vnodeGlobal
.
tp
[
i
].
threads
[
j
]),
NULL
,
loop
,
&
vnodeGlobal
.
tp
[
i
]);
}
}
if
(
walInit
()
<
0
)
{
...
...
@@ -92,27 +92,29 @@ void vnodeCleanup() {
if
(
init
==
0
)
return
;
// set stop
taosThreadMutexLock
(
&
(
vnodeGlobal
.
mutex
));
vnodeGlobal
.
stop
=
1
;
taosThreadCondBroadcast
(
&
(
vnodeGlobal
.
hasTask
));
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
mutex
));
for
(
int32_t
i
=
0
;
i
<
ARRAY_SIZE
(
vnodeGlobal
.
tp
);
i
++
)
{
taosThreadMutexLock
(
&
(
vnodeGlobal
.
tp
[
i
].
mutex
));
taosThreadCondBroadcast
(
&
(
vnodeGlobal
.
tp
[
i
].
hasTask
));
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
tp
[
i
].
mutex
));
// wait for threads
for
(
int
j
=
0
;
j
<
vnodeGlobal
.
tp
[
i
].
nthreads
;
j
++
)
{
taosThreadJoin
(
vnodeGlobal
.
tp
[
i
].
threads
[
j
],
NULL
);
}
// wait for threads
for
(
int
i
=
0
;
i
<
vnodeGlobal
.
nthreads
;
i
++
)
{
taosThreadJoin
(
vnodeGlobal
.
threads
[
i
],
NULL
);
// clear source
taosMemoryFreeClear
(
vnodeGlobal
.
tp
[
i
].
threads
);
taosThreadCondDestroy
(
&
(
vnodeGlobal
.
tp
[
i
].
hasTask
));
taosThreadMutexDestroy
(
&
(
vnodeGlobal
.
tp
[
i
].
mutex
));
}
// clear source
taosMemoryFreeClear
(
vnodeGlobal
.
threads
);
taosThreadCondDestroy
(
&
(
vnodeGlobal
.
hasTask
));
taosThreadMutexDestroy
(
&
(
vnodeGlobal
.
mutex
));
walCleanUp
();
tqCleanUp
();
smaCleanUp
();
}
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
)
{
int
vnodeScheduleTask
Ex
(
int
tpid
,
int
(
*
execute
)(
void
*
),
void
*
arg
)
{
SVnodeTask
*
pTask
;
ASSERT
(
!
vnodeGlobal
.
stop
);
...
...
@@ -126,35 +128,38 @@ int vnodeScheduleTask(int (*execute)(void*), void* arg) {
pTask
->
execute
=
execute
;
pTask
->
arg
=
arg
;
taosThreadMutexLock
(
&
(
vnodeGlobal
.
mutex
));
pTask
->
next
=
&
vnodeGlobal
.
queue
;
pTask
->
prev
=
vnodeGlobal
.
queue
.
prev
;
vnodeGlobal
.
queue
.
prev
->
next
=
pTask
;
vnodeGlobal
.
queue
.
prev
=
pTask
;
taosThreadCondSignal
(
&
(
vnodeGlobal
.
hasTask
));
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
mutex
));
taosThreadMutexLock
(
&
(
vnodeGlobal
.
tp
[
tpid
].
mutex
));
pTask
->
next
=
&
vnodeGlobal
.
tp
[
tpid
].
queue
;
pTask
->
prev
=
vnodeGlobal
.
tp
[
tpid
].
queue
.
prev
;
vnodeGlobal
.
tp
[
tpid
].
queue
.
prev
->
next
=
pTask
;
vnodeGlobal
.
tp
[
tpid
].
queue
.
prev
=
pTask
;
taosThreadCondSignal
(
&
(
vnodeGlobal
.
tp
[
tpid
].
hasTask
));
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
tp
[
tpid
].
mutex
));
return
0
;
}
int
vnodeScheduleTask
(
int
(
*
execute
)(
void
*
),
void
*
arg
)
{
return
vnodeScheduleTaskEx
(
0
,
execute
,
arg
);
}
/* ------------------------ STATIC METHODS ------------------------ */
static
void
*
loop
(
void
*
arg
)
{
SVnodeTask
*
pTask
;
int
ret
;
SVnodeThreadPool
*
tp
=
(
SVnodeThreadPool
*
)
arg
;
SVnodeTask
*
pTask
;
int
ret
;
setThreadName
(
"vnode-commit"
);
for
(;;)
{
taosThreadMutexLock
(
&
(
vnodeGlobal
.
mutex
));
taosThreadMutexLock
(
&
(
tp
->
mutex
));
for
(;;)
{
pTask
=
vnodeGlobal
.
queue
.
next
;
if
(
pTask
==
&
vnodeGlobal
.
queue
)
{
pTask
=
tp
->
queue
.
next
;
if
(
pTask
==
&
tp
->
queue
)
{
// no task
if
(
vnodeGlobal
.
stop
)
{
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
mutex
));
taosThreadMutexUnlock
(
&
(
tp
->
mutex
));
return
NULL
;
}
else
{
taosThreadCondWait
(
&
(
vnodeGlobal
.
hasTask
),
&
(
vnodeGlobal
.
mutex
));
taosThreadCondWait
(
&
(
tp
->
hasTask
),
&
(
tp
->
mutex
));
}
}
else
{
// has task
...
...
@@ -164,7 +169,7 @@ static void* loop(void* arg) {
}
}
taosThreadMutexUnlock
(
&
(
vnodeGlobal
.
mutex
));
taosThreadMutexUnlock
(
&
(
tp
->
mutex
));
pTask
->
execute
(
pTask
->
arg
);
taosMemoryFree
(
pTask
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录