Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
274d310f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
274d310f
编写于
9月 19, 2022
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: retention should not block data commit
上级
bd3db36a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
262 addition
and
6 deletion
+262
-6
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+1
-1
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+5
-0
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbRetention.c
source/dnode/vnode/src/tsdb/tsdbRetention.c
+21
-3
source/dnode/vnode/src/tsdb/tsdbRetention2.c
source/dnode/vnode/src/tsdb/tsdbRetention2.c
+140
-0
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+12
-0
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+82
-1
未找到文件。
source/dnode/vnode/CMakeLists.txt
浏览文件 @
274d310f
...
...
@@ -49,7 +49,7 @@ target_sources(
"src/tsdb/tsdbUtil.c"
"src/tsdb/tsdbSnapshot.c"
"src/tsdb/tsdbCacheRead.c"
"src/tsdb/tsdbRetention.c"
"src/tsdb/tsdbRetention
2
.c"
"src/tsdb/tsdbDiskData.c"
"src/tsdb/tsdbCompress.c"
"src/tsdb/tsdbCompact.c"
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
274d310f
...
...
@@ -58,6 +58,7 @@ typedef struct STQ STQ;
typedef
struct
SVState
SVState
;
typedef
struct
SVBufPool
SVBufPool
;
typedef
struct
SQWorker
SQHandle
;
typedef
struct
STrimDbHandle
STrimDbHandle
;
typedef
struct
STsdbKeepCfg
STsdbKeepCfg
;
typedef
struct
SMetaSnapReader
SMetaSnapReader
;
typedef
struct
SMetaSnapWriter
SMetaSnapWriter
;
...
...
@@ -301,6 +302,9 @@ struct STsdbKeepCfg {
int32_t
keep1
;
int32_t
keep2
;
};
struct
STrimDbHandle
{
volatile
int8_t
state
;
// 0 not in trim, 1 in trim
};
struct
SVnode
{
char
*
path
;
...
...
@@ -325,6 +329,7 @@ struct SVnode {
bool
restored
;
tsem_t
syncSem
;
SQHandle
*
pQuery
;
STrimDbHandle
trimDbH
;
};
#define TD_VID(PVNODE) ((PVNODE)->config.vgId)
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
274d310f
...
...
@@ -1045,7 +1045,7 @@ _err:
return
code
;
}
int32_t
tsdbFSRef
(
STsdb
*
pTsdb
,
STsdbFS
*
pFS
)
{
int32_t
tsdbFSRef
(
STsdb
*
pTsdb
,
STsdbFS
*
pFS
)
{
int32_t
code
=
0
;
int32_t
nRef
;
...
...
source/dnode/vnode/src/tsdb/tsdbRetention.c
浏览文件 @
274d310f
...
...
@@ -16,10 +16,28 @@
#include "tsdb.h"
static
bool
tsdbShouldDoRetention
(
STsdb
*
pTsdb
,
int64_t
now
)
{
if
(
taosArrayGetSize
(
pTsdb
->
fs
.
aDFileSet
)
==
0
)
{
return
false
;
}
SDFileSet
*
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
.
aDFileSet
,
0
);
if
(
tsdbFidLevel
(
pSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
)
<
0
)
{
return
true
;
}
if
(
tfsGetLevel
(
pTsdb
->
pVnode
->
pTfs
)
<
2
)
{
return
false
;
}
STsdbKeepCfg
*
keepCfg
=
&
pTsdb
->
keepCfg
;
if
(
keepCfg
->
keep0
==
keepCfg
->
keep1
&&
keepCfg
->
keep1
==
keepCfg
->
keep2
)
{
return
false
;
}
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
pTsdb
->
fs
.
aDFileSet
);
iSet
++
)
{
SDFileSet
*
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
.
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
);
SDiskID
did
;
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
.
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pSet
->
fid
,
keepCfg
,
now
);
SDiskID
did
;
if
(
expLevel
==
pSet
->
diskId
.
level
)
continue
;
...
...
source/dnode/vnode/src/tsdb/tsdbRetention2.c
0 → 100644
浏览文件 @
274d310f
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tsdb.h"
static
bool
tsdbShouldDoRetention
(
STsdb
*
pTsdb
,
int64_t
now
)
{
if
(
taosArrayGetSize
(
pTsdb
->
fs
.
aDFileSet
)
==
0
)
{
return
false
;
}
SDFileSet
*
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
.
aDFileSet
,
0
);
if
(
tsdbFidLevel
(
pSet
->
fid
,
&
pTsdb
->
keepCfg
,
now
)
<
0
)
{
return
true
;
}
if
(
tfsGetLevel
(
pTsdb
->
pVnode
->
pTfs
)
<
2
)
{
return
false
;
}
STsdbKeepCfg
*
keepCfg
=
&
pTsdb
->
keepCfg
;
if
(
keepCfg
->
keep0
==
keepCfg
->
keep1
&&
keepCfg
->
keep1
==
keepCfg
->
keep2
)
{
return
false
;
}
for
(
int32_t
iSet
=
0
;
iSet
<
taosArrayGetSize
(
pTsdb
->
fs
.
aDFileSet
);
iSet
++
)
{
pSet
=
(
SDFileSet
*
)
taosArrayGet
(
pTsdb
->
fs
.
aDFileSet
,
iSet
);
int32_t
expLevel
=
tsdbFidLevel
(
pSet
->
fid
,
keepCfg
,
now
);
SDiskID
did
;
if
(
expLevel
==
pSet
->
diskId
.
level
)
continue
;
if
(
expLevel
<
0
)
{
return
true
;
}
else
{
if
(
tfsAllocDisk
(
pTsdb
->
pVnode
->
pTfs
,
expLevel
,
&
did
)
<
0
)
{
return
false
;
}
if
(
did
.
level
==
pSet
->
diskId
.
level
)
continue
;
return
true
;
}
}
return
false
;
}
/**
* @brief Data migration between multi-tier storage, including remove expired data.
* 1) firstly, remove expired DFileSet;
* 2) partition the tsdbFS by the expLevel and fileSize(e.g. 500G, configurable), and migrate DFileSet groups between multi-tier storage;
* 3) update the tsdbFS and CURRENT in the same transaction;
* 4) finish
* @param pTsdb
* @param now
* @return int32_t
*/
int32_t
tsdbDoRetention
(
STsdb
*
pTsdb
,
int64_t
now
)
{
int32_t
code
=
0
;
if
(
!
tsdbShouldDoRetention
(
pTsdb
,
now
))
{
return
code
;
}
// do retention
STsdbFS
fs
;
code
=
tsdbFSCopy
(
pTsdb
,
&
fs
);
if
(
code
)
goto
_err
;
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
)
{
taosMemoryFree
(
pSet
->
pHeadF
);
taosMemoryFree
(
pSet
->
pDataF
);
taosMemoryFree
(
pSet
->
aSttF
[
0
]);
taosMemoryFree
(
pSet
->
pSmaF
);
taosArrayRemove
(
fs
.
aDFileSet
,
iSet
);
iSet
--
;
}
else
{
if
(
expLevel
==
0
)
continue
;
if
(
tfsAllocDisk
(
pTsdb
->
pVnode
->
pTfs
,
expLevel
,
&
did
)
<
0
)
{
code
=
terrno
;
goto
_exit
;
}
if
(
did
.
level
==
pSet
->
diskId
.
level
)
continue
;
// copy file to new disk (todo)
SDFileSet
fSet
=
*
pSet
;
fSet
.
diskId
=
did
;
code
=
tsdbDFileSetCopy
(
pTsdb
,
pSet
,
&
fSet
);
if
(
code
)
goto
_err
;
code
=
tsdbFSUpsertFSet
(
&
fs
,
&
fSet
);
if
(
code
)
goto
_err
;
}
}
// do change fs
code
=
tsdbFSCommit1
(
pTsdb
,
&
fs
);
if
(
code
)
goto
_err
;
taosThreadRwlockWrlock
(
&
pTsdb
->
rwLock
);
code
=
tsdbFSCommit2
(
pTsdb
,
&
fs
);
if
(
code
)
{
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
goto
_err
;
}
taosThreadRwlockUnlock
(
&
pTsdb
->
rwLock
);
tsdbFSDestroy
(
&
fs
);
_exit:
return
code
;
_err:
tsdbError
(
"vgId:%d, tsdb do retention failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
ASSERT
(
0
);
// tsdbFSRollback(pTsdb->pFS);
return
code
;
}
\ No newline at end of file
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
274d310f
...
...
@@ -186,6 +186,17 @@ void vnodePreClose(SVnode *pVnode) {
}
}
static
void
vnodeTrimDbClose
(
SVnode
*
pVnode
)
{
int32_t
nLoops
=
0
;
while
(
atomic_load_8
(
&
pVnode
->
trimDbH
.
state
)
!=
0
)
{
if
(
++
nLoops
>
1000
)
{
vTrace
(
"vgId:%d, wait for trimDb task to finish"
,
TD_VID
(
pVnode
));
sched_yield
();
nLoops
=
0
;
}
}
}
void
vnodeClose
(
SVnode
*
pVnode
)
{
if
(
pVnode
)
{
vnodeCommit
(
pVnode
);
...
...
@@ -197,6 +208,7 @@ void vnodeClose(SVnode *pVnode) {
smaClose
(
pVnode
->
pSma
);
metaClose
(
pVnode
->
pMeta
);
vnodeCloseBufPool
(
pVnode
);
vnodeTrimDbClose
(
pVnode
);
// destroy handle
tsem_destroy
(
&
(
pVnode
->
canCommit
));
tsem_destroy
(
&
pVnode
->
syncSem
);
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
274d310f
...
...
@@ -378,6 +378,7 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
pMetaRsp
->
precision
=
pVnode
->
config
.
tsdbCfg
.
precision
;
}
#if 0
static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
int32_t code = 0;
SVTrimDbReq trimReq = {0};
...
...
@@ -400,6 +401,85 @@ static int32_t vnodeProcessTrimReq(SVnode *pVnode, int64_t version, void *pReq,
_exit:
return code;
}
#endif
typedef
struct
{
SVnode
*
pVnode
;
SVTrimDbReq
trimReq
;
}
SVndTrimDbReq
;
void
*
vnodeProcessTrimReqFunc
(
void
*
param
)
{
int32_t
code
=
0
;
int8_t
oldVal
=
0
;
SVndTrimDbReq
*
pReq
=
(
SVndTrimDbReq
*
)
param
;
SVnode
*
pVnode
=
pReq
->
pVnode
;
setThreadName
(
"vnode-trim"
);
// process
code
=
tsdbDoRetention
(
pVnode
->
pTsdb
,
pReq
->
trimReq
.
timestamp
);
if
(
code
)
goto
_exit
;
code
=
smaDoRetention
(
pVnode
->
pSma
,
pReq
->
trimReq
.
timestamp
);
if
(
code
)
goto
_exit
;
_exit:
vInfo
(
"vgId:%d, trim vnode thread finished, time:%d"
,
TD_VID
(
pVnode
),
pReq
->
trimReq
.
timestamp
);
oldVal
=
atomic_val_compare_exchange_8
(
&
pVnode
->
trimDbH
.
state
,
1
,
0
);
ASSERT
(
oldVal
==
1
);
taosMemoryFree
(
pReq
);
return
NULL
;
}
static
int32_t
vnodeProcessTrimReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
)
{
int32_t
code
=
0
;
SVndTrimDbReq
*
pVndTrimReq
=
taosMemoryMalloc
(
sizeof
(
SVndTrimDbReq
));
STrimDbHandle
*
pHandle
=
&
pVnode
->
trimDbH
;
if
(
!
pVndTrimReq
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pVndTrimReq
->
pVnode
=
pVnode
;
if
(
tDeserializeSVTrimDbReq
(
pReq
,
len
,
&
pVndTrimReq
->
trimReq
)
!=
0
)
{
taosMemoryFree
(
pVndTrimReq
);
code
=
TSDB_CODE_INVALID_MSG
;
goto
_exit
;
}
if
(
atomic_val_compare_exchange_8
(
&
pHandle
->
state
,
0
,
1
)
!=
0
)
{
vInfo
(
"vgId:%d, trim vnode request will not be processed since duplicated req, time:%d"
,
TD_VID
(
pVnode
),
pVndTrimReq
->
trimReq
.
timestamp
);
taosMemoryFree
(
pVndTrimReq
);
goto
_exit
;
}
vInfo
(
"vgId:%d, trim vnode request will be processed, time:%d"
,
TD_VID
(
pVnode
),
pVndTrimReq
->
trimReq
.
timestamp
);
TdThreadAttr
thAttr
=
{
0
};
taosThreadAttrInit
(
&
thAttr
);
taosThreadAttrSetDetachState
(
&
thAttr
,
PTHREAD_CREATE_DETACHED
);
TdThread
tid
;
if
(
taosThreadCreate
(
&
tid
,
&
thAttr
,
vnodeProcessTrimReqFunc
,
(
void
*
)
pVndTrimReq
)
!=
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
taosMemoryFree
(
pVndTrimReq
);
taosThreadAttrDestroy
(
&
thAttr
);
int8_t
oldVal
=
atomic_val_compare_exchange_8
(
&
pHandle
->
state
,
1
,
0
);
ASSERT
(
oldVal
==
1
);
vError
(
"vgId:%d, failed to create pthread for trim vnode since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
code
));
goto
_exit
;
}
vDebug
(
"vgId:%d, success to create pthread for trim vnode"
,
TD_VID
(
pVnode
));
taosThreadAttrDestroy
(
&
thAttr
);
_exit:
terrno
=
code
;
return
code
;
}
static
int32_t
vnodeProcessDropTtlTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
)
{
SArray
*
tbUids
=
taosArrayInit
(
8
,
sizeof
(
int64_t
));
...
...
@@ -921,7 +1001,8 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
}
if
(
taosArrayGetSize
(
newTbUids
)
>
0
)
{
vDebug
(
"vgId:%d, add %d table into query table list in handling submit"
,
TD_VID
(
pVnode
),
(
int32_t
)
taosArrayGetSize
(
newTbUids
));
vDebug
(
"vgId:%d, add %d table into query table list in handling submit"
,
TD_VID
(
pVnode
),
(
int32_t
)
taosArrayGetSize
(
newTbUids
));
}
tqUpdateTbUidList
(
pVnode
->
pTq
,
newTbUids
,
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录