Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
706b081f
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看板
提交
706b081f
编写于
7月 19, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: r/w concurrency
上级
f3204ed9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
68 addition
and
40 deletion
+68
-40
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+8
-7
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+22
-20
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+2
-0
source/dnode/vnode/src/vnd/vnodeBufPool.c
source/dnode/vnode/src/vnd/vnodeBufPool.c
+26
-3
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+6
-10
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+4
-0
未找到文件。
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
706b081f
...
...
@@ -62,12 +62,13 @@ struct SVBufPoolNode {
};
struct
SVBufPool
{
SVBufPool
*
next
;
int64_t
nRef
;
int64_t
size
;
uint8_t
*
ptr
;
SVBufPoolNode
*
pTail
;
SVBufPoolNode
node
;
SVBufPool
*
next
;
SVnode
*
pVnode
;
volatile
int32_t
nRef
;
int64_t
size
;
uint8_t
*
ptr
;
SVBufPoolNode
*
pTail
;
SVBufPoolNode
node
;
};
int32_t
vnodeOpenBufPool
(
SVnode
*
pVnode
,
int64_t
size
);
...
...
@@ -78,7 +79,7 @@ void vnodeBufPoolReset(SVBufPool* pPool);
int32_t
vnodeQueryOpen
(
SVnode
*
pVnode
);
void
vnodeQueryClose
(
SVnode
*
pVnode
);
int32_t
vnodeGetTableMeta
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int
vnodeGetTableCfg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int
vnodeGetTableCfg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
// vnodeCommit.c
int32_t
vnodeBegin
(
SVnode
*
pVnode
);
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
706b081f
...
...
@@ -77,6 +77,8 @@ typedef struct SSnapDataHdr SSnapDataHdr;
// vnd.h
void
*
vnodeBufPoolMalloc
(
SVBufPool
*
pPool
,
int
size
);
void
vnodeBufPoolFree
(
SVBufPool
*
pPool
,
void
*
p
);
void
vnodeBufPoolRef
(
SVBufPool
*
pPool
);
void
vnodeBufPoolUnRef
(
SVBufPool
*
pPool
);
// meta
typedef
struct
SMCtbCursor
SMCtbCursor
;
...
...
@@ -247,26 +249,26 @@ struct STsdbKeepCfg {
};
struct
SVnode
{
char
*
path
;
SVnodeCfg
config
;
SVState
state
;
STfs
*
pTfs
;
SMsgCb
msgCb
;
SVBufPool
*
pPool
;
SVBufPool
*
inUse
;
SVBufPool
*
onCommit
;
SVBufPool
*
onRecycl
e
;
SMeta
*
pMeta
;
SSma
*
pSma
;
STsdb
*
pTsdb
;
SWal
*
pWal
;
STQ
*
pTq
;
SSink
*
pSink
;
tsem_t
canCommit
;
int64_t
sync
;
int32_t
blockCount
;
tsem_t
syncSem
;
SQHandle
*
pQuery
;
char
*
path
;
SVnodeCfg
config
;
SVState
state
;
STfs
*
pTfs
;
SMsgCb
msgCb
;
TdThreadMutex
mutex
;
TdThreadCond
poolNotEmpty
;
SVBufPool
*
pPool
;
SVBufPool
*
inUs
e
;
SMeta
*
pMeta
;
SSma
*
pSma
;
STsdb
*
pTsdb
;
SWal
*
pWal
;
STQ
*
pTq
;
SSink
*
pSink
;
tsem_t
canCommit
;
int64_t
sync
;
int32_t
blockCount
;
tsem_t
syncSem
;
SQHandle
*
pQuery
;
};
#define TD_VID(PVNODE) ((PVNODE)->config.vgId)
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
706b081f
...
...
@@ -55,6 +55,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
taosMemoryFree
(
pMemTable
);
goto
_err
;
}
vnodeBufPoolRef
(
pMemTable
->
pPool
);
*
ppMemTable
=
pMemTable
;
return
code
;
...
...
@@ -66,6 +67,7 @@ _err:
void
tsdbMemTableDestroy
(
SMemTable
*
pMemTable
)
{
if
(
pMemTable
)
{
vnodeBufPoolUnRef
(
pMemTable
->
pPool
);
taosArrayDestroy
(
pMemTable
->
aTbData
);
taosMemoryFree
(
pMemTable
);
}
...
...
source/dnode/vnode/src/vnd/vnodeBufPool.c
浏览文件 @
706b081f
...
...
@@ -17,7 +17,7 @@
/* ------------------------ STRUCTURES ------------------------ */
static
int
vnodeBufPoolCreate
(
int64_t
size
,
SVBufPool
**
ppPool
);
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int64_t
size
,
SVBufPool
**
ppPool
);
static
int
vnodeBufPoolDestroy
(
SVBufPool
*
pPool
);
int
vnodeOpenBufPool
(
SVnode
*
pVnode
,
int64_t
size
)
{
...
...
@@ -28,7 +28,7 @@ int vnodeOpenBufPool(SVnode *pVnode, int64_t size) {
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
// create pool
ret
=
vnodeBufPoolCreate
(
size
,
&
pPool
);
ret
=
vnodeBufPoolCreate
(
pVnode
,
size
,
&
pPool
);
if
(
ret
<
0
)
{
vError
(
"vgId:%d, failed to open vnode buffer pool since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
vnodeCloseBufPool
(
pVnode
);
...
...
@@ -120,7 +120,7 @@ void vnodeBufPoolFree(SVBufPool *pPool, void *p) {
}
// STATIC METHODS -------------------
static
int
vnodeBufPoolCreate
(
int64_t
size
,
SVBufPool
**
ppPool
)
{
static
int
vnodeBufPoolCreate
(
SVnode
*
pVnode
,
int64_t
size
,
SVBufPool
**
ppPool
)
{
SVBufPool
*
pPool
;
pPool
=
taosMemoryMalloc
(
sizeof
(
SVBufPool
)
+
size
);
...
...
@@ -130,6 +130,7 @@ static int vnodeBufPoolCreate(int64_t size, SVBufPool **ppPool) {
}
pPool
->
next
=
NULL
;
pPool
->
pVnode
=
pVnode
;
pPool
->
nRef
=
0
;
pPool
->
size
=
0
;
pPool
->
ptr
=
pPool
->
node
.
data
;
...
...
@@ -146,4 +147,26 @@ static int vnodeBufPoolDestroy(SVBufPool *pPool) {
vnodeBufPoolReset
(
pPool
);
taosMemoryFree
(
pPool
);
return
0
;
}
void
vnodeBufPoolRef
(
SVBufPool
*
pPool
)
{
int32_t
nRef
=
atomic_fetch_add_32
(
&
pPool
->
nRef
,
1
);
ASSERT
(
nRef
>
0
);
}
void
vnodeBufPoolUnRef
(
SVBufPool
*
pPool
)
{
int32_t
nRef
=
atomic_sub_fetch_32
(
&
pPool
->
nRef
,
1
);
if
(
nRef
==
0
)
{
SVnode
*
pVnode
=
pPool
->
pVnode
;
vnodeBufPoolReset
(
pPool
);
taosThreadMutexLock
(
&
pVnode
->
mutex
);
pPool
->
next
=
pVnode
->
pPool
;
pVnode
->
pPool
=
pPool
;
taosThreadCondSignal
(
&
pVnode
->
poolNotEmpty
);
taosThreadMutexUnlock
(
&
pVnode
->
mutex
);
}
}
\ No newline at end of file
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
706b081f
...
...
@@ -15,7 +15,7 @@
#include "vnd.h"
#define VND_INFO_FNAME "vnode.json"
#define VND_INFO_FNAME
"vnode.json"
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
static
int
vnodeEncodeInfo
(
const
SVnodeInfo
*
pInfo
,
char
**
ppData
);
...
...
@@ -27,18 +27,18 @@ static void vnodeWaitCommit(SVnode *pVnode);
int
vnodeBegin
(
SVnode
*
pVnode
)
{
// alloc buffer pool
/* pthread_mutex_lock(); */
taosThreadMutexLock
(
&
pVnode
->
mutex
);
while
(
pVnode
->
pPool
==
NULL
)
{
/* pthread_cond_wait(); */
taosThreadCondWait
(
&
pVnode
->
poolNotEmpty
,
&
pVnode
->
mutex
);
}
pVnode
->
inUse
=
pVnode
->
pPool
;
pVnode
->
inUse
->
nRef
=
1
;
pVnode
->
pPool
=
pVnode
->
inUse
->
next
;
pVnode
->
inUse
->
next
=
NULL
;
/* ref pVnode->inUse buffer pool */
/* pthread_mutex_unlock(); */
taosThreadMutexUnlock
(
&
pVnode
->
mutex
);
pVnode
->
state
.
commitID
++
;
// begin meta
...
...
@@ -217,7 +217,7 @@ int vnodeCommit(SVnode *pVnode) {
vInfo
(
"vgId:%d, start to commit, commit ID:%"
PRId64
" version:%"
PRId64
,
TD_VID
(
pVnode
),
pVnode
->
state
.
commitID
,
pVnode
->
state
.
applied
);
pVnode
->
onCommit
=
pVnode
->
inUse
;
vnodeBufPoolUnRef
(
pVnode
->
inUse
)
;
pVnode
->
inUse
=
NULL
;
// save info
...
...
@@ -284,10 +284,6 @@ int vnodeCommit(SVnode *pVnode) {
// apply the commit (TODO)
walEndSnapshot
(
pVnode
->
pWal
);
vnodeBufPoolReset
(
pVnode
->
onCommit
);
pVnode
->
onCommit
->
next
=
pVnode
->
pPool
;
pVnode
->
pPool
=
pVnode
->
onCommit
;
pVnode
->
onCommit
=
NULL
;
vInfo
(
"vgId:%d, commit over"
,
TD_VID
(
pVnode
));
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
706b081f
...
...
@@ -89,6 +89,8 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
tsem_init
(
&
pVnode
->
syncSem
,
0
,
0
);
tsem_init
(
&
(
pVnode
->
canCommit
),
0
,
1
);
taosThreadMutexInit
(
&
pVnode
->
mutex
,
NULL
);
taosThreadCondInit
(
&
pVnode
->
poolNotEmpty
,
NULL
);
// open buffer pool
if
(
vnodeOpenBufPool
(
pVnode
,
pVnode
->
config
.
isHeap
?
0
:
pVnode
->
config
.
szBuf
/
3
)
<
0
)
{
...
...
@@ -195,6 +197,8 @@ void vnodeClose(SVnode *pVnode) {
// destroy handle
tsem_destroy
(
&
(
pVnode
->
canCommit
));
tsem_destroy
(
&
pVnode
->
syncSem
);
taosThreadCondDestroy
(
&
pVnode
->
poolNotEmpty
);
taosThreadMutexDestroy
(
&
pVnode
->
mutex
);
taosMemoryFree
(
pVnode
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录