Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
43389aa5
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看板
提交
43389aa5
编写于
3月 30, 2022
作者:
A
Alex Duan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add delete
上级
a99b0376
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
922 addition
and
13 deletion
+922
-13
src/client/inc/tscDelete.h
src/client/inc/tscDelete.h
+32
-0
src/client/inc/tscSubquery.h
src/client/inc/tscSubquery.h
+1
-1
src/client/src/tscDelete.c
src/client/src/tscDelete.c
+136
-0
src/client/src/tscServer.c
src/client/src/tscServer.c
+2
-2
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+3
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+8
-1
src/tsdb/inc/tsdbDelete.h
src/tsdb/inc/tsdbDelete.h
+3
-3
src/tsdb/inc/tsdbMemTable.h
src/tsdb/inc/tsdbMemTable.h
+1
-1
src/tsdb/inc/tsdbint.h
src/tsdb/inc/tsdbint.h
+2
-2
src/tsdb/src/tsdbDelete.c
src/tsdb/src/tsdbDelete.c
+734
-0
未找到文件。
src/client/inc/tscDelete.h
0 → 100644
浏览文件 @
43389aa5
/*
* 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/>.
*/
#ifndef TDENGINE_TSCDELETE_H
#define TDENGINE_TSCDELETE_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "qTableMeta.h"
int32_t
executeDelete
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_TSCDELETE_H
src/client/inc/tscSubquery.h
浏览文件 @
43389aa5
...
@@ -54,7 +54,7 @@ void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs);
...
@@ -54,7 +54,7 @@ void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs);
void
tscFreeRetrieveSup
(
void
**
param
);
void
tscFreeRetrieveSup
(
void
**
param
);
SSqlObj
*
tscCreateSTableSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
,
int32_t
cmd
,
__async_cb_func_t
fp
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/client/src/tscDelete.c
0 → 100644
浏览文件 @
43389aa5
/*
* 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 "os.h"
#include "tcmdtype.h"
#include "tscLog.h"
#include "tscUtil.h"
#include "tsclient.h"
#include "tscDelete.h"
int32_t
executeDelete
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
// not super table
pSql
->
cmd
.
active
=
pQueryInfo
;
return
tscBuildAndSendRequest
(
pSql
,
pQueryInfo
);
}
//
// super table
//
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
// pRes->code check only serves in launching super table sub-queries
if
(
pRes
->
code
==
TSDB_CODE_TSC_QUERY_CANCELLED
)
{
pCmd
->
command
=
TSDB_SQL_RETRIEVE_GLOBALMERGE
;
// enable the abort of kill super table function.
return
pRes
->
code
;
}
tExtMemBuffer
**
pMemoryBuf
=
NULL
;
tOrderDescriptor
*
pDesc
=
NULL
;
pRes
->
qId
=
0x1
;
// hack the qhandle check
uint32_t
nBufferSize
=
(
1u
<<
18u
);
// 256KB, default buffer size
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
SSubqueryState
*
pState
=
&
pSql
->
subState
;
int32_t
numOfSub
=
(
pTableMetaInfo
->
pVgroupTables
==
NULL
)
?
pTableMetaInfo
->
vgroupList
->
numOfVgroups
:
(
int32_t
)
taosArrayGetSize
(
pTableMetaInfo
->
pVgroupTables
);
int32_t
ret
=
doInitSubState
(
pSql
,
numOfSub
);
if
(
ret
!=
0
)
{
tscAsyncResultOnError
(
pSql
);
return
ret
;
}
ret
=
tscCreateGlobalMergerEnv
(
pQueryInfo
,
&
pMemoryBuf
,
pSql
->
subState
.
numOfSub
,
&
pDesc
,
&
nBufferSize
,
pSql
->
self
);
if
(
ret
!=
0
)
{
pRes
->
code
=
ret
;
tscAsyncResultOnError
(
pSql
);
tfree
(
pDesc
);
tfree
(
pMemoryBuf
);
return
ret
;
}
tscDebug
(
"0x%"
PRIx64
" retrieved query data from %d vnode(s)"
,
pSql
->
self
,
pState
->
numOfSub
);
pRes
->
code
=
TSDB_CODE_SUCCESS
;
int32_t
i
=
0
;
for
(;
i
<
pState
->
numOfSub
;
++
i
)
{
SRetrieveSupport
*
trs
=
(
SRetrieveSupport
*
)
calloc
(
1
,
sizeof
(
SRetrieveSupport
));
if
(
trs
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" failed to malloc buffer for SRetrieveSupport, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
break
;
}
trs
->
pExtMemBuffer
=
pMemoryBuf
;
trs
->
pOrderDescriptor
=
pDesc
;
trs
->
localBuffer
=
(
tFilePage
*
)
calloc
(
1
,
nBufferSize
+
sizeof
(
tFilePage
));
trs
->
localBufferSize
=
nBufferSize
+
sizeof
(
tFilePage
);
if
(
trs
->
localBuffer
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" failed to malloc buffer for local buffer, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
tfree
(
trs
);
break
;
}
trs
->
localBuffer
->
num
=
0
;
trs
->
subqueryIndex
=
i
;
trs
->
pParentSql
=
pSql
;
SSqlObj
*
pNew
=
tscCreateSTableSubquery
(
pSql
,
trs
,
NULL
);
if
(
pNew
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" failed to malloc buffer for subObj, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
tfree
(
trs
->
localBuffer
);
tfree
(
trs
);
break
;
}
// todo handle multi-vnode situation
if
(
pQueryInfo
->
tsBuf
)
{
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfo
(
&
pNew
->
cmd
);
pNewQueryInfo
->
tsBuf
=
tsBufClone
(
pQueryInfo
->
tsBuf
);
assert
(
pNewQueryInfo
->
tsBuf
!=
NULL
);
}
tscDebug
(
"0x%"
PRIx64
" sub:0x%"
PRIx64
" create subquery success. orderOfSub:%d"
,
pSql
->
self
,
pNew
->
self
,
trs
->
subqueryIndex
);
}
if
(
i
<
pState
->
numOfSub
)
{
tscError
(
"0x%"
PRIx64
" failed to prepare subquery structure and launch subqueries"
,
pSql
->
self
);
pRes
->
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
tscDestroyGlobalMergerEnv
(
pMemoryBuf
,
pDesc
,
pState
->
numOfSub
);
doCleanupSubqueries
(
pSql
,
i
);
return
pRes
->
code
;
// free all allocated resource
}
if
(
pRes
->
code
==
TSDB_CODE_TSC_QUERY_CANCELLED
)
{
tscDestroyGlobalMergerEnv
(
pMemoryBuf
,
pDesc
,
pState
->
numOfSub
);
doCleanupSubqueries
(
pSql
,
i
);
return
pRes
->
code
;
}
doConcurrentlySendSubQueries
(
pSql
);
return
TSDB_CODE_SUCCESS
;
}
\ No newline at end of file
src/client/src/tscServer.c
浏览文件 @
43389aa5
...
@@ -3380,7 +3380,7 @@ int tscBuildDelDataMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
...
@@ -3380,7 +3380,7 @@ int tscBuildDelDataMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
return
build
S
TableDelDataMsg
(
pSql
,
pCmd
,
pQueryInfo
,
pTableMetaInfo
,
pInfo
);
return
buildTableDelDataMsg
(
pSql
,
pCmd
,
pQueryInfo
,
pTableMetaInfo
,
pInfo
);
}
else
{
}
else
{
return
buildTableDelDataMsg
(
pSql
,
pCmd
,
pQueryInfo
,
pTableMetaInfo
,
pInfo
);
return
buildTableDelDataMsg
(
pSql
,
pCmd
,
pQueryInfo
,
pTableMetaInfo
,
pInfo
);
}
}
...
@@ -3390,6 +3390,7 @@ void tscInitMsgsFp() {
...
@@ -3390,6 +3390,7 @@ void tscInitMsgsFp() {
tscBuildMsg
[
TSDB_SQL_SELECT
]
=
tscBuildQueryMsg
;
tscBuildMsg
[
TSDB_SQL_SELECT
]
=
tscBuildQueryMsg
;
tscBuildMsg
[
TSDB_SQL_INSERT
]
=
tscBuildSubmitMsg
;
tscBuildMsg
[
TSDB_SQL_INSERT
]
=
tscBuildSubmitMsg
;
tscBuildMsg
[
TSDB_SQL_FETCH
]
=
tscBuildFetchMsg
;
tscBuildMsg
[
TSDB_SQL_FETCH
]
=
tscBuildFetchMsg
;
tscBuildMsg
[
TSDB_SQL_DELETE_DATA
]
=
tscBuildDelDataMsg
;
tscBuildMsg
[
TSDB_SQL_CREATE_DB
]
=
tscBuildCreateDbMsg
;
tscBuildMsg
[
TSDB_SQL_CREATE_DB
]
=
tscBuildCreateDbMsg
;
tscBuildMsg
[
TSDB_SQL_CREATE_USER
]
=
tscBuildUserMsg
;
tscBuildMsg
[
TSDB_SQL_CREATE_USER
]
=
tscBuildUserMsg
;
...
@@ -3425,7 +3426,6 @@ void tscInitMsgsFp() {
...
@@ -3425,7 +3426,6 @@ void tscInitMsgsFp() {
tscBuildMsg
[
TSDB_SQL_KILL_QUERY
]
=
tscBuildKillMsg
;
tscBuildMsg
[
TSDB_SQL_KILL_QUERY
]
=
tscBuildKillMsg
;
tscBuildMsg
[
TSDB_SQL_KILL_STREAM
]
=
tscBuildKillMsg
;
tscBuildMsg
[
TSDB_SQL_KILL_STREAM
]
=
tscBuildKillMsg
;
tscBuildMsg
[
TSDB_SQL_KILL_CONNECTION
]
=
tscBuildKillMsg
;
tscBuildMsg
[
TSDB_SQL_KILL_CONNECTION
]
=
tscBuildKillMsg
;
tscBuildMsg
[
TSDB_SQL_DELETE_DATA
]
=
tscBuildDelDataMsg
;
tscProcessMsgRsp
[
TSDB_SQL_SELECT
]
=
tscProcessQueryRsp
;
tscProcessMsgRsp
[
TSDB_SQL_SELECT
]
=
tscProcessQueryRsp
;
tscProcessMsgRsp
[
TSDB_SQL_FETCH
]
=
tscProcessRetrieveRspFromNode
;
tscProcessMsgRsp
[
TSDB_SQL_FETCH
]
=
tscProcessRetrieveRspFromNode
;
...
...
src/client/src/tscSubquery.c
浏览文件 @
43389aa5
...
@@ -2716,7 +2716,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
...
@@ -2716,7 +2716,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
trs
->
subqueryIndex
=
i
;
trs
->
subqueryIndex
=
i
;
trs
->
pParentSql
=
pSql
;
trs
->
pParentSql
=
pSql
;
SSqlObj
*
pNew
=
tscCreateSTableSubquery
(
pSql
,
trs
,
NULL
);
SSqlObj
*
pNew
=
tscCreateSTableSubquery
(
pSql
,
trs
,
NULL
,
tscRetrieveDataRes
,
CMD_SQL_SELECT
);
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" failed to malloc buffer for subObj, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
tscError
(
"0x%"
PRIx64
" failed to malloc buffer for subObj, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
tfree
(
trs
->
localBuffer
);
tfree
(
trs
->
localBuffer
);
...
@@ -3165,12 +3165,12 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
...
@@ -3165,12 +3165,12 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
}
}
}
}
static
SSqlObj
*
tscCreateSTableSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
)
{
static
SSqlObj
*
tscCreateSTableSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
,
int32_t
cmd
,
__async_cb_func_t
fp
)
{
const
int32_t
table_index
=
0
;
const
int32_t
table_index
=
0
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfo
(
pCmd
);
// Parent SQueryInfo
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfo
(
pCmd
);
// Parent SQueryInfo
SSqlObj
*
pNew
=
createSubqueryObj
(
pSql
,
table_index
,
tscRetrieveDataRes
,
trsupport
,
TSDB_SQL_SELECT
,
prevSqlObj
);
SSqlObj
*
pNew
=
createSubqueryObj
(
pSql
,
table_index
,
fp
,
trsupport
,
cmd
,
prevSqlObj
);
if
(
pNew
!=
NULL
)
{
// the sub query of two-stage super table query
if
(
pNew
!=
NULL
)
{
// the sub query of two-stage super table query
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
&
pNew
->
cmd
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
&
pNew
->
cmd
);
...
...
src/client/src/tscUtil.c
浏览文件 @
43389aa5
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include "ttimer.h"
#include "ttimer.h"
#include "ttokendef.h"
#include "ttokendef.h"
#include "cJSON.h"
#include "cJSON.h"
#include "tscDelete.h"
#ifdef HTTP_EMBEDDED
#ifdef HTTP_EMBEDDED
#include "httpInt.h"
#include "httpInt.h"
...
@@ -4168,6 +4169,12 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
...
@@ -4168,6 +4169,12 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
if
(
pSql
->
cmd
.
command
==
TSDB_SQL_RETRIEVE_EMPTY_RESULT
)
{
if
(
pSql
->
cmd
.
command
==
TSDB_SQL_RETRIEVE_EMPTY_RESULT
)
{
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
0
);
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
0
);
return
;
return
;
}
else
if
(
pSql
->
cmd
.
command
==
TSDB_SQL_DELETE_DATA
)
{
code
=
executeDelete
(
pSql
,
pQueryInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
0
);
}
return
;
}
}
if
(
pSql
->
cmd
.
command
==
TSDB_SQL_SELECT
)
{
if
(
pSql
->
cmd
.
command
==
TSDB_SQL_SELECT
)
{
...
...
src/tsdb/inc/tsdb
Trunca
te.h
→
src/tsdb/inc/tsdb
Dele
te.h
浏览文件 @
43389aa5
...
@@ -12,8 +12,8 @@
...
@@ -12,8 +12,8 @@
* You should have received a copy of the GNU Affero General Public License
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef _TD_TSDB_
TRUNCA
TE_H_
#ifndef _TD_TSDB_
DELE
TE_H_
#define _TD_TSDB_
TRUNCA
TE_H_
#define _TD_TSDB_
DELE
TE_H_
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -38,4 +38,4 @@ int tsdbControlDelete(STsdbRepo* pRepo, SControlDataInfo* pCtlDataInfo);
...
@@ -38,4 +38,4 @@ int tsdbControlDelete(STsdbRepo* pRepo, SControlDataInfo* pCtlDataInfo);
}
}
#endif
#endif
#endif
/* _TD_TSDB_TRUNCATE_H_ */
#endif
/* _TD_TSDB_DELETE_H_ */
\ No newline at end of file
\ No newline at end of file
src/tsdb/inc/tsdbMemTable.h
浏览文件 @
43389aa5
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#ifndef _TD_TSDB_MEMTABLE_H_
#ifndef _TD_TSDB_MEMTABLE_H_
#define _TD_TSDB_MEMTABLE_H_
#define _TD_TSDB_MEMTABLE_H_
#include "tsdb
Trunca
te.h"
#include "tsdb
Dele
te.h"
typedef
struct
{
typedef
struct
{
int
rowsInserted
;
int
rowsInserted
;
int
rowsUpdated
;
int
rowsUpdated
;
...
...
src/tsdb/inc/tsdbint.h
浏览文件 @
43389aa5
...
@@ -66,8 +66,8 @@ extern "C" {
...
@@ -66,8 +66,8 @@ extern "C" {
#include "tsdbCommit.h"
#include "tsdbCommit.h"
// Compact
// Compact
#include "tsdbCompact.h"
#include "tsdbCompact.h"
//
Trunca
te
//
Dele
te
#include "tsdb
Trunca
te.h"
#include "tsdb
Dele
te.h"
// Commit Queue
// Commit Queue
#include "tsdbCommitQueue.h"
#include "tsdbCommitQueue.h"
...
...
src/tsdb/src/tsdb
Trunca
te.c
→
src/tsdb/src/tsdb
Dele
te.c
浏览文件 @
43389aa5
...
@@ -13,12 +13,12 @@
...
@@ -13,12 +13,12 @@
* 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 "tsdb
Trunca
te.h"
#include "tsdb
Dele
te.h"
enum
{
enum
{
TSDB_NO_
TRUNCA
TE
,
TSDB_NO_
DELE
TE
,
TSDB_IN_
TRUNCA
TE
,
TSDB_IN_
DELE
TE
,
TSDB_WAITING_
TRUNCA
TE
,
TSDB_WAITING_
DELE
TE
,
};
};
enum
BlockSolve
{
enum
BlockSolve
{
...
@@ -32,12 +32,12 @@ typedef struct {
...
@@ -32,12 +32,12 @@ typedef struct {
SBlockIdx
*
pBlkIdx
;
SBlockIdx
*
pBlkIdx
;
SBlockIdx
bIndex
;
SBlockIdx
bIndex
;
SBlockInfo
*
pInfo
;
SBlockInfo
*
pInfo
;
}
STable
Trunca
teH
;
}
STable
Dele
teH
;
typedef
struct
{
typedef
struct
{
SRtn
rtn
;
SRtn
rtn
;
SFSIter
fsIter
;
SFSIter
fsIter
;
SArray
*
tblArray
;
// STable
Trunca
teH, table array to cache table obj and block indexes
SArray
*
tblArray
;
// STable
Dele
teH, table array to cache table obj and block indexes
SReadH
readh
;
SReadH
readh
;
SDFileSet
wSet
;
SDFileSet
wSet
;
SArray
*
aBlkIdx
;
SArray
*
aBlkIdx
;
...
@@ -45,46 +45,44 @@ typedef struct {
...
@@ -45,46 +45,44 @@ typedef struct {
SArray
*
aSubBlk
;
SArray
*
aSubBlk
;
SDataCols
*
pDCols
;
SDataCols
*
pDCols
;
SControlDataInfo
*
pCtlInfo
;
SControlDataInfo
*
pCtlInfo
;
}
STruncateH
;
}
SDeleteH
;
#define TSDB_TRUNCATE_WSET(ptru) (&((ptru)->wSet))
#define TSDB_DELETE_WSET(pdh) (&((pdh)->wSet))
#define TSDB_TRUNCATE_REPO(ptru) TSDB_READ_REPO(&((ptru)->readh))
#define TSDB_DELETE_REPO(pdh) TSDB_READ_REPO(&((pdh)->readh))
#define TSDB_TRUNCATE_HEAD_FILE(ptru) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(ptru), TSDB_FILE_HEAD)
#define TSDB_DELETE_HEAD_FILE(pdh) TSDB_DFILE_IN_SET(TSDB_DELETE_WSET(pdh), TSDB_FILE_HEAD)
#define TSDB_TRUNCATE_DATA_FILE(ptru) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(ptru), TSDB_FILE_DATA)
#define TSDB_DELETE_DATA_FILE(pdh) TSDB_DFILE_IN_SET(TSDB_DELETE_WSET(pdh), TSDB_FILE_DATA)
#define TSDB_TRUNCATE_LAST_FILE(ptru) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(ptru), TSDB_FILE_LAST)
#define TSDB_DELETE_LAST_FILE(pdh) TSDB_DFILE_IN_SET(TSDB_DELETE_WSET(pdh), TSDB_FILE_LAST)
#define TSDB_TRUNCATE_SMAD_FILE(ptru) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(ptru), TSDB_FILE_SMAD)
#define TSDB_DELETE_SMAD_FILE(pdh) TSDB_DFILE_IN_SET(TSDB_DELETE_WSET(pdh), TSDB_FILE_SMAD)
#define TSDB_TRUNCATE_SMAL_FILE(ptru) TSDB_DFILE_IN_SET(TSDB_TRUNCATE_WSET(ptru), TSDB_FILE_SMAL)
#define TSDB_DELETE_SMAL_FILE(pdh) TSDB_DFILE_IN_SET(TSDB_DELETE_WSET(pdh), TSDB_FILE_SMAL)
#define TSDB_TRUNCATE_BUF(ptru) TSDB_READ_BUF(&((ptru)->readh))
#define TSDB_DELETE_BUF(pdh) TSDB_READ_BUF(&((pdh)->readh))
#define TSDB_TRUNCATE_COMP_BUF(ptru) TSDB_READ_COMP_BUF(&((ptru)->readh))
#define TSDB_DELETE_COMP_BUF(pdh) TSDB_READ_COMP_BUF(&((pdh)->readh))
#define TSDB_TRUNCATE_EXBUF(ptru) TSDB_READ_EXBUF(&((ptru)->readh))
#define TSDB_DELETE_EXBUF(pdh) TSDB_READ_EXBUF(&((pdh)->readh))
static
void
tsdbStartTruncate
(
STsdbRepo
*
pRepo
);
static
void
tsdbStartDelete
(
STsdbRepo
*
pRepo
);
static
void
tsdbEndTruncate
(
STsdbRepo
*
pRepo
,
int
eno
);
static
void
tsdbEndDelete
(
STsdbRepo
*
pRepo
,
int
eno
);
static
int
tsdbTruncateMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbDeleteMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbTruncateTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
static
int
tsdbDeleteTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
static
int
tsdbFSetTruncate
(
STruncateH
*
ptru
,
SDFileSet
*
pSet
);
static
int
tsdbFSetDelete
(
SDeleteH
*
pdh
,
SDFileSet
*
pSet
);
static
int
tsdbFSetDelete
(
STruncateH
*
ptru
,
SDFileSet
*
pSet
);
static
int
tsdbInitDeleteH
(
SDeleteH
*
pdh
,
STsdbRepo
*
pRepo
);
static
int
tsdbInitTruncateH
(
STruncateH
*
ptru
,
STsdbRepo
*
pRepo
);
static
void
tsdbDestroyDeleteH
(
SDeleteH
*
pdh
);
static
void
tsdbDestroyTruncateH
(
STruncateH
*
ptru
);
static
int
tsdbInitDeleteTblArray
(
SDeleteH
*
pdh
);
static
int
tsdbInitTruncateTblArray
(
STruncateH
*
ptru
);
static
void
tsdbDestroyDeleteTblArray
(
SDeleteH
*
pdh
);
static
void
tsdbDestroyTruncateTblArray
(
STruncateH
*
ptru
);
static
int
tsdbCacheFSetIndex
(
SDeleteH
*
pdh
);
static
int
tsdbCacheFSetIndex
(
STruncateH
*
ptru
);
static
int
tsdbDeleteCache
(
STsdbRepo
*
pRepo
,
void
*
param
);
static
int
tsdbTruncateCache
(
STsdbRepo
*
pRepo
,
void
*
param
);
static
int
tsdbFSetInit
(
SDeleteH
*
pdh
,
SDFileSet
*
pSet
);
static
int
tsdbFSetInit
(
STruncateH
*
ptru
,
SDFileSet
*
pSet
);
static
void
tsdbDeleteFSetEnd
(
SDeleteH
*
pdh
);
static
void
tsdbTruncateFSetEnd
(
STruncateH
*
ptru
);
static
int
tsdbFSetDeleteImpl
(
SDeleteH
*
pdh
);
static
int
tsdbTruncateFSetImpl
(
STruncateH
*
ptru
);
static
int
tsdbBlockSolve
(
SDeleteH
*
pdh
,
SBlock
*
pBlock
);
static
int
tsdbFSetDeleteImpl
(
STruncateH
*
ptru
);
static
int
tsdbWriteBlockToFile
(
SDeleteH
*
pdh
,
STable
*
pTable
,
SDataCols
*
pDCols
,
void
**
ppBuf
,
static
int
tsdbBlockSolve
(
STruncateH
*
ptru
,
SBlock
*
pBlock
);
static
int
tsdbWriteBlockToFile
(
STruncateH
*
ptru
,
STable
*
pTable
,
SDataCols
*
pDCols
,
void
**
ppBuf
,
void
**
ppCBuf
,
void
**
ppExBuf
,
SBlock
*
pBlock
);
void
**
ppCBuf
,
void
**
ppExBuf
,
SBlock
*
pBlock
);
static
int
tsdb
Trunca
teImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
static
int
tsdb
Dele
teImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
// delete
// delete
int
tsdbControlDelete
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
int
tsdbControlDelete
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
int32_t
ret
=
tsdb
Trunca
teImplCommon
(
pRepo
,
pCtlInfo
);
int32_t
ret
=
tsdb
Dele
teImplCommon
(
pRepo
,
pCtlInfo
);
if
(
pCtlInfo
->
pRsp
)
{
if
(
pCtlInfo
->
pRsp
)
{
pCtlInfo
->
pRsp
->
affectedRows
=
htonl
(
pCtlInfo
->
pRsp
->
affectedRows
);
pCtlInfo
->
pRsp
->
affectedRows
=
htonl
(
pCtlInfo
->
pRsp
->
affectedRows
);
pCtlInfo
->
pRsp
->
code
=
ret
;
pCtlInfo
->
pRsp
->
code
=
ret
;
...
@@ -93,10 +91,10 @@ int tsdbControlDelete(STsdbRepo* pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -93,10 +91,10 @@ int tsdbControlDelete(STsdbRepo* pRepo, SControlDataInfo* pCtlInfo) {
return
ret
;
return
ret
;
}
}
static
int
tsdb
Trunca
teImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
static
int
tsdb
Dele
teImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
// Step 1: check and clear cache
// Step 1: check and clear cache
if
((
code
=
tsdb
Trunca
teCache
(
pRepo
,
pCtlInfo
))
!=
0
)
{
if
((
code
=
tsdb
Dele
teCache
(
pRepo
,
pCtlInfo
))
!=
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
));
...
@@ -106,34 +104,34 @@ static int tsdbTruncateImplCommon(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo)
...
@@ -106,34 +104,34 @@ static int tsdbTruncateImplCommon(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo)
// Step 2: truncate and rebuild DFileSets
// Step 2: truncate and rebuild DFileSets
// Check if there are files in TSDB FS to truncate
// Check if there are files in TSDB FS to truncate
if
((
REPO_FS
(
pRepo
)
->
cstatus
->
pmf
==
NULL
)
||
(
taosArrayGetSize
(
REPO_FS
(
pRepo
)
->
cstatus
->
df
)
<=
0
))
{
if
((
REPO_FS
(
pRepo
)
->
cstatus
->
pmf
==
NULL
)
||
(
taosArrayGetSize
(
REPO_FS
(
pRepo
)
->
cstatus
->
df
)
<=
0
))
{
pRepo
->
truncateState
=
TSDB_NO_
TRUNCA
TE
;
pRepo
->
truncateState
=
TSDB_NO_
DELE
TE
;
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
-
1
;
return
-
1
;
}
}
tsdbStart
Trunca
te
(
pRepo
);
tsdbStart
Dele
te
(
pRepo
);
if
(
tsdb
Trunca
teMeta
(
pRepo
)
<
0
)
{
if
(
tsdb
Dele
teMeta
(
pRepo
)
<
0
)
{
tsdbError
(
"vgId:%d failed to truncate META data since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to truncate META data since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
goto
_err
;
goto
_err
;
}
}
if
(
tsdb
Trunca
teTSData
(
pRepo
,
pCtlInfo
)
<
0
)
{
if
(
tsdb
Dele
teTSData
(
pRepo
,
pCtlInfo
)
<
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
;
}
}
tsdbEnd
Trunca
te
(
pRepo
,
TSDB_CODE_SUCCESS
);
tsdbEnd
Dele
te
(
pRepo
,
TSDB_CODE_SUCCESS
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_err:
_err:
pRepo
->
code
=
terrno
;
pRepo
->
code
=
terrno
;
tsdbEnd
Trunca
te
(
pRepo
,
terrno
);
tsdbEnd
Dele
te
(
pRepo
,
terrno
);
return
-
1
;
return
-
1
;
}
}
static
int
tsdb
Trunca
teCache
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
static
int
tsdb
Dele
teCache
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
// step 1: reset query cache(reset all or the specific cache)
// step 1: reset query cache(reset all or the specific cache)
// TODO ... check with Doctor Liao
// TODO ... check with Doctor Liao
// if(... <0){
// if(... <0){
...
@@ -151,39 +149,39 @@ static int tsdbTruncateCache(STsdbRepo *pRepo, void *param) {
...
@@ -151,39 +149,39 @@ static int tsdbTruncateCache(STsdbRepo *pRepo, void *param) {
return
0
;
return
0
;
}
}
static
void
tsdbStart
Trunca
te
(
STsdbRepo
*
pRepo
)
{
static
void
tsdbStart
Dele
te
(
STsdbRepo
*
pRepo
)
{
assert
(
pRepo
->
truncateState
!=
TSDB_IN_
TRUNCA
TE
);
assert
(
pRepo
->
truncateState
!=
TSDB_IN_
DELE
TE
);
tsdbInfo
(
"vgId:%d start to truncate!"
,
REPO_ID
(
pRepo
));
tsdbInfo
(
"vgId:%d start to truncate!"
,
REPO_ID
(
pRepo
));
tsdbStartFSTxn
(
pRepo
,
0
,
0
);
tsdbStartFSTxn
(
pRepo
,
0
,
0
);
pRepo
->
code
=
TSDB_CODE_SUCCESS
;
pRepo
->
code
=
TSDB_CODE_SUCCESS
;
pRepo
->
truncateState
=
TSDB_IN_
TRUNCA
TE
;
pRepo
->
truncateState
=
TSDB_IN_
DELE
TE
;
}
}
static
void
tsdbEnd
Trunca
te
(
STsdbRepo
*
pRepo
,
int
eno
)
{
static
void
tsdbEnd
Dele
te
(
STsdbRepo
*
pRepo
,
int
eno
)
{
if
(
eno
!=
TSDB_CODE_SUCCESS
)
{
if
(
eno
!=
TSDB_CODE_SUCCESS
)
{
tsdbEndFSTxnWithError
(
REPO_FS
(
pRepo
));
tsdbEndFSTxnWithError
(
REPO_FS
(
pRepo
));
}
else
{
}
else
{
tsdbEndFSTxn
(
pRepo
);
tsdbEndFSTxn
(
pRepo
);
}
}
pRepo
->
truncateState
=
TSDB_NO_
TRUNCA
TE
;
pRepo
->
truncateState
=
TSDB_NO_
DELE
TE
;
tsdbInfo
(
"vgId:%d truncate over, %s"
,
REPO_ID
(
pRepo
),
(
eno
==
TSDB_CODE_SUCCESS
)
?
"succeed"
:
"failed"
);
tsdbInfo
(
"vgId:%d truncate over, %s"
,
REPO_ID
(
pRepo
),
(
eno
==
TSDB_CODE_SUCCESS
)
?
"succeed"
:
"failed"
);
tsem_post
(
&
(
pRepo
->
readyToCommit
));
tsem_post
(
&
(
pRepo
->
readyToCommit
));
}
}
static
int
tsdb
Trunca
teMeta
(
STsdbRepo
*
pRepo
)
{
static
int
tsdb
Dele
teMeta
(
STsdbRepo
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
tsdbUpdateMFile
(
pfs
,
pfs
->
cstatus
->
pmf
);
tsdbUpdateMFile
(
pfs
,
pfs
->
cstatus
->
pmf
);
return
0
;
return
0
;
}
}
static
int
tsdb
Trunca
teTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
static
int
tsdb
Dele
teTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
S
Trunca
teH
truncateH
=
{
0
};
S
Dele
teH
truncateH
=
{
0
};
SDFileSet
*
pSet
=
NULL
;
SDFileSet
*
pSet
=
NULL
;
tsdbDebug
(
"vgId:%d start to truncate TS data for %d"
,
REPO_ID
(
pRepo
),
pCtlInfo
->
ctlData
.
tids
[
0
]);
tsdbDebug
(
"vgId:%d start to truncate TS data for %d"
,
REPO_ID
(
pRepo
),
pCtlInfo
->
ctlData
.
tids
[
0
]);
if
(
tsdbInit
Trunca
teH
(
&
truncateH
,
pRepo
)
<
0
)
{
if
(
tsdbInit
Dele
teH
(
&
truncateH
,
pRepo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -218,15 +216,10 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -218,15 +216,10 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
}
}
#endif
#endif
if
(
pCtlInfo
->
ctlData
.
command
==
CMD_TRUNCATE
)
{
if
(
tsdbFSetTruncate
(
&
truncateH
,
pSet
)
<
0
)
{
if
(
pCtlInfo
->
ctlData
.
command
==
CMD_DELETE_DATA
)
{
tsdbDestroyTruncateH
(
&
truncateH
);
tsdbError
(
"vgId:%d failed to truncate table in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
return
-
1
;
}
}
else
if
(
pCtlInfo
->
ctlData
.
command
==
CMD_DELETE_DATA
)
{
if
(
tsdbFSetDelete
(
&
truncateH
,
pSet
)
<
0
)
{
if
(
tsdbFSetDelete
(
&
truncateH
,
pSet
)
<
0
)
{
tsdbDestroy
Trunca
teH
(
&
truncateH
);
tsdbDestroy
Dele
teH
(
&
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
));
return
-
1
;
return
-
1
;
}
}
...
@@ -236,29 +229,29 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -236,29 +229,29 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
}
}
tsdbDestroy
Trunca
teH
(
&
truncateH
);
tsdbDestroy
Dele
teH
(
&
truncateH
);
tsdbDebug
(
"vgId:%d truncate TS data over"
,
REPO_ID
(
pRepo
));
tsdbDebug
(
"vgId:%d truncate TS data over"
,
REPO_ID
(
pRepo
));
return
0
;
return
0
;
}
}
static
int
tsdbFSetDelete
(
S
TruncateH
*
ptru
,
SDFileSet
*
pSet
)
{
static
int
tsdbFSetDelete
(
S
DeleteH
*
pdh
,
SDFileSet
*
pSet
)
{
STsdbRepo
*
pRepo
=
TSDB_
TRUNCATE_REPO
(
ptru
);
STsdbRepo
*
pRepo
=
TSDB_
DELETE_REPO
(
pdh
);
SDiskID
did
=
{
0
};
SDiskID
did
=
{
0
};
SDFileSet
*
pWSet
=
TSDB_
TRUNCATE_WSET
(
ptru
);
SDFileSet
*
pWSet
=
TSDB_
DELETE_WSET
(
pdh
);
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
(
tsdbFSetInit
(
p
tru
,
pSet
)
<
0
)
{
if
(
tsdbFSetInit
(
p
dh
,
pSet
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// Create new fset as truncated fset
// Create new fset as truncated fset
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
p
tru
->
rtn
)),
&
(
did
.
level
),
&
(
did
.
id
));
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
p
dh
->
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
));
tsdb
TruncateFSetEnd
(
ptru
);
tsdb
DeleteFSetEnd
(
pdh
);
return
-
1
;
return
-
1
;
}
}
...
@@ -282,146 +275,90 @@ static int tsdbFSetDelete(STruncateH *ptru, SDFileSet *pSet) {
...
@@ -282,146 +275,90 @@ static int tsdbFSetDelete(STruncateH *ptru, SDFileSet *pSet) {
return
-
1
;
return
-
1
;
}
}
if
(
tsdbFSetDeleteImpl
(
p
tru
)
<
0
)
{
if
(
tsdbFSetDeleteImpl
(
p
dh
)
<
0
)
{
tsdbCloseDFileSet
(
TSDB_
TRUNCATE_WSET
(
ptru
));
tsdbCloseDFileSet
(
TSDB_
DELETE_WSET
(
pdh
));
tsdbRemoveDFileSet
(
TSDB_
TRUNCATE_WSET
(
ptru
));
tsdbRemoveDFileSet
(
TSDB_
DELETE_WSET
(
pdh
));
tsdb
TruncateFSetEnd
(
ptru
);
tsdb
DeleteFSetEnd
(
pdh
);
return
-
1
;
return
-
1
;
}
}
tsdbCloseDFileSet
(
TSDB_
TRUNCATE_WSET
(
ptru
));
tsdbCloseDFileSet
(
TSDB_
DELETE_WSET
(
pdh
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_
TRUNCATE_WSET
(
ptru
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_
DELETE_WSET
(
pdh
));
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
);
tsdb
TruncateFSetEnd
(
ptru
);
tsdb
DeleteFSetEnd
(
pdh
);
return
0
;
return
0
;
}
}
static
int
tsdbFSetTruncate
(
STruncateH
*
ptru
,
SDFileSet
*
pSet
)
{
static
int
tsdbInitDeleteH
(
SDeleteH
*
pdh
,
STsdbRepo
*
pRepo
)
{
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
ptru
);
SDiskID
did
=
{
0
};
SDFileSet
*
pWSet
=
TSDB_TRUNCATE_WSET
(
ptru
);
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
));
if
(
tsdbFSetInit
(
ptru
,
pSet
)
<
0
)
{
return
-
1
;
}
// Create new fset as truncated fset
tfsAllocDisk
(
tsdbGetFidLevel
(
pSet
->
fid
,
&
(
ptru
->
rtn
)),
&
(
did
.
level
),
&
(
did
.
id
));
if
(
did
.
level
==
TFS_UNDECIDED_LEVEL
)
{
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
));
tsdbTruncateFSetEnd
(
ptru
);
return
-
1
;
}
// Only .head is created, use original .data/.last/.smad/.smal
tsdbInitDFileSetEx
(
pWSet
,
pSet
);
pWSet
->
state
=
0
;
SDFile
*
pHeadFile
=
TSDB_DFILE_IN_SET
(
pWSet
,
TSDB_FILE_HEAD
);
tsdbInitDFile
(
pHeadFile
,
did
,
REPO_ID
(
pRepo
),
TSDB_FSET_FID
(
pSet
),
FS_TXN_VERSION
(
REPO_FS
(
pRepo
)),
TSDB_FILE_HEAD
);
if
(
tsdbCreateDFile
(
pHeadFile
,
true
,
TSDB_FILE_HEAD
)
<
0
)
{
tsdbError
(
"vgId:%d failed to truncate table in FSET %d since %s"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tstrerror
(
terrno
));
tsdbCloseDFile
(
pHeadFile
);
tsdbRemoveDFile
(
pHeadFile
);
return
-
1
;
}
tsdbCloseDFile
(
pHeadFile
);
if
(
tsdbOpenDFileSet
(
pWSet
,
O_RDWR
)
<
0
)
{
tsdbError
(
"vgId:%d failed to open file set %d since %s"
,
REPO_ID
(
pRepo
),
TSDB_FSET_FID
(
pWSet
),
tstrerror
(
terrno
));
return
-
1
;
}
if
(
tsdbTruncateFSetImpl
(
ptru
)
<
0
)
{
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
ptru
));
tsdbRemoveDFileSet
(
TSDB_TRUNCATE_WSET
(
ptru
));
tsdbTruncateFSetEnd
(
ptru
);
return
-
1
;
}
tsdbCloseDFileSet
(
TSDB_TRUNCATE_WSET
(
ptru
));
tsdbUpdateDFileSet
(
REPO_FS
(
pRepo
),
TSDB_TRUNCATE_WSET
(
ptru
));
tsdbDebug
(
"vgId:%d FSET %d truncate table over"
,
REPO_ID
(
pRepo
),
pSet
->
fid
);
tsdbTruncateFSetEnd
(
ptru
);
return
0
;
}
static
int
tsdbInitTruncateH
(
STruncateH
*
ptru
,
STsdbRepo
*
pRepo
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
memset
(
p
tru
,
0
,
sizeof
(
*
ptru
));
memset
(
p
dh
,
0
,
sizeof
(
*
pdh
));
TSDB_FSET_SET_CLOSED
(
TSDB_
TRUNCATE_WSET
(
ptru
));
TSDB_FSET_SET_CLOSED
(
TSDB_
DELETE_WSET
(
pdh
));
tsdbGetRtnSnap
(
pRepo
,
&
(
p
tru
->
rtn
));
tsdbGetRtnSnap
(
pRepo
,
&
(
p
dh
->
rtn
));
tsdbFSIterInit
(
&
(
p
tru
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
tsdbFSIterInit
(
&
(
p
dh
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
if
(
tsdbInitReadH
(
&
(
p
tru
->
readh
),
pRepo
)
<
0
)
{
if
(
tsdbInitReadH
(
&
(
p
dh
->
readh
),
pRepo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
if
(
tsdbInit
TruncateTblArray
(
ptru
)
<
0
)
{
if
(
tsdbInit
DeleteTblArray
(
pdh
)
<
0
)
{
tsdbDestroy
TruncateH
(
ptru
);
tsdbDestroy
DeleteH
(
pdh
);
return
-
1
;
return
-
1
;
}
}
p
tru
->
aBlkIdx
=
taosArrayInit
(
1024
,
sizeof
(
SBlockIdx
));
p
dh
->
aBlkIdx
=
taosArrayInit
(
1024
,
sizeof
(
SBlockIdx
));
if
(
p
tru
->
aBlkIdx
==
NULL
)
{
if
(
p
dh
->
aBlkIdx
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroy
TruncateH
(
ptru
);
tsdbDestroy
DeleteH
(
pdh
);
return
-
1
;
return
-
1
;
}
}
p
tru
->
aSupBlk
=
taosArrayInit
(
1024
,
sizeof
(
SBlock
));
p
dh
->
aSupBlk
=
taosArrayInit
(
1024
,
sizeof
(
SBlock
));
if
(
p
tru
->
aSupBlk
==
NULL
)
{
if
(
p
dh
->
aSupBlk
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroy
TruncateH
(
ptru
);
tsdbDestroy
DeleteH
(
pdh
);
return
-
1
;
return
-
1
;
}
}
p
tru
->
aSubBlk
=
taosArrayInit
(
20
,
sizeof
(
SBlock
));
p
dh
->
aSubBlk
=
taosArrayInit
(
20
,
sizeof
(
SBlock
));
if
(
p
tru
->
aSubBlk
==
NULL
)
{
if
(
p
dh
->
aSubBlk
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroy
TruncateH
(
ptru
);
tsdbDestroy
DeleteH
(
pdh
);
return
-
1
;
return
-
1
;
}
}
p
tru
->
pDCols
=
tdNewDataCols
(
0
,
pCfg
->
maxRowsPerFileBlock
);
p
dh
->
pDCols
=
tdNewDataCols
(
0
,
pCfg
->
maxRowsPerFileBlock
);
if
(
p
tru
->
pDCols
==
NULL
)
{
if
(
p
dh
->
pDCols
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbDestroy
TruncateH
(
ptru
);
tsdbDestroy
DeleteH
(
pdh
);
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static
void
tsdbDestroy
TruncateH
(
STruncateH
*
ptru
)
{
static
void
tsdbDestroy
DeleteH
(
SDeleteH
*
pdh
)
{
p
tru
->
pDCols
=
tdFreeDataCols
(
ptru
->
pDCols
);
p
dh
->
pDCols
=
tdFreeDataCols
(
pdh
->
pDCols
);
p
tru
->
aSupBlk
=
taosArrayDestroy
(
&
ptru
->
aSupBlk
);
p
dh
->
aSupBlk
=
taosArrayDestroy
(
&
pdh
->
aSupBlk
);
p
tru
->
aSubBlk
=
taosArrayDestroy
(
&
ptru
->
aSubBlk
);
p
dh
->
aSubBlk
=
taosArrayDestroy
(
&
pdh
->
aSubBlk
);
p
tru
->
aBlkIdx
=
taosArrayDestroy
(
&
ptru
->
aBlkIdx
);
p
dh
->
aBlkIdx
=
taosArrayDestroy
(
&
pdh
->
aBlkIdx
);
tsdbDestroy
TruncateTblArray
(
ptru
);
tsdbDestroy
DeleteTblArray
(
pdh
);
tsdbDestroyReadH
(
&
(
p
tru
->
readh
));
tsdbDestroyReadH
(
&
(
p
dh
->
readh
));
tsdbCloseDFileSet
(
TSDB_
TRUNCATE_WSET
(
ptru
));
tsdbCloseDFileSet
(
TSDB_
DELETE_WSET
(
pdh
));
}
}
// init tbl array with pRepo->meta
// init tbl array with pRepo->meta
static
int
tsdbInit
TruncateTblArray
(
STruncateH
*
ptru
)
{
static
int
tsdbInit
DeleteTblArray
(
SDeleteH
*
pdh
)
{
STsdbRepo
*
pRepo
=
TSDB_
TRUNCATE_REPO
(
ptru
);
STsdbRepo
*
pRepo
=
TSDB_
DELETE_REPO
(
pdh
);
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
if
(
tsdbRLockRepoMeta
(
pRepo
)
<
0
)
return
-
1
;
if
(
tsdbRLockRepoMeta
(
pRepo
)
<
0
)
return
-
1
;
p
tru
->
tblArray
=
taosArrayInit
(
pMeta
->
maxTables
,
sizeof
(
STableTrunca
teH
));
p
dh
->
tblArray
=
taosArrayInit
(
pMeta
->
maxTables
,
sizeof
(
STableDele
teH
));
if
(
p
tru
->
tblArray
==
NULL
)
{
if
(
p
dh
->
tblArray
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbUnlockRepoMeta
(
pRepo
);
tsdbUnlockRepoMeta
(
pRepo
);
return
-
1
;
return
-
1
;
...
@@ -429,13 +366,13 @@ static int tsdbInitTruncateTblArray(STruncateH *ptru) {
...
@@ -429,13 +366,13 @@ static int tsdbInitTruncateTblArray(STruncateH *ptru) {
// Note here must start from 0
// Note here must start from 0
for
(
int
i
=
0
;
i
<
pMeta
->
maxTables
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pMeta
->
maxTables
;
++
i
)
{
STable
Trunca
teH
tbl
=
{
0
};
STable
Dele
teH
tbl
=
{
0
};
if
(
pMeta
->
tables
[
i
]
!=
NULL
)
{
if
(
pMeta
->
tables
[
i
]
!=
NULL
)
{
tsdbRefTable
(
pMeta
->
tables
[
i
]);
tsdbRefTable
(
pMeta
->
tables
[
i
]);
tbl
.
pTable
=
pMeta
->
tables
[
i
];
tbl
.
pTable
=
pMeta
->
tables
[
i
];
}
}
if
(
taosArrayPush
(
p
tru
->
tblArray
,
&
tbl
)
==
NULL
)
{
if
(
taosArrayPush
(
p
dh
->
tblArray
,
&
tbl
)
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbUnlockRepoMeta
(
pRepo
);
tsdbUnlockRepoMeta
(
pRepo
);
return
-
1
;
return
-
1
;
...
@@ -446,13 +383,13 @@ static int tsdbInitTruncateTblArray(STruncateH *ptru) {
...
@@ -446,13 +383,13 @@ static int tsdbInitTruncateTblArray(STruncateH *ptru) {
return
0
;
return
0
;
}
}
static
void
tsdbDestroy
TruncateTblArray
(
STruncateH
*
ptru
)
{
static
void
tsdbDestroy
DeleteTblArray
(
SDeleteH
*
pdh
)
{
STable
Trunca
teH
*
pItem
=
NULL
;
STable
Dele
teH
*
pItem
=
NULL
;
if
(
p
tru
->
tblArray
==
NULL
)
return
;
if
(
p
dh
->
tblArray
==
NULL
)
return
;
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
p
tru
->
tblArray
);
++
i
)
{
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
p
dh
->
tblArray
);
++
i
)
{
pItem
=
(
STable
TruncateH
*
)
taosArrayGet
(
ptru
->
tblArray
,
i
);
pItem
=
(
STable
DeleteH
*
)
taosArrayGet
(
pdh
->
tblArray
,
i
);
if
(
pItem
->
pTable
)
{
if
(
pItem
->
pTable
)
{
tsdbUnRefTable
(
pItem
->
pTable
);
tsdbUnRefTable
(
pItem
->
pTable
);
}
}
...
@@ -460,19 +397,19 @@ static void tsdbDestroyTruncateTblArray(STruncateH *ptru) {
...
@@ -460,19 +397,19 @@ static void tsdbDestroyTruncateTblArray(STruncateH *ptru) {
tfree
(
pItem
->
pInfo
);
tfree
(
pItem
->
pInfo
);
}
}
p
tru
->
tblArray
=
taosArrayDestroy
(
&
ptru
->
tblArray
);
p
dh
->
tblArray
=
taosArrayDestroy
(
&
pdh
->
tblArray
);
}
}
static
int
tsdbCacheFSetIndex
(
S
TruncateH
*
ptru
)
{
static
int
tsdbCacheFSetIndex
(
S
DeleteH
*
pdh
)
{
SReadH
*
pReadH
=
&
(
p
tru
->
readh
);
SReadH
*
pReadH
=
&
(
p
dh
->
readh
);
if
(
tsdbLoadBlockIdx
(
pReadH
)
<
0
)
{
if
(
tsdbLoadBlockIdx
(
pReadH
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
size_t
cnt
=
taosArrayGetSize
(
p
tru
->
tblArray
);
size_t
cnt
=
taosArrayGetSize
(
p
dh
->
tblArray
);
for
(
size_t
tid
=
1
;
tid
<
cnt
;
++
tid
)
{
for
(
size_t
tid
=
1
;
tid
<
cnt
;
++
tid
)
{
STable
TruncateH
*
pItem
=
(
STableTruncateH
*
)
taosArrayGet
(
ptru
->
tblArray
,
tid
);
STable
DeleteH
*
pItem
=
(
STableDeleteH
*
)
taosArrayGet
(
pdh
->
tblArray
,
tid
);
pItem
->
pBlkIdx
=
NULL
;
pItem
->
pBlkIdx
=
NULL
;
if
(
pItem
->
pTable
==
NULL
)
if
(
pItem
->
pTable
==
NULL
)
...
@@ -493,30 +430,30 @@ static int tsdbCacheFSetIndex(STruncateH *ptru) {
...
@@ -493,30 +430,30 @@ static int tsdbCacheFSetIndex(STruncateH *ptru) {
return
0
;
return
0
;
}
}
static
int
tsdbFSetInit
(
S
TruncateH
*
ptru
,
SDFileSet
*
pSet
)
{
static
int
tsdbFSetInit
(
S
DeleteH
*
pdh
,
SDFileSet
*
pSet
)
{
taosArrayClear
(
p
tru
->
aBlkIdx
);
taosArrayClear
(
p
dh
->
aBlkIdx
);
taosArrayClear
(
p
tru
->
aSupBlk
);
taosArrayClear
(
p
dh
->
aSupBlk
);
// open
// open
if
(
tsdbSetAndOpenReadFSet
(
&
(
p
tru
->
readh
),
pSet
)
<
0
)
{
if
(
tsdbSetAndOpenReadFSet
(
&
(
p
dh
->
readh
),
pSet
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// load index to cache
// load index to cache
if
(
tsdbCacheFSetIndex
(
p
tru
)
<
0
)
{
if
(
tsdbCacheFSetIndex
(
p
dh
)
<
0
)
{
tsdbCloseAndUnsetFSet
(
&
(
p
tru
->
readh
));
tsdbCloseAndUnsetFSet
(
&
(
p
dh
->
readh
));
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static
void
tsdb
TruncateFSetEnd
(
STruncateH
*
ptru
)
{
tsdbCloseAndUnsetFSet
(
&
(
ptru
->
readh
));
}
static
void
tsdb
DeleteFSetEnd
(
SDeleteH
*
pdh
)
{
tsdbCloseAndUnsetFSet
(
&
(
pdh
->
readh
));
}
static
int32_t
tsdbFilterDataCols
(
S
TruncateH
*
ptru
,
SDataCols
*
pSrcDCols
)
{
static
int32_t
tsdbFilterDataCols
(
S
DeleteH
*
pdh
,
SDataCols
*
pSrcDCols
)
{
SDataCols
*
pDstDCols
=
p
tru
->
pDCols
;
SDataCols
*
pDstDCols
=
p
dh
->
pDCols
;
SControlData
*
pCtlData
=
&
p
tru
->
pCtlInfo
->
ctlData
;
SControlData
*
pCtlData
=
&
p
dh
->
pCtlInfo
->
ctlData
;
int32_t
delRows
=
0
;
int32_t
delRows
=
0
;
tdResetDataCols
(
pDstDCols
);
tdResetDataCols
(
pDstDCols
);
...
@@ -542,71 +479,27 @@ static int32_t tsdbFilterDataCols(STruncateH *ptru, SDataCols *pSrcDCols) {
...
@@ -542,71 +479,27 @@ static int32_t tsdbFilterDataCols(STruncateH *ptru, SDataCols *pSrcDCols) {
}
}
// affectedRows
// affectedRows
if
(
p
tru
->
pCtlInfo
->
pRsp
)
{
if
(
p
dh
->
pCtlInfo
->
pRsp
)
{
p
tru
->
pCtlInfo
->
pRsp
->
affectedRows
+=
delRows
;
p
dh
->
pCtlInfo
->
pRsp
->
affectedRows
+=
delRows
;
}
}
return
0
;
return
0
;
}
}
// table in delete list
// table in delete list
bool
tableInDel
(
S
TruncateH
*
ptru
,
int32_t
tid
)
{
bool
tableInDel
(
S
DeleteH
*
pdh
,
int32_t
tid
)
{
for
(
int32_t
i
=
0
;
i
<
p
tru
->
pCtlInfo
->
ctlData
.
tnum
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
p
dh
->
pCtlInfo
->
ctlData
.
tnum
;
i
++
)
{
if
(
tid
==
p
tru
->
pCtlInfo
->
ctlData
.
tids
[
i
])
if
(
tid
==
p
dh
->
pCtlInfo
->
ctlData
.
tids
[
i
])
return
true
;
return
true
;
}
}
return
false
;
return
false
;
}
}
static
int
tsdbTruncateFSetImpl
(
STruncateH
*
ptru
)
{
STsdbRepo
*
pRepo
=
TSDB_TRUNCATE_REPO
(
ptru
);
// SReadH * pReadh = &(ptru->readh);
SBlockIdx
*
pBlkIdx
=
NULL
;
void
**
ppBuf
=
&
(
TSDB_TRUNCATE_BUF
(
ptru
));
// void ** ppCBuf = &(TSDB_TRUNCATE_COMP_BUF(ptru));
// void ** ppExBuf = &(TSDB_TRUNCATE_EXBUF(ptru));
taosArrayClear
(
ptru
->
aBlkIdx
);
for
(
size_t
tid
=
1
;
tid
<
taosArrayGetSize
(
ptru
->
tblArray
);
++
tid
)
{
STableTruncateH
*
pItem
=
(
STableTruncateH
*
)
taosArrayGet
(
ptru
->
tblArray
,
tid
);
pBlkIdx
=
pItem
->
pBlkIdx
;
if
(
pItem
->
pTable
==
NULL
||
pItem
->
pBlkIdx
==
NULL
)
continue
;
taosArrayClear
(
ptru
->
aSupBlk
);
if
(
!
tableInDel
(
ptru
,
tid
))
{
if
((
pBlkIdx
->
numOfBlocks
>
0
)
&&
(
taosArrayPush
(
ptru
->
aBlkIdx
,
(
const
void
*
)(
pBlkIdx
))
==
NULL
))
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
}
else
{
// Loop to mark delete flag for each block data
tsdbDebug
(
"vgId:%d tid %ld matched to truncate"
,
REPO_ID
(
pRepo
),
tid
);
// for (int i = 0; i < pItem->pBlkIdx->numOfBlocks; ++i) {
// SBlock *pBlock = pItem->pInfo->blocks + i;
// if (tsdbWriteBlockToFile(ptru, pItem->pTable, ptru->pDCols, ppBuf, ppCBuf, ppExBuf) <
// 0) {
// return -1;
// }
// }
}
}
if
(
tsdbWriteBlockIdx
(
TSDB_TRUNCATE_HEAD_FILE
(
ptru
),
ptru
->
aBlkIdx
,
ppBuf
)
<
0
)
{
return
-
1
;
}
return
0
;
}
// if pBlock is border block return true else return false
// if pBlock is border block return true else return false
static
int
tsdbBlockSolve
(
S
TruncateH
*
ptru
,
SBlock
*
pBlock
)
{
static
int
tsdbBlockSolve
(
S
DeleteH
*
pdh
,
SBlock
*
pBlock
)
{
// delete window
// delete window
STimeWindow
*
pdel
=
&
p
tru
->
pCtlInfo
->
ctlData
.
win
;
STimeWindow
*
pdel
=
&
p
dh
->
pCtlInfo
->
ctlData
.
win
;
// do nothing for no delete
// do nothing for no delete
if
(
pBlock
->
keyFirst
>
pdel
->
ekey
||
pBlock
->
keyLast
<
pdel
->
skey
)
if
(
pBlock
->
keyFirst
>
pdel
->
ekey
||
pBlock
->
keyLast
<
pdel
->
skey
)
...
@@ -621,7 +514,7 @@ static int tsdbBlockSolve(STruncateH *ptru, SBlock *pBlock) {
...
@@ -621,7 +514,7 @@ static int tsdbBlockSolve(STruncateH *ptru, SBlock *pBlock) {
}
}
// remove del block from pBlockInfo
// remove del block from pBlockInfo
int
tsdbRemoveDelBlocks
(
S
TruncateH
*
ptru
,
STableTrunca
teH
*
pItem
)
{
int
tsdbRemoveDelBlocks
(
S
DeleteH
*
pdh
,
STableDele
teH
*
pItem
)
{
// loop
// loop
int
numOfBlocks
=
pItem
->
pBlkIdx
->
numOfBlocks
;
int
numOfBlocks
=
pItem
->
pBlkIdx
->
numOfBlocks
;
int
from
=
-
1
;
int
from
=
-
1
;
...
@@ -629,7 +522,7 @@ int tsdbRemoveDelBlocks(STruncateH *ptru, STableTruncateH * pItem) {
...
@@ -629,7 +522,7 @@ int tsdbRemoveDelBlocks(STruncateH *ptru, STableTruncateH * pItem) {
for
(
int
i
=
numOfBlocks
-
1
;
i
>=
0
;
--
i
)
{
for
(
int
i
=
numOfBlocks
-
1
;
i
>=
0
;
--
i
)
{
SBlock
*
pBlock
=
pItem
->
pInfo
->
blocks
+
i
;
SBlock
*
pBlock
=
pItem
->
pInfo
->
blocks
+
i
;
int32_t
solve
=
tsdbBlockSolve
(
p
tru
,
pBlock
);
int32_t
solve
=
tsdbBlockSolve
(
p
dh
,
pBlock
);
if
(
solve
==
BLOCK_DELETE
)
{
if
(
solve
==
BLOCK_DELETE
)
{
if
(
from
==
-
1
)
if
(
from
==
-
1
)
from
=
i
;
from
=
i
;
...
@@ -653,35 +546,35 @@ int tsdbRemoveDelBlocks(STruncateH *ptru, STableTruncateH * pItem) {
...
@@ -653,35 +546,35 @@ int tsdbRemoveDelBlocks(STruncateH *ptru, STableTruncateH * pItem) {
// set value
// set value
pItem
->
pBlkIdx
->
numOfBlocks
=
numOfBlocks
;
pItem
->
pBlkIdx
->
numOfBlocks
=
numOfBlocks
;
if
(
p
tru
->
pCtlInfo
->
pRsp
)
{
if
(
p
dh
->
pCtlInfo
->
pRsp
)
{
p
tru
->
pCtlInfo
->
pRsp
->
affectedRows
+=
delRows
;
p
dh
->
pCtlInfo
->
pRsp
->
affectedRows
+=
delRows
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
tsdbAddBlock
(
S
TruncateH
*
ptru
,
STableTrunca
teH
*
pItem
,
SBlock
*
pBlock
)
{
static
void
tsdbAddBlock
(
S
DeleteH
*
pdh
,
STableDele
teH
*
pItem
,
SBlock
*
pBlock
)
{
// append sub if have
// append sub if have
if
(
pBlock
->
numOfSubBlocks
>
1
)
{
if
(
pBlock
->
numOfSubBlocks
>
1
)
{
int64_t
offset
=
taosArrayGetSize
(
p
tru
->
aSubBlk
)
*
sizeof
(
SBlock
);
int64_t
offset
=
taosArrayGetSize
(
p
dh
->
aSubBlk
)
*
sizeof
(
SBlock
);
SBlock
*
jBlock
=
POINTER_SHIFT
(
pItem
->
pInfo
,
pBlock
->
offset
);;
SBlock
*
jBlock
=
POINTER_SHIFT
(
pItem
->
pInfo
,
pBlock
->
offset
);;
for
(
int
j
=
0
;
j
<
pBlock
->
numOfSubBlocks
;
j
++
)
{
for
(
int
j
=
0
;
j
<
pBlock
->
numOfSubBlocks
;
j
++
)
{
taosArrayPush
(
p
tru
->
aSubBlk
,
(
const
void
*
)
jBlock
++
);
taosArrayPush
(
p
dh
->
aSubBlk
,
(
const
void
*
)
jBlock
++
);
}
}
// set new offset if have sub
// set new offset if have sub
pBlock
->
offset
=
offset
;
pBlock
->
offset
=
offset
;
}
}
// append super
// append super
taosArrayPush
(
p
tru
->
aSupBlk
,
(
const
void
*
)
pBlock
);
taosArrayPush
(
p
dh
->
aSupBlk
,
(
const
void
*
)
pBlock
);
}
}
// need modify blocks
// need modify blocks
static
int
tsdbModifyBlocks
(
S
TruncateH
*
ptru
,
STableTrunca
teH
*
pItem
)
{
static
int
tsdbModifyBlocks
(
S
DeleteH
*
pdh
,
STableDele
teH
*
pItem
)
{
SReadH
*
pReadh
=
&
(
p
tru
->
readh
);
SReadH
*
pReadh
=
&
(
p
dh
->
readh
);
void
**
ppBuf
=
&
(
TSDB_
TRUNCATE_BUF
(
ptru
));
void
**
ppBuf
=
&
(
TSDB_
DELETE_BUF
(
pdh
));
void
**
ppCBuf
=
&
(
TSDB_
TRUNCATE_COMP_BUF
(
ptru
));
void
**
ppCBuf
=
&
(
TSDB_
DELETE_COMP_BUF
(
pdh
));
void
**
ppExBuf
=
&
(
TSDB_
TRUNCATE_EXBUF
(
ptru
));
void
**
ppExBuf
=
&
(
TSDB_
DELETE_EXBUF
(
pdh
));
STSchema
*
pSchema
=
NULL
;
STSchema
*
pSchema
=
NULL
;
SBlockIdx
blkIdx
=
{
0
};
SBlockIdx
blkIdx
=
{
0
};
...
@@ -690,7 +583,7 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
...
@@ -690,7 +583,7 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
return
-
1
;
return
-
1
;
}
}
if
((
tdInitDataCols
(
p
tru
->
pDCols
,
pSchema
)
<
0
)
||
(
tdInitDataCols
(
pReadh
->
pDCols
[
0
],
pSchema
)
<
0
)
||
if
((
tdInitDataCols
(
p
dh
->
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
);
...
@@ -699,21 +592,21 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
...
@@ -699,21 +592,21 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
tdFreeSchema
(
pSchema
);
tdFreeSchema
(
pSchema
);
// delete block
// delete block
tsdbRemoveDelBlocks
(
p
tru
,
pItem
);
tsdbRemoveDelBlocks
(
p
dh
,
pItem
);
if
(
pItem
->
pBlkIdx
->
numOfBlocks
==
0
)
{
if
(
pItem
->
pBlkIdx
->
numOfBlocks
==
0
)
{
// all blocks were deleted
// all blocks were deleted
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
taosArrayClear
(
p
tru
->
aSupBlk
);
taosArrayClear
(
p
dh
->
aSupBlk
);
taosArrayClear
(
p
tru
->
aSubBlk
);
taosArrayClear
(
p
dh
->
aSubBlk
);
// Loop to truncate each block data
// Loop to truncate each block data
for
(
int
i
=
0
;
i
<
pItem
->
pBlkIdx
->
numOfBlocks
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pItem
->
pBlkIdx
->
numOfBlocks
;
++
i
)
{
SBlock
*
pBlock
=
pItem
->
pInfo
->
blocks
+
i
;
SBlock
*
pBlock
=
pItem
->
pInfo
->
blocks
+
i
;
int32_t
solve
=
tsdbBlockSolve
(
p
tru
,
pBlock
);
int32_t
solve
=
tsdbBlockSolve
(
p
dh
,
pBlock
);
if
(
solve
==
BLOCK_READ
)
{
if
(
solve
==
BLOCK_READ
)
{
tsdbAddBlock
(
p
tru
,
pItem
,
pBlock
);
tsdbAddBlock
(
p
dh
,
pItem
,
pBlock
);
continue
;
continue
;
}
}
...
@@ -722,28 +615,28 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
...
@@ -722,28 +615,28 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
return
-
1
;
return
-
1
;
}
}
tsdbFilterDataCols
(
p
tru
,
pReadh
->
pDCols
[
0
]);
tsdbFilterDataCols
(
p
dh
,
pReadh
->
pDCols
[
0
]);
if
(
p
tru
->
pDCols
->
numOfRows
<=
0
)
{
if
(
p
dh
->
pDCols
->
numOfRows
<=
0
)
{
continue
;
continue
;
}
}
SBlock
newBlock
=
{
0
};
SBlock
newBlock
=
{
0
};
if
(
tsdbWriteBlockToFile
(
p
tru
,
pItem
->
pTable
,
ptru
->
pDCols
,
ppBuf
,
ppCBuf
,
ppExBuf
,
&
newBlock
)
<
0
)
{
if
(
tsdbWriteBlockToFile
(
p
dh
,
pItem
->
pTable
,
pdh
->
pDCols
,
ppBuf
,
ppCBuf
,
ppExBuf
,
&
newBlock
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// add new block to info
// add new block to info
tsdbAddBlock
(
p
tru
,
pItem
,
&
newBlock
);
tsdbAddBlock
(
p
dh
,
pItem
,
&
newBlock
);
}
}
// write block info for each table
// write block info for each table
if
(
tsdbWriteBlockInfoImpl
(
TSDB_
TRUNCATE_HEAD_FILE
(
ptru
),
pItem
->
pTable
,
ptru
->
aSupBlk
,
ptru
->
aSubBlk
,
if
(
tsdbWriteBlockInfoImpl
(
TSDB_
DELETE_HEAD_FILE
(
pdh
),
pItem
->
pTable
,
pdh
->
aSupBlk
,
pdh
->
aSubBlk
,
ppBuf
,
&
blkIdx
)
<
0
)
{
ppBuf
,
&
blkIdx
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
// each table's blkIdx
// each table's blkIdx
if
(
blkIdx
.
numOfBlocks
>
0
&&
taosArrayPush
(
p
tru
->
aBlkIdx
,
(
const
void
*
)(
&
blkIdx
))
==
NULL
)
{
if
(
blkIdx
.
numOfBlocks
>
0
&&
taosArrayPush
(
p
dh
->
aBlkIdx
,
(
const
void
*
)(
&
blkIdx
))
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -752,27 +645,27 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
...
@@ -752,27 +645,27 @@ static int tsdbModifyBlocks(STruncateH *ptru, STableTruncateH *pItem) {
}
}
// keep intact blocks info and write to head file then save offset to blkIdx
// keep intact blocks info and write to head file then save offset to blkIdx
static
int
tsdbKeepIntactBlocks
(
S
TruncateH
*
ptru
,
STableTrunca
teH
*
pItem
)
{
static
int
tsdbKeepIntactBlocks
(
S
DeleteH
*
pdh
,
STableDele
teH
*
pItem
)
{
// init
// init
SBlockIdx
blkIdx
=
{
0
};
SBlockIdx
blkIdx
=
{
0
};
taosArrayClear
(
p
tru
->
aSupBlk
);
taosArrayClear
(
p
dh
->
aSupBlk
);
taosArrayClear
(
p
tru
->
aSubBlk
);
taosArrayClear
(
p
dh
->
aSubBlk
);
for
(
int32_t
i
=
0
;
i
<
pItem
->
pBlkIdx
->
numOfBlocks
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
pItem
->
pBlkIdx
->
numOfBlocks
;
i
++
)
{
SBlock
*
pBlock
=
pItem
->
pInfo
->
blocks
+
i
;
SBlock
*
pBlock
=
pItem
->
pInfo
->
blocks
+
i
;
tsdbAddBlock
(
p
tru
,
pItem
,
pBlock
);
tsdbAddBlock
(
p
dh
,
pItem
,
pBlock
);
}
}
// write block info for one table
// write block info for one table
void
**
ppBuf
=
&
(
TSDB_
TRUNCATE_BUF
(
ptru
));
void
**
ppBuf
=
&
(
TSDB_
DELETE_BUF
(
pdh
));
int32_t
ret
=
tsdbWriteBlockInfoImpl
(
TSDB_
TRUNCATE_HEAD_FILE
(
ptru
),
pItem
->
pTable
,
ptru
->
aSupBlk
,
int32_t
ret
=
tsdbWriteBlockInfoImpl
(
TSDB_
DELETE_HEAD_FILE
(
pdh
),
pItem
->
pTable
,
pdh
->
aSupBlk
,
p
tru
->
aSubBlk
,
ppBuf
,
&
blkIdx
);
p
dh
->
aSubBlk
,
ppBuf
,
&
blkIdx
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
// each table's blkIdx
// each table's blkIdx
if
(
blkIdx
.
numOfBlocks
>
0
&&
taosArrayPush
(
p
tru
->
aBlkIdx
,
(
const
void
*
)
&
blkIdx
)
==
NULL
)
{
if
(
blkIdx
.
numOfBlocks
>
0
&&
taosArrayPush
(
p
dh
->
aBlkIdx
,
(
const
void
*
)
&
blkIdx
)
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -780,43 +673,43 @@ static int tsdbKeepIntactBlocks(STruncateH *ptru, STableTruncateH * pItem) {
...
@@ -780,43 +673,43 @@ static int tsdbKeepIntactBlocks(STruncateH *ptru, STableTruncateH * pItem) {
return
ret
;
return
ret
;
}
}
static
int
tsdbFSetDeleteImpl
(
S
TruncateH
*
ptru
)
{
static
int
tsdbFSetDeleteImpl
(
S
DeleteH
*
pdh
)
{
void
**
ppBuf
=
&
(
TSDB_
TRUNCATE_BUF
(
ptru
));
void
**
ppBuf
=
&
(
TSDB_
DELETE_BUF
(
pdh
));
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
// 1.INIT
// 1.INIT
taosArrayClear
(
p
tru
->
aBlkIdx
);
taosArrayClear
(
p
dh
->
aBlkIdx
);
for
(
size_t
tid
=
1
;
tid
<
taosArrayGetSize
(
p
tru
->
tblArray
);
++
tid
)
{
for
(
size_t
tid
=
1
;
tid
<
taosArrayGetSize
(
p
dh
->
tblArray
);
++
tid
)
{
STable
TruncateH
*
pItem
=
(
STableTruncateH
*
)
taosArrayGet
(
ptru
->
tblArray
,
tid
);
STable
DeleteH
*
pItem
=
(
STableDeleteH
*
)
taosArrayGet
(
pdh
->
tblArray
,
tid
);
// no table in this tid position
// no table in this tid position
if
(
pItem
->
pTable
==
NULL
||
pItem
->
pBlkIdx
==
NULL
)
if
(
pItem
->
pTable
==
NULL
||
pItem
->
pBlkIdx
==
NULL
)
continue
;
continue
;
// 2.WRITE INFO OF EACH TABLE BLOCK INFO TO HEAD FILE
// 2.WRITE INFO OF EACH TABLE BLOCK INFO TO HEAD FILE
if
(
tableInDel
(
p
tru
,
tid
))
{
if
(
tableInDel
(
p
dh
,
tid
))
{
// modify blocks info and write to head file then save offset to blkIdx
// modify blocks info and write to head file then save offset to blkIdx
ret
=
tsdbModifyBlocks
(
p
tru
,
pItem
);
ret
=
tsdbModifyBlocks
(
p
dh
,
pItem
);
}
else
{
}
else
{
// keep intact blocks info and write to head file then save offset to blkIdx
// keep intact blocks info and write to head file then save offset to blkIdx
ret
=
tsdbKeepIntactBlocks
(
p
tru
,
pItem
);
ret
=
tsdbKeepIntactBlocks
(
p
dh
,
pItem
);
}
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
if
(
ret
!=
TSDB_CODE_SUCCESS
)
return
ret
;
return
ret
;
}
// tid for
}
// tid for
// 3.WRITE INDEX OF ALL TABLE'S BLOCK TO HEAD FILE
// 3.WRITE INDEX OF ALL TABLE'S BLOCK TO HEAD FILE
if
(
tsdbWriteBlockIdx
(
TSDB_
TRUNCATE_HEAD_FILE
(
ptru
),
ptru
->
aBlkIdx
,
ppBuf
)
<
0
)
{
if
(
tsdbWriteBlockIdx
(
TSDB_
DELETE_HEAD_FILE
(
pdh
),
pdh
->
aBlkIdx
,
ppBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
return
ret
;
return
ret
;
}
}
static
int
tsdbWriteBlockToFile
(
S
TruncateH
*
ptru
,
STable
*
pTable
,
SDataCols
*
pDCols
,
void
**
ppBuf
,
static
int
tsdbWriteBlockToFile
(
S
DeleteH
*
pdh
,
STable
*
pTable
,
SDataCols
*
pDCols
,
void
**
ppBuf
,
void
**
ppCBuf
,
void
**
ppExBuf
,
SBlock
*
pBlock
)
{
void
**
ppCBuf
,
void
**
ppExBuf
,
SBlock
*
pBlock
)
{
STsdbRepo
*
pRepo
=
TSDB_
TRUNCATE_REPO
(
ptru
);
STsdbRepo
*
pRepo
=
TSDB_
DELETE_REPO
(
pdh
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
SDFile
*
pDFile
=
NULL
;
SDFile
*
pDFile
=
NULL
;
bool
isLast
=
false
;
bool
isLast
=
false
;
...
@@ -824,15 +717,15 @@ static int tsdbWriteBlockToFile(STruncateH *ptru, STable *pTable, SDataCols *pDC
...
@@ -824,15 +717,15 @@ static int tsdbWriteBlockToFile(STruncateH *ptru, STable *pTable, SDataCols *pDC
ASSERT
(
pDCols
->
numOfRows
>
0
);
ASSERT
(
pDCols
->
numOfRows
>
0
);
if
(
pDCols
->
numOfRows
<
pCfg
->
minRowsPerFileBlock
)
{
if
(
pDCols
->
numOfRows
<
pCfg
->
minRowsPerFileBlock
)
{
pDFile
=
TSDB_
TRUNCATE_LAST_FILE
(
ptru
);
pDFile
=
TSDB_
DELETE_LAST_FILE
(
pdh
);
isLast
=
true
;
isLast
=
true
;
}
else
{
}
else
{
pDFile
=
TSDB_
TRUNCATE_DATA_FILE
(
ptru
);
pDFile
=
TSDB_
DELETE_DATA_FILE
(
pdh
);
isLast
=
false
;
isLast
=
false
;
}
}
if
(
tsdbWriteBlockImpl
(
pRepo
,
pTable
,
pDFile
,
if
(
tsdbWriteBlockImpl
(
pRepo
,
pTable
,
pDFile
,
isLast
?
TSDB_
TRUNCATE_SMAL_FILE
(
ptru
)
:
TSDB_TRUNCATE_SMAD_FILE
(
ptru
),
pDCols
,
isLast
?
TSDB_
DELETE_SMAL_FILE
(
pdh
)
:
TSDB_DELETE_SMAD_FILE
(
pdh
),
pDCols
,
pBlock
,
isLast
,
true
,
ppBuf
,
ppCBuf
,
ppExBuf
)
<
0
)
{
pBlock
,
isLast
,
true
,
ppBuf
,
ppCBuf
,
ppExBuf
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录