Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
876c0068
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看板
提交
876c0068
编写于
4月 06, 2022
作者:
A
Alex Duan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-238]<feature>(tsdb): fixed last_row() return empty.
上级
3a56d8a8
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
102 addition
and
58 deletion
+102
-58
src/client/src/tscDelete.c
src/client/src/tscDelete.c
+9
-28
src/tsdb/inc/tsdbint.h
src/tsdb/inc/tsdbint.h
+2
-1
src/tsdb/src/tsdbDelete.c
src/tsdb/src/tsdbDelete.c
+65
-14
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+25
-14
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+1
-1
未找到文件。
src/client/src/tscDelete.c
浏览文件 @
876c0068
...
@@ -58,13 +58,11 @@ void tscSubDeleteCallback(void *param, TAOS_RES *tres, int code) {
...
@@ -58,13 +58,11 @@ void tscSubDeleteCallback(void *param, TAOS_RES *tres, int code) {
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
tscError
(
"0x%"
PRIx64
" query cancelled or failed, sub:0x%"
PRIx64
", vgId:%d, orderOfSub:%d, code:%s, global code:%s"
,
tscError
(
"0x%"
PRIx64
" query cancelled or failed, sub:0x%"
PRIx64
", vgId:%d, orderOfSub:%d, code:%s, global code:%s"
,
pParentSql
->
self
,
pSql
->
self
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
,
tstrerror
(
code
),
tstrerror
(
pParentSql
->
res
.
code
));
pParentSql
->
self
,
pSql
->
self
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
,
tstrerror
(
code
),
tstrerror
(
pParentSql
->
res
.
code
));
tscHandleSubDeleteError
(
param
,
tres
,
code
);
if
(
subAndCheckDone
(
pSql
,
pParentSql
,
trsupport
->
subqueryIndex
))
{
if
(
subAndCheckDone
(
pSql
,
pParentSql
,
trsupport
->
subqueryIndex
))
{
// all sub done, call parentSQL callback to finish
// all sub done, call parentSQL callback to finish
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
numOfRows
);
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
numOfRows
);
}
}
tfree
(
pSql
->
param
);
return
;
return
;
}
}
...
@@ -76,42 +74,27 @@ void tscSubDeleteCallback(void *param, TAOS_RES *tres, int code) {
...
@@ -76,42 +74,27 @@ void tscSubDeleteCallback(void *param, TAOS_RES *tres, int code) {
* NOTE: thread safe is required.
* NOTE: thread safe is required.
*/
*/
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
assert
(
code
==
taos_errno
(
pSql
));
tscError
(
":CDEL 0x%"
PRIx64
" sub:0x%"
PRIx64
" reach the max retry times or no need to retry, set global code:%s"
,
pParentSql
->
self
,
pSql
->
self
,
tstrerror
(
code
));
int32_t
sent
=
0
;
if
(
trsupport
->
numOfRetry
++
<
MAX_NUM_OF_SUBQUERY_RETRY
&&
(
code
!=
TSDB_CODE_TDB_INVALID_TABLE_ID
&&
code
!=
TSDB_CODE_VND_INVALID_VGROUP_ID
))
{
tscError
(
"0x%"
PRIx64
" sub:0x%"
PRIx64
" failed code:%s, retry:%d"
,
pParentSql
->
self
,
pSql
->
self
,
tstrerror
(
code
),
trsupport
->
numOfRetry
);
//tscReissueSubquery(trsupport, pSql, code, &sent);
if
(
sent
)
{
return
;
}
}
else
{
tscError
(
"0x%"
PRIx64
" sub:0x%"
PRIx64
" reach the max retry times or no need to retry, set global code:%s"
,
pParentSql
->
self
,
pSql
->
self
,
tstrerror
(
code
));
atomic_val_compare_exchange_32
(
&
pParentSql
->
res
.
code
,
TSDB_CODE_SUCCESS
,
code
);
// set global code and abort
atomic_val_compare_exchange_32
(
&
pParentSql
->
res
.
code
,
TSDB_CODE_SUCCESS
,
code
);
// set global code and abort
}
tscHandleSubDeleteError
(
param
,
tres
,
pParentSql
->
res
.
code
);
tscHandleSubDeleteError
(
param
,
tres
,
pParentSql
->
res
.
code
);
if
(
!
sent
)
{
if
(
subAndCheckDone
(
pSql
,
pParentSql
,
trsupport
->
subqueryIndex
))
{
if
(
subAndCheckDone
(
pSql
,
pParentSql
,
trsupport
->
subqueryIndex
))
{
// all sub done, call parentSQL callback to finish
// all sub done, call parentSQL callback to finish
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
numOfRows
);
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
numOfRows
);
}
}
}
tfree
(
pSql
->
param
);
return
;
return
;
}
}
tscDebug
(
"0x%"
PRIx64
":CDEL sub:0x%"
PRIx64
" query complete, ep:%s, vgId:%d, orderOfSub:%d, retrieve data"
,
trsupport
->
pParentSql
->
self
,
tscDebug
(
"0x%"
PRIx64
":CDEL sub:0x%"
PRIx64
" query complete, ep:%s, vgId:%d, orderOfSub:%d, retrieve data"
,
trsupport
->
pParentSql
->
self
,
pSql
->
self
,
pVgroup
->
epAddr
[
pSql
->
epSet
.
inUse
].
fqdn
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
);
pSql
->
self
,
pVgroup
->
epAddr
[
pSql
->
epSet
.
inUse
].
fqdn
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
);
//
do merge
//
success do total count
pParentSql
->
res
.
numOfRows
+=
pSql
->
res
.
numOfRows
;
pParentSql
->
res
.
numOfRows
+=
pSql
->
res
.
numOfRows
;
if
(
subAndCheckDone
(
pSql
,
pParentSql
,
trsupport
->
subqueryIndex
))
{
if
(
subAndCheckDone
(
pSql
,
pParentSql
,
trsupport
->
subqueryIndex
))
{
// all sub done, call parentSQL callback to finish
// all sub done, call parentSQL callback to finish
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
numOfRows
);
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
numOfRows
);
}
}
tfree
(
pSql
->
param
);
return
;
return
;
}
}
...
@@ -206,7 +189,6 @@ int32_t executeDelete(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
...
@@ -206,7 +189,6 @@ int32_t executeDelete(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
return
TSDB_CODE_VND_INVALID_VGROUP_ID
;
return
TSDB_CODE_VND_INVALID_VGROUP_ID
;
}
}
pRes
->
qId
=
0x1
;
// hack the qhandle check
SSubqueryState
*
pState
=
&
pSql
->
subState
;
SSubqueryState
*
pState
=
&
pSql
->
subState
;
int32_t
numOfSub
=
pTableMetaInfo
->
vgroupList
->
numOfVgroups
;
int32_t
numOfSub
=
pTableMetaInfo
->
vgroupList
->
numOfVgroups
;
...
@@ -237,7 +219,6 @@ int32_t executeDelete(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
...
@@ -237,7 +219,6 @@ int32_t executeDelete(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
SSqlObj
*
pNew
=
tscCreateSTableSubDelete
(
pSql
,
pVgroupMsg
,
trs
);
SSqlObj
*
pNew
=
tscCreateSTableSubDelete
(
pSql
,
pVgroupMsg
,
trs
);
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
tscError
(
"0x%"
PRIx64
"CDEL failed to malloc buffer for subObj, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
tscError
(
"0x%"
PRIx64
"CDEL failed to malloc buffer for subObj, orderOfSub:%d, reason:%s"
,
pSql
->
self
,
i
,
strerror
(
errno
));
tfree
(
trs
->
localBuffer
);
tfree
(
trs
);
tfree
(
trs
);
break
;
break
;
}
}
...
...
src/tsdb/inc/tsdbint.h
浏览文件 @
876c0068
...
@@ -116,9 +116,10 @@ STsdbMeta* tsdbGetMeta(STsdbRepo* pRepo);
...
@@ -116,9 +116,10 @@ STsdbMeta* tsdbGetMeta(STsdbRepo* pRepo);
int
tsdbCheckCommit
(
STsdbRepo
*
pRepo
);
int
tsdbCheckCommit
(
STsdbRepo
*
pRepo
);
int
tsdbRestoreInfo
(
STsdbRepo
*
pRepo
);
int
tsdbRestoreInfo
(
STsdbRepo
*
pRepo
);
UNUSED_FUNC
int
tsdbCacheLastData
(
STsdbRepo
*
pRepo
,
STsdbCfg
*
oldCfg
);
UNUSED_FUNC
int
tsdbCacheLastData
(
STsdbRepo
*
pRepo
,
STsdbCfg
*
oldCfg
);
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
);
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
bool
lastKey
);
void
tsdbGetRootDir
(
int
repoid
,
char
dirName
[]);
void
tsdbGetRootDir
(
int
repoid
,
char
dirName
[]);
void
tsdbGetDataDir
(
int
repoid
,
char
dirName
[]);
void
tsdbGetDataDir
(
int
repoid
,
char
dirName
[]);
int
tsdbRestoreLastRow
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SReadH
*
pReadh
,
SBlockIdx
*
pIdx
,
bool
onlyKey
);
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
)
{
ASSERT
(
pRepo
!=
NULL
);
ASSERT
(
pRepo
!=
NULL
);
...
...
src/tsdb/src/tsdbDelete.c
浏览文件 @
876c0068
...
@@ -32,9 +32,11 @@ typedef struct {
...
@@ -32,9 +32,11 @@ typedef struct {
SBlockIdx
*
pBlkIdx
;
SBlockIdx
*
pBlkIdx
;
SBlockIdx
bIndex
;
SBlockIdx
bIndex
;
SBlockInfo
*
pInfo
;
SBlockInfo
*
pInfo
;
bool
update
;
// need update lastrow
}
STableDeleteH
;
}
STableDeleteH
;
typedef
struct
{
typedef
struct
{
STsdbRepo
*
pRepo
;
SRtn
rtn
;
SRtn
rtn
;
SFSIter
fsIter
;
SFSIter
fsIter
;
SArray
*
tblArray
;
// STableDeleteH, table array to cache table obj and block indexes
SArray
*
tblArray
;
// STableDeleteH, table array to cache table obj and block indexes
...
@@ -45,6 +47,7 @@ typedef struct {
...
@@ -45,6 +47,7 @@ typedef struct {
SArray
*
aSubBlk
;
SArray
*
aSubBlk
;
SDataCols
*
pDCols
;
SDataCols
*
pDCols
;
SControlDataInfo
*
pCtlInfo
;
SControlDataInfo
*
pCtlInfo
;
SArray
*
aUpdates
;
}
SDeleteH
;
}
SDeleteH
;
...
@@ -63,7 +66,7 @@ typedef struct {
...
@@ -63,7 +66,7 @@ typedef struct {
static
void
tsdbStartDelete
(
STsdbRepo
*
pRepo
);
static
void
tsdbStartDelete
(
STsdbRepo
*
pRepo
);
static
void
tsdbEndDelete
(
STsdbRepo
*
pRepo
,
int
eno
);
static
void
tsdbEndDelete
(
STsdbRepo
*
pRepo
,
int
eno
);
static
int
tsdbDeleteMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbDeleteMeta
(
STsdbRepo
*
pRepo
);
static
int
tsdbDeleteTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
);
static
int
tsdbDeleteTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
,
SArray
*
pArray
);
static
int
tsdbFSetDelete
(
SDeleteH
*
pdh
,
SDFileSet
*
pSet
);
static
int
tsdbFSetDelete
(
SDeleteH
*
pdh
,
SDFileSet
*
pSet
);
static
int
tsdbInitDeleteH
(
SDeleteH
*
pdh
,
STsdbRepo
*
pRepo
);
static
int
tsdbInitDeleteH
(
SDeleteH
*
pdh
,
STsdbRepo
*
pRepo
);
static
void
tsdbDestroyDeleteH
(
SDeleteH
*
pdh
);
static
void
tsdbDestroyDeleteH
(
SDeleteH
*
pdh
);
...
@@ -91,6 +94,24 @@ int tsdbControlDelete(STsdbRepo* pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -91,6 +94,24 @@ int tsdbControlDelete(STsdbRepo* pRepo, SControlDataInfo* pCtlInfo) {
return
ret
;
return
ret
;
}
}
static
void
tsdbUpdateLastRow
(
STsdbRepo
*
pRepo
,
SArray
*
pArray
)
{
size_t
cnt
=
taosArrayGetSize
(
pArray
);
for
(
size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
STable
*
pTable
=
taosArrayGetP
(
pArray
,
i
);
tsdbLoadLastCache
(
pRepo
,
pTable
,
true
);
}
}
static
void
tsdbClearUpdates
(
SArray
*
pArray
)
{
size_t
cnt
=
taosArrayGetSize
(
pArray
);
for
(
size_t
i
=
0
;
i
<
cnt
;
++
i
)
{
STable
*
pTable
=
taosArrayGetP
(
pArray
,
i
);
tsdbUnRefTable
(
pTable
);
}
// destory
taosArrayDestroy
(
&
pArray
);
}
static
int
tsdbDeleteImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
static
int
tsdbDeleteImplCommon
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
// Step 1: check and clear cache
// Step 1: check and clear cache
...
@@ -117,17 +138,23 @@ static int tsdbDeleteImplCommon(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -117,17 +138,23 @@ static int tsdbDeleteImplCommon(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
goto
_err
;
goto
_err
;
}
}
if
(
tsdbDeleteTSData
(
pRepo
,
pCtlInfo
)
<
0
)
{
SArray
*
aUpdates
=
taosArrayInit
(
10
,
sizeof
(
STable
*
));
if
(
tsdbDeleteTSData
(
pRepo
,
pCtlInfo
,
aUpdates
)
<
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
;
}
}
tsdbEndDelete
(
pRepo
,
TSDB_CODE_SUCCESS
);
tsdbEndDelete
(
pRepo
,
TSDB_CODE_SUCCESS
);
// update last row
tsdbUpdateLastRow
(
pRepo
,
aUpdates
);
tsdbClearUpdates
(
aUpdates
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_err:
_err:
pRepo
->
code
=
terrno
;
pRepo
->
code
=
terrno
;
tsdbEndDelete
(
pRepo
,
terrno
);
tsdbEndDelete
(
pRepo
,
terrno
);
tsdbClearUpdates
(
aUpdates
);
return
-
1
;
return
-
1
;
}
}
...
@@ -174,27 +201,28 @@ static int tsdbDeleteMeta(STsdbRepo *pRepo) {
...
@@ -174,27 +201,28 @@ static int tsdbDeleteMeta(STsdbRepo *pRepo) {
return
0
;
return
0
;
}
}
static
int
tsdbDeleteTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
)
{
static
int
tsdbDeleteTSData
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlInfo
,
SArray
*
pArray
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pRepo
);
SDeleteH
trunca
teH
=
{
0
};
SDeleteH
dele
teH
=
{
0
};
SDFileSet
*
pSet
=
NULL
;
SDFileSet
*
pSet
=
NULL
;
tsdbDebug
(
"vgId:%d start to truncate TS data for %d"
,
REPO_ID
(
pRepo
),
pCtlInfo
->
tids
[
0
]);
tsdbDebug
(
"vgId:%d start to truncate TS data for %d"
,
REPO_ID
(
pRepo
),
pCtlInfo
->
tids
[
0
]);
if
(
tsdbInitDeleteH
(
&
trunca
teH
,
pRepo
)
<
0
)
{
if
(
tsdbInitDeleteH
(
&
dele
teH
,
pRepo
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
truncateH
.
pCtlInfo
=
pCtlInfo
;
deleteH
.
aUpdates
=
pArray
;
deleteH
.
pCtlInfo
=
pCtlInfo
;
STimeWindow
win
=
pCtlInfo
->
win
;
STimeWindow
win
=
pCtlInfo
->
win
;
int
sFid
=
TSDB_KEY_FID
(
win
.
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
sFid
=
TSDB_KEY_FID
(
win
.
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
eFid
=
TSDB_KEY_FID
(
win
.
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
(
&
(
trunca
teH
.
fsIter
))))
{
while
((
pSet
=
tsdbFSIterNext
(
&
(
dele
teH
.
fsIter
))))
{
// remove expired files
// remove expired files
if
(
pSet
->
fid
<
trunca
teH
.
rtn
.
minFid
)
{
if
(
pSet
->
fid
<
dele
teH
.
rtn
.
minFid
)
{
tsdbInfo
(
"vgId:%d FSET %d on level %d disk id %d expires, remove it"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
tsdbInfo
(
"vgId:%d FSET %d on level %d disk id %d expires, remove it"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
TSDB_FSET_LEVEL
(
pSet
),
TSDB_FSET_ID
(
pSet
));
continue
;
continue
;
...
@@ -202,7 +230,7 @@ static int tsdbDeleteTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -202,7 +230,7 @@ static int tsdbDeleteTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
if
((
pSet
->
fid
<
sFid
)
||
(
pSet
->
fid
>
eFid
))
{
if
((
pSet
->
fid
<
sFid
)
||
(
pSet
->
fid
>
eFid
))
{
tsdbDebug
(
"vgId:%d no need to truncate FSET %d, sFid %d, eFid %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
sFid
,
eFid
);
tsdbDebug
(
"vgId:%d no need to truncate FSET %d, sFid %d, eFid %d"
,
REPO_ID
(
pRepo
),
pSet
->
fid
,
sFid
,
eFid
);
if
(
tsdbApplyRtnOnFSet
(
pRepo
,
pSet
,
&
(
trunca
teH
.
rtn
))
<
0
)
{
if
(
tsdbApplyRtnOnFSet
(
pRepo
,
pSet
,
&
(
dele
teH
.
rtn
))
<
0
)
{
return
-
1
;
return
-
1
;
}
}
continue
;
continue
;
...
@@ -217,8 +245,8 @@ static int tsdbDeleteTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -217,8 +245,8 @@ static int tsdbDeleteTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
#endif
#endif
if
(
pCtlInfo
->
command
&
CMD_DELETE_DATA
)
{
if
(
pCtlInfo
->
command
&
CMD_DELETE_DATA
)
{
if
(
tsdbFSetDelete
(
&
trunca
teH
,
pSet
)
<
0
)
{
if
(
tsdbFSetDelete
(
&
dele
teH
,
pSet
)
<
0
)
{
tsdbDestroyDeleteH
(
&
trunca
teH
);
tsdbDestroyDeleteH
(
&
dele
teH
);
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
;
}
}
...
@@ -228,7 +256,7 @@ static int tsdbDeleteTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
...
@@ -228,7 +256,7 @@ static int tsdbDeleteTSData(STsdbRepo *pRepo, SControlDataInfo* pCtlInfo) {
}
}
tsdbDestroyDeleteH
(
&
trunca
teH
);
tsdbDestroyDeleteH
(
&
dele
teH
);
tsdbDebug
(
"vgId:%d truncate TS data over"
,
REPO_ID
(
pRepo
));
tsdbDebug
(
"vgId:%d truncate TS data over"
,
REPO_ID
(
pRepo
));
return
0
;
return
0
;
}
}
...
@@ -295,6 +323,7 @@ static int tsdbInitDeleteH(SDeleteH *pdh, STsdbRepo *pRepo) {
...
@@ -295,6 +323,7 @@ static int tsdbInitDeleteH(SDeleteH *pdh, STsdbRepo *pRepo) {
memset
(
pdh
,
0
,
sizeof
(
*
pdh
));
memset
(
pdh
,
0
,
sizeof
(
*
pdh
));
TSDB_FSET_SET_CLOSED
(
TSDB_DELETE_WSET
(
pdh
));
TSDB_FSET_SET_CLOSED
(
TSDB_DELETE_WSET
(
pdh
));
pdh
->
pRepo
=
pRepo
;
tsdbGetRtnSnap
(
pRepo
,
&
(
pdh
->
rtn
));
tsdbGetRtnSnap
(
pRepo
,
&
(
pdh
->
rtn
));
tsdbFSIterInit
(
&
(
pdh
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
tsdbFSIterInit
(
&
(
pdh
->
fsIter
),
REPO_FS
(
pRepo
),
TSDB_FS_ITER_FORWARD
);
...
@@ -349,6 +378,21 @@ static void tsdbDestroyDeleteH(SDeleteH *pdh) {
...
@@ -349,6 +378,21 @@ static void tsdbDestroyDeleteH(SDeleteH *pdh) {
tsdbCloseDFileSet
(
TSDB_DELETE_WSET
(
pdh
));
tsdbCloseDFileSet
(
TSDB_DELETE_WSET
(
pdh
));
}
}
void
tsdbAddUpdates
(
SArray
*
pArray
,
STable
*
pTable
)
{
size_t
cnt
=
taosArrayGetSize
(
pArray
);
for
(
size_t
i
=
0
;
i
<
cnt
;
i
++
)
{
STable
*
pt
=
taosArrayGetP
(
pArray
,
i
);
if
(
pt
==
pTable
)
{
// found
return
;
}
}
// ref count ++
tsdbRefTable
(
pTable
);
// append
taosArrayAddBatch
(
pArray
,
&
pTable
,
1
);
}
// init tbl array with pRepo->meta
// init tbl array with pRepo->meta
static
int
tsdbInitDeleteTblArray
(
SDeleteH
*
pdh
)
{
static
int
tsdbInitDeleteTblArray
(
SDeleteH
*
pdh
)
{
STsdbRepo
*
pRepo
=
TSDB_DELETE_REPO
(
pdh
);
STsdbRepo
*
pRepo
=
TSDB_DELETE_REPO
(
pdh
);
...
@@ -640,7 +684,14 @@ static int tsdbModifyBlocks(SDeleteH *pdh, STableDeleteH *pItem) {
...
@@ -640,7 +684,14 @@ static int tsdbModifyBlocks(SDeleteH *pdh, STableDeleteH *pItem) {
return
-
1
;
return
-
1
;
}
}
return
0
;
// update new last row in last row was deleted
TSKEY
lastKey
=
pItem
->
pTable
->
lastKey
;
if
(
lastKey
>=
pdh
->
pCtlInfo
->
win
.
skey
&&
lastKey
<=
pdh
->
pCtlInfo
->
win
.
ekey
)
{
// update lastkey and lastrow
tsdbAddUpdates
(
pdh
->
aUpdates
,
pItem
->
pTable
);
}
return
TSDB_CODE_SUCCESS
;
}
}
// 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
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
876c0068
...
@@ -30,7 +30,6 @@ static void tsdbFreeRepo(STsdbRepo *pRepo);
...
@@ -30,7 +30,6 @@ static void tsdbFreeRepo(STsdbRepo *pRepo);
static
void
tsdbStartStream
(
STsdbRepo
*
pRepo
);
static
void
tsdbStartStream
(
STsdbRepo
*
pRepo
);
static
void
tsdbStopStream
(
STsdbRepo
*
pRepo
);
static
void
tsdbStopStream
(
STsdbRepo
*
pRepo
);
static
int
tsdbRestoreLastColumns
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SReadH
*
pReadh
);
static
int
tsdbRestoreLastColumns
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SReadH
*
pReadh
);
static
int
tsdbRestoreLastRow
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SReadH
*
pReadh
,
SBlockIdx
*
pIdx
);
// Function declaration
// Function declaration
int32_t
tsdbCreateRepo
(
int
repoid
)
{
int32_t
tsdbCreateRepo
(
int
repoid
)
{
...
@@ -814,8 +813,7 @@ out:
...
@@ -814,8 +813,7 @@ out:
return
err
;
return
err
;
}
}
static
int
tsdbRestoreLastRow
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SReadH
*
pReadh
,
SBlockIdx
*
pIdx
)
{
int
tsdbRestoreLastRow
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SReadH
*
pReadh
,
SBlockIdx
*
pIdx
,
bool
onlyKey
)
{
ASSERT
(
pTable
->
lastRow
==
NULL
);
if
(
tsdbLoadBlockInfo
(
pReadh
,
NULL
,
NULL
)
<
0
)
{
if
(
tsdbLoadBlockInfo
(
pReadh
,
NULL
,
NULL
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -844,15 +842,22 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh,
...
@@ -844,15 +842,22 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh,
}
}
TSKEY
lastKey
=
memRowKey
(
lastRow
);
TSKEY
lastKey
=
memRowKey
(
lastRow
);
// during the load data in file, new data would be inserted and last row has been updated
// during the load data in file, new data would be inserted and last row has been updated
TSDB_WLOCK_TABLE
(
pTable
);
TSDB_WLOCK_TABLE
(
pTable
);
if
(
onlyKey
)
{
pTable
->
lastKey
=
lastKey
;
}
else
{
// set
if
(
pTable
->
lastRow
==
NULL
)
{
if
(
pTable
->
lastRow
==
NULL
)
{
pTable
->
lastKey
=
lastKey
;
pTable
->
lastKey
=
lastKey
;
pTable
->
lastRow
=
lastRow
;
pTable
->
lastRow
=
lastRow
;
lastRow
=
NULL
;
}
}
TSDB_WUNLOCK_TABLE
(
pTable
);
TSDB_WUNLOCK_TABLE
(
pTable
);
}
else
{
if
(
lastRow
)
{
TSDB_WUNLOCK_TABLE
(
pTable
);
taosTZfree
(
lastRow
);
taosTZfree
(
lastRow
);
}
}
...
@@ -908,7 +913,7 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) {
...
@@ -908,7 +913,7 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) {
if
(
pIdx
&&
lastKey
<
pIdx
->
maxKey
)
{
if
(
pIdx
&&
lastKey
<
pIdx
->
maxKey
)
{
pTable
->
lastKey
=
pIdx
->
maxKey
;
pTable
->
lastKey
=
pIdx
->
maxKey
;
if
(
CACHE_LAST_ROW
(
pCfg
)
&&
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
)
!=
0
)
{
if
(
CACHE_LAST_ROW
(
pCfg
)
&&
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
,
false
)
!=
0
)
{
tsdbDestroyReadH
(
&
readh
);
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
return
-
1
;
}
}
...
@@ -933,10 +938,11 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) {
...
@@ -933,10 +938,11 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) {
return
0
;
return
0
;
}
}
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
)
{
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
bool
lastKey
)
{
SFSIter
fsiter
;
SFSIter
fsiter
;
SReadH
readh
;
SReadH
readh
;
SDFileSet
*
pSet
;
SDFileSet
*
pSet
;
bool
onlyKey
=
false
;
int
cacheLastRowTableNum
=
0
;
int
cacheLastRowTableNum
=
0
;
int
cacheLastColTableNum
=
0
;
int
cacheLastColTableNum
=
0
;
...
@@ -956,14 +962,19 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable *pTable) {
...
@@ -956,14 +962,19 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable *pTable) {
}
}
if
(
!
cacheLastRow
&&
!
cacheLastCol
)
{
if
(
!
cacheLastRow
&&
!
cacheLastCol
)
{
if
(
!
lastKey
)
return
0
;
return
0
;
onlyKey
=
true
;
}
}
cacheLastRowTableNum
=
(
cacheLastRow
&&
pTable
->
lastRow
==
NULL
)
?
1
:
0
;
cacheLastRowTableNum
=
(
cacheLastRow
&&
pTable
->
lastRow
==
NULL
)
?
1
:
0
;
cacheLastColTableNum
=
(
cacheLastCol
&&
pTable
->
lastCols
==
NULL
)
?
1
:
0
;
cacheLastColTableNum
=
(
cacheLastCol
&&
pTable
->
lastCols
==
NULL
)
?
1
:
0
;
if
(
cacheLastRowTableNum
==
0
&&
cacheLastColTableNum
==
0
)
{
if
(
cacheLastRowTableNum
==
0
&&
cacheLastColTableNum
==
0
)
{
if
(
!
lastKey
)
return
0
;
return
0
;
onlyKey
=
true
;
cacheLastRowTableNum
=
1
;
}
}
if
(
tsdbInitReadH
(
&
readh
,
pRepo
)
<
0
)
{
if
(
tsdbInitReadH
(
&
readh
,
pRepo
)
<
0
)
{
...
@@ -997,7 +1008,7 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable *pTable) {
...
@@ -997,7 +1008,7 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable *pTable) {
SBlockIdx
*
pIdx
=
readh
.
pBlkIdx
;
SBlockIdx
*
pIdx
=
readh
.
pBlkIdx
;
if
(
pIdx
&&
(
cacheLastRowTableNum
>
0
)
&&
(
pTable
->
lastRow
==
NULL
))
{
if
(
pIdx
&&
(
cacheLastRowTableNum
>
0
)
&&
(
pTable
->
lastRow
==
NULL
))
{
if
(
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
)
!=
0
)
{
if
(
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
,
onlyKey
)
!=
0
)
{
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbDestroyReadH
(
&
readh
);
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
return
-
1
;
...
@@ -1116,7 +1127,7 @@ UNUSED_FUNC int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) {
...
@@ -1116,7 +1127,7 @@ UNUSED_FUNC int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) {
if
(
pIdx
&&
cacheLastRowTableNum
>
0
&&
pTable
->
lastRow
==
NULL
)
{
if
(
pIdx
&&
cacheLastRowTableNum
>
0
&&
pTable
->
lastRow
==
NULL
)
{
pTable
->
lastKey
=
pIdx
->
maxKey
;
pTable
->
lastKey
=
pIdx
->
maxKey
;
if
(
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
)
!=
0
)
{
if
(
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
,
false
)
!=
0
)
{
tsdbDestroyReadH
(
&
readh
);
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
return
-
1
;
}
}
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
876c0068
...
@@ -635,7 +635,7 @@ static int32_t lazyLoadCacheLast(STsdbQueryHandle* pQueryHandle) {
...
@@ -635,7 +635,7 @@ static int32_t lazyLoadCacheLast(STsdbQueryHandle* pQueryHandle) {
if
(
pTable
->
cacheLastConfigVersion
==
pRepo
->
cacheLastConfigVersion
)
{
if
(
pTable
->
cacheLastConfigVersion
==
pRepo
->
cacheLastConfigVersion
)
{
continue
;
continue
;
}
}
code
=
tsdbLoadLastCache
(
pRepo
,
pTable
);
code
=
tsdbLoadLastCache
(
pRepo
,
pTable
,
false
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tsdbError
(
"%p uid:%"
PRId64
", tid:%d, failed to load last cache since %s"
,
pQueryHandle
,
pTable
->
tableId
.
uid
,
tsdbError
(
"%p uid:%"
PRId64
", tid:%d, failed to load last cache since %s"
,
pQueryHandle
,
pTable
->
tableId
.
uid
,
pTable
->
tableId
.
tid
,
tstrerror
(
terrno
));
pTable
->
tableId
.
tid
,
tstrerror
(
terrno
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录