Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c22de779
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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,发现更多精彩内容 >>
提交
c22de779
编写于
1月 11, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tmemmem
上级
39f38085
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
15 deletion
+41
-15
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+37
-15
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+1
-0
source/libs/wal/test/walMetaTest.cpp
source/libs/wal/test/walMetaTest.cpp
+3
-0
未找到文件。
source/libs/wal/src/walMeta.c
浏览文件 @
c22de779
...
...
@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "cJSON.h"
#include "os.h"
#include "taoserror.h"
...
...
@@ -33,6 +32,24 @@ static inline int walBuildMetaName(SWal* pWal, int metaVer, char* buf) {
return
sprintf
(
buf
,
"%s/meta-ver%d"
,
pWal
->
path
,
metaVer
);
}
void
*
tmemmem
(
char
*
haystack
,
int
hlen
,
char
*
needle
,
int
nlen
)
{
char
*
limit
;
if
(
nlen
==
0
||
hlen
<
nlen
)
{
return
false
;
}
limit
=
haystack
+
hlen
-
nlen
+
1
;
while
((
haystack
=
(
char
*
)
memchr
(
haystack
,
needle
[
0
],
limit
-
haystack
))
!=
NULL
)
{
if
(
memcmp
(
haystack
,
needle
,
nlen
)
==
0
)
{
return
haystack
;
}
haystack
++
;
}
return
NULL
;
}
static
inline
int64_t
walScanLogGetLastVer
(
SWal
*
pWal
)
{
ASSERT
(
pWal
->
fileInfoSet
!=
NULL
);
int
sz
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
...
...
@@ -47,7 +64,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) {
struct
stat
statbuf
;
stat
(
fnameStr
,
&
statbuf
);
int
readSize
=
MIN
(
WAL_MAX_SIZE
,
statbuf
.
st_size
);
int
readSize
=
MIN
(
WAL_MAX_SIZE
+
2
,
statbuf
.
st_size
);
FileFd
fd
=
taosOpenFileRead
(
fnameStr
);
if
(
fd
<
0
)
{
...
...
@@ -64,6 +81,7 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) {
return
-
1
;
}
taosLSeekFile
(
fd
,
-
readSize
,
SEEK_END
);
if
(
readSize
!=
taosReadFile
(
fd
,
buf
,
readSize
))
{
free
(
buf
);
taosCloseFile
(
fd
);
...
...
@@ -71,21 +89,25 @@ static inline int64_t walScanLogGetLastVer(SWal* pWal) {
return
-
1
;
}
char
*
found
=
strstr
(
buf
,
(
const
char
*
)
&
magic
);
if
(
found
==
NULL
)
{
ASSERT
(
false
);
// file has to be deleted
free
(
buf
);
taosCloseFile
(
fd
);
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
return
-
1
;
}
char
*
another
;
while
((
another
=
strstr
(
found
+
1
,
(
const
char
*
)
&
magic
))
!=
NULL
)
{
char
*
haystack
=
buf
;
char
*
found
=
NULL
;
char
*
candidate
=
NULL
;
while
((
candidate
=
tmemmem
(
haystack
,
readSize
-
(
haystack
-
buf
),
(
char
*
)
&
magic
,
sizeof
(
uint64_t
)))
!=
NULL
)
{
// read and validate
SWalHead
*
logContent
=
(
SWalHead
*
)
another
;
SWalHead
*
logContent
=
(
SWalHead
*
)
candidate
;
if
(
walValidHeadCksum
(
logContent
)
==
0
&&
walValidBodyCksum
(
logContent
)
==
0
)
{
found
=
another
;
found
=
candidate
;
}
haystack
=
candidate
+
1
;
}
if
(
found
==
buf
)
{
SWalHead
*
logContent
=
(
SWalHead
*
)
found
;
if
(
walValidHeadCksum
(
logContent
)
!=
0
||
walValidBodyCksum
(
logContent
)
!=
0
)
{
// file has to be deleted
free
(
buf
);
taosCloseFile
(
fd
);
terrno
=
TSDB_CODE_WAL_FILE_CORRUPTED
;
return
-
1
;
}
}
taosCloseFile
(
fd
);
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
c22de779
...
...
@@ -106,6 +106,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
// init write buffer
memset
(
&
pWal
->
writeHead
,
0
,
sizeof
(
SWalHead
));
pWal
->
writeHead
.
head
.
headVer
=
WAL_HEAD_VER
;
pWal
->
writeHead
.
magic
=
WAL_MAGIC
;
if
(
pthread_mutex_init
(
&
pWal
->
mutex
,
NULL
)
<
0
)
{
taosArrayDestroy
(
pWal
->
fileInfoSet
);
...
...
source/libs/wal/test/walMetaTest.cpp
浏览文件 @
c22de779
...
...
@@ -340,7 +340,10 @@ TEST_F(WalRetentionEnv, repairMeta1) {
char
buf
[
100
];
sprintf
(
buf
,
"%s/meta-ver%d"
,
pathName
,
0
);
remove
(
buf
);
sprintf
(
buf
,
"%s/meta-ver%d"
,
pathName
,
1
);
remove
(
buf
);
SetUp
();
//getchar();
ASSERT_EQ
(
pWal
->
vers
.
lastVer
,
99
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录