Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3074ab65
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看板
提交
3074ab65
编写于
6月 19, 2023
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code
上级
de60e688
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
236 addition
and
1 deletion
+236
-1
source/dnode/vnode/src/tsdb/tsdbRetention.c
source/dnode/vnode/src/tsdb/tsdbRetention.c
+236
-1
未找到文件。
source/dnode/vnode/src/tsdb/tsdbRetention.c
浏览文件 @
3074ab65
...
...
@@ -14,6 +14,7 @@
*/
#include "tsdb.h"
#include "tsdbFS2.h"
static
bool
tsdbShouldDoRetentionImpl
(
STsdb
*
pTsdb
,
int64_t
now
)
{
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
pTsdb
->
fs
.
aDFileSet
);
iSet
++
)
{
...
...
@@ -111,4 +112,238 @@ int32_t tsdbCommitRetention(STsdb *pTsdb) {
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
tsdbInfo
(
"vgId:%d %s done"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
);
return
0
;
}
\ No newline at end of file
}
// new ==============
typedef
struct
{
STsdb
*
tsdb
;
int32_t
szPage
;
int64_t
now
;
int64_t
cid
;
TFileSetArray
*
fsetArr
;
TFileOpArray
*
fopArr
;
struct
{
int32_t
fsetArrIdx
;
STFileSet
*
fset
;
}
ctx
[
1
];
}
SRTXer
;
static
int32_t
tsdbDoRemoveFileObject
(
SRTXer
*
rtxer
,
const
STFileObj
*
fobj
)
{
STFileOp
op
=
{
.
optype
=
TSDB_FOP_REMOVE
,
.
fid
=
fobj
->
f
->
fid
,
.
of
=
fobj
->
f
[
0
],
};
return
TARRAY2_APPEND
(
rtxer
->
fopArr
,
op
);
}
static
int32_t
tsdbDoCopyFile
(
SRTXer
*
rtxer
,
const
STFileObj
*
from
,
const
STFile
*
to
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
char
fname
[
TSDB_FILENAME_LEN
];
TdFilePtr
fdFrom
=
NULL
;
TdFilePtr
fdTo
=
NULL
;
tsdbTFileName
(
rtxer
->
tsdb
,
to
,
fname
);
fdFrom
=
taosOpenFile
(
from
->
fname
,
TD_FILE_READ
);
if
(
fdFrom
==
NULL
)
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
fdTo
=
taosOpenFile
(
fname
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
fdTo
==
NULL
)
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
int64_t
n
=
taosFSendFile
(
fdTo
,
fdFrom
,
0
,
tsdbLogicToFileSize
(
from
->
f
->
size
,
rtxer
->
szPage
));
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
taosCloseFile
(
&
fdFrom
);
taosCloseFile
(
&
fdTo
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
lino
,
code
);
taosCloseFile
(
&
fdFrom
);
taosCloseFile
(
&
fdTo
);
}
return
code
;
}
static
int32_t
tsdbDoMigrateFileObj
(
SRTXer
*
rtxer
,
const
STFileObj
*
fobj
,
const
SDiskID
*
did
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
STFileOp
op
=
{
0
};
// remove old
op
=
(
STFileOp
){
.
optype
=
TSDB_FOP_REMOVE
,
.
fid
=
fobj
->
f
->
fid
,
.
of
=
fobj
->
f
[
0
],
};
code
=
TARRAY2_APPEND
(
rtxer
->
fopArr
,
op
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// create new
op
=
(
STFileOp
){
.
optype
=
TSDB_FOP_CREATE
,
.
fid
=
fobj
->
f
->
fid
,
.
nf
=
{
.
type
=
fobj
->
f
->
type
,
.
did
=
did
[
0
],
.
fid
=
fobj
->
f
->
fid
,
.
cid
=
rtxer
->
cid
,
.
size
=
fobj
->
f
->
size
,
.
stt
[
0
]
=
{
.
level
=
fobj
->
f
->
stt
[
0
].
level
,
},
},
};
code
=
TARRAY2_APPEND
(
rtxer
->
fopArr
,
op
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
// do copy the file
code
=
tsdbDoCopyFile
(
rtxer
,
fobj
,
&
op
.
nf
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
lino
,
code
);
}
return
code
;
}
static
int32_t
tsdbDoRetentionBegin
(
STsdb
*
tsdb
,
SRTXer
*
rtxer
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
// TODO: wait for merge and compact task done
rtxer
->
tsdb
=
tsdb
;
rtxer
->
szPage
=
tsdb
->
pVnode
->
config
.
tsdbPageSize
;
rtxer
->
now
=
taosGetTimestampMs
();
rtxer
->
cid
=
tsdbFSAllocEid
(
tsdb
->
pFS
);
code
=
tsdbFSCreateCopySnapshot
(
tsdb
->
pFS
,
&
rtxer
->
fsetArr
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
lino
,
code
);
}
else
{
tsdbInfo
(
"vid:%d, cid:%"
PRId64
", %s done"
,
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
rtxer
->
cid
,
__func__
);
}
return
code
;
}
static
int32_t
tsdbDoRetentionEnd
(
SRTXer
*
rtxer
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
if
(
TARRAY2_SIZE
(
rtxer
->
fopArr
)
==
0
)
goto
_exit
;
code
=
tsdbFSEditBegin
(
rtxer
->
tsdb
->
pFS
,
rtxer
->
fopArr
,
TSDB_FEDIT_MERGE
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
taosThreadRwlockWrlock
(
&
rtxer
->
tsdb
->
rwLock
);
code
=
tsdbFSEditCommit
(
rtxer
->
tsdb
->
pFS
);
if
(
code
)
{
taosThreadRwlockUnlock
(
&
rtxer
->
tsdb
->
rwLock
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
taosThreadRwlockUnlock
(
&
rtxer
->
tsdb
->
rwLock
);
TARRAY2_DESTROY
(
rtxer
->
fopArr
,
NULL
);
tsdbFSDestroyCopySnapshot
(
&
rtxer
->
fsetArr
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
lino
,
code
);
}
else
{
tsdbInfo
(
"vid:%d, cid:%"
PRId64
", %s done"
,
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
rtxer
->
cid
,
__func__
);
}
return
code
;
}
static
int32_t
tsdbDoRetention2
(
STsdb
*
tsdb
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SRTXer
rtxer
[
1
]
=
{
0
};
code
=
tsdbDoRetentionBegin
(
tsdb
,
rtxer
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
while
(
rtxer
->
ctx
->
fsetArrIdx
<
TARRAY2_SIZE
(
rtxer
->
fsetArr
))
{
rtxer
->
ctx
->
fset
=
TARRAY2_GET
(
rtxer
->
fsetArr
,
rtxer
->
ctx
->
fsetArrIdx
);
STFileObj
*
fobj
;
int32_t
expLevel
=
tsdbFidLevel
(
rtxer
->
ctx
->
fset
->
fid
,
&
rtxer
->
tsdb
->
keepCfg
,
rtxer
->
now
);
if
(
expLevel
<
0
)
{
// remove the file set
for
(
int32_t
ftype
=
0
;
(
ftype
<
TSDB_FTYPE_MAX
)
&&
(
fobj
=
rtxer
->
ctx
->
fset
->
farr
[
ftype
],
1
);
++
ftype
)
{
if
(
fobj
==
NULL
)
continue
;
code
=
tsdbDoRemoveFileObject
(
rtxer
,
fobj
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
SSttLvl
*
lvl
;
TARRAY2_FOREACH
(
rtxer
->
ctx
->
fset
->
lvlArr
,
lvl
)
{
TARRAY2_FOREACH
(
lvl
->
fobjArr
,
fobj
)
{
code
=
tsdbDoRemoveFileObject
(
rtxer
,
fobj
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
}
else
if
(
expLevel
==
0
)
{
continue
;
}
else
{
SDiskID
did
;
if
(
tfsAllocDisk
(
rtxer
->
tsdb
->
pVnode
->
pTfs
,
expLevel
,
&
did
)
<
0
)
{
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// data
for
(
int32_t
ftype
=
0
;
ftype
<
TSDB_FTYPE_MAX
&&
(
fobj
=
rtxer
->
ctx
->
fset
->
farr
[
ftype
],
1
);
++
ftype
)
{
if
(
fobj
==
NULL
)
continue
;
if
(
fobj
->
f
->
did
.
level
==
did
.
level
)
continue
;
code
=
tsdbDoMigrateFileObj
(
rtxer
,
fobj
,
&
did
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
// stt
SSttLvl
*
lvl
;
TARRAY2_FOREACH
(
rtxer
->
ctx
->
fset
->
lvlArr
,
lvl
)
{
TARRAY2_FOREACH
(
lvl
->
fobjArr
,
fobj
)
{
if
(
fobj
->
f
->
did
.
level
==
did
.
level
)
continue
;
code
=
tsdbDoMigrateFileObj
(
rtxer
,
fobj
,
&
did
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
}
}
}
}
code
=
tsdbDoRetentionEnd
(
rtxer
);
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
_exit:
if
(
code
)
{
TSDB_ERROR_LOG
(
TD_VID
(
rtxer
->
tsdb
->
pVnode
),
lino
,
code
);
}
return
code
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录