Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
be1af580
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
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看板
提交
be1af580
编写于
7月 10, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tsdb retention function
上级
8c45b028
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
206 addition
and
45 deletion
+206
-45
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+35
-33
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+8
-0
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+111
-0
source/dnode/vnode/src/tsdb/tsdbRetention.c
source/dnode/vnode/src/tsdb/tsdbRetention.c
+31
-1
source/dnode/vnode/src/tsdb/tsdbUtil.c
source/dnode/vnode/src/tsdb/tsdbUtil.c
+21
-11
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
be1af580
...
@@ -32,39 +32,38 @@ extern "C" {
...
@@ -32,39 +32,38 @@ extern "C" {
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
// clang-format on
typedef
struct
TSDBROW
TSDBROW
;
typedef
struct
TSDBROW
TSDBROW
;
typedef
struct
TABLEID
TABLEID
;
typedef
struct
TABLEID
TABLEID
;
typedef
struct
TSDBKEY
TSDBKEY
;
typedef
struct
TSDBKEY
TSDBKEY
;
typedef
struct
SDelData
SDelData
;
typedef
struct
SDelData
SDelData
;
typedef
struct
SDelIdx
SDelIdx
;
typedef
struct
SDelIdx
SDelIdx
;
typedef
struct
STbData
STbData
;
typedef
struct
STbData
STbData
;
typedef
struct
SMemTable
SMemTable
;
typedef
struct
SMemTable
SMemTable
;
typedef
struct
STbDataIter
STbDataIter
;
typedef
struct
STbDataIter
STbDataIter
;
typedef
struct
STable
STable
;
typedef
struct
STable
STable
;
typedef
struct
SMapData
SMapData
;
typedef
struct
SMapData
SMapData
;
typedef
struct
SBlockIdx
SBlockIdx
;
typedef
struct
SBlockIdx
SBlockIdx
;
typedef
struct
SBlock
SBlock
;
typedef
struct
SBlock
SBlock
;
typedef
struct
SBlockStatis
SBlockStatis
;
typedef
struct
SBlockStatis
SBlockStatis
;
typedef
struct
SAggrBlkCol
SAggrBlkCol
;
typedef
struct
SAggrBlkCol
SAggrBlkCol
;
typedef
struct
SColData
SColData
;
typedef
struct
SColData
SColData
;
typedef
struct
SBlockDataHdr
SBlockDataHdr
;
typedef
struct
SBlockDataHdr
SBlockDataHdr
;
typedef
struct
SBlockData
SBlockData
;
typedef
struct
SBlockData
SBlockData
;
typedef
struct
SDelFile
SDelFile
;
typedef
struct
SDelFile
SDelFile
;
typedef
struct
STsdbCacheFile
STsdbCacheFile
;
typedef
struct
SHeadFile
SHeadFile
;
typedef
struct
SHeadFile
SHeadFile
;
typedef
struct
SDataFile
SDataFile
;
typedef
struct
SDataFile
SDataFile
;
typedef
struct
SLastFile
SLastFile
;
typedef
struct
SLastFile
SLastFile
;
typedef
struct
SSmaFile
SSmaFile
;
typedef
struct
SSmaFile
SSmaFile
;
typedef
struct
SDFileSet
SDFileSet
;
typedef
struct
SDFileSet
SDFileSet
;
typedef
struct
SDataFWriter
SDataFWriter
;
typedef
struct
SDataFWriter
SDataFWriter
;
typedef
struct
SDataFReader
SDataFReader
;
typedef
struct
SDataFReader
SDataFReader
;
typedef
struct
SDelFWriter
SDelFWriter
;
typedef
struct
SDelFWriter
SDelFWriter
;
typedef
struct
SDelFReader
SDelFReader
;
typedef
struct
SDelFReader
SDelFReader
;
typedef
struct
SRowIter
SRowIter
;
typedef
struct
SRowIter
SRowIter
;
typedef
struct
STsdbFS
STsdbFS
;
typedef
struct
STsdbFS
STsdbFS
;
typedef
struct
SRowMerger
SRowMerger
;
typedef
struct
SRowMerger
SRowMerger
;
typedef
struct
STsdbFSState
STsdbFSState
;
typedef
struct
STsdbFSState
STsdbFSState
;
typedef
struct
STsdbSnapHdr
STsdbSnapHdr
;
typedef
struct
STsdbSnapHdr
STsdbSnapHdr
;
#define TSDB_MAX_SUBBLOCKS 8
#define TSDB_MAX_SUBBLOCKS 8
#define TSDB_FHDR_SIZE 512
#define TSDB_FHDR_SIZE 512
...
@@ -163,6 +162,7 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData);
...
@@ -163,6 +162,7 @@ int32_t tGetMapData(uint8_t *p, SMapData *pMapData);
// other
// other
int32_t
tsdbKeyFid
(
TSKEY
key
,
int32_t
minutes
,
int8_t
precision
);
int32_t
tsdbKeyFid
(
TSKEY
key
,
int32_t
minutes
,
int8_t
precision
);
void
tsdbFidKeyRange
(
int32_t
fid
,
int32_t
minutes
,
int8_t
precision
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
);
void
tsdbFidKeyRange
(
int32_t
fid
,
int32_t
minutes
,
int8_t
precision
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
);
int32_t
tsdbFidLevel
(
int32_t
fid
,
STsdbKeepCfg
*
pKeepCfg
,
int64_t
now
);
int32_t
tsdbBuildDeleteSkyline
(
SArray
*
aDelData
,
int32_t
sidx
,
int32_t
eidx
,
SArray
*
aSkyline
);
int32_t
tsdbBuildDeleteSkyline
(
SArray
*
aDelData
,
int32_t
sidx
,
int32_t
eidx
,
SArray
*
aSkyline
);
void
tsdbCalcColDataSMA
(
SColData
*
pColData
,
SColumnDataAgg
*
pColAgg
);
void
tsdbCalcColDataSMA
(
SColData
*
pColData
,
SColumnDataAgg
*
pColAgg
);
// tsdbMemTable ==============================================================================================
// tsdbMemTable ==============================================================================================
...
@@ -200,6 +200,7 @@ int32_t tsdbFSRollback(STsdbFS *pFS);
...
@@ -200,6 +200,7 @@ int32_t tsdbFSRollback(STsdbFS *pFS);
int32_t
tsdbFSStateUpsertDelFile
(
STsdbFSState
*
pState
,
SDelFile
*
pDelFile
);
int32_t
tsdbFSStateUpsertDelFile
(
STsdbFSState
*
pState
,
SDelFile
*
pDelFile
);
int32_t
tsdbFSStateUpsertDFileSet
(
STsdbFSState
*
pState
,
SDFileSet
*
pSet
);
int32_t
tsdbFSStateUpsertDFileSet
(
STsdbFSState
*
pState
,
SDFileSet
*
pSet
);
void
tsdbFSStateDeleteDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
);
SDelFile
*
tsdbFSStateGetDelFile
(
STsdbFSState
*
pState
);
SDelFile
*
tsdbFSStateGetDelFile
(
STsdbFSState
*
pState
);
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
);
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
);
// tsdbReaderWriter.c ==============================================================================================
// tsdbReaderWriter.c ==============================================================================================
...
@@ -213,6 +214,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_
...
@@ -213,6 +214,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, uint8_
SBlockIdx
*
pBlockIdx
,
SBlock
*
pBlock
,
int8_t
cmprAlg
);
SBlockIdx
*
pBlockIdx
,
SBlock
*
pBlock
,
int8_t
cmprAlg
);
SDFileSet
*
tsdbDataFWriterGetWSet
(
SDataFWriter
*
pWriter
);
SDFileSet
*
tsdbDataFWriterGetWSet
(
SDataFWriter
*
pWriter
);
int32_t
tsdbDFileSetCopy
(
STsdb
*
pTsdb
,
SDFileSet
*
pSetFrom
,
SDFileSet
*
pSetTo
);
// SDataFReader
// SDataFReader
int32_t
tsdbDataFReaderOpen
(
SDataFReader
**
ppReader
,
STsdb
*
pTsdb
,
SDFileSet
*
pSet
);
int32_t
tsdbDataFReaderOpen
(
SDataFReader
**
ppReader
,
STsdb
*
pTsdb
,
SDFileSet
*
pSet
);
int32_t
tsdbDataFReaderClose
(
SDataFReader
**
ppReader
);
int32_t
tsdbDataFReaderClose
(
SDataFReader
**
ppReader
);
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
be1af580
...
@@ -688,6 +688,14 @@ _exit:
...
@@ -688,6 +688,14 @@ _exit:
return
code
;
return
code
;
}
}
void
tsdbFSStateDeleteDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
)
{
int32_t
idx
;
idx
=
taosArraySearchIdx
(
pState
->
aDFileSet
,
&
(
SDFileSet
){.
fid
=
fid
},
tDFileSetCmprFn
,
TD_EQ
);
ASSERT
(
idx
>=
0
);
taosArrayRemove
(
pState
->
aDFileSet
,
idx
);
}
SDelFile
*
tsdbFSStateGetDelFile
(
STsdbFSState
*
pState
)
{
return
pState
->
pDelFile
;
}
SDelFile
*
tsdbFSStateGetDelFile
(
STsdbFSState
*
pState
)
{
return
pState
->
pDelFile
;
}
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
)
{
SDFileSet
*
tsdbFSStateGetDFileSet
(
STsdbFSState
*
pState
,
int32_t
fid
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
be1af580
...
@@ -1913,3 +1913,114 @@ _err:
...
@@ -1913,3 +1913,114 @@ _err:
taosArrayDestroy
(
aBlockCol
);
taosArrayDestroy
(
aBlockCol
);
return
code
;
return
code
;
}
}
int32_t
tsdbDFileSetCopy
(
STsdb
*
pTsdb
,
SDFileSet
*
pSetFrom
,
SDFileSet
*
pSetTo
)
{
int32_t
code
=
0
;
int64_t
n
;
int64_t
size
;
TdFilePtr
pOutFD
=
NULL
;
// TODO
TdFilePtr
PInFD
=
NULL
;
// TODO
char
fNameFrom
[
TSDB_FILENAME_LEN
];
char
fNameTo
[
TSDB_FILENAME_LEN
];
// head
tsdbDataFileName
(
pTsdb
,
pSetFrom
,
TSDB_HEAD_FILE
,
fNameFrom
);
tsdbDataFileName
(
pTsdb
,
pSetTo
,
TSDB_HEAD_FILE
,
fNameTo
);
pOutFD
=
taosOpenFile
(
fNameTo
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
pOutFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
PInFD
=
taosOpenFile
(
fNameFrom
,
TD_FILE_READ
);
if
(
PInFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosFSendFile
(
pOutFD
,
PInFD
,
0
,
pSetFrom
->
fHead
.
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pOutFD
);
taosCloseFile
(
&
PInFD
);
// data
tsdbDataFileName
(
pTsdb
,
pSetFrom
,
TSDB_DATA_FILE
,
fNameFrom
);
tsdbDataFileName
(
pTsdb
,
pSetTo
,
TSDB_DATA_FILE
,
fNameTo
);
pOutFD
=
taosOpenFile
(
fNameTo
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
pOutFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
PInFD
=
taosOpenFile
(
fNameFrom
,
TD_FILE_READ
);
if
(
PInFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosFSendFile
(
pOutFD
,
PInFD
,
0
,
pSetFrom
->
fData
.
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pOutFD
);
taosCloseFile
(
&
PInFD
);
// last
tsdbDataFileName
(
pTsdb
,
pSetFrom
,
TSDB_LAST_FILE
,
fNameFrom
);
tsdbDataFileName
(
pTsdb
,
pSetTo
,
TSDB_LAST_FILE
,
fNameTo
);
pOutFD
=
taosOpenFile
(
fNameTo
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
pOutFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
PInFD
=
taosOpenFile
(
fNameFrom
,
TD_FILE_READ
);
if
(
PInFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosFSendFile
(
pOutFD
,
PInFD
,
0
,
pSetFrom
->
fLast
.
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pOutFD
);
taosCloseFile
(
&
PInFD
);
// sma
tsdbDataFileName
(
pTsdb
,
pSetFrom
,
TSDB_SMA_FILE
,
fNameFrom
);
tsdbDataFileName
(
pTsdb
,
pSetTo
,
TSDB_SMA_FILE
,
fNameTo
);
pOutFD
=
taosOpenFile
(
fNameTo
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
pOutFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
PInFD
=
taosOpenFile
(
fNameFrom
,
TD_FILE_READ
);
if
(
PInFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
n
=
taosFSendFile
(
pOutFD
,
PInFD
,
0
,
pSetFrom
->
fSma
.
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
taosCloseFile
(
&
pOutFD
);
taosCloseFile
(
&
PInFD
);
return
code
;
_err:
tsdbError
(
"vgId:%d tsdb DFileSet copy failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbRetention.c
浏览文件 @
be1af580
...
@@ -25,8 +25,37 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) {
...
@@ -25,8 +25,37 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) {
// do retention
// do retention
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
pTsdb
->
fs
->
nState
->
aDFileSet
);
iSet
++
)
{
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
pTsdb
->
fs
->
nState
->
aDFileSet
);
iSet
++
)
{
SDFileSet
*
pDFileSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
->
nState
->
aDFileSet
,
iSet
);
SDFileSet
*
pDFileSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
->
nState
->
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pDFileSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
);
SDiskID
did
;
// TODO
// check
if
(
expLevel
==
pDFileSet
->
fid
)
continue
;
if
(
expLevel
<
0
)
{
tsdbFSStateDeleteDFileSet
(
pTsdb
->
fs
->
nState
,
pDFileSet
->
fid
);
iSet
--
;
// tsdbInfo("vgId:%d file is out of data, remove it", td);
}
else
{
// alloc
if
(
tfsAllocDisk
(
pTsdb
->
pVnode
->
pTfs
,
expLevel
,
&
did
)
<
0
)
{
code
=
terrno
;
goto
_err
;
}
if
(
did
.
level
==
pDFileSet
->
diskId
.
level
)
continue
;
ASSERT
(
did
.
level
>
pDFileSet
->
diskId
.
level
);
// copy the file to new disk
SDFileSet
nDFileSet
=
*
pDFileSet
;
nDFileSet
.
diskId
=
did
;
code
=
tsdbDFileSetCopy
(
pTsdb
,
pDFileSet
,
&
nDFileSet
);
if
(
code
)
goto
_err
;
code
=
tsdbFSStateUpsertDFileSet
(
pTsdb
->
fs
->
nState
,
&
nDFileSet
);
if
(
code
)
goto
_err
;
}
}
}
// commit
// commit
...
@@ -38,5 +67,6 @@ _exit:
...
@@ -38,5 +67,6 @@ _exit:
_err:
_err:
tsdbError
(
"vgId:%d tsdb do retention failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d tsdb do retention failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbFSRollback
(
pTsdb
->
fs
);
return
code
;
return
code
;
}
}
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbUtil.c
浏览文件 @
be1af580
...
@@ -465,17 +465,27 @@ void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minK
...
@@ -465,17 +465,27 @@ void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minK
*
maxKey
=
*
minKey
+
minutes
*
tsTickPerMin
[
precision
]
-
1
;
*
maxKey
=
*
minKey
+
minutes
*
tsTickPerMin
[
precision
]
-
1
;
}
}
// int tsdFidLevel(int fid, TSKEY now, minute) {
int32_t
tsdbFidLevel
(
int32_t
fid
,
STsdbKeepCfg
*
pKeepCfg
,
int64_t
now
)
{
// if (fid >= pRtn->maxFid) {
int32_t
aFid
[
3
];
// return 0;
TSKEY
key
;
// } else if (fid >= pRtn->midFid) {
// return 1;
key
=
now
-
pKeepCfg
->
keep0
*
tsTickPerMin
[
pKeepCfg
->
precision
];
// } else if (fid >= pRtn->minFid) {
aFid
[
0
]
=
tsdbKeyFid
(
key
,
pKeepCfg
->
days
,
pKeepCfg
->
keep0
);
// return 2;
key
=
now
-
pKeepCfg
->
keep1
*
tsTickPerMin
[
pKeepCfg
->
precision
];
// } else {
aFid
[
1
]
=
tsdbKeyFid
(
key
,
pKeepCfg
->
days
,
pKeepCfg
->
keep1
);
// return -1;
key
=
now
-
pKeepCfg
->
keep2
*
tsTickPerMin
[
pKeepCfg
->
precision
];
// }
aFid
[
2
]
=
tsdbKeyFid
(
key
,
pKeepCfg
->
days
,
pKeepCfg
->
keep2
);
// }
if
(
fid
>=
aFid
[
0
])
{
return
0
;
}
else
if
(
fid
>=
aFid
[
1
])
{
return
1
;
}
else
if
(
fid
>=
aFid
[
2
])
{
return
2
;
}
else
{
return
-
1
;
}
}
// TSDBROW ======================================================
// TSDBROW ======================================================
void
tsdbRowGetColVal
(
TSDBROW
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
)
{
void
tsdbRowGetColVal
(
TSDBROW
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录