Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6185cef9
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
提交
6185cef9
编写于
3月 24, 2022
作者:
A
Alex Duan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-238]<feature>(tsdb): single table del data first ok
上级
5a5b4bf5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
204 addition
and
265 deletion
+204
-265
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-0
src/tsdb/inc/tsdbTruncate.h
src/tsdb/inc/tsdbTruncate.h
+8
-2
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+0
-11
src/tsdb/src/tsdbTruncate.c
src/tsdb/src/tsdbTruncate.c
+195
-252
未找到文件。
src/inc/taosmsg.h
浏览文件 @
6185cef9
...
@@ -1004,6 +1004,7 @@ typedef struct {
...
@@ -1004,6 +1004,7 @@ typedef struct {
}
STLV
;
}
STLV
;
#define CMD_DELETE_DATA 0x00000001
#define CMD_DELETE_DATA 0x00000001
#define CMD_TRUNCATE 0x00000002
typedef
struct
SControlData
{
typedef
struct
SControlData
{
uint32_t
command
;
// see define CMD_???
uint32_t
command
;
// see define CMD_???
STimeWindow
win
;
STimeWindow
win
;
...
...
src/tsdb/inc/tsdbTruncate.h
浏览文件 @
6185cef9
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
// SControlData addition information
typedef
struct
{
typedef
struct
{
SControlData
ctlData
;
SControlData
ctlData
;
// addition info
// addition info
...
@@ -25,11 +27,15 @@ typedef struct {
...
@@ -25,11 +27,15 @@ typedef struct {
int32_t
tid
;
// table id
int32_t
tid
;
// table id
tsem_t
*
pSem
;
tsem_t
*
pSem
;
bool
memNull
;
// pRepo->mem is NULL, this is true
bool
memNull
;
// pRepo->mem is NULL, this is true
uint64_t
*
uids
;
// delete table
int32_t
uidCount
;
SShellSubmitRspMsg
*
pRsp
;
SShellSubmitRspMsg
*
pRsp
;
}
SControlDataInfo
;
}
SControlDataInfo
;
void
*
tsdbTruncateImpl
(
STsdbRepo
*
pRepo
,
void
*
param
);
// -------- interface ---------
void
*
tsdbDeleteImpl
(
STsdbRepo
*
pRepo
,
void
*
param
);
// delete
int
tsdbControlDelete
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
6185cef9
...
@@ -1780,17 +1780,6 @@ int tsdbApplyRtn(STsdbRepo *pRepo) {
...
@@ -1780,17 +1780,6 @@ int tsdbApplyRtn(STsdbRepo *pRepo) {
return
0
;
return
0
;
}
}
int
tsdbControlDelete
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
)
{
int
ret
=
TSDB_CODE_SUCCESS
;
if
(
pCtlDataInfo
->
pRsp
)
{
pCtlDataInfo
->
pRsp
->
affectedRows
=
htonl
(
23
);
pCtlDataInfo
->
pRsp
->
code
=
ret
;
}
return
ret
;
}
// do control task
// do control task
int
tsdbCommitControl
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
)
{
int
tsdbCommitControl
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
)
{
int
ret
=
TSDB_CODE_SUCCESS
;
int
ret
=
TSDB_CODE_SUCCESS
;
...
...
src/tsdb/src/tsdbTruncate.c
浏览文件 @
6185cef9
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "tsdbint.h"
#include "tsdbint.h"
#include "tsdbTruncate.h"
typedef
struct
{
typedef
struct
{
STable
*
pTable
;
STable
*
pTable
;
...
@@ -30,43 +31,43 @@ typedef struct {
...
@@ -30,43 +31,43 @@ typedef struct {
SArray
*
aBlkIdx
;
SArray
*
aBlkIdx
;
SArray
*
aSupBlk
;
SArray
*
aSupBlk
;
SDataCols
*
pDCols
;
SDataCols
*
pDCols
;
void
*
param
;
// STruncateTblMsg or SDeleteTblMsg
SControlDataInfo
*
pCtlInfo
;
TSDB_REQ_T
type
;
// truncate or delete
}
STruncateH
;
}
STruncateH
;
#define TSDB_TRUNCATE_WSET(pTruncateH) (&((pTruncateH)->wSet))
#define TSDB_TRUNCATE_WSET(prh) (&((prh)->wSet))
#define TSDB_TRUNCATE_REPO(pTruncateH) TSDB_READ_REPO(&((pTruncateH)->readh))
#define TSDB_TRUNCATE_REPO(prh) TSDB_READ_REPO(&((prh)->readh))
#define TSDB_TRUNCATE_HEAD_FILE(pTruncateH) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(pTruncateH), TSDB_FILE_HEAD)
#define TSDB_TRUNCATE_HEAD_FILE(prh) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(prh), TSDB_FILE_HEAD)
#define TSDB_TRUNCATE_DATA_FILE(pTruncateH) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(pTruncateH), TSDB_FILE_DATA)
#define TSDB_TRUNCATE_DATA_FILE(prh) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(prh), TSDB_FILE_DATA)
#define TSDB_TRUNCATE_LAST_FILE(pTruncateH) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(pTruncateH), TSDB_FILE_LAST)
#define TSDB_TRUNCATE_LAST_FILE(prh) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(prh), TSDB_FILE_LAST)
#define TSDB_TRUNCATE_SMAD_FILE(pTruncateH) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(pTruncateH), TSDB_FILE_SMAD)
#define TSDB_TRUNCATE_SMAD_FILE(prh) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(prh), TSDB_FILE_SMAD)
#define TSDB_TRUNCATE_SMAL_FILE(pTruncateH) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(pTruncateH), TSDB_FILE_SMAL)
#define TSDB_TRUNCATE_SMAL_FILE(prh) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(prh), TSDB_FILE_SMAL)
#define TSDB_TRUNCATE_BUF(pTruncateH) TSDB_READ_BUF(&((pTruncateH)->readh))
#define TSDB_TRUNCATE_BUF(prh) TSDB_READ_BUF(&((prh)->readh))
#define TSDB_TRUNCATE_COMP_BUF(pTruncateH) TSDB_READ_COMP_BUF(&((pTruncateH)->readh))
#define TSDB_TRUNCATE_COMP_BUF(prh) TSDB_READ_COMP_BUF(&((prh)->readh))
#define TSDB_TRUNCATE_EXBUF(pTruncateH) TSDB_READ_EXBUF(&((pTruncateH)->readh))
#define TSDB_TRUNCATE_EXBUF(prh) TSDB_READ_EXBUF(&((prh)->readh))
/*
static int tsdbAsyncTruncate(STsdbRepo *pRepo, void *param, TSDB_REQ_T type);
static
void
tsdbStartTruncate
(
STsdbRepo
*
pRepo
);
static
void
tsdbStartTruncate
(
STsdbRepo
*
pRepo
);
static
void
tsdbEndTruncate
(
STsdbRepo
*
pRepo
,
int
eno
);
static
void
tsdbEndTruncate
(
STsdbRepo
*
pRepo
,
int
eno
);
static
int
tsdbTruncateMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbTruncateMeta
(
STsdbRepo
*
pRepo
);
static int tsdbTruncateTSData(STsdbRepo *pRepo,
void *param, TSDB_REQ_T type
);
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
//static int tsdbTruncateFSet(STruncateH *pTruncateH
, SDFileSet *pSet);
static
int
tsdbTruncateFSet
(
STruncateH
*
prh
,
SDFileSet
*
pSet
);
//static int tsdbDeleteFSet(STruncateH *pTruncateH
, SDFileSet *pSet);
static
int
tsdbDeleteFSet
(
STruncateH
*
prh
,
SDFileSet
*
pSet
);
static int tsdbInitTruncateH(STruncateH *p
TruncateH
, STsdbRepo *pRepo);
static
int
tsdbInitTruncateH
(
STruncateH
*
p
rh
,
STsdbRepo
*
pRepo
);
static void tsdbDestroyTruncateH(STruncateH *p
TruncateH
);
static
void
tsdbDestroyTruncateH
(
STruncateH
*
p
rh
);
static int tsdbInitTruncateTblArray(STruncateH *p
TruncateH
);
static
int
tsdbInitTruncateTblArray
(
STruncateH
*
p
rh
);
static void tsdbDestroyTruncateTblArray(STruncateH *p
TruncateH
);
static
void
tsdbDestroyTruncateTblArray
(
STruncateH
*
p
rh
);
static int tsdbCacheFSetIndex(STruncateH *p
TruncateH
);
static
int
tsdbCacheFSetIndex
(
STruncateH
*
p
rh
);
static
int
tsdbTruncateCache
(
STsdbRepo
*
pRepo
,
void
*
param
);
static
int
tsdbTruncateCache
(
STsdbRepo
*
pRepo
,
void
*
param
);
static int tsdbTruncateFSetInit(STruncateH *p
TruncateH
, SDFileSet *pSet);
static
int
tsdbTruncateFSetInit
(
STruncateH
*
p
rh
,
SDFileSet
*
pSet
);
static void tsdbTruncateFSetEnd(STruncateH *p
TruncateH
);
static
void
tsdbTruncateFSetEnd
(
STruncateH
*
p
rh
);
static int tsdbTruncateFSetImpl(STruncateH *p
TruncateH
);
static
int
tsdbTruncateFSetImpl
(
STruncateH
*
p
rh
);
static int tsdbDeleteFSetImpl(STruncateH *p
TruncateH
);
static
int
tsdbDeleteFSetImpl
(
STruncateH
*
p
rh
);
static bool tsdbBlockInterleaved(STruncateH *p
TruncateH
, SBlock *pBlock);
static
bool
tsdbBlockInterleaved
(
STruncateH
*
p
rh
,
SBlock
*
pBlock
);
static int tsdbWriteBlockToRightFile(STruncateH *p
TruncateH
, STable *pTable, SDataCols *pDCols, void **ppBuf,
static
int
tsdbWriteBlockToRightFile
(
STruncateH
*
p
rh
,
STable
*
pTable
,
SDataCols
*
pDCols
,
void
**
ppBuf
,
void
**
ppCBuf
,
void
**
ppExBuf
);
void
**
ppCBuf
,
void
**
ppExBuf
);
//static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T type);
static
int
tsdbTruncateImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
enum
{
enum
{
TSDB_NO_TRUNCATE
,
TSDB_NO_TRUNCATE
,
...
@@ -74,28 +75,26 @@ enum {
...
@@ -74,28 +75,26 @@ enum {
TSDB_WAITING_TRUNCATE
,
TSDB_WAITING_TRUNCATE
,
};
};
int tsdbTruncateTbl(STsdbRepo *pRepo, void *param) { return tsdbAsyncTruncate(pRepo, param, CONTROL_REQ); }
// delete
int tsdbDeleteData(STsdbRepo *pRepo, void *param) { return tsdbAsyncTruncate(pRepo, param, CONTROL_REQ); }
int
tsdbControlDelete
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
int
ret
=
TSDB_CODE_SUCCESS
;
void *tsdbTruncateImpl(STsdbRepo *pRepo, void *param) {
if
(
pCtlInfo
->
pRsp
)
{
//tsdbTruncateImplCommon(pRepo, param, TRUNCATE_TBL_REQ);
pCtlInfo
->
pRsp
->
affectedRows
=
htonl
(
23
);
return NULL;
pCtlInfo
->
pRsp
->
code
=
ret
;
}
}
void *tsdbDeleteImpl(STsdbRepo *pRepo, void *param) {
//tsdbTruncateImplCommon(pRepo, param, DELETE_TBL_REQ);
return NULL;
}
return
tsdbTruncateImplCommon
(
pRepo
,
pCtlInfo
);
}
static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
static
int
tsdbTruncateImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
ASSERT(param != NULL);
int32_t
code
=
0
;
int32_t
code
=
0
;
// Step 1: check and clear cache
// Step 1: check and clear cache
if ((code = tsdbTruncateCache(pRepo, p
aram
)) != 0) {
if
((
code
=
tsdbTruncateCache
(
pRepo
,
p
CtlInfo
))
!=
0
)
{
pRepo
->
code
=
terrno
;
pRepo
->
code
=
terrno
;
tsem_post
(
&
(
pRepo
->
readyToCommit
));
tsem_post
(
&
(
pRepo
->
readyToCommit
));
tsdbInfo
(
"vgId:%d failed to truncate since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
tsdbInfo
(
"vgId:%d failed to truncate since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
return
NULL
;
return
-
1
;
}
}
// Step 2: truncate and rebuild DFileSets
// Step 2: truncate and rebuild DFileSets
...
@@ -104,7 +103,7 @@ static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T ty
...
@@ -104,7 +103,7 @@ static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T ty
pRepo
->
truncateState
=
TSDB_NO_TRUNCATE
;
pRepo
->
truncateState
=
TSDB_NO_TRUNCATE
;
tsem_post
(
&
(
pRepo
->
readyToCommit
));
tsem_post
(
&
(
pRepo
->
readyToCommit
));
tsdbInfo
(
"vgId:%d truncate over, no meta or data file"
,
REPO_ID
(
pRepo
));
tsdbInfo
(
"vgId:%d truncate over, no meta or data file"
,
REPO_ID
(
pRepo
));
return
NULL
;
return
-
1
;
}
}
tsdbStartTruncate
(
pRepo
);
tsdbStartTruncate
(
pRepo
);
...
@@ -114,18 +113,18 @@ static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T ty
...
@@ -114,18 +113,18 @@ static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T ty
goto
_err
;
goto
_err
;
}
}
if (tsdbTruncateTSData(pRepo, p
aram, type
) < 0) {
if
(
tsdbTruncateTSData
(
pRepo
,
p
CtlInfo
)
<
0
)
{
tsdbError
(
"vgId:%d failed to truncate TS data since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate TS data since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
goto
_err
;
goto
_err
;
}
}
tsdbEndTruncate
(
pRepo
,
TSDB_CODE_SUCCESS
);
tsdbEndTruncate
(
pRepo
,
TSDB_CODE_SUCCESS
);
return
NULL
;
return
TSDB_CODE_SUCCESS
;
_err:
_err:
pRepo
->
code
=
terrno
;
pRepo
->
code
=
terrno
;
tsdbEndTruncate
(
pRepo
,
terrno
);
tsdbEndTruncate
(
pRepo
,
terrno
);
return
NULL
;
return
-
1
;
}
}
static
int
tsdbTruncateCache
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
static
int
tsdbTruncateCache
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
...
@@ -146,28 +145,6 @@ static int tsdbTruncateCache(STsdbRepo *pRepo, void *param) {
...
@@ -146,28 +145,6 @@ static int tsdbTruncateCache(STsdbRepo *pRepo, void *param) {
return
0
;
return
0
;
}
}
static int tsdbAsyncTruncate(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
// avoid repeated input of commands by end users in a short period of time
if (pRepo->truncateState != TSDB_NO_TRUNCATE) {
tsdbInfo("vgId:%d retry later as tsdb in truncating state", REPO_ID(pRepo));
return -1;
}
pRepo->truncateState = TSDB_WAITING_TRUNCATE;
// flush the mem data to disk synchronously(have impact on the compression rate)
if (tsdbSyncCommit(pRepo) < 0) {
return -1;
}
// truncate
tsem_wait(&(pRepo->readyToCommit));
int code = tsdbScheduleCommit(pRepo, param, type);
if (code < 0) {
tsem_post(&(pRepo->readyToCommit));
}
return code;
}
static
void
tsdbStartTruncate
(
STsdbRepo
*
pRepo
)
{
static
void
tsdbStartTruncate
(
STsdbRepo
*
pRepo
)
{
assert
(
pRepo
->
truncateState
!=
TSDB_IN_TRUNCATE
);
assert
(
pRepo
->
truncateState
!=
TSDB_IN_TRUNCATE
);
tsdbInfo
(
"vgId:%d start to truncate!"
,
REPO_ID
(
pRepo
));
tsdbInfo
(
"vgId:%d start to truncate!"
,
REPO_ID
(
pRepo
));
...
@@ -193,23 +170,22 @@ static int tsdbTruncateMeta(STsdbRepo *pRepo) {
...
@@ -193,23 +170,22 @@ static int tsdbTruncateMeta(STsdbRepo *pRepo) {
return
0
;
return
0
;
}
}
static int tsdbTruncateTSData(STsdbRepo *pRepo,
void *param, TSDB_REQ_T type
) {
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STruncateH
truncateH
=
{
0
};
STruncateH
truncateH
=
{
0
};
SDFileSet
*
pSet
=
NULL
;
SDFileSet
*
pSet
=
NULL
;
STruncateTblMsg *pMsg = (STruncateTblMsg *)param;
tsdbDebug("vgId:%d start to truncate TS data for %" PRIu64, REPO_ID(pRepo), p
Msg
->uid);
tsdbDebug
(
"vgId:%d start to truncate TS data for %"
PRIu64
,
REPO_ID
(
pRepo
),
p
CtlInfo
->
uid
);
if
(
tsdbInitTruncateH
(
&
truncateH
,
pRepo
)
<
0
)
{
if
(
tsdbInitTruncateH
(
&
truncateH
,
pRepo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
truncateH.p
aram = pMsg
;
truncateH
.
p
CtlInfo
=
pCtlInfo
;
truncateH.type = type
;
STimeWindow
win
=
pCtlInfo
->
ctlData
.
win
;
int sFid = TSDB_KEY_FID(
pMsg->span[0]
.skey, pCfg->daysPerFile, pCfg->precision);
int
sFid
=
TSDB_KEY_FID
(
win
.
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int eFid = TSDB_KEY_FID(
pMsg->span[0]
.ekey, pCfg->daysPerFile, pCfg->precision);
int
eFid
=
TSDB_KEY_FID
(
win
.
ekey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
ASSERT
(
sFid
<=
eFid
);
ASSERT
(
sFid
<=
eFid
);
while
((
pSet
=
tsdbFSIterNext
(
&
(
truncateH
.
fsIter
))))
{
while
((
pSet
=
tsdbFSIterNext
(
&
(
truncateH
.
fsIter
))))
{
...
@@ -236,13 +212,13 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
...
@@ -236,13 +212,13 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
}
}
#endif
#endif
if (
truncateH.type == TRUNCATE_TBL_REQ
) {
if
(
pCtlInfo
->
ctlData
.
command
==
CMD_TRUNCATE
)
{
if
(
tsdbTruncateFSet
(
&
truncateH
,
pSet
)
<
0
)
{
if
(
tsdbTruncateFSet
(
&
truncateH
,
pSet
)
<
0
)
{
tsdbDestroyTruncateH
(
&
truncateH
);
tsdbDestroyTruncateH
(
&
truncateH
);
tsdbError
(
"vgId:%d failed to truncate table in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate table in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
return
-
1
;
return
-
1
;
}
}
} else if (
truncateH.type == DELETE_TBL_REQ
) {
}
else
if
(
pCtlInfo
->
ctlData
.
command
==
CMD_DELETE_DATA
)
{
if
(
tsdbDeleteFSet
(
&
truncateH
,
pSet
)
<
0
)
{
if
(
tsdbDeleteFSet
(
&
truncateH
,
pSet
)
<
0
)
{
tsdbDestroyTruncateH
(
&
truncateH
);
tsdbDestroyTruncateH
(
&
truncateH
);
tsdbError
(
"vgId:%d failed to truncate data in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate data in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
...
@@ -259,68 +235,68 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
...
@@ -259,68 +235,68 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
return
0
;
return
0
;
}
}
static int tsdbDeleteFSet(STruncateH *p
TruncateH
, SDFileSet *pSet) {
static
int
tsdbDeleteFSet
(
STruncateH
*
p
rh
,
SDFileSet
*
pSet
)
{
STsdbRepo *pRepo = TSDB_TRUNCATE_REPO(p
TruncateH
);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
p
rh
);
SDiskID
did
=
{
0
};
SDiskID
did
=
{
0
};
tsdbDebug
(
"vgId:%d start to truncate data in FSET %d on level %d id %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tsdbDebug
(
"vgId:%d start to truncate data in FSET %d on level %d id %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
if (tsdbTruncateFSetInit(p
TruncateH
, pSet) < 0) {
if
(
tsdbTruncateFSetInit
(
p
rh
,
pSet
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// Create new fset as deleted fset
// Create new fset as deleted fset
tfsAllocDisk(tsdbGetFidLevel(pSet->fid, &(p
TruncateH
->rtn)), &(did.level), &(did.id));
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
p
rh
->
rtn
)),
&
(
did
.
level
),
&
(
did
.
id
));
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
terrno
=
TSDB_CODE_TDB_NO_AVAIL_DISK
;
terrno
=
TSDB_CODE_TDB_NO_AVAIL_DISK
;
tsdbError
(
"vgId:%d failed to truncate data in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate data in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
tsdbInitDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
), did, REPO_ID(pRepo), TSDB_FSET_FID(pSet),
tsdbInitDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
),
did
,
REPO_ID
(
pRepo
),
TSDB_FSET_FID
(
pSet
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)),
TSDB_LATEST_FSET_VER
);
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)),
TSDB_LATEST_FSET_VER
);
if (tsdbCreateDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
), true) < 0) {
if
(
tsdbCreateDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
),
true
)
<
0
)
{
tsdbError
(
"vgId:%d failed to truncate data in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate data in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
if (tsdbDeleteFSetImpl(p
TruncateH
) < 0) {
if
(
tsdbDeleteFSetImpl
(
p
rh
)
<
0
)
{
tsdbCloseDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbRemoveDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbRemoveDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
tsdbCloseDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbUpdateDFileSet(REPO_FS(pRepo), TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbDebug
(
"vgId:%d FSET %d truncate data over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbDebug
(
"vgId:%d FSET %d truncate data over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
0
;
return
0
;
}
}
static int tsdbTruncateFSet(STruncateH *p
TruncateH
, SDFileSet *pSet) {
static
int
tsdbTruncateFSet
(
STruncateH
*
p
rh
,
SDFileSet
*
pSet
)
{
STsdbRepo *pRepo = TSDB_TRUNCATE_REPO(p
TruncateH
);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
p
rh
);
SDiskID
did
=
{
0
};
SDiskID
did
=
{
0
};
SDFileSet *pWSet = TSDB_TRUNCATE_WSET(p
TruncateH
);
SDFileSet
*
pWSet
=
TSDB_TRUNCATE_WSET
(
p
rh
);
tsdbDebug
(
"vgId:%d start to truncate table in FSET %d on level %d id %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tsdbDebug
(
"vgId:%d start to truncate table in FSET %d on level %d id %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
if (tsdbTruncateFSetInit(p
TruncateH
, pSet) < 0) {
if
(
tsdbTruncateFSetInit
(
p
rh
,
pSet
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// Create new fset as truncated fset
// Create new fset as truncated fset
tfsAllocDisk(tsdbGetFidLevel(pSet->fid, &(p
TruncateH
->rtn)), &(did.level), &(did.id));
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
p
rh
->
rtn
)),
&
(
did
.
level
),
&
(
did
.
id
));
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
terrno
=
TSDB_CODE_TDB_NO_AVAIL_DISK
;
terrno
=
TSDB_CODE_TDB_NO_AVAIL_DISK
;
tsdbError
(
"vgId:%d failed to truncate table in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate table in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
...
@@ -344,81 +320,81 @@ static int tsdbTruncateFSet(STruncateH *pTruncateH, SDFileSet *pSet) {
...
@@ -344,81 +320,81 @@ static int tsdbTruncateFSet(STruncateH *pTruncateH, SDFileSet *pSet) {
return
-
1
;
return
-
1
;
}
}
if (tsdbTruncateFSetImpl(p
TruncateH
) < 0) {
if
(
tsdbTruncateFSetImpl
(
p
rh
)
<
0
)
{
tsdbCloseDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbRemoveDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbRemoveDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
tsdbCloseDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbUpdateDFileSet(REPO_FS(pRepo), TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbDebug
(
"vgId:%d FSET %d truncate table over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbDebug
(
"vgId:%d FSET %d truncate table over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbTruncateFSetEnd(p
TruncateH
);
tsdbTruncateFSetEnd
(
p
rh
);
return
0
;
return
0
;
}
}
static int tsdbInitTruncateH(STruncateH *p
TruncateH
, STsdbRepo *pRepo) {
static
int
tsdbInitTruncateH
(
STruncateH
*
p
rh
,
STsdbRepo
*
pRepo
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
memset(p
TruncateH, 0, sizeof(*pTruncateH
));
memset
(
p
rh
,
0
,
sizeof
(
*
prh
));
TSDB_FSET_SET_CLOSED(TSDB_TRUNCATE_WSET(p
TruncateH
));
TSDB_FSET_SET_CLOSED
(
TSDB_TRUNCATE_WSET
(
p
rh
));
tsdbGetRtnSnap(pRepo, &(p
TruncateH
->rtn));
tsdbGetRtnSnap
(
pRepo
,
&
(
p
rh
->
rtn
));
tsdbFSIterInit(&(p
TruncateH
->fsIter), REPO_FS(pRepo), TSDB_FS_ITER_FORWARD);
tsdbFSIterInit
(
&
(
p
rh
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
if (tsdbInitReadH(&(p
TruncateH
->readh), pRepo) < 0) {
if
(
tsdbInitReadH
(
&
(
p
rh
->
readh
),
pRepo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if (tsdbInitTruncateTblArray(p
TruncateH
) < 0) {
if
(
tsdbInitTruncateTblArray
(
p
rh
)
<
0
)
{
tsdbDestroyTruncateH(p
TruncateH
);
tsdbDestroyTruncateH
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
p
TruncateH
->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx));
p
rh
->
aBlkIdx
=
taosArrayInit
(
1024
,
sizeof
(
SBlockIdx
));
if (p
TruncateH
->aBlkIdx == NULL) {
if
(
p
rh
->
aBlkIdx
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroyTruncateH(p
TruncateH
);
tsdbDestroyTruncateH
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
p
TruncateH
->aSupBlk = taosArrayInit(1024, sizeof(SBlock));
p
rh
->
aSupBlk
=
taosArrayInit
(
1024
,
sizeof
(
SBlock
));
if (p
TruncateH
->aSupBlk == NULL) {
if
(
p
rh
->
aSupBlk
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroyTruncateH(p
TruncateH
);
tsdbDestroyTruncateH
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
p
TruncateH
->pDCols = tdNewDataCols(0, pCfg->maxRowsPerFileBlock);
p
rh
->
pDCols
=
tdNewDataCols
(
0
,
pCfg
->
maxRowsPerFileBlock
);
if (p
TruncateH
->pDCols == NULL) {
if
(
p
rh
->
pDCols
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroyTruncateH(p
TruncateH
);
tsdbDestroyTruncateH
(
p
rh
);
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static void tsdbDestroyTruncateH(STruncateH *p
TruncateH
) {
static
void
tsdbDestroyTruncateH
(
STruncateH
*
p
rh
)
{
p
TruncateH->pDCols = tdFreeDataCols(pTruncateH
->pDCols);
p
rh
->
pDCols
=
tdFreeDataCols
(
prh
->
pDCols
);
p
TruncateH->aSupBlk = taosArrayDestroy(&pTruncateH
->aSupBlk);
p
rh
->
aSupBlk
=
taosArrayDestroy
(
&
prh
->
aSupBlk
);
p
TruncateH->aBlkIdx = taosArrayDestroy(&pTruncateH
->aBlkIdx);
p
rh
->
aBlkIdx
=
taosArrayDestroy
(
&
prh
->
aBlkIdx
);
tsdbDestroyTruncateTblArray(p
TruncateH
);
tsdbDestroyTruncateTblArray
(
p
rh
);
tsdbDestroyReadH(&(p
TruncateH
->readh));
tsdbDestroyReadH
(
&
(
p
rh
->
readh
));
tsdbCloseDFileSet(TSDB_TRUNCATE_WSET(p
TruncateH
));
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
p
rh
));
}
}
static int tsdbInitTruncateTblArray(STruncateH *p
TruncateH
) {
static
int
tsdbInitTruncateTblArray
(
STruncateH
*
p
rh
)
{
STsdbRepo *pRepo = TSDB_TRUNCATE_REPO(p
TruncateH
);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
p
rh
);
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
if
(
tsdbRLockRepoMeta
(
pRepo
)
<
0
)
return
-
1
;
if
(
tsdbRLockRepoMeta
(
pRepo
)
<
0
)
return
-
1
;
p
TruncateH
->tblArray = taosArrayInit(pMeta->maxTables, sizeof(STableTruncateH));
p
rh
->
tblArray
=
taosArrayInit
(
pMeta
->
maxTables
,
sizeof
(
STableTruncateH
));
if (p
TruncateH
->tblArray == NULL) {
if
(
p
rh
->
tblArray
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbUnlockRepoMeta
(
pRepo
);
tsdbUnlockRepoMeta
(
pRepo
);
return
-
1
;
return
-
1
;
...
@@ -432,7 +408,7 @@ static int tsdbInitTruncateTblArray(STruncateH *pTruncateH) {
...
@@ -432,7 +408,7 @@ static int tsdbInitTruncateTblArray(STruncateH *pTruncateH) {
ch
.
pTable
=
pMeta
->
tables
[
i
];
ch
.
pTable
=
pMeta
->
tables
[
i
];
}
}
if (taosArrayPush(p
TruncateH
->tblArray, &ch) == NULL) {
if
(
taosArrayPush
(
p
rh
->
tblArray
,
&
ch
)
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbUnlockRepoMeta
(
pRepo
);
tsdbUnlockRepoMeta
(
pRepo
);
return
-
1
;
return
-
1
;
...
@@ -443,46 +419,46 @@ static int tsdbInitTruncateTblArray(STruncateH *pTruncateH) {
...
@@ -443,46 +419,46 @@ static int tsdbInitTruncateTblArray(STruncateH *pTruncateH) {
return
0
;
return
0
;
}
}
static void tsdbDestroyTruncateTblArray(STruncateH *p
TruncateH
) {
static
void
tsdbDestroyTruncateTblArray
(
STruncateH
*
p
rh
)
{
STableTruncateH *p
Tbl
Handle = NULL;
STableTruncateH
*
pHandle
=
NULL
;
if (p
TruncateH
->tblArray == NULL) return;
if
(
p
rh
->
tblArray
==
NULL
)
return
;
for (size_t i = 0; i < taosArrayGetSize(p
TruncateH
->tblArray); ++i) {
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
p
rh
->
tblArray
);
++
i
)
{
p
TblHandle = (STableTruncateH *)taosArrayGet(pTruncateH
->tblArray, i);
p
Handle
=
(
STableTruncateH
*
)
taosArrayGet
(
prh
->
tblArray
,
i
);
if (p
Tbl
Handle->pTable) {
if
(
pHandle
->
pTable
)
{
tsdbUnRefTable(p
Tbl
Handle->pTable);
tsdbUnRefTable
(
pHandle
->
pTable
);
}
}
tfree(p
Tbl
Handle->pInfo);
tfree
(
pHandle
->
pInfo
);
}
}
p
TruncateH->tblArray = taosArrayDestroy(&pTruncateH
->tblArray);
p
rh
->
tblArray
=
taosArrayDestroy
(
&
prh
->
tblArray
);
}
}
static int tsdbCacheFSetIndex(STruncateH *p
TruncateH
) {
static
int
tsdbCacheFSetIndex
(
STruncateH
*
p
rh
)
{
SReadH *pReadH = &(p
TruncateH
->readh);
SReadH
*
pReadH
=
&
(
p
rh
->
readh
);
if
(
tsdbLoadBlockIdx
(
pReadH
)
<
0
)
{
if
(
tsdbLoadBlockIdx
(
pReadH
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
size_t tblArraySize = taosArrayGetSize(p
TruncateH
->tblArray);
size_t
tblArraySize
=
taosArrayGetSize
(
p
rh
->
tblArray
);
for
(
size_t
tid
=
1
;
tid
<
tblArraySize
;
++
tid
)
{
for
(
size_t
tid
=
1
;
tid
<
tblArraySize
;
++
tid
)
{
STableTruncateH *p
TblHandle = (STableTruncateH *)taosArrayGet(pTruncateH
->tblArray, tid);
STableTruncateH
*
p
Handle
=
(
STableTruncateH
*
)
taosArrayGet
(
prh
->
tblArray
,
tid
);
p
Tbl
Handle->pBlkIdx = NULL;
pHandle
->
pBlkIdx
=
NULL
;
if (p
Tbl
Handle->pTable == NULL) continue;
if
(
pHandle
->
pTable
==
NULL
)
continue
;
if (tsdbSetReadTable(pReadH, p
Tbl
Handle->pTable) < 0) {
if
(
tsdbSetReadTable
(
pReadH
,
pHandle
->
pTable
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if
(
pReadH
->
pBlkIdx
==
NULL
)
continue
;
if
(
pReadH
->
pBlkIdx
==
NULL
)
continue
;
p
Tbl
Handle->bIndex = *(pReadH->pBlkIdx);
pHandle
->
bIndex
=
*
(
pReadH
->
pBlkIdx
);
p
TblHandle->pBlkIdx = &(pTbl
Handle->bIndex);
p
Handle
->
pBlkIdx
=
&
(
p
Handle
->
bIndex
);
uint32_t
originLen
=
0
;
uint32_t
originLen
=
0
;
if (tsdbLoadBlockInfo(pReadH, (void **)(&(p
Tbl
Handle->pInfo)), &originLen) < 0) {
if
(
tsdbLoadBlockInfo
(
pReadH
,
(
void
**
)(
&
(
pHandle
->
pInfo
)),
&
originLen
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
}
}
...
@@ -490,26 +466,26 @@ static int tsdbCacheFSetIndex(STruncateH *pTruncateH) {
...
@@ -490,26 +466,26 @@ static int tsdbCacheFSetIndex(STruncateH *pTruncateH) {
return
0
;
return
0
;
}
}
static int tsdbTruncateFSetInit(STruncateH *p
TruncateH
, SDFileSet *pSet) {
static
int
tsdbTruncateFSetInit
(
STruncateH
*
p
rh
,
SDFileSet
*
pSet
)
{
taosArrayClear(p
TruncateH
->aBlkIdx);
taosArrayClear
(
p
rh
->
aBlkIdx
);
taosArrayClear(p
TruncateH
->aSupBlk);
taosArrayClear
(
p
rh
->
aSupBlk
);
if (tsdbSetAndOpenReadFSet(&(p
TruncateH
->readh), pSet) < 0) {
if
(
tsdbSetAndOpenReadFSet
(
&
(
p
rh
->
readh
),
pSet
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if (tsdbCacheFSetIndex(p
TruncateH
) < 0) {
if
(
tsdbCacheFSetIndex
(
p
rh
)
<
0
)
{
tsdbCloseAndUnsetFSet(&(p
TruncateH
->readh));
tsdbCloseAndUnsetFSet
(
&
(
p
rh
->
readh
));
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static void tsdbTruncateFSetEnd(STruncateH *p
TruncateH) { tsdbCloseAndUnsetFSet(&(pTruncateH
->readh)); }
static
void
tsdbTruncateFSetEnd
(
STruncateH
*
p
rh
)
{
tsdbCloseAndUnsetFSet
(
&
(
prh
->
readh
));
}
static bool tsdbBlockInterleaved(STruncateH *p
TruncateH
, SBlock *pBlock) {
static
bool
tsdbBlockInterleaved
(
STruncateH
*
p
rh
,
SBlock
*
pBlock
)
{
// STruncateTblMsg *pMsg = (STruncateTblMsg *)p
TruncateH
->param;
// STruncateTblMsg *pMsg = (STruncateTblMsg *)p
rh
->param;
// for (uint16_t i = 0; i < pMsg->nSpan; ++i) {
// for (uint16_t i = 0; i < pMsg->nSpan; ++i) {
// STimeWindow tw = pMsg->span[i];
// STimeWindow tw = pMsg->span[i];
// if (!(pBlock->keyFirst > tw.ekey || pBlock->keyLast < tw.skey)) {
// if (!(pBlock->keyFirst > tw.ekey || pBlock->keyLast < tw.skey)) {
...
@@ -520,9 +496,9 @@ static bool tsdbBlockInterleaved(STruncateH *pTruncateH, SBlock *pBlock) {
...
@@ -520,9 +496,9 @@ static bool tsdbBlockInterleaved(STruncateH *pTruncateH, SBlock *pBlock) {
return
true
;
return
true
;
}
}
static int32_t tsdbFilterDataCols(STruncateH *p
TruncateH
, SDataCols *pSrcDCols) {
static
int32_t
tsdbFilterDataCols
(
STruncateH
*
p
rh
,
SDataCols
*
pSrcDCols
)
{
S
TruncateTblMsg *pMsg = (STruncateTblMsg *)pTruncateH->param
;
S
DataCols
*
pDstDCols
=
prh
->
pDCols
;
S
DataCols * pDstDCols = pTruncateH->pDCols
;
S
ControlData
*
pCtlData
=
&
prh
->
pCtlInfo
->
ctlData
;
tdResetDataCols
(
pDstDCols
);
tdResetDataCols
(
pDstDCols
);
pDstDCols
->
maxCols
=
pSrcDCols
->
maxCols
;
pDstDCols
->
maxCols
=
pSrcDCols
->
maxCols
;
...
@@ -532,7 +508,7 @@ static int32_t tsdbFilterDataCols(STruncateH *pTruncateH, SDataCols *pSrcDCols)
...
@@ -532,7 +508,7 @@ static int32_t tsdbFilterDataCols(STruncateH *pTruncateH, SDataCols *pSrcDCols)
for
(
int
i
=
0
;
i
<
pSrcDCols
->
numOfRows
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSrcDCols
->
numOfRows
;
++
i
)
{
int64_t
tsKey
=
*
(
int64_t
*
)
tdGetColDataOfRow
(
pSrcDCols
->
cols
,
i
);
int64_t
tsKey
=
*
(
int64_t
*
)
tdGetColDataOfRow
(
pSrcDCols
->
cols
,
i
);
if ((tsKey >= p
Msg->span[0].skey) && (tsKey <= pMsg->span[0]
.ekey)) {
if
((
tsKey
>=
p
CtlData
->
win
.
skey
)
&&
(
tsKey
<=
pCtlData
->
win
.
ekey
))
{
printf
(
"tsKey %"
PRId64
" is filtered
\n
"
,
tsKey
);
printf
(
"tsKey %"
PRId64
" is filtered
\n
"
,
tsKey
);
continue
;
continue
;
}
}
...
@@ -548,39 +524,38 @@ static int32_t tsdbFilterDataCols(STruncateH *pTruncateH, SDataCols *pSrcDCols)
...
@@ -548,39 +524,38 @@ static int32_t tsdbFilterDataCols(STruncateH *pTruncateH, SDataCols *pSrcDCols)
return
0
;
return
0
;
}
}
static int tsdbTruncateFSetImpl(STruncateH *pTruncateH) {
static
int
tsdbTruncateFSetImpl
(
STruncateH
*
prh
)
{
STsdbRepo * pRepo = TSDB_TRUNCATE_REPO(pTruncateH);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
prh
);
STruncateTblMsg *pMsg = (STruncateTblMsg *)pTruncateH->param;
// SReadH * pReadh = &(prh->readh);
// SReadH * pReadh = &(pTruncateH->readh);
SBlockIdx
*
pBlkIdx
=
NULL
;
SBlockIdx
*
pBlkIdx
=
NULL
;
void ** ppBuf = &(TSDB_TRUNCATE_BUF(p
TruncateH
));
void
**
ppBuf
=
&
(
TSDB_TRUNCATE_BUF
(
p
rh
));
// void ** ppCBuf = &(TSDB_TRUNCATE_COMP_BUF(p
TruncateH
));
// void ** ppCBuf = &(TSDB_TRUNCATE_COMP_BUF(p
rh
));
// void ** ppExBuf = &(TSDB_TRUNCATE_EXBUF(p
TruncateH
));
// void ** ppExBuf = &(TSDB_TRUNCATE_EXBUF(p
rh
));
taosArrayClear(p
TruncateH
->aBlkIdx);
taosArrayClear
(
p
rh
->
aBlkIdx
);
for (size_t tid = 1; tid < taosArrayGetSize(p
TruncateH
->tblArray); ++tid) {
for
(
size_t
tid
=
1
;
tid
<
taosArrayGetSize
(
p
rh
->
tblArray
);
++
tid
)
{
STableTruncateH *p
TblHandle = (STableTruncateH *)taosArrayGet(pTruncateH
->tblArray, tid);
STableTruncateH
*
p
Handle
=
(
STableTruncateH
*
)
taosArrayGet
(
prh
->
tblArray
,
tid
);
pBlkIdx = p
Tbl
Handle->pBlkIdx;
pBlkIdx
=
pHandle
->
pBlkIdx
;
if (p
TblHandle->pTable == NULL || pTbl
Handle->pBlkIdx == NULL) continue;
if
(
p
Handle
->
pTable
==
NULL
||
p
Handle
->
pBlkIdx
==
NULL
)
continue
;
taosArrayClear(p
TruncateH
->aSupBlk);
taosArrayClear
(
p
rh
->
aSupBlk
);
uint64_t uid = p
Tbl
Handle->pTable->tableId.uid;
uint64_t
uid
=
pHandle
->
pTable
->
tableId
.
uid
;
if (uid != p
Msg
->uid) {
if
(
uid
!=
p
rh
->
pCtlInfo
->
uid
)
{
if ((pBlkIdx->numOfBlocks > 0) && (taosArrayPush(p
TruncateH
->aBlkIdx, (const void *)(pBlkIdx)) == NULL)) {
if
((
pBlkIdx
->
numOfBlocks
>
0
)
&&
(
taosArrayPush
(
p
rh
->
aBlkIdx
,
(
const
void
*
)(
pBlkIdx
))
==
NULL
))
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
}
else
{
}
else
{
// Loop to mark delete flag for each block data
// Loop to mark delete flag for each block data
tsdbDebug
(
"vgId:%d uid %"
PRIu64
" matched to truncate"
,
REPO_ID
(
pRepo
),
uid
);
tsdbDebug
(
"vgId:%d uid %"
PRIu64
" matched to truncate"
,
REPO_ID
(
pRepo
),
uid
);
// for (int i = 0; i < p
Tbl
Handle->pBlkIdx->numOfBlocks; ++i) {
// for (int i = 0; i < pHandle->pBlkIdx->numOfBlocks; ++i) {
// SBlock *pBlock = p
Tbl
Handle->pInfo->blocks + i;
// SBlock *pBlock = pHandle->pInfo->blocks + i;
// if (tsdbWriteBlockToRightFile(p
TruncateH, pTblHandle->pTable, pTruncateH
->pDCols, ppBuf, ppCBuf, ppExBuf) <
// if (tsdbWriteBlockToRightFile(p
rh, pHandle->pTable, prh
->pDCols, ppBuf, ppCBuf, ppExBuf) <
// 0) {
// 0) {
// return -1;
// return -1;
// }
// }
...
@@ -588,44 +563,43 @@ static int tsdbTruncateFSetImpl(STruncateH *pTruncateH) {
...
@@ -588,44 +563,43 @@ static int tsdbTruncateFSetImpl(STruncateH *pTruncateH) {
}
}
}
}
if (tsdbWriteBlockIdx(TSDB_TRUNCATE_HEAD_FILE(p
TruncateH), pTruncateH
->aBlkIdx, ppBuf) < 0) {
if
(
tsdbWriteBlockIdx
(
TSDB_TRUNCATE_HEAD_FILE
(
p
rh
),
prh
->
aBlkIdx
,
ppBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static int tsdbDeleteFSetImpl(STruncateH *pTruncateH) {
static
int
tsdbDeleteFSetImpl
(
STruncateH
*
prh
)
{
STsdbRepo * pRepo = TSDB_TRUNCATE_REPO(pTruncateH);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
prh
);
STruncateTblMsg *pMsg = (STruncateTblMsg *)pTruncateH->param;
// STsdbCfg * pCfg = REPO_CFG(pRepo);
// STsdbCfg * pCfg = REPO_CFG(pRepo);
SReadH * pReadh = &(p
TruncateH
->readh);
SReadH
*
pReadh
=
&
(
p
rh
->
readh
);
SBlockIdx
blkIdx
=
{
0
};
SBlockIdx
blkIdx
=
{
0
};
void ** ppBuf = &(TSDB_TRUNCATE_BUF(p
TruncateH
));
void
**
ppBuf
=
&
(
TSDB_TRUNCATE_BUF
(
p
rh
));
void ** ppCBuf = &(TSDB_TRUNCATE_COMP_BUF(p
TruncateH
));
void
**
ppCBuf
=
&
(
TSDB_TRUNCATE_COMP_BUF
(
p
rh
));
void ** ppExBuf = &(TSDB_TRUNCATE_EXBUF(p
TruncateH
));
void
**
ppExBuf
=
&
(
TSDB_TRUNCATE_EXBUF
(
p
rh
));
// int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock);
// int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock);
taosArrayClear(p
TruncateH
->aBlkIdx);
taosArrayClear
(
p
rh
->
aBlkIdx
);
for (size_t tid = 1; tid < taosArrayGetSize(p
TruncateH
->tblArray); ++tid) {
for
(
size_t
tid
=
1
;
tid
<
taosArrayGetSize
(
p
rh
->
tblArray
);
++
tid
)
{
STableTruncateH *p
TblHandle = (STableTruncateH *)taosArrayGet(pTruncateH
->tblArray, tid);
STableTruncateH
*
p
Handle
=
(
STableTruncateH
*
)
taosArrayGet
(
prh
->
tblArray
,
tid
);
STSchema
*
pSchema
=
NULL
;
STSchema
*
pSchema
=
NULL
;
if (p
TblHandle->pTable == NULL || pTbl
Handle->pBlkIdx == NULL) continue;
if
(
p
Handle
->
pTable
==
NULL
||
p
Handle
->
pBlkIdx
==
NULL
)
continue
;
if ((pSchema = tsdbGetTableSchemaImpl(p
Tbl
Handle->pTable, true, true, -1, -1)) == NULL) {
if
((
pSchema
=
tsdbGetTableSchemaImpl
(
pHandle
->
pTable
,
true
,
true
,
-
1
,
-
1
))
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
taosArrayClear(p
TruncateH
->aSupBlk);
taosArrayClear
(
p
rh
->
aSupBlk
);
uint64_t uid = p
Tbl
Handle->pTable->tableId.uid;
uint64_t
uid
=
pHandle
->
pTable
->
tableId
.
uid
;
// if(uid != pMsg->uid) {
// if(uid != pMsg->uid) {
// TODO: copy the block data directly
// TODO: copy the block data directly
// }
// }
if ((tdInitDataCols(p
TruncateH
->pDCols, pSchema) < 0) || (tdInitDataCols(pReadh->pDCols[0], pSchema) < 0) ||
if
((
tdInitDataCols
(
p
rh
->
pDCols
,
pSchema
)
<
0
)
||
(
tdInitDataCols
(
pReadh
->
pDCols
[
0
],
pSchema
)
<
0
)
||
(
tdInitDataCols
(
pReadh
->
pDCols
[
1
],
pSchema
)
<
0
))
{
(
tdInitDataCols
(
pReadh
->
pDCols
[
1
],
pSchema
)
<
0
))
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tdFreeSchema
(
pSchema
);
tdFreeSchema
(
pSchema
);
...
@@ -635,57 +609,57 @@ static int tsdbDeleteFSetImpl(STruncateH *pTruncateH) {
...
@@ -635,57 +609,57 @@ static int tsdbDeleteFSetImpl(STruncateH *pTruncateH) {
tdFreeSchema
(
pSchema
);
tdFreeSchema
(
pSchema
);
// Loop to truncate each block data
// Loop to truncate each block data
for (int i = 0; i < p
Tbl
Handle->pBlkIdx->numOfBlocks; ++i) {
for
(
int
i
=
0
;
i
<
pHandle
->
pBlkIdx
->
numOfBlocks
;
++
i
)
{
SBlock *pBlock = p
Tbl
Handle->pInfo->blocks + i;
SBlock
*
pBlock
=
pHandle
->
pInfo
->
blocks
+
i
;
// Copy the Blocks directly if TS is not interleaved.
// Copy the Blocks directly if TS is not interleaved.
if (!tsdbBlockInterleaved(p
TruncateH
, pBlock)) {
if
(
!
tsdbBlockInterleaved
(
p
rh
,
pBlock
))
{
// tsdbWriteBlockAndDataToFile();
// tsdbWriteBlockAndDataToFile();
continue
;
continue
;
}
}
// Otherwise load the block data and copy the specific rows.
// Otherwise load the block data and copy the specific rows.
if (tsdbLoadBlockData(pReadh, pBlock, p
Tbl
Handle->pInfo) < 0) {
if
(
tsdbLoadBlockData
(
pReadh
,
pBlock
,
pHandle
->
pInfo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if (uid == p
Msg
->uid) {
if
(
uid
==
p
rh
->
pCtlInfo
->
uid
)
{
tsdbFilterDataCols(p
TruncateH
, pReadh->pDCols[0]);
tsdbFilterDataCols
(
p
rh
,
pReadh
->
pDCols
[
0
]);
tsdbDebug
(
"vgId:%d uid %"
PRIu64
" matched, filter block data from rows %d to %d rows"
,
REPO_ID
(
pRepo
),
uid
,
tsdbDebug
(
"vgId:%d uid %"
PRIu64
" matched, filter block data from rows %d to %d rows"
,
REPO_ID
(
pRepo
),
uid
,
pReadh->pDCols[0]->numOfRows, p
TruncateH
->pDCols->numOfRows);
pReadh
->
pDCols
[
0
]
->
numOfRows
,
p
rh
->
pDCols
->
numOfRows
);
if (p
TruncateH
->pDCols->numOfRows <= 0) continue;
if
(
p
rh
->
pDCols
->
numOfRows
<=
0
)
continue
;
if (tsdbWriteBlockToRightFile(p
TruncateH, pTblHandle->pTable, pTruncateH
->pDCols, ppBuf, ppCBuf, ppExBuf) < 0) {
if
(
tsdbWriteBlockToRightFile
(
p
rh
,
pHandle
->
pTable
,
prh
->
pDCols
,
ppBuf
,
ppCBuf
,
ppExBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
}
else
{
}
else
{
tsdbDebug
(
"vgId:%d uid %"
PRIu64
" not matched, copy block data directly
\n
"
,
REPO_ID
(
pRepo
),
uid
);
tsdbDebug
(
"vgId:%d uid %"
PRIu64
" not matched, copy block data directly
\n
"
,
REPO_ID
(
pRepo
),
uid
);
if (tsdbWriteBlockToRightFile(p
TruncateH, pTbl
Handle->pTable, pReadh->pDCols[0], ppBuf, ppCBuf, ppExBuf) < 0) {
if
(
tsdbWriteBlockToRightFile
(
p
rh
,
p
Handle
->
pTable
,
pReadh
->
pDCols
[
0
],
ppBuf
,
ppCBuf
,
ppExBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
}
}
}
}
if (tsdbWriteBlockInfoImpl(TSDB_TRUNCATE_HEAD_FILE(p
TruncateH), pTblHandle->pTable, pTruncateH
->aSupBlk, NULL,
if
(
tsdbWriteBlockInfoImpl
(
TSDB_TRUNCATE_HEAD_FILE
(
p
rh
),
pHandle
->
pTable
,
prh
->
aSupBlk
,
NULL
,
ppBuf
,
&
blkIdx
)
<
0
)
{
ppBuf
,
&
blkIdx
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if ((blkIdx.numOfBlocks > 0) && (taosArrayPush(p
TruncateH
->aBlkIdx, (const void *)(&blkIdx)) == NULL)) {
if
((
blkIdx
.
numOfBlocks
>
0
)
&&
(
taosArrayPush
(
p
rh
->
aBlkIdx
,
(
const
void
*
)(
&
blkIdx
))
==
NULL
))
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
}
}
if (tsdbWriteBlockIdx(TSDB_TRUNCATE_HEAD_FILE(p
TruncateH), pTruncateH
->aBlkIdx, ppBuf) < 0) {
if
(
tsdbWriteBlockIdx
(
TSDB_TRUNCATE_HEAD_FILE
(
p
rh
),
prh
->
aBlkIdx
,
ppBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static int tsdbWriteBlockToRightFile(STruncateH *p
TruncateH
, STable *pTable, SDataCols *pDCols, void **ppBuf,
static
int
tsdbWriteBlockToRightFile
(
STruncateH
*
p
rh
,
STable
*
pTable
,
SDataCols
*
pDCols
,
void
**
ppBuf
,
void
**
ppCBuf
,
void
**
ppExBuf
)
{
void
**
ppCBuf
,
void
**
ppExBuf
)
{
STsdbRepo *pRepo = TSDB_TRUNCATE_REPO(p
TruncateH
);
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
p
rh
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
SDFile
*
pDFile
=
NULL
;
SDFile
*
pDFile
=
NULL
;
bool
isLast
=
false
;
bool
isLast
=
false
;
...
@@ -694,54 +668,23 @@ static int tsdbWriteBlockToRightFile(STruncateH *pTruncateH, STable *pTable, SDa
...
@@ -694,54 +668,23 @@ static int tsdbWriteBlockToRightFile(STruncateH *pTruncateH, STable *pTable, SDa
ASSERT
(
pDCols
->
numOfRows
>
0
);
ASSERT
(
pDCols
->
numOfRows
>
0
);
if
(
pDCols
->
numOfRows
<
pCfg
->
minRowsPerFileBlock
)
{
if
(
pDCols
->
numOfRows
<
pCfg
->
minRowsPerFileBlock
)
{
pDFile = TSDB_TRUNCATE_LAST_FILE(p
TruncateH
);
pDFile
=
TSDB_TRUNCATE_LAST_FILE
(
p
rh
);
isLast
=
true
;
isLast
=
true
;
}
else
{
}
else
{
pDFile = TSDB_TRUNCATE_DATA_FILE(p
TruncateH
);
pDFile
=
TSDB_TRUNCATE_DATA_FILE
(
p
rh
);
isLast
=
false
;
isLast
=
false
;
}
}
if
(
tsdbWriteBlockImpl
(
pRepo
,
pTable
,
pDFile
,
if
(
tsdbWriteBlockImpl
(
pRepo
,
pTable
,
pDFile
,
isLast ? TSDB_TRUNCATE_SMAL_FILE(p
TruncateH) : TSDB_TRUNCATE_SMAD_FILE(pTruncateH
), pDCols,
isLast
?
TSDB_TRUNCATE_SMAL_FILE
(
p
rh
)
:
TSDB_TRUNCATE_SMAD_FILE
(
prh
),
pDCols
,
&
block
,
isLast
,
true
,
ppBuf
,
ppCBuf
,
ppExBuf
)
<
0
)
{
&
block
,
isLast
,
true
,
ppBuf
,
ppCBuf
,
ppExBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if (taosArrayPush(p
TruncateH
->aSupBlk, (void *)(&block)) == NULL) {
if
(
taosArrayPush
(
p
rh
->
aSupBlk
,
(
void
*
)(
&
block
))
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
// static int tsdbWriteBlockAndDataToFile(STruncateH *pTruncateH, STable *pTable, SBlock *pSupBlock, void **ppBuf,
// void **ppCBuf, void **ppExBuf) {
// STsdbRepo *pRepo = TSDB_TRUNCATE_REPO(pTruncateH);
// SDFile * pDFile = NULL;
// bool isLast = false;
// ASSERT(pSupBlock->numOfRows > 0);
// if (pSupBlock->last) {
// pDFile = TSDB_TRUNCATE_LAST_FILE(pTruncateH);
// isLast = true;
// } else {
// pDFile = TSDB_TRUNCATE_DATA_FILE(pTruncateH);
// isLast = false;
// }
// if (tsdbWriteBlockImpl(pRepo, pTable, pDFile,
// isLast ? TSDB_TRUNCATE_SMAL_FILE(pTruncateH) : TSDB_TRUNCATE_SMAD_FILE(pTruncateH),
// pDCols, &block, isLast, true, ppBuf, ppCBuf, ppExBuf) < 0) {
// return -1;
// }
// if (taosArrayPush(pTruncateH->aSupBlk, (void *)(&block)) == NULL) {
// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
// return -1;
// }
// return 0;
// }
*/
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录