Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
823e0d26
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看板
提交
823e0d26
编写于
8月 13, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6044]<hotfix>: WAL compatibility since v2.1.5.0
上级
052ace85
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
94 addition
and
7 deletion
+94
-7
src/inc/twal.h
src/inc/twal.h
+1
-1
src/wal/src/walWrite.c
src/wal/src/walWrite.c
+93
-6
未找到文件。
src/inc/twal.h
浏览文件 @
823e0d26
...
...
@@ -32,7 +32,7 @@ typedef enum {
typedef
struct
{
int8_t
msgType
;
int8_t
sver
;
int8_t
sver
;
// sver 2 for WAL SDataRow/SMemRow compatibility
int8_t
reserved
[
2
];
int32_t
len
;
uint64_t
version
;
...
...
src/wal/src/walWrite.c
浏览文件 @
823e0d26
...
...
@@ -17,6 +17,7 @@
#define TAOS_RANDOM_FILE_FAIL_TEST
#include "os.h"
#include "taoserror.h"
#include "taosmsg.h"
#include "tchecksum.h"
#include "tfile.h"
#include "twal.h"
...
...
@@ -114,7 +115,7 @@ void walRemoveAllOldFiles(void *handle) {
#if defined(WAL_CHECKSUM_WHOLE)
static
void
walUpdateChecksum
(
SWalHead
*
pHead
)
{
pHead
->
sver
=
1
;
pHead
->
sver
=
2
;
pHead
->
cksum
=
0
;
pHead
->
cksum
=
taosCalcChecksum
(
0
,
(
uint8_t
*
)
pHead
,
sizeof
(
*
pHead
)
+
pHead
->
len
);
}
...
...
@@ -122,7 +123,7 @@ static void walUpdateChecksum(SWalHead *pHead) {
static
int
walValidateChecksum
(
SWalHead
*
pHead
)
{
if
(
pHead
->
sver
==
0
)
{
// for compatible with wal before sver 1
return
taosCheckChecksumWhole
((
uint8_t
*
)
pHead
,
sizeof
(
*
pHead
));
}
else
if
(
pHead
->
sver
=
=
1
)
{
}
else
if
(
pHead
->
sver
>
=
1
)
{
uint32_t
cksum
=
pHead
->
cksum
;
pHead
->
cksum
=
0
;
return
taosCheckChecksum
((
uint8_t
*
)
pHead
,
sizeof
(
*
pHead
)
+
pHead
->
len
,
cksum
);
...
...
@@ -281,7 +282,7 @@ static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int64_t tfd,
return
TSDB_CODE_SUCCESS
;
}
if
(
pHead
->
sver
=
=
1
)
{
if
(
pHead
->
sver
>
=
1
)
{
if
(
tfRead
(
tfd
,
pHead
->
cont
,
pHead
->
len
)
<
pHead
->
len
)
{
wError
(
"vgId:%d, read to end of corrupted wal file, offset:%"
PRId64
,
pWal
->
vgId
,
pos
);
return
TSDB_CODE_WAL_FILE_CORRUPTED
;
...
...
@@ -306,7 +307,88 @@ static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int64_t tfd,
return
TSDB_CODE_WAL_FILE_CORRUPTED
;
}
// Add SMemRowType ahead of SDataRow
static
void
expandSubmitBlk
(
SSubmitBlk
*
pDest
,
SSubmitBlk
*
pSrc
,
int32_t
*
lenExpand
)
{
memcpy
(
pDest
,
pSrc
,
sizeof
(
SSubmitBlk
));
int
nRows
=
htons
(
pSrc
->
numOfRows
);
if
(
nRows
<=
0
)
{
return
;
}
char
*
pDestData
=
pDest
->
data
;
char
*
pSrcData
=
pSrc
->
data
;
for
(
int
i
=
0
;
i
<
nRows
;
++
i
)
{
memRowSetType
(
pDestData
,
SMEM_ROW_DATA
);
memcpy
(
memRowDataBody
(
pDestData
),
pSrcData
,
dataRowLen
(
pSrcData
));
pDestData
=
POINTER_SHIFT
(
pDestData
,
memRowTLen
(
pDestData
));
pSrcData
=
POINTER_SHIFT
(
pSrcData
,
dataRowLen
(
pSrcData
));
++
(
*
lenExpand
);
}
int32_t
dataLen
=
htonl
(
pDest
->
dataLen
);
pDest
->
dataLen
=
htonl
(
dataLen
+
nRows
*
sizeof
(
uint8_t
));
}
static
bool
walIsSDataRow
(
void
*
pBlkData
,
int
nRows
,
int32_t
dataLen
)
{
int32_t
len
=
0
;
for
(
int
i
=
0
;
i
<
nRows
;
++
i
)
{
len
+=
dataRowLen
(
pBlkData
);
if
(
len
>
dataLen
)
{
return
false
;
}
pBlkData
=
POINTER_SHIFT
(
pBlkData
,
dataRowLen
(
pBlkData
));
}
if
(
len
!=
dataLen
)
{
return
false
;
}
return
true
;
}
// for WAL SMemRow/SDataRow compatibility
static
int
walSMemRowCheck
(
SWalHead
*
pHead
)
{
if
((
pHead
->
sver
<
2
)
&&
(
pHead
->
msgType
==
TSDB_MSG_TYPE_SUBMIT
))
{
SSubmitMsg
*
pMsg
=
(
SSubmitMsg
*
)
pHead
->
cont
;
int32_t
numOfBlocks
=
htonl
(
pMsg
->
numOfBlocks
);
if
(
numOfBlocks
<=
0
)
{
return
0
;
}
int32_t
nTotalRows
=
0
;
SSubmitBlk
*
pBlk
=
(
SSubmitBlk
*
)
pMsg
->
blocks
;
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
int32_t
dataLen
=
htonl
(
pBlk
->
dataLen
);
int32_t
nRows
=
htons
(
pBlk
->
numOfRows
);
nTotalRows
+=
nRows
;
if
(
!
walIsSDataRow
(
pBlk
->
data
,
nRows
,
dataLen
))
{
return
0
;
}
pBlk
=
(
SSubmitBlk
*
)
POINTER_SHIFT
(
pBlk
,
sizeof
(
SSubmitBlk
)
+
dataLen
);
}
SWalHead
*
pWalHead
=
(
SWalHead
*
)
calloc
(
sizeof
(
SWalHead
)
+
pHead
->
len
+
nTotalRows
*
sizeof
(
uint8_t
),
1
);
if
(
pWalHead
==
NULL
)
{
return
-
1
;
}
memcpy
(
pWalHead
,
pHead
,
sizeof
(
SWalHead
)
+
sizeof
(
SSubmitMsg
));
SSubmitMsg
*
pDestMsg
=
(
SSubmitMsg
*
)
pWalHead
->
cont
;
SSubmitBlk
*
pDestBlks
=
(
SSubmitBlk
*
)
pDestMsg
->
blocks
;
SSubmitBlk
*
pSrcBlks
=
(
SSubmitBlk
*
)
pMsg
->
blocks
;
int32_t
lenExpand
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
expandSubmitBlk
(
pDestBlks
,
pSrcBlks
,
&
lenExpand
);
pDestBlks
=
POINTER_SHIFT
(
pDestBlks
,
htonl
(
pDestBlks
->
dataLen
)
+
sizeof
(
SSubmitBlk
));
pSrcBlks
=
POINTER_SHIFT
(
pSrcBlks
,
htonl
(
pSrcBlks
->
dataLen
)
+
sizeof
(
SSubmitBlk
));
}
if
(
lenExpand
>
0
)
{
pDestMsg
->
header
.
contLen
=
htonl
(
pDestMsg
->
length
)
+
lenExpand
;
pDestMsg
->
length
=
htonl
(
pDestMsg
->
header
.
contLen
);
pWalHead
->
len
=
pWalHead
->
len
+
lenExpand
;
}
memcpy
(
pHead
,
pWalHead
,
sizeof
(
SWalHead
)
+
pWalHead
->
len
);
tfree
(
pWalHead
);
}
return
0
;
}
static
int32_t
walRestoreWalFile
(
SWal
*
pWal
,
void
*
pVnode
,
FWalWrite
writeFp
,
char
*
name
,
int64_t
fileId
)
{
int32_t
size
=
WAL_MAX_SIZE
;
...
...
@@ -346,7 +428,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
}
#if defined(WAL_CHECKSUM_WHOLE)
if
((
pHead
->
sver
==
0
&&
!
walValidateChecksum
(
pHead
))
||
pHead
->
sver
<
0
||
pHead
->
sver
>
1
)
{
if
((
pHead
->
sver
==
0
&&
!
walValidateChecksum
(
pHead
))
||
pHead
->
sver
<
0
||
pHead
->
sver
>
2
)
{
wError
(
"vgId:%d, file:%s, wal head cksum is messed up, hver:%"
PRIu64
" len:%d offset:%"
PRId64
,
pWal
->
vgId
,
name
,
pHead
->
version
,
pHead
->
len
,
offset
);
code
=
walSkipCorruptedRecord
(
pWal
,
pHead
,
tfd
,
&
offset
);
...
...
@@ -379,7 +461,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
continue
;
}
if
(
pHead
->
sver
==
1
&&
!
walValidateChecksum
(
pHead
))
{
if
(
(
pHead
->
sver
>=
1
)
&&
!
walValidateChecksum
(
pHead
))
{
wError
(
"vgId:%d, file:%s, wal whole cksum is messed up, hver:%"
PRIu64
" len:%d offset:%"
PRId64
,
pWal
->
vgId
,
name
,
pHead
->
version
,
pHead
->
len
,
offset
);
code
=
walSkipCorruptedRecord
(
pWal
,
pHead
,
tfd
,
&
offset
);
...
...
@@ -431,7 +513,12 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
pWal
->
version
=
pHead
->
version
;
//wInfo("writeFp: %ld", offset);
// wInfo("writeFp: %ld", offset);
if
(
0
!=
walSMemRowCheck
(
pHead
))
{
wError
(
"vgId:%d, restore wal, fileId:%"
PRId64
" hver:%"
PRIu64
" wver:%"
PRIu64
" len:%d offset:%"
PRId64
,
pWal
->
vgId
,
fileId
,
pHead
->
version
,
pWal
->
version
,
pHead
->
len
,
offset
);
return
TAOS_SYSTEM_ERROR
(
errno
);
}
(
*
writeFp
)(
pVnode
,
pHead
,
TAOS_QTYPE_WAL
,
NULL
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录