Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
15995e76
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看板
提交
15995e76
编写于
1月 09, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
37554543
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
131 addition
and
47 deletion
+131
-47
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+6
-4
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-0
source/dnode/vnode/src/vnd/vnodeBufPool.c
source/dnode/vnode/src/vnd/vnodeBufPool.c
+56
-38
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+68
-5
未找到文件。
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
15995e76
...
...
@@ -61,12 +61,14 @@ struct SVBufPoolNode {
};
struct
SVBufPool
{
SVBufPool
*
freeNext
;
SVBufPool
*
recycleNext
;
SVBufPool
*
recyclePrev
;
SVBufPool
*
freeNext
;
SVBufPool
*
recycleNext
;
SVBufPool
*
recyclePrev
;
SVnode
*
pVnode
;
TdThreadSpinlock
*
lock
;
int32_t
id
;
volatile
int32_t
nRef
;
TdThreadSpinlock
*
lock
;
int64_t
size
;
uint8_t
*
ptr
;
SVBufPoolNode
*
pTail
;
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
15995e76
...
...
@@ -344,6 +344,7 @@ struct SVnode {
SVBufPool
*
onCommit
;
SVBufPool
*
recycleHead
;
SVBufPool
*
recycleTail
;
SVBufPool
*
onRecycle
;
SMeta
*
pMeta
;
SSma
*
pSma
;
...
...
source/dnode/vnode/src/vnd/vnodeBufPool.c
浏览文件 @
15995e76
...
...
@@ -16,7 +16,7 @@
#include "vnd.h"
/* ------------------------ STRUCTURES ------------------------ */
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int64_t
size
,
SVBufPool
**
ppPool
)
{
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int
32_t
id
,
int
64_t
size
,
SVBufPool
**
ppPool
)
{
SVBufPool
*
pPool
;
pPool
=
taosMemoryMalloc
(
sizeof
(
SVBufPool
)
+
size
);
...
...
@@ -24,6 +24,14 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memset
(
pPool
,
0
,
sizeof
(
SVBufPool
));
pPool
->
pVnode
=
pVnode
;
pPool
->
id
=
id
;
pPool
->
ptr
=
pPool
->
node
.
data
;
pPool
->
pTail
=
&
pPool
->
node
;
pPool
->
node
.
prev
=
NULL
;
pPool
->
node
.
pnext
=
&
pPool
->
pTail
;
pPool
->
node
.
size
=
size
;
if
(
VND_IS_RSMA
(
pVnode
))
{
pPool
->
lock
=
taosMemoryMalloc
(
sizeof
(
TdThreadSpinlock
));
...
...
@@ -42,16 +50,6 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
pPool
->
lock
=
NULL
;
}
pPool
->
freeNext
=
NULL
;
pPool
->
pVnode
=
pVnode
;
pPool
->
nRef
=
0
;
pPool
->
size
=
0
;
pPool
->
ptr
=
pPool
->
node
.
data
;
pPool
->
pTail
=
&
pPool
->
node
;
pPool
->
node
.
prev
=
NULL
;
pPool
->
node
.
pnext
=
&
pPool
->
pTail
;
pPool
->
node
.
size
=
size
;
*
ppPool
=
pPool
;
return
0
;
}
...
...
@@ -71,7 +69,7 @@ int vnodeOpenBufPool(SVnode *pVnode) {
for
(
int
i
=
0
;
i
<
VNODE_BUFPOOL_SEGMENTS
;
i
++
)
{
// create pool
if
(
vnodeBufPoolCreate
(
pVnode
,
size
,
&
pVnode
->
aBufPool
[
i
]))
{
if
(
vnodeBufPoolCreate
(
pVnode
,
i
,
size
,
&
pVnode
->
aBufPool
[
i
]))
{
vError
(
"vgId:%d, failed to open vnode buffer pool since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
vnodeCloseBufPool
(
pVnode
);
return
-
1
;
...
...
@@ -206,34 +204,54 @@ void vnodeBufPoolRef(SVBufPool *pPool) {
}
void
vnodeBufPoolUnRef
(
SVBufPool
*
pPool
)
{
if
(
pPool
==
NULL
)
{
return
;
}
int32_t
nRef
=
atomic_sub_fetch_32
(
&
pPool
->
nRef
,
1
);
if
(
nRef
==
0
)
{
SVnode
*
pVnode
=
pPool
->
pVnode
;
vnodeBufPoolReset
(
pPool
);
taosThreadMutexLock
(
&
pVnode
->
mutex
);
int64_t
size
=
pVnode
->
config
.
szBuf
/
VNODE_BUFPOOL_SEGMENTS
;
if
(
pPool
->
node
.
size
!=
size
)
{
SVBufPool
*
pPoolT
=
NULL
;
if
(
vnodeBufPoolCreate
(
pVnode
,
size
,
&
pPoolT
)
<
0
)
{
vWarn
(
"vgId:%d, try to change buf pools size from %"
PRId64
" to %"
PRId64
" since %s"
,
TD_VID
(
pVnode
),
pPool
->
node
.
size
,
size
,
tstrerror
(
errno
));
}
else
{
vnodeBufPoolDestroy
(
pPool
);
pPool
=
pPoolT
;
vDebug
(
"vgId:%d, change buf pools size from %"
PRId64
" to %"
PRId64
,
TD_VID
(
pVnode
),
pPool
->
node
.
size
,
size
);
}
if
(
pPool
==
NULL
)
return
;
if
(
atomic_sub_fetch_32
(
&
pPool
->
nRef
,
1
)
>
0
)
return
;
SVnode
*
pVnode
=
pPool
->
pVnode
;
taosThreadMutexLock
(
&
pVnode
->
mutex
);
// remove from recycle list or on-recycle position
if
(
pVnode
->
onRecycle
==
pPool
)
{
pVnode
->
onRecycle
=
NULL
;
}
else
{
if
(
pPool
->
recyclePrev
)
{
pPool
->
recyclePrev
->
recycleNext
=
pPool
->
recycleNext
;
}
else
{
pVnode
->
recycleHead
=
pPool
->
recycleNext
;
}
pPool
->
freeNext
=
pVnode
->
freeList
;
pVnode
->
freeList
=
pPool
;
taosThreadCondSignal
(
&
pVnode
->
poolNotEmpty
);
if
(
pPool
->
recycleNext
)
{
pPool
->
recycleNext
->
recyclePrev
=
pPool
->
recyclePrev
;
}
else
{
pVnode
->
recycleTail
=
pPool
->
recyclePrev
;
}
pPool
->
recyclePrev
=
pPool
->
recycleNext
=
NULL
;
}
taosThreadMutexUnlock
(
&
pVnode
->
mutex
);
// change the pool size if need
int64_t
size
=
pVnode
->
config
.
szBuf
/
VNODE_BUFPOOL_SEGMENTS
;
if
(
pPool
->
node
.
size
!=
size
)
{
SVBufPool
*
pNewPool
=
NULL
;
if
(
vnodeBufPoolCreate
(
pVnode
,
pPool
->
id
,
size
,
&
pNewPool
)
<
0
)
{
vWarn
(
"vgId:%d failed to change buffer pool of id %d size from %"
PRId64
" to %"
PRId64
" since %s"
,
TD_VID
(
pVnode
),
pPool
->
id
,
pPool
->
node
.
size
,
size
,
tstrerror
(
errno
));
}
else
{
vInfo
(
"vgId:%d buffer pool of id %d size changed from %"
PRId64
" to %"
PRId64
,
TD_VID
(
pVnode
),
pPool
->
id
,
pPool
->
node
.
size
,
size
);
vnodeBufPoolDestroy
(
pPool
);
pPool
=
pNewPool
;
pVnode
->
aBufPool
[
pPool
->
id
]
=
pPool
;
}
}
// add to free list
vnodeBufPoolReset
(
pPool
);
pPool
->
freeNext
=
pVnode
->
freeList
;
pVnode
->
freeList
=
pPool
;
taosThreadCondSignal
(
&
pVnode
->
poolNotEmpty
);
taosThreadMutexUnlock
(
&
pVnode
->
mutex
);
}
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
15995e76
...
...
@@ -25,7 +25,34 @@ static int vnodeCommitImpl(SCommitInfo *pInfo);
static
int32_t
vnodeTryRecycleBufPool
(
SVnode
*
pVnode
)
{
int32_t
code
=
0
;
ASSERT
(
0
);
// TODO
if
(
pVnode
->
onRecycle
)
{
vDebug
(
"vgId:%d buffer pool %p of id %d is on recycling"
,
TD_VID
(
pVnode
),
pVnode
->
onRecycle
,
pVnode
->
onRecycle
->
id
);
goto
_exit
;
}
if
(
pVnode
->
recycleHead
)
{
vDebug
(
"vgId:%d buffer pool %p of id %d on recycle list, try to recycle"
,
TD_VID
(
pVnode
),
pVnode
->
recycleHead
,
pVnode
->
recycleHead
->
id
);
// pop the header buffer pool for recycling
pVnode
->
onRecycle
=
pVnode
->
recycleHead
;
if
(
pVnode
->
recycleHead
==
pVnode
->
recycleTail
)
{
pVnode
->
recycleHead
=
pVnode
->
recycleTail
=
NULL
;
}
else
{
pVnode
->
recycleHead
=
pVnode
->
recycleHead
->
recycleNext
;
pVnode
->
recycleHead
->
recyclePrev
=
NULL
;
}
pVnode
->
onRecycle
->
recycleNext
=
pVnode
->
onRecycle
->
recyclePrev
=
NULL
;
{
// TODO: do recycle the buffer pool
ASSERT
(
0
);
}
}
else
{
vDebug
(
"vgId:%d no recyclable buffer pool"
,
TD_VID
(
pVnode
));
}
_exit:
return
code
;
}
...
...
@@ -36,7 +63,8 @@ int vnodeBegin(SVnode *pVnode) {
int32_t
nTry
=
0
;
while
(
++
nTry
)
{
if
(
pVnode
->
freeList
)
{
vDebug
(
"vgId:%d allocate free buffer pool on %d try, pPool:%p"
,
TD_VID
(
pVnode
),
nTry
,
pVnode
->
freeList
);
vDebug
(
"vgId:%d allocate free buffer pool on %d try, pPool:%p id:%d"
,
TD_VID
(
pVnode
),
nTry
,
pVnode
->
freeList
,
pVnode
->
freeList
->
id
);
pVnode
->
inUse
=
pVnode
->
freeList
;
pVnode
->
inUse
->
nRef
=
1
;
...
...
@@ -259,8 +287,11 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
code
=
smaPrepareAsyncCommit
(
pVnode
->
pSma
);
if
(
code
)
goto
_exit
;
vnodeBufPoolUnRef
(
pVnode
->
inUse
);
taosThreadMutexLock
(
&
pVnode
->
mutex
);
ASSERT
(
pVnode
->
onCommit
==
NULL
);
pVnode
->
onCommit
=
pVnode
->
inUse
;
pVnode
->
inUse
=
NULL
;
taosThreadMutexUnlock
(
&
pVnode
->
mutex
);
_exit:
if
(
code
)
{
...
...
@@ -272,19 +303,51 @@ _exit:
return
code
;
}
static
int32_t
vnodeCommitTask
(
void
*
arg
)
{
int32_t
code
=
0
;
SCommitInfo
*
pInfo
=
(
SCommitInfo
*
)
arg
;
SVnode
*
pVnode
=
pInfo
->
pVnode
;
// commit
code
=
vnodeCommitImpl
(
pInfo
);
if
(
code
)
goto
_exit
;
// recycle buffer pool
SVBufPool
*
pPool
=
pVnode
->
onCommit
;
taosThreadMutexLock
(
&
pVnode
->
mutex
);
pVnode
->
onCommit
=
NULL
;
int32_t
nRef
=
atomic_sub_fetch_32
(
&
pPool
->
nRef
,
1
);
if
(
nRef
==
0
)
{
// add to free list
vDebug
(
"vgId:%d buffer pool %p of id %d is added to free list"
,
TD_VID
(
pVnode
),
pPool
,
pPool
->
id
);
vnodeBufPoolReset
(
pPool
);
pPool
->
freeNext
=
pVnode
->
freeList
;
pVnode
->
freeList
=
pPool
;
taosThreadCondSignal
(
&
pVnode
->
poolNotEmpty
);
}
else
{
// add to recycle list
vDebug
(
"vgId:%d buffer pool %p of id %d is added to recycle list"
,
TD_VID
(
pVnode
),
pPool
,
pPool
->
id
);
if
(
pVnode
->
recycleTail
==
NULL
)
{
pPool
->
recyclePrev
=
pPool
->
recycleNext
=
NULL
;
pVnode
->
recycleHead
=
pVnode
->
recycleTail
=
pPool
;
}
else
{
pPool
->
recyclePrev
=
pVnode
->
recycleTail
;
pPool
->
recycleNext
=
NULL
;
pVnode
->
recycleTail
->
recycleNext
=
pPool
;
pVnode
->
recycleTail
=
pPool
;
}
}
taosThreadMutexUnlock
(
&
pVnode
->
mutex
);
_exit:
// end commit
tsem_post
(
&
p
Info
->
p
Vnode
->
canCommit
);
tsem_post
(
&
pVnode
->
canCommit
);
taosMemoryFree
(
pInfo
);
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录