Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
44721767
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看板
提交
44721767
编写于
1月 15, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more refact
上级
dc2d5541
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
135 deletion
+40
-135
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+40
-135
未找到文件。
src/tsdb/src/tsdbCommit.c
浏览文件 @
44721767
...
...
@@ -604,182 +604,90 @@ static int tsdbCommitToTable(SCommitH *pCommith, int tid) {
SCommitIter
*
pIter
=
pCommith
->
iters
+
tid
;
TSKEY
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
tsdbResetCommitTable
(
pCommith
);
TSDB_RLOCK_TABLE
(
pIter
->
pTable
);
// Set commit table
tsdbResetCommitTable
(
pCommith
);
if
(
tsdbSetCommitTable
(
pCommith
,
pIter
->
pTable
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
// No disk data and no memory data, just return
if
(
pCommith
->
readh
.
pBlkIdx
==
NULL
&&
(
nextKey
==
TSDB_DATA_TIMESTAMP_NULL
||
nextKey
>
pCommith
->
maxKey
))
{
// No disk data and no memory data
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
0
;
}
else
{
// Must has disk data, maybe has memory data
int
nBlocks
;
int
bidx
=
0
;
SBlock
*
pBlock
;
if
(
pCommith
->
readh
.
pBlkIdx
)
{
if
(
tsdbLoadBlockInfo
(
&
(
pCommith
->
readh
),
NULL
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
nBlocks
=
pCommith
->
readh
.
pBlkIdx
->
numOfBlocks
;
}
else
{
nBlocks
=
0
;
}
if
(
bidx
<
nBlocks
)
{
pBlock
=
pCommith
->
readh
.
pBlkInfo
->
blocks
+
bidx
;
}
else
{
pBlock
=
NULL
;
}
while
(
true
)
{
if
(
pBlock
==
NULL
&&
(
nextKey
==
TSDB_DATA_TIMESTAMP_NULL
||
nextKey
>
pCommith
->
maxKey
))
break
;
if
((
nextKey
==
TSDB_DATA_TIMESTAMP_NULL
||
nextKey
>
pCommith
->
maxKey
)
||
(
pBlock
&&
(
!
pBlock
->
last
)
&&
tsdbComparKeyBlock
((
void
*
)(
&
nextKey
),
pBlock
)
>
0
))
{
if
(
tsdbMoveBlock
(
pCommith
,
bidx
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
bidx
++
;
if
(
bidx
<
nBlocks
)
{
pBlock
=
pCommith
->
readh
.
pBlkInfo
->
blocks
+
bidx
;
}
else
{
pBlock
=
NULL
;
}
}
else
if
(
pBlock
&&
(
pBlock
->
last
||
tsdbComparKeyBlock
((
void
*
)(
&
nextKey
),
pBlock
)
==
0
))
{
// merge pBlock data and memory data
if
(
tsdbMergeMemData
(
pCommith
,
pIter
,
bidx
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
bidx
++
;
if
(
bidx
<
nBlocks
)
{
pBlock
=
pCommith
->
readh
.
pBlkInfo
->
blocks
+
bidx
;
}
else
{
pBlock
=
NULL
;
}
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
}
else
{
// Only commit memory data
if
(
pBlock
==
NULL
)
{
if
(
tsdbCommitMemData
(
pCommith
,
pIter
,
pCommith
->
maxKey
,
false
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
}
else
{
if
(
tsdbCommitMemData
(
pCommith
,
pIter
,
pBlock
->
keyFirst
-
1
,
true
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
}
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
}
}
}
#if 0
if (!pCommith->isRFileSet) {
if (pIter->pIter == NULL) {
// No memory data
TSDB_RUNLOCK_TABLE(pIter->pTable);
return 0;
} else {
// TODO: think about no data committed at all
if (tsdbCommitMemData(pCommith, pIter, pCommith->maxKey, true) < 0) {
TSDB_RUNLOCK_TABLE(pIter->pTable);
return -1;
}
// Must has disk data or has memory data
int
nBlocks
;
int
bidx
=
0
;
SBlock
*
pBlock
;
if
(
pCommith
->
readh
.
pBlkIdx
)
{
if
(
tsdbLoadBlockInfo
(
&
(
pCommith
->
readh
),
NULL
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
if (tsdbWriteBlockInfo(pCommith) < 0) {
return -1;
}
return 0;
return
-
1
;
}
}
// No memory data and no disk data, just return
if (pIter->pIter == NULL && pCommith->readh.pBlkIdx == NULL) {
TSDB_RUNLOCK_TABLE(pIter->pTable);
return 0;
}
if (tsdbLoadBlockInfo(&(pCommith->readh), NULL) < 0) {
TSDB_RUNLOCK_TABLE(pIter->pTable);
return -1;
nBlocks
=
pCommith
->
readh
.
pBlkIdx
->
numOfBlocks
;
}
else
{
nBlocks
=
0
;
}
// Process merge commit
int nBlocks = (pCommith->readh.pBlkIdx == NULL) ? 0 : pCommith->readh.pBlkIdx->numOfBlocks;
TSKEY nextKey = tsdbNextIterKey(pIter->pIter);
int cidx = 0;
void * ptr = NULL;
SBlock *pBlock;
if (cidx < nBlocks) {
pBlock = pCommith->readh.pBlkInfo->blocks + cidx;
if
(
bidx
<
nBlocks
)
{
pBlock
=
pCommith
->
readh
.
pBlkInfo
->
blocks
+
bidx
;
}
else
{
pBlock
=
NULL
;
}
while
(
true
)
{
if (
(nextKey == TSDB_DATA_TIMESTAMP_NULL || nextKey > pCommith->maxKey) && (pBlock == NULL
)) break;
if
(
pBlock
==
NULL
&&
(
nextKey
==
TSDB_DATA_TIMESTAMP_NULL
||
nextKey
>
pCommith
->
maxKey
))
break
;
if
((
nextKey
==
TSDB_DATA_TIMESTAMP_NULL
||
nextKey
>
pCommith
->
maxKey
)
||
(
pBlock
&&
(
!
pBlock
->
last
)
&&
tsdbComparKeyBlock
((
void
*
)(
&
nextKey
),
pBlock
)
>
0
))
{
if (tsdbMoveBlock(pCommith,
c
idx) < 0) {
if
(
tsdbMoveBlock
(
pCommith
,
b
idx
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
c
idx++;
if (
c
idx < nBlocks) {
pBlock = pCommith->readh.pBlkInfo->blocks +
c
idx;
b
idx
++
;
if
(
b
idx
<
nBlocks
)
{
pBlock
=
pCommith
->
readh
.
pBlkInfo
->
blocks
+
b
idx
;
}
else
{
pBlock
=
NULL
;
}
} else if ((cidx < nBlocks) && (pBlock->last || tsdbComparKeyBlock((void *)(&nextKey), pBlock) == 0)) {
if (tsdbMergeMemData(pCommith, pIter, cidx) < 0) {
}
else
if
(
pBlock
&&
(
pBlock
->
last
||
tsdbComparKeyBlock
((
void
*
)(
&
nextKey
),
pBlock
)
==
0
))
{
// merge pBlock data and memory data
if
(
tsdbMergeMemData
(
pCommith
,
pIter
,
bidx
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
c
idx++;
if (
c
idx < nBlocks) {
pBlock = pCommith->readh.pBlkInfo->blocks +
c
idx;
b
idx
++
;
if
(
b
idx
<
nBlocks
)
{
pBlock
=
pCommith
->
readh
.
pBlkInfo
->
blocks
+
b
idx
;
}
else
{
pBlock
=
NULL
;
}
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
}
else
{
// Only commit memory data
if
(
pBlock
==
NULL
)
{
if
(
tsdbCommitMemData
(
pCommith
,
pIter
,
pCommith
->
maxKey
,
false
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
nextKey = tsdbNextIterKey(pIter->pIter);
}
else
{
if
(
tsdbCommitMemData
(
pCommith
,
pIter
,
pBlock
->
keyFirst
-
1
,
true
)
<
0
)
{
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
return
-
1
;
}
nextKey = tsdbNextIterKey(pIter->pIter);
}
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
}
}
#endif
TSDB_RUNLOCK_TABLE
(
pIter
->
pTable
);
...
...
@@ -961,8 +869,7 @@ static int tsdbWriteBlock(SCommitH *pCommith, SDFile *pDFile, SDataCols *pDataCo
}
static
int
tsdbWriteBlockInfo
(
SCommitH
*
pCommih
)
{
SDFile
*
pHeadf
=
TSDB_COMMIT_HEAD_FILE
(
pCommih
);
SDFile
*
pHeadf
=
TSDB_COMMIT_HEAD_FILE
(
pCommih
);
SBlockIdx
blkIdx
;
STable
*
pTable
=
TSDB_COMMIT_TABLE
(
pCommih
);
SBlock
*
pBlock
;
...
...
@@ -974,9 +881,13 @@ static int tsdbWriteBlockInfo(SCommitH *pCommih) {
nSupBlocks
=
taosArrayGetSize
(
pCommih
->
aSupBlk
);
nSubBlocks
=
taosArrayGetSize
(
pCommih
->
aSubBlk
);
tlen
=
sizeof
(
SBlockInfo
)
+
sizeof
(
SBlock
)
*
(
nSupBlocks
+
nSubBlocks
)
+
sizeof
(
TSCKSUM
);
ASSERT
(
nSupBlocks
>
0
);
if
(
nSupBlocks
<=
0
)
{
// No data (data all deleted)
return
0
;
}
tlen
=
sizeof
(
SBlockInfo
)
+
sizeof
(
SBlock
)
*
(
nSupBlocks
+
nSubBlocks
)
+
sizeof
(
TSCKSUM
);
// Write SBlockInfo part
if
(
tsdbMakeRoom
((
void
**
)(
&
(
TSDB_COMMIT_BUF
(
pCommih
))),
tlen
)
<
0
)
return
-
1
;
...
...
@@ -1001,16 +912,7 @@ static int tsdbWriteBlockInfo(SCommitH *pCommih) {
taosCalcChecksumAppend
(
0
,
(
uint8_t
*
)
pBlkInfo
,
tlen
);
offset
=
tsdbSeekDFile
(
pHeadf
,
0
,
SEEK_END
);
if
(
offset
<
0
)
{
tsdbError
(
"vgId:%d failed to write block info part to file %s while seek since %s"
,
TSDB_COMMIT_REPO_ID
(
pCommih
),
TSDB_FILE_FULL_NAME
(
pHeadf
),
tstrerror
(
terrno
));
return
-
1
;
}
if
(
tsdbWriteDFile
(
pHeadf
,
TSDB_COMMIT_BUF
(
pCommih
),
tlen
)
<
tlen
)
{
tsdbError
(
"vgId:%d failed to write block info part to file %s since %s"
,
TSDB_COMMIT_REPO_ID
(
pCommih
),
TSDB_FILE_FULL_NAME
(
pHeadf
),
tstrerror
(
terrno
));
if
(
tsdbAppendDFile
(
pHeadf
,
TSDB_COMMIT_BUF
(
pCommih
),
tlen
,
&
offset
)
<
0
)
{
return
-
1
;
}
...
...
@@ -1044,7 +946,10 @@ static int tsdbWriteBlockIdx(SCommitH *pCommih) {
int
tlen
=
0
,
size
;
int64_t
offset
;
ASSERT
(
nidx
>
0
);
if
(
nidx
<=
0
)
{
// All data are deleted
return
0
;
}
for
(
size_t
i
=
0
;
i
<
nidx
;
i
++
)
{
pBlkIdx
=
(
SBlockIdx
*
)
taosArrayGet
(
pCommih
->
aBlkIdx
,
i
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录