Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
466c05a4
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看板
提交
466c05a4
编写于
9月 23, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code refactor
上级
6562e725
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
18 deletion
+27
-18
src/tsdb/inc/tsdbReadImpl.h
src/tsdb/inc/tsdbReadImpl.h
+2
-2
src/tsdb/src/tsdbReadImpl.c
src/tsdb/src/tsdbReadImpl.c
+25
-16
未找到文件。
src/tsdb/inc/tsdbReadImpl.h
浏览文件 @
466c05a4
...
...
@@ -67,8 +67,8 @@ typedef struct {
TSKEY keyLast
/**
* aggrStat; //
0 - no aggr part in .data/.last/.sma, 1 - has aggr in .sma
* blkVer; // 0 - original block, 1 - block since importing .sma
* aggrStat; //
only valid when blkVer > 0. 0 - no aggr part in .data/.last/.smad/.smal, 1 - has aggr in .smad/.smal
* blkVer; // 0 - original block, 1 - block since importing .sma
d/.smal
* aggrOffset; // only valid when blkVer > 0 and aggrStat > 0
*/
#define SBlockFieldsP1 \
...
...
src/tsdb/src/tsdbReadImpl.c
浏览文件 @
466c05a4
...
...
@@ -268,31 +268,40 @@ static FORCE_INLINE size_t tsdbSizeOfSBlock(int32_t sBlkVer) {
}
}
static
int
tsdbHeadRefactor
(
SDFile
*
pHeadf
,
SBlockInfo
**
pDstBlkInfo
,
uint32_t
srcBlkInfoLen
,
uint32_t
*
dstBlkInfoLen
)
{
static
int
tsdbHeadRefactor
(
SDFile
*
pHeadf
,
SBlockInfo
**
pDstBlkInfo
,
SBlockIdx
*
pBlkIdx
,
uint32_t
*
dstBlkInfoLen
)
{
int
sBlkVer
=
tsdbGetSBlockVer
(
pHeadf
->
info
.
fver
);
if
(
sBlkVer
==
SBlockVerLatest
)
{
*
dstBlkInfoLen
=
srcBlkInfoL
en
;
*
dstBlkInfoLen
=
pBlkIdx
->
l
en
;
return
TSDB_CODE_SUCCESS
;
}
size_t
originBlkSize
=
tsdbSizeOfSBlock
(
sBlkVer
);
size_t
nBlks
=
(
srcBlkInfoL
en
-
sizeof
(
SBlockInfo
))
/
originBlkSize
;
size_t
nBlks
=
(
pBlkIdx
->
l
en
-
sizeof
(
SBlockInfo
))
/
originBlkSize
;
*
dstBlkInfoLen
=
(
uint32_t
)(
sizeof
(
SBlockInfo
)
+
nBlks
*
sizeof
(
SBlock
));
if
(
srcBlkInfoL
en
==
*
dstBlkInfoLen
)
{
if
(
pBlkIdx
->
l
en
==
*
dstBlkInfoLen
)
{
return
TSDB_CODE_SUCCESS
;
}
ASSERT
(
*
dstBlkInfoLen
>=
srcBlkInfoL
en
);
ASSERT
(
*
dstBlkInfoLen
>=
pBlkIdx
->
l
en
);
SBlockInfo
*
tmpBlkInfo
=
NULL
;
if
(
tsdbMakeRoom
((
void
**
)(
&
tmpBlkInfo
),
*
dstBlkInfoLen
)
<
0
)
return
-
1
;
memset
(
tmpBlkInfo
,
0
,
*
dstBlkInfoLen
);
// the blkVer is set to 0
memcpy
(
tmpBlkInfo
,
*
pDstBlkInfo
,
sizeof
(
SBlockInfo
));
// copy header
uint32_t
nSubBlks
=
0
;
for
(
int
i
=
0
;
i
<
nBlks
;
++
i
)
{
memcpy
(
tmpBlkInfo
->
blocks
+
i
,
POINTER_SHIFT
((
*
pDstBlkInfo
)
->
blocks
,
i
*
originBlkSize
),
originBlkSize
);
// TODO: update the fields if the SBlock definition changed later
SBlock
*
tmpBlk
=
tmpBlkInfo
->
blocks
+
i
;
memcpy
(
tmpBlk
,
POINTER_SHIFT
((
*
pDstBlkInfo
)
->
blocks
,
i
*
originBlkSize
),
originBlkSize
);
if
(
i
<
pBlkIdx
->
numOfBlocks
)
{
// super blocks
if
(
tmpBlk
->
numOfSubBlocks
>
1
)
{
// has sub blocks
tmpBlk
->
offset
=
sizeof
(
SBlockInfo
)
+
(
pBlkIdx
->
numOfBlocks
+
nSubBlks
)
*
sizeof
(
SBlock
);
nSubBlks
+=
tmpBlk
->
numOfSubBlocks
;
}
}
// TODO: update the fields if the SBlock definition change later
}
taosTZfree
(
*
pDstBlkInfo
);
*
pDstBlkInfo
=
tmpBlkInfo
;
...
...
@@ -337,7 +346,7 @@ int tsdbLoadBlockInfo(SReadH *pReadh, void **pTarget, uint32_t *extendedLen) {
ASSERT
(
pBlkIdx
->
tid
==
pReadh
->
pBlkInfo
->
tid
&&
pBlkIdx
->
uid
==
pReadh
->
pBlkInfo
->
uid
);
uint32_t
dstBlkInfoLen
=
0
;
if
(
tsdbHeadRefactor
(
pHeadf
,
&
(
pReadh
->
pBlkInfo
),
pBlkIdx
->
len
,
&
dstBlkInfoLen
)
<
0
)
{
if
(
tsdbHeadRefactor
(
pHeadf
,
&
(
pReadh
->
pBlkInfo
),
pBlkIdx
,
&
dstBlkInfoLen
)
<
0
)
{
return
-
1
;
}
...
...
@@ -416,7 +425,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
static
int
tsdbLoadBlockStatisFromDFile
(
SReadH
*
pReadh
,
SBlock
*
pBlock
)
{
SDFile
*
pDFile
=
(
pBlock
->
last
)
?
TSDB_READ_LAST_FILE
(
pReadh
)
:
TSDB_READ_DATA_FILE
(
pReadh
);
if
(
tsdbSeekDFile
(
pDFile
,
pBlock
->
offset
,
SEEK_SET
)
<
0
)
{
tsdbError
(
"vgId:%d failed to load block
statis
part while seek file %s to offset %"
PRId64
" since %s"
,
tsdbError
(
"vgId:%d failed to load block
aggr
part while seek file %s to offset %"
PRId64
" since %s"
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFile
),
(
int64_t
)
pBlock
->
offset
,
tstrerror
(
terrno
));
return
-
1
;
}
...
...
@@ -426,14 +435,14 @@ static int tsdbLoadBlockStatisFromDFile(SReadH *pReadh, SBlock *pBlock) {
int64_t
nread
=
tsdbReadDFile
(
pDFile
,
(
void
*
)(
pReadh
->
pBlkData
),
size
);
if
(
nread
<
0
)
{
tsdbError
(
"vgId:%d failed to load block
statis
part while read file %s since %s, offset:%"
PRId64
" len :%"
PRIzu
,
tsdbError
(
"vgId:%d failed to load block
aggr
part while read file %s since %s, offset:%"
PRId64
" len :%"
PRIzu
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFile
),
tstrerror
(
terrno
),
(
int64_t
)
pBlock
->
offset
,
size
);
return
-
1
;
}
if
(
nread
<
size
)
{
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
tsdbError
(
"vgId:%d block
statis
part in file %s is corrupted, offset:%"
PRId64
" expected bytes:%"
PRIzu
tsdbError
(
"vgId:%d block
aggr
part in file %s is corrupted, offset:%"
PRId64
" expected bytes:%"
PRIzu
" read bytes: %"
PRId64
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFile
),
(
int64_t
)
pBlock
->
offset
,
size
,
nread
);
return
-
1
;
...
...
@@ -441,7 +450,7 @@ static int tsdbLoadBlockStatisFromDFile(SReadH *pReadh, SBlock *pBlock) {
if
(
!
taosCheckChecksumWhole
((
uint8_t
*
)(
pReadh
->
pBlkData
),
(
uint32_t
)
size
))
{
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
tsdbError
(
"vgId:%d block
statis
part in file %s is corrupted since wrong checksum, offset:%"
PRId64
" len :%"
PRIzu
,
tsdbError
(
"vgId:%d block
aggr
part in file %s is corrupted since wrong checksum, offset:%"
PRId64
" len :%"
PRIzu
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFile
),
(
int64_t
)
pBlock
->
offset
,
size
);
return
-
1
;
}
...
...
@@ -453,7 +462,7 @@ static int tsdbLoadBlockStatisFromAggr(SReadH *pReadh, SBlock *pBlock) {
SDFile
*
pDFileAggr
=
pBlock
->
last
?
TSDB_READ_SMAL_FILE
(
pReadh
)
:
TSDB_READ_SMAD_FILE
(
pReadh
);
if
(
tsdbSeekDFile
(
pDFileAggr
,
pBlock
->
aggrOffset
,
SEEK_SET
)
<
0
)
{
tsdbError
(
"vgId:%d failed to load block
statis
part while seek file %s to offset %"
PRId64
" since %s"
,
tsdbError
(
"vgId:%d failed to load block
aggr
part while seek file %s to offset %"
PRId64
" since %s"
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFileAggr
),
(
int64_t
)
pBlock
->
aggrOffset
,
tstrerror
(
terrno
));
return
-
1
;
...
...
@@ -464,7 +473,7 @@ static int tsdbLoadBlockStatisFromAggr(SReadH *pReadh, SBlock *pBlock) {
int64_t
nreadAggr
=
tsdbReadDFile
(
pDFileAggr
,
(
void
*
)(
pReadh
->
pAggrBlkData
),
sizeAggr
);
if
(
nreadAggr
<
0
)
{
tsdbError
(
"vgId:%d failed to load block
statis
part while read file %s since %s, offset:%"
PRId64
" len :%"
PRIzu
,
tsdbError
(
"vgId:%d failed to load block
aggr
part while read file %s since %s, offset:%"
PRId64
" len :%"
PRIzu
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFileAggr
),
tstrerror
(
terrno
),
(
int64_t
)
pBlock
->
aggrOffset
,
sizeAggr
);
return
-
1
;
...
...
@@ -472,7 +481,7 @@ static int tsdbLoadBlockStatisFromAggr(SReadH *pReadh, SBlock *pBlock) {
if
(
nreadAggr
<
sizeAggr
)
{
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
tsdbError
(
"vgId:%d block
statis
part in file %s is corrupted, offset:%"
PRId64
" expected bytes:%"
PRIzu
tsdbError
(
"vgId:%d block
aggr
part in file %s is corrupted, offset:%"
PRId64
" expected bytes:%"
PRIzu
" read bytes: %"
PRId64
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFileAggr
),
(
int64_t
)
pBlock
->
aggrOffset
,
sizeAggr
,
nreadAggr
);
...
...
@@ -481,7 +490,7 @@ static int tsdbLoadBlockStatisFromAggr(SReadH *pReadh, SBlock *pBlock) {
if
(
!
taosCheckChecksumWhole
((
uint8_t
*
)(
pReadh
->
pAggrBlkData
),
(
uint32_t
)
sizeAggr
))
{
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
tsdbError
(
"vgId:%d block
statis
part in file %s is corrupted since wrong checksum, offset:%"
PRId64
" len :%"
PRIzu
,
tsdbError
(
"vgId:%d block
aggr
part in file %s is corrupted since wrong checksum, offset:%"
PRId64
" len :%"
PRIzu
,
TSDB_READ_REPO_ID
(
pReadh
),
TSDB_FILE_FULL_NAME
(
pDFileAggr
),
(
int64_t
)
pBlock
->
aggrOffset
,
sizeAggr
);
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录