Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bd408504
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看板
提交
bd408504
编写于
12月 10, 2021
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make wal meta serialized and flushed into disk
上级
713c20c4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
35 deletion
+58
-35
source/libs/wal/inc/walInt.h
source/libs/wal/inc/walInt.h
+2
-2
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+53
-27
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+0
-2
source/libs/wal/test/walMetaTest.cpp
source/libs/wal/test/walMetaTest.cpp
+3
-4
未找到文件。
source/libs/wal/inc/walInt.h
浏览文件 @
bd408504
...
...
@@ -83,8 +83,8 @@ int walReadMeta(SWal* pWal);
int
walWriteMeta
(
SWal
*
pWal
);
int
walRollFileInfo
(
SWal
*
pWal
);
char
*
wal
FileInfo
Serialize
(
SWal
*
pWal
);
SArray
*
walFileInfoDeserialize
(
const
char
*
bytes
);
char
*
wal
Meta
Serialize
(
SWal
*
pWal
);
int
walMetaDeserialize
(
SWal
*
pWal
,
const
char
*
bytes
);
//meta section end
int64_t
walGetSeq
();
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
bd408504
...
...
@@ -47,49 +47,74 @@ int walRollFileInfo(SWal* pWal) {
return
0
;
}
char
*
wal
FileInfo
Serialize
(
SWal
*
pWal
)
{
char
*
wal
Meta
Serialize
(
SWal
*
pWal
)
{
char
buf
[
30
];
if
(
pWal
==
NULL
||
pWal
->
fileInfoSet
==
NULL
)
return
0
;
int
sz
=
pWal
->
fileInfoSet
->
size
;
cJSON
*
root
=
cJSON_CreateArray
();
cJSON
*
field
;
if
(
root
==
NULL
)
{
cJSON
*
pRoot
=
cJSON_CreateObject
();
cJSON
*
pMeta
=
cJSON_CreateObject
();
cJSON
*
pFiles
=
cJSON_CreateArray
();
cJSON
*
pField
;
if
(
pRoot
==
NULL
||
pMeta
==
NULL
||
pFiles
==
NULL
)
{
//TODO
return
NULL
;
}
cJSON_AddItemToObject
(
pRoot
,
"meta"
,
pMeta
);
sprintf
(
buf
,
"%"
PRId64
,
pWal
->
firstVersion
);
cJSON_AddStringToObject
(
pMeta
,
"firstVer"
,
buf
);
sprintf
(
buf
,
"%"
PRId64
,
pWal
->
snapshotVersion
);
cJSON_AddStringToObject
(
pMeta
,
"snapshotVer"
,
buf
);
sprintf
(
buf
,
"%"
PRId64
,
pWal
->
commitVersion
);
cJSON_AddStringToObject
(
pMeta
,
"commitVer"
,
buf
);
sprintf
(
buf
,
"%"
PRId64
,
pWal
->
lastVersion
);
cJSON_AddStringToObject
(
pMeta
,
"lastVer"
,
buf
);
cJSON_AddItemToObject
(
pRoot
,
"files"
,
pFiles
);
WalFileInfo
*
pData
=
pWal
->
fileInfoSet
->
pData
;
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
WalFileInfo
*
pInfo
=
&
pData
[
i
];
cJSON_AddItemToArray
(
root
,
f
ield
=
cJSON_CreateObject
());
if
(
f
ield
==
NULL
)
{
cJSON_Delete
(
r
oot
);
cJSON_AddItemToArray
(
pFiles
,
pF
ield
=
cJSON_CreateObject
());
if
(
pF
ield
==
NULL
)
{
cJSON_Delete
(
pR
oot
);
return
NULL
;
}
//cjson only support int32_t or double
//string are used to prohibit the loss of precision
sprintf
(
buf
,
"%
ld"
,
pInfo
->
firstVer
);
cJSON_AddStringToObject
(
f
ield
,
"firstVer"
,
buf
);
sprintf
(
buf
,
"%
ld"
,
pInfo
->
lastVer
);
cJSON_AddStringToObject
(
f
ield
,
"lastVer"
,
buf
);
sprintf
(
buf
,
"%
ld"
,
pInfo
->
createTs
);
cJSON_AddStringToObject
(
f
ield
,
"createTs"
,
buf
);
sprintf
(
buf
,
"%
ld"
,
pInfo
->
closeTs
);
cJSON_AddStringToObject
(
f
ield
,
"closeTs"
,
buf
);
sprintf
(
buf
,
"%
ld"
,
pInfo
->
fileSize
);
cJSON_AddStringToObject
(
f
ield
,
"fileSize"
,
buf
);
sprintf
(
buf
,
"%
"
PRId64
,
pInfo
->
firstVer
);
cJSON_AddStringToObject
(
pF
ield
,
"firstVer"
,
buf
);
sprintf
(
buf
,
"%
"
PRId64
,
pInfo
->
lastVer
);
cJSON_AddStringToObject
(
pF
ield
,
"lastVer"
,
buf
);
sprintf
(
buf
,
"%
"
PRId64
,
pInfo
->
createTs
);
cJSON_AddStringToObject
(
pF
ield
,
"createTs"
,
buf
);
sprintf
(
buf
,
"%
"
PRId64
,
pInfo
->
closeTs
);
cJSON_AddStringToObject
(
pF
ield
,
"closeTs"
,
buf
);
sprintf
(
buf
,
"%
"
PRId64
,
pInfo
->
fileSize
);
cJSON_AddStringToObject
(
pF
ield
,
"fileSize"
,
buf
);
}
return
cJSON_Print
(
r
oot
);
return
cJSON_Print
(
pR
oot
);
}
SArray
*
walFileInfoDeserialize
(
const
char
*
bytes
)
{
cJSON
*
root
,
*
pInfoJson
,
*
pField
;
root
=
cJSON_Parse
(
bytes
);
int
sz
=
cJSON_GetArraySize
(
root
);
int
walMetaDeserialize
(
SWal
*
pWal
,
const
char
*
bytes
)
{
ASSERT
(
taosArrayGetSize
(
pWal
->
fileInfoSet
)
==
0
);
cJSON
*
pRoot
,
*
pMeta
,
*
pFiles
,
*
pInfoJson
,
*
pField
;
pRoot
=
cJSON_Parse
(
bytes
);
pMeta
=
cJSON_GetObjectItem
(
pRoot
,
"meta"
);
pField
=
cJSON_GetObjectItem
(
pMeta
,
"firstVer"
);
pWal
->
firstVersion
=
atoll
(
cJSON_GetStringValue
(
pField
));
pField
=
cJSON_GetObjectItem
(
pMeta
,
"snapshotVer"
);
pWal
->
snapshotVersion
=
atoll
(
cJSON_GetStringValue
(
pField
));
pField
=
cJSON_GetObjectItem
(
pMeta
,
"commitVer"
);
pWal
->
commitVersion
=
atoll
(
cJSON_GetStringValue
(
pField
));
pField
=
cJSON_GetObjectItem
(
pMeta
,
"lastVer"
);
pWal
->
lastVersion
=
atoll
(
cJSON_GetStringValue
(
pField
));
pFiles
=
cJSON_GetObjectItem
(
pRoot
,
"files"
);
int
sz
=
cJSON_GetArraySize
(
pFiles
);
//deserialize
SArray
*
pArray
=
taosArrayInit
(
sz
,
sizeof
(
WalFileInfo
));
WalFileInfo
*
pData
=
pArray
->
pData
;
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
cJSON
*
pInfoJson
=
cJSON_GetArrayItem
(
root
,
i
);
cJSON
*
pInfoJson
=
cJSON_GetArrayItem
(
pFiles
,
i
);
WalFileInfo
*
pInfo
=
&
pData
[
i
];
pField
=
cJSON_GetObjectItem
(
pInfoJson
,
"firstVer"
);
pInfo
->
firstVer
=
atoll
(
cJSON_GetStringValue
(
pField
));
...
...
@@ -103,7 +128,8 @@ SArray* walFileInfoDeserialize(const char* bytes) {
pInfo
->
fileSize
=
atoll
(
cJSON_GetStringValue
(
pField
));
}
taosArraySetSize
(
pArray
,
sz
);
return
pArray
;
pWal
->
fileInfoSet
=
pArray
;
return
0
;
}
static
inline
int
walBuildMetaName
(
SWal
*
pWal
,
int
metaVer
,
char
*
buf
)
{
...
...
@@ -144,7 +170,7 @@ int walWriteMeta(SWal* pWal) {
if
(
metaTfd
<
0
)
{
return
-
1
;
}
char
*
serialized
=
wal
FileInfo
Serialize
(
pWal
);
char
*
serialized
=
wal
Meta
Serialize
(
pWal
);
int
len
=
strlen
(
serialized
);
if
(
len
!=
tfWrite
(
metaTfd
,
serialized
,
len
))
{
//TODO:clean file
...
...
@@ -183,8 +209,8 @@ int walReadMeta(SWal* pWal) {
return
-
1
;
}
//load into fileInfoSet
pWal
->
fileInfoSet
=
walFileInfoDeserialize
(
buf
);
if
(
pWal
->
fileInfoSet
==
NULL
)
{
int
code
=
walMetaDeserialize
(
pWal
,
buf
);
if
(
code
!=
0
)
{
free
(
buf
);
return
-
1
;
}
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
bd408504
...
...
@@ -175,8 +175,6 @@ static void walFreeObj(void *wal) {
tfClose
(
pWal
->
writeIdxTfd
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
pWal
->
fileInfoSet
=
NULL
;
taosArrayDestroy
(
pWal
->
fileInfoSet
);
pWal
->
fileInfoSet
=
NULL
;
pthread_mutex_destroy
(
&
pWal
->
mutex
);
tfree
(
pWal
);
}
...
...
source/libs/wal/test/walMetaTest.cpp
浏览文件 @
bd408504
...
...
@@ -92,7 +92,7 @@ TEST_F(WalCleanEnv, serialize) {
ASSERT
(
code
==
0
);
code
=
walRollFileInfo
(
pWal
);
ASSERT
(
code
==
0
);
char
*
ss
=
wal
FileInfo
Serialize
(
pWal
);
char
*
ss
=
wal
Meta
Serialize
(
pWal
);
printf
(
"%s
\n
"
,
ss
);
code
=
walWriteMeta
(
pWal
);
ASSERT
(
code
==
0
);
...
...
@@ -113,20 +113,19 @@ TEST_F(WalCleanEnv, removeOldMeta) {
TEST_F
(
WalKeepEnv
,
readOldMeta
)
{
int
code
=
walRollFileInfo
(
pWal
);
ASSERT
(
code
==
0
);
ASSERT
(
pWal
->
fileInfoSet
!=
NULL
);
code
=
walWriteMeta
(
pWal
);
ASSERT
(
code
==
0
);
code
=
walRollFileInfo
(
pWal
);
ASSERT
(
code
==
0
);
code
=
walWriteMeta
(
pWal
);
ASSERT
(
code
==
0
);
char
*
oldss
=
wal
FileInfo
Serialize
(
pWal
);
char
*
oldss
=
wal
Meta
Serialize
(
pWal
);
TearDown
();
SetUp
();
code
=
walReadMeta
(
pWal
);
ASSERT
(
code
==
0
);
char
*
newss
=
wal
FileInfo
Serialize
(
pWal
);
char
*
newss
=
wal
Meta
Serialize
(
pWal
);
int
len
=
strlen
(
oldss
);
ASSERT_EQ
(
len
,
strlen
(
newss
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录