Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0841442d
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看板
提交
0841442d
编写于
9月 28, 2022
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: logic optimization for data migration
上级
27799576
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
24 deletion
+54
-24
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+1
-3
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+18
-6
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+11
-7
source/dnode/vnode/src/tsdb/tsdbRetention.c
source/dnode/vnode/src/tsdb/tsdbRetention.c
+24
-8
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
0841442d
...
...
@@ -322,6 +322,7 @@ int32_t tsdbCacheLastArray2Row(SArray *pLastArray, STSRow **ppRow, STSchema *pSc
// structs =======================
struct
STsdbFS
{
int64_t
version
;
SDelFile
*
pDelFile
;
SArray
*
aDFileSet
;
// SArray<SDFileSet>
};
...
...
@@ -575,9 +576,6 @@ struct SDFileSet {
SSttFile
*
aSttF
[
TSDB_MAX_STT_TRIGGER
];
};
#define SET_DFSET_EXPIRED(d) ((d)->diskId.id = -1)
#define IS_DFSET_EXPIRED(d) ((d)->diskId.id == -1)
struct
SRowIter
{
TSDBROW
*
pRow
;
STSchema
*
pTSchema
;
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
0841442d
...
...
@@ -988,21 +988,33 @@ static int32_t tsdbEndCommit(SCommitter *pCommitter, int32_t eno) {
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pCommitter
->
pTsdb
;
SMemTable
*
pMemTable
=
pTsdb
->
imem
;
bool
inTrim
=
atomic_load_8
(
&
pTsdb
->
pVnode
->
trimDbH
.
state
)
;
STsdbFS
fsLatest
=
{
0
}
;
ASSERT
(
eno
==
0
);
if
(
inTrim
)
taosThreadRwlockWrlock
(
&
pTsdb
->
rwLock
);
// lock
taosThreadRwlockWrlock
(
&
pTsdb
->
rwLock
);
ASSERT
(
pCommitter
->
fs
.
version
<=
pTsdb
->
fs
.
version
);
if
(
pCommitter
->
fs
.
version
<
pTsdb
->
fs
.
version
)
{
if
((
code
=
tsdbFSCopy
(
pTsdb
,
&
fsLatest
)))
{
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
goto
_err
;
}
if
((
code
=
tsdbFSUpdDel
(
pTsdb
,
&
pCommitter
->
fs
,
&
fsLatest
,
pTsdb
->
trimHdl
.
minCommitFid
-
1
)))
{
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
goto
_err
;
}
}
code
=
tsdbFSCommit1
(
pTsdb
,
&
pCommitter
->
fs
);
if
(
code
)
{
if
(
inTrim
)
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
goto
_err
;
}
// lock
if
(
!
inTrim
)
taosThreadRwlockWrlock
(
&
pTsdb
->
rwLock
);
// commit or rollback
code
=
tsdbFSCommit2
(
pTsdb
,
&
pCommitter
->
fs
);
if
(
code
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
0841442d
...
...
@@ -419,6 +419,7 @@ int32_t tsdbFSOpen(STsdb *pTsdb) {
int32_t
code
=
0
;
// open handle
pTsdb
->
fs
.
version
=
0
;
pTsdb
->
fs
.
pDelFile
=
NULL
;
pTsdb
->
fs
.
aDFileSet
=
taosArrayInit
(
0
,
sizeof
(
SDFileSet
));
if
(
pTsdb
->
fs
.
aDFileSet
==
NULL
)
{
...
...
@@ -534,6 +535,7 @@ int32_t tsdbFSClose(STsdb *pTsdb) {
int32_t
tsdbFSCopy
(
STsdb
*
pTsdb
,
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
pFS
->
version
=
pTsdb
->
fs
.
version
;
pFS
->
pDelFile
=
NULL
;
pFS
->
aDFileSet
=
taosArrayInit
(
taosArrayGetSize
(
pTsdb
->
fs
.
aDFileSet
),
sizeof
(
SDFileSet
));
if
(
pFS
->
aDFileSet
==
NULL
)
{
...
...
@@ -746,12 +748,12 @@ int32_t tsdbFSUpdDel(STsdb *pTsdb, STsdbFS *pFS, STsdbFS *pFSNew, int32_t maxFid
if
(
pSetOld
&&
pSetNew
)
{
if
(
pSetOld
->
fid
==
pSetNew
->
fid
)
{
if
(
IS_DFSET_EXPIRED
(
pSetNew
))
goto
_remove_old
;
goto
_merge_migrate
;
}
else
if
(
pSetOld
->
fid
<
pSetNew
->
fid
)
{
++
iO
ld
;
}
else
if
(
pSetOld
->
fid
>
pSetNew
->
fid
)
{
goto
_remove_o
ld
;
}
else
{
++
iNew
;
++
iOld
;
ASSERT
(
0
);
}
continue
;
}
else
{
...
...
@@ -794,8 +796,8 @@ int32_t tsdbFSUpdDel(STsdb *pTsdb, STsdbFS *pFS, STsdbFS *pFSNew, int32_t maxFid
pSetOld
->
diskId
=
pSetNew
->
diskId
;
}
iOld
++
;
iNew
++
;
++
iOld
;
++
iNew
;
continue
;
_remove_old:
...
...
@@ -806,7 +808,7 @@ int32_t tsdbFSUpdDel(STsdb *pTsdb, STsdbFS *pFS, STsdbFS *pFSNew, int32_t maxFid
}
taosMemoryFree
(
pSetOld
->
pSmaF
);
taosArrayRemove
(
pFS
->
aDFileSet
,
iOld
);
iNew
++
;
++
iNew
;
continue
;
}
...
...
@@ -850,6 +852,8 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
int32_t
nRef
;
char
fname
[
TSDB_FILENAME_LEN
];
++
pTsdb
->
fs
.
version
;
// del
if
(
pFSNew
->
pDelFile
)
{
SDelFile
*
pDelFile
=
pTsdb
->
fs
.
pDelFile
;
...
...
source/dnode/vnode/src/tsdb/tsdbRetention.c
浏览文件 @
0841442d
...
...
@@ -17,7 +17,7 @@
enum
{
RETENTION_NO
=
0
,
RETENTION_EXPIRED
=
1
,
RETENTION_MIGRATE
=
2
};
#define MIGRATE_MAX_SPEED (1048576 <<
5) // 32 MB
#define MIGRATE_MAX_SPEED (1048576 <<
4) // 16 MB, vnode level
#define MIGRATE_MIN_COST (5) // second
static
bool
tsdbShouldDoMigrate
(
STsdb
*
pTsdb
);
...
...
@@ -105,8 +105,8 @@ _retention_loop:
code
=
tsdbFSCopy
(
pTsdb
,
&
fs
);
if
(
code
)
goto
_exit
;
int32_t
fsSize
=
taosArrayGetSize
(
fs
.
aDFileSet
);
if
(
type
==
RETENTION_MIGRATE
)
{
int32_t
fsSize
=
taosArrayGetSize
(
fs
.
aDFileSet
);
for
(
int32_t
iSet
=
0
;
iSet
<
fsSize
;
++
iSet
)
{
SDFileSet
*
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
fs
.
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
);
...
...
@@ -119,26 +119,35 @@ _retention_loop:
maxFid
=
pSet
->
fid
;
fSize
+=
(
pSet
->
pDataF
->
size
+
pSet
->
pHeadF
->
size
+
pSet
->
pSmaF
->
size
);
if
(
fSize
/
speed
>
MIGRATE_MIN_COST
)
{
tsdbDebug
(
"vgId:%d migrate loop %d with maxFid:%d"
,
TD_VID
(
pTsdb
->
pVnode
),
nBatch
,
maxFid
);
break
;
}
for
(
int32_t
iStt
=
0
;
iStt
<
pSet
->
nSttF
;
++
iStt
)
{
fSize
+=
pSet
->
aSttF
[
iStt
]
->
size
;
}
if
(
fSize
/
speed
>
MIGRATE_MIN_COST
)
{
tsdbDebug
(
"vgId:%d migrate loop
[%d]
with maxFid:%d"
,
TD_VID
(
pTsdb
->
pVnode
),
nBatch
,
maxFid
);
tsdbDebug
(
"vgId:%d migrate loop
%d
with maxFid:%d"
,
TD_VID
(
pTsdb
->
pVnode
),
nBatch
,
maxFid
);
break
;
}
}
}
}
else
if
(
type
==
RETENTION_EXPIRED
)
{
for
(
int32_t
iSet
=
0
;
iSet
<
fsSize
;
++
iSet
)
{
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
fs
.
aDFileSet
)
;
++
iSet
)
{
SDFileSet
*
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
fs
.
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
);
SDiskID
did
;
if
(
expLevel
<
0
)
{
SET_DFSET_EXPIRED
(
pSet
);
ASSERT
(
pSet
->
fid
>
maxFid
);
if
(
pSet
->
fid
>
maxFid
)
maxFid
=
pSet
->
fid
;
taosMemoryFree
(
pSet
->
pHeadF
);
taosMemoryFree
(
pSet
->
pDataF
);
taosMemoryFree
(
pSet
->
pSmaF
);
for
(
int32_t
iStt
=
0
;
iStt
<
pSet
->
nSttF
;
++
iStt
)
{
taosMemoryFree
(
pSet
->
aSttF
[
iStt
]);
}
taosArrayRemove
(
fs
.
aDFileSet
,
iSet
);
--
iSet
;
}
else
{
break
;
}
...
...
@@ -167,18 +176,25 @@ _commit_conflict_check:
// migrate
if
(
type
==
RETENTION_MIGRATE
)
{
for
(
int32_t
iSet
=
0
;
iSet
<
fsSize
;
++
iSet
)
{
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
fs
.
aDFileSet
)
;
++
iSet
)
{
SDFileSet
*
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
fs
.
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
);
SDiskID
did
;
if
(
pSet
->
fid
>
maxFid
)
break
;
tsdbDebug
(
"vgId:%d migrate loop
[%d]
with maxFid:%d, fid:%d, did:%d, level:%d, expLevel:%d"
,
TD_VID
(
pTsdb
->
pVnode
),
tsdbDebug
(
"vgId:%d migrate loop
%d
with maxFid:%d, fid:%d, did:%d, level:%d, expLevel:%d"
,
TD_VID
(
pTsdb
->
pVnode
),
nBatch
,
maxFid
,
pSet
->
fid
,
pSet
->
diskId
.
id
,
pSet
->
diskId
.
level
,
expLevel
);
if
(
expLevel
<
0
)
{
SET_DFSET_EXPIRED
(
pSet
);
taosMemoryFree
(
pSet
->
pHeadF
);
taosMemoryFree
(
pSet
->
pDataF
);
taosMemoryFree
(
pSet
->
pSmaF
);
for
(
int32_t
iStt
=
0
;
iStt
<
pSet
->
nSttF
;
++
iStt
)
{
taosMemoryFree
(
pSet
->
aSttF
[
iStt
]);
}
taosArrayRemove
(
fs
.
aDFileSet
,
iSet
);
--
iSet
;
}
else
{
if
(
expLevel
==
pSet
->
diskId
.
level
)
continue
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录