Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
63cc4e27
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
63cc4e27
编写于
12月 09, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
0707de66
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
124 addition
and
50 deletion
+124
-50
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+3
-0
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+0
-3
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+1
-3
source/dnode/vnode/src/vnd/vnodeSnapshot.c
source/dnode/vnode/src/vnd/vnodeSnapshot.c
+120
-40
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+0
-4
未找到文件。
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
63cc4e27
...
...
@@ -87,11 +87,14 @@ typedef struct SCommitInfo SCommitInfo;
#define VNODE_RSMA1_DIR "rsma1"
#define VNODE_RSMA2_DIR "rsma2"
#define VND_INFO_FNAME "vnode.json"
// vnd.h
void
*
vnodeBufPoolMalloc
(
SVBufPool
*
pPool
,
int
size
);
void
vnodeBufPoolFree
(
SVBufPool
*
pPool
,
void
*
p
);
void
vnodeBufPoolRef
(
SVBufPool
*
pPool
);
void
vnodeBufPoolUnRef
(
SVBufPool
*
pPool
);
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
SVnodeInfo
*
pInfo
);
// meta
typedef
struct
SMCtbCursor
SMCtbCursor
;
...
...
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
63cc4e27
...
...
@@ -135,9 +135,6 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
tjsonAddItemToArray
(
pNodeInfoArr
,
pNodeInfo
);
}
// add tsdb page size config
if
(
tjsonAddIntegerToObject
(
pJson
,
"tsdbPageSize"
,
pCfg
->
tsdbPageSize
)
<
0
)
return
-
1
;
return
0
;
}
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
63cc4e27
...
...
@@ -16,11 +16,9 @@
#include "vnd.h"
#include "vnodeInt.h"
#define VND_INFO_FNAME "vnode.json"
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
static
int
vnodeEncodeInfo
(
const
SVnodeInfo
*
pInfo
,
char
**
ppData
);
static
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
SVnodeInfo
*
pInfo
);
static
int
vnodeCommitImpl
(
SCommitInfo
*
pInfo
);
int
vnodeBegin
(
SVnode
*
pVnode
)
{
...
...
@@ -407,7 +405,7 @@ _err:
return
-
1
;
}
static
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
SVnodeInfo
*
pInfo
)
{
int
vnodeDecodeInfo
(
uint8_t
*
pData
,
SVnodeInfo
*
pInfo
)
{
SJson
*
pJson
=
NULL
;
pJson
=
tjsonParse
(
pData
);
...
...
source/dnode/vnode/src/vnd/vnodeSnapshot.c
浏览文件 @
63cc4e27
...
...
@@ -21,6 +21,8 @@ struct SVSnapReader {
int64_t
sver
;
int64_t
ever
;
int64_t
index
;
// config
int8_t
cfgDone
;
// meta
int8_t
metaDone
;
SMetaSnapReader
*
pMetaReader
;
...
...
@@ -88,6 +90,53 @@ int32_t vnodeSnapReaderClose(SVSnapReader *pReader) {
int32_t
vnodeSnapRead
(
SVSnapReader
*
pReader
,
uint8_t
**
ppData
,
uint32_t
*
nData
)
{
int32_t
code
=
0
;
// CONFIG ==============
// FIXME: if commit multiple times and the config changed?
if
(
!
pReader
->
cfgDone
)
{
char
fName
[
TSDB_FILENAME_LEN
];
if
(
pReader
->
pVnode
->
pTfs
)
{
snprintf
(
fName
,
TSDB_FILENAME_LEN
,
"%s%s%s%s%s"
,
tfsGetPrimaryPath
(
pReader
->
pVnode
->
pTfs
),
TD_DIRSEP
,
pReader
->
pVnode
->
path
,
TD_DIRSEP
,
VND_INFO_FNAME
);
}
else
{
snprintf
(
fName
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
pReader
->
pVnode
->
path
,
TD_DIRSEP
,
VND_INFO_FNAME
);
}
TdFilePtr
pFile
=
taosOpenFile
(
fName
,
TD_FILE_READ
);
if
(
NULL
==
pFile
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
int64_t
size
;
if
(
taosFStatFile
(
pFile
,
&
size
,
NULL
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
taosCloseFile
(
&
pFile
);
goto
_err
;
}
*
ppData
=
taosMemoryMalloc
(
sizeof
(
SSnapDataHdr
)
+
size
+
1
);
if
(
*
ppData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
taosCloseFile
(
&
pFile
);
goto
_err
;
}
((
SSnapDataHdr
*
)(
*
ppData
))
->
type
=
SNAP_DATA_CFG
;
((
SSnapDataHdr
*
)(
*
ppData
))
->
size
=
size
+
1
;
((
SSnapDataHdr
*
)(
*
ppData
))
->
data
[
size
]
=
'\0'
;
if
(
taosReadFile
(
pFile
,
((
SSnapDataHdr
*
)(
*
ppData
))
->
data
,
size
)
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
taosMemoryFree
(
*
ppData
);
taosCloseFile
(
&
pFile
);
goto
_err
;
}
taosCloseFile
(
&
pFile
);
pReader
->
cfgDone
=
1
;
goto
_exit
;
}
// META ==============
if
(
!
pReader
->
metaDone
)
{
// open reader if not
...
...
@@ -230,6 +279,8 @@ struct SVSnapWriter {
int64_t
ever
;
int64_t
commitID
;
int64_t
index
;
// config
SVnodeInfo
info
;
// meta
SMetaSnapWriter
*
pMetaSnapWriter
;
// tsdb
...
...
@@ -248,6 +299,10 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWr
int32_t
code
=
0
;
SVSnapWriter
*
pWriter
=
NULL
;
// commit memory data
vnodeAsyncCommit
(
pVnode
);
tsem_wait
(
&
pVnode
->
canCommit
);
// alloc
pWriter
=
(
SVSnapWriter
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pWriter
));
if
(
pWriter
==
NULL
)
{
...
...
@@ -258,16 +313,8 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, int64_t sver, int64_t ever, SVSnapWr
pWriter
->
sver
=
sver
;
pWriter
->
ever
=
ever
;
// commit it
code
=
vnodeSyncCommit
(
pVnode
);
if
(
code
)
{
taosMemoryFree
(
pWriter
);
goto
_err
;
}
// inc commit ID
pVnode
->
state
.
commitID
++
;
pWriter
->
commitID
=
pVnode
->
state
.
commitID
;
pWriter
->
commitID
=
++
pVnode
->
state
.
commitID
;
vInfo
(
"vgId:%d, vnode snapshot writer opened, sver:%"
PRId64
" ever:%"
PRId64
" commit id:%"
PRId64
,
TD_VID
(
pVnode
),
sver
,
ever
,
pWriter
->
commitID
);
...
...
@@ -284,53 +331,82 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *
int32_t
code
=
0
;
SVnode
*
pVnode
=
pWriter
->
pVnode
;
if
(
!
rollback
)
{
pVnode
->
config
=
pWriter
->
info
.
config
;
pVnode
->
state
=
(
SVState
){.
committed
=
pWriter
->
info
.
state
.
committed
,
.
applied
=
pWriter
->
info
.
state
.
committed
,
.
commitID
=
pWriter
->
commitID
,
.
commitTerm
=
pWriter
->
info
.
state
.
commitTerm
,
.
applyTerm
=
pWriter
->
info
.
state
.
commitTerm
};
pVnode
->
statis
=
pWriter
->
info
.
statis
;
char
dir
[
TSDB_FILENAME_LEN
]
=
{
0
};
if
(
pWriter
->
pVnode
->
pTfs
)
{
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
TD_DIRSEP
,
pVnode
->
path
);
}
else
{
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s"
,
pWriter
->
pVnode
->
path
);
}
vnodeCommitInfo
(
dir
,
&
pWriter
->
info
);
}
else
{
vnodeRollback
(
pWriter
->
pVnode
);
}
if
(
pWriter
->
pMetaSnapWriter
)
{
code
=
metaSnapWriterClose
(
&
pWriter
->
pMetaSnapWriter
,
rollback
);
if
(
code
)
goto
_e
rr
;
if
(
code
)
goto
_e
xit
;
}
if
(
pWriter
->
pTsdbSnapWriter
)
{
code
=
tsdbSnapWriterClose
(
&
pWriter
->
pTsdbSnapWriter
,
rollback
);
if
(
code
)
goto
_e
rr
;
if
(
code
)
goto
_e
xit
;
}
if
(
pWriter
->
pRsmaSnapWriter
)
{
code
=
rsmaSnapWriterClose
(
&
pWriter
->
pRsmaSnapWriter
,
rollback
);
if
(
code
)
goto
_e
rr
;
if
(
code
)
goto
_e
xit
;
}
if
(
!
rollback
)
{
SVnodeInfo
info
=
{
0
};
char
dir
[
TSDB_FILENAME_LEN
];
pVnode
->
state
.
committed
=
pWriter
->
ever
;
pVnode
->
state
.
applied
=
pWriter
->
ever
;
pVnode
->
state
.
applyTerm
=
pSnapshot
->
lastApplyTerm
;
pVnode
->
state
.
commitTerm
=
pSnapshot
->
lastApplyTerm
;
info
.
config
=
pVnode
->
config
;
info
.
state
.
committed
=
pVnode
->
state
.
applied
;
info
.
state
.
commitTerm
=
pVnode
->
state
.
applyTerm
;
info
.
state
.
commitID
=
pVnode
->
state
.
commitID
;
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
TD_DIRSEP
,
pVnode
->
path
);
code
=
vnodeSaveInfo
(
dir
,
&
info
);
if
(
code
)
goto
_err
;
code
=
vnodeCommitInfo
(
dir
,
&
info
);
if
(
code
)
goto
_err
;
vnodeBegin
(
pVnode
);
}
else
{
ASSERT
(
0
);
}
_exit:
if
(
code
)
{
vError
(
"vgId:%d, vnode snapshot writer close failed since %s"
,
TD_VID
(
pWriter
->
pVnode
),
tstrerror
(
code
));
}
else
{
vInfo
(
"vgId:%d, vnode snapshot writer closed, rollback:%d"
,
TD_VID
(
pVnode
),
rollback
);
taosMemoryFree
(
pWriter
);
}
tsem_wait
(
&
pVnode
->
canCommit
);
return
code
;
}
_err:
vError
(
"vgId:%d, vnode snapshot writer close failed since %s"
,
TD_VID
(
pWriter
->
pVnode
),
tstrerror
(
code
));
static
int32_t
vnodeSnapWriteInfo
(
SVSnapWriter
*
pWriter
,
uint8_t
*
pData
,
uint32_t
nData
)
{
int32_t
code
=
0
;
SSnapDataHdr
*
pHdr
=
(
SSnapDataHdr
*
)
pData
;
// decode info
if
(
vnodeDecodeInfo
(
pHdr
->
data
,
&
pWriter
->
info
)
<
0
)
{
code
=
TSDB_CODE_INVALID_MSG
;
goto
_exit
;
}
// change some value
pWriter
->
info
.
state
.
commitID
=
pWriter
->
commitID
;
// modify info as needed
char
dir
[
TSDB_FILENAME_LEN
]
=
{
0
};
if
(
pWriter
->
pVnode
->
pTfs
)
{
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
tfsGetPrimaryPath
(
pWriter
->
pVnode
->
pTfs
),
TD_DIRSEP
,
pWriter
->
pVnode
->
path
);
}
else
{
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s"
,
pWriter
->
pVnode
->
path
);
}
if
(
vnodeSaveInfo
(
dir
,
&
pWriter
->
info
)
<
0
)
{
code
=
terrno
;
goto
_exit
;
}
_exit:
return
code
;
}
...
...
@@ -347,6 +423,10 @@ int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
pHdr
->
type
,
nData
);
switch
(
pHdr
->
type
)
{
case
SNAP_DATA_CFG
:
{
code
=
vnodeSnapWriteInfo
(
pWriter
,
pData
,
nData
);
if
(
code
)
goto
_err
;
}
break
;
case
SNAP_DATA_META
:
{
// meta
if
(
pWriter
->
pMetaSnapWriter
==
NULL
)
{
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
63cc4e27
...
...
@@ -317,11 +317,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
// commit if need
if
(
vnodeShouldCommit
(
pVnode
))
{
vInfo
(
"vgId:%d, commit at version %"
PRId64
,
TD_VID
(
pVnode
),
version
);
#if 0
vnodeSyncCommit(pVnode);
#else
vnodeAsyncCommit
(
pVnode
);
#endif
// start a new one
if
(
vnodeBegin
(
pVnode
)
<
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录