Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
3dfe486d
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3dfe486d
编写于
4月 09, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-100
上级
b0fe9341
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
122 addition
and
13 deletion
+122
-13
src/vnode/tsdb/src/tsdbRWHelper.c
src/vnode/tsdb/src/tsdbRWHelper.c
+122
-13
未找到文件。
src/vnode/tsdb/src/tsdbRWHelper.c
浏览文件 @
3dfe486d
...
@@ -673,37 +673,46 @@ _err:
...
@@ -673,37 +673,46 @@ _err:
return
-
1
;
return
-
1
;
}
}
static
int
tsdb
InsertSuperBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
int
blkIdx
)
{
static
int
tsdb
AdjustInfoSizeIfNeeded
(
SRWHelper
*
pHelper
,
size_t
spaceNeeded
)
{
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<=
pIdx
->
numOfSuperBlocks
);
ASSERT
(
pCompBlock
->
numOfSubBlocks
==
1
);
// Adjust memory if no more room
size_t
spaceNeed
=
sizeof
(
SCompBlock
);
size_t
spaceLeft
=
pHelper
->
compInfoSize
-
pIdx
->
len
;
size_t
spaceLeft
=
pHelper
->
compInfoSize
-
pIdx
->
len
;
ASSERT
(
spaceLeft
>=
0
);
ASSERT
(
spaceLeft
>=
0
);
if
(
spaceLeft
<
spaceNeed
)
{
if
(
spaceLeft
<
spaceNeed
ed
)
{
size_t
tsize
=
pHelper
->
compInfoSize
+
sizeof
(
SCompBlock
)
*
16
;
size_t
tsize
=
pHelper
->
compInfoSize
+
sizeof
(
SCompBlock
)
*
16
;
if
(
pHelper
->
compInfoSize
==
0
)
tsize
+=
sizeof
(
SCompInfo
);
if
(
pHelper
->
compInfoSize
==
0
)
tsize
+=
sizeof
(
SCompInfo
);
pHelper
->
pCompInfo
=
(
SCompInfo
*
)
realloc
((
void
*
)(
pHelper
->
pCompInfo
),
tsize
);
pHelper
->
pCompInfo
=
(
SCompInfo
*
)
realloc
((
void
*
)(
pHelper
->
pCompInfo
),
tsize
);
if
(
pHelper
->
pCompInfo
==
NULL
)
goto
_err
;
if
(
pHelper
->
pCompInfo
==
NULL
)
return
-
1
;
pHelper
->
compInfoSize
=
tsize
;
}
}
return
0
;
}
static
int
tsdbInsertSuperBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
int
blkIdx
)
{
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<=
pIdx
->
numOfSuperBlocks
);
ASSERT
(
pCompBlock
->
numOfSubBlocks
==
1
);
// Adjust memory if no more room
if
(
tsdbAdjustInfoSizeIfNeeded
(
pHelper
,
sizeof
(
SCompBlock
))
<
0
)
goto
_err
;
// Insert the block
// Insert the block
if
(
blkIdx
<
pIdx
->
numOfSuperBlocks
)
{
if
(
blkIdx
<
pIdx
->
numOfSuperBlocks
)
{
SCompBlock
*
pTCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
blkIdx
;
SCompBlock
*
pTCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
blkIdx
;
memmove
((
void
*
)(
pTCompBlock
+
1
),
(
void
*
)
pTCompBlock
,
pIdx
->
len
-
sizeof
(
SCompInfo
)
-
sizeof
(
SCompBlock
)
*
blkIdx
);
memmove
((
void
*
)(
pTCompBlock
+
1
),
(
void
*
)
pTCompBlock
,
pIdx
->
len
-
sizeof
(
SCompInfo
)
-
sizeof
(
SCompBlock
)
*
blkIdx
);
pTCompBlock
++
;
pTCompBlock
++
;
for
(
int
i
=
0
;
i
<
pIdx
->
numOfSuperBlocks
-
blkIdx
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pIdx
->
numOfSuperBlocks
-
blkIdx
;
i
++
)
{
pTCompBlock
->
offset
++
;
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
+=
sizeof
(
SCompBlock
)
;
}
}
}
}
pHelper
->
pCompInfo
->
blocks
[
blkIdx
]
=
*
pCompBlock
;
pHelper
->
pCompInfo
->
blocks
[
blkIdx
]
=
*
pCompBlock
;
pIdx
->
numOfSuperBlocks
++
;
pIdx
->
numOfSuperBlocks
++
;
pIdx
->
len
++
;
pIdx
->
len
+=
sizeof
(
SCompBlock
)
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
keyLast
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
last
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
last
;
...
@@ -713,12 +722,112 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
...
@@ -713,12 +722,112 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
return
-
1
;
return
-
1
;
}
}
static
int
tsdbAddSubBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
)
{
static
int
tsdbAddSubBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
int
blkIdx
,
int
rowsAdded
)
{
// TODO
ASSERT
(
pCompBlock
->
numOfSubBlocks
==
0
);
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
SCompBlock
*
pSCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
blkIdx
;
ASSERT
(
pSCompBlock
->
numOfSubBlocks
>=
1
&&
pSCompBlock
->
numOfSubBlocks
<
TSDB_MAX_SUBBLOCKS
);
size_t
spaceNeeded
=
(
pSCompBlock
->
numOfSubBlocks
==
1
)
?
sizeof
(
SCompBlock
)
*
2
:
sizeof
(
SCompBlock
);
if
(
tsdbAdjustInfoSizeIfNeeded
(
pHelper
,
spaceNeeded
)
<
0
)
goto
_err
;
// Add the sub-block
if
(
pSCompBlock
->
numOfSubBlocks
>
1
)
{
size_t
tsize
=
pIdx
->
len
-
(
pSCompBlock
->
offset
+
pSCompBlock
->
len
);
if
(
tsize
>
0
)
{
memmove
((
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
+
sizeof
(
SCompBlock
)),
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
),
tsize
);
for
(
int
i
=
blkIdx
;
i
<
pIdx
->
numOfSuperBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
&
pHelper
->
pCompInfo
->
blocks
[
i
];
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
+=
sizeof
(
SCompBlock
);
}
}
*
(
SCompBlock
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
)
=
*
pCompBlock
;
pSCompBlock
->
numOfSubBlocks
++
;
pSCompBlock
->
len
+=
sizeof
(
SCompBlock
);
pIdx
->
len
+=
sizeof
(
SCompBlock
);
}
else
{
// Need to create two sub-blocks
void
*
ptr
=
NULL
;
for
(
int
i
=
blkIdx
-
1
;
i
>=
0
;
i
--
)
{
SCompBlock
*
pTCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
i
;
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
{
ptr
=
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pTCompBlock
->
offset
+
pTCompBlock
->
len
);
break
;
}
}
if
(
ptr
==
NULL
)
ptr
=
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
sizeof
(
SCompInfo
)
+
sizeof
(
SCompBlock
)
*
pIdx
->
numOfSuperBlocks
);
size_t
tsize
=
pIdx
->
len
-
((
char
*
)
ptr
-
(
char
*
)(
pHelper
->
pCompInfo
));
if
(
tsize
>
0
)
{
memmove
((
void
*
)((
char
*
)
ptr
+
sizeof
(
SCompBlock
)
*
2
),
ptr
,
tsize
);
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOfSuperBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
i
;
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
+=
(
sizeof
(
SCompBlock
)
*
2
);
}
}
((
SCompBlock
*
)
ptr
)[
0
]
=
*
pSCompBlock
;
((
SCompBlock
*
)
ptr
)[
0
].
numOfSubBlocks
=
0
;
((
SCompBlock
*
)
ptr
)[
1
]
=
*
pCompBlock
;
pSCompBlock
->
numOfSubBlocks
=
2
;
pSCompBlock
->
numOfPoints
+=
rowsAdded
;
pSCompBlock
->
offset
=
((
char
*
)
ptr
)
-
((
char
*
)
pHelper
->
pCompInfo
);
pSCompBlock
->
len
=
sizeof
(
SCompBlock
)
*
2
;
pSCompBlock
->
keyFirst
=
MIN
(((
SCompBlock
*
)
ptr
)[
0
].
keyFirst
,
((
SCompBlock
*
)
ptr
)[
1
].
keyFirst
);
pSCompBlock
->
keyLast
=
MAX
(((
SCompBlock
*
)
ptr
)[
0
].
keyLast
,
((
SCompBlock
*
)
ptr
)[
1
].
keyLast
);
pIdx
->
len
+=
(
sizeof
(
SCompBlock
)
*
2
);
}
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
last
;
return
0
;
return
0
;
_err:
return
-
1
;
}
}
static
int
tsdbUpdateSuperBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
int
blkIdx
)
{
static
int
tsdbUpdateSuperBlock
(
SRWHelper
*
pHelper
,
SCompBlock
*
pCompBlock
,
int
blkIdx
)
{
// TODO
ASSERT
(
pCompBlock
->
numOfSubBlocks
==
1
);
SCompIdx
*
pIdx
=
pHelper
->
pCompIdx
+
pHelper
->
tableInfo
.
tid
;
ASSERT
(
blkIdx
>=
0
&&
blkIdx
<
pIdx
->
numOfSuperBlocks
);
SCompBlock
*
pSCompBlock
=
pHelper
->
pCompInfo
->
blocks
+
blkIdx
;
ASSERT
(
pSCompBlock
->
numOfSubBlocks
>=
1
);
// Delete the sub blocks it has
if
(
pSCompBlock
->
numOfSubBlocks
>
1
)
{
size_t
tsize
=
pIdx
->
len
-
(
pSCompBlock
->
offset
+
pSCompBlock
->
len
);
if
(
tsize
>
0
)
{
memmove
((
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
),
(
void
*
)((
char
*
)(
pHelper
->
pCompInfo
)
+
pSCompBlock
->
offset
+
pSCompBlock
->
len
),
tsize
);
}
for
(
int
i
=
blkIdx
+
1
;
i
<
pIdx
->
numOfSuperBlocks
;
i
++
)
{
SCompBlock
*
pTCompBlock
=
&
pHelper
->
pCompInfo
->
blocks
[
i
];
if
(
pTCompBlock
->
numOfSubBlocks
>
1
)
pTCompBlock
->
offset
-=
(
sizeof
(
SCompBlock
)
*
pSCompBlock
->
numOfSubBlocks
);
}
pIdx
->
len
-=
(
sizeof
(
SCompBlock
)
*
pSCompBlock
->
numOfSubBlocks
);
}
*
pSCompBlock
=
*
pCompBlock
;
pIdx
->
maxKey
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
keyLast
;
pIdx
->
hasLast
=
pHelper
->
pCompInfo
->
blocks
[
pIdx
->
numOfSuperBlocks
-
1
].
last
;
return
0
;
return
0
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录