Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f48a1f1f
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
f48a1f1f
编写于
10月 25, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-493-M]<enhance>: postpone cache last to query time
上级
fc8b47ea
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
153 addition
and
21 deletion
+153
-21
src/tsdb/inc/tsdbMeta.h
src/tsdb/inc/tsdbMeta.h
+1
-0
src/tsdb/inc/tsdbint.h
src/tsdb/inc/tsdbint.h
+4
-3
src/tsdb/src/tsdbCommitQueue.c
src/tsdb/src/tsdbCommitQueue.c
+3
-1
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+110
-16
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+3
-0
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+1
-0
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+31
-1
未找到文件。
src/tsdb/inc/tsdbMeta.h
浏览文件 @
f48a1f1f
...
...
@@ -41,6 +41,7 @@ typedef struct STable {
int16_t
restoreColumnNum
;
bool
hasRestoreLastColumn
;
int
lastColSVersion
;
int16_t
cacheLastConfigVersion
;
T_REF_DECLARE
()
}
STable
;
...
...
src/tsdb/inc/tsdbint.h
浏览文件 @
f48a1f1f
...
...
@@ -79,8 +79,8 @@ struct STsdbRepo {
STsdbCfg
save_config
;
// save apply config
bool
config_changed
;
// config changed flag
pthread_mutex_t
save_mutex
;
// protect save config
uint8_t
hasCachedLastColum
n
;
int16_t
cacheLastConfigVersio
n
;
STsdbAppH
appH
;
STsdbStat
stat
;
...
...
@@ -110,7 +110,8 @@ int tsdbUnlockRepo(STsdbRepo* pRepo);
STsdbMeta
*
tsdbGetMeta
(
STsdbRepo
*
pRepo
);
int
tsdbCheckCommit
(
STsdbRepo
*
pRepo
);
int
tsdbRestoreInfo
(
STsdbRepo
*
pRepo
);
int
tsdbCacheLastData
(
STsdbRepo
*
pRepo
,
STsdbCfg
*
oldCfg
);
UNUSED_FUNC
int
tsdbCacheLastData
(
STsdbRepo
*
pRepo
,
STsdbCfg
*
oldCfg
);
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
);
void
tsdbGetRootDir
(
int
repoid
,
char
dirName
[]);
void
tsdbGetDataDir
(
int
repoid
,
char
dirName
[]);
...
...
src/tsdb/src/tsdbCommitQueue.c
浏览文件 @
f48a1f1f
...
...
@@ -146,7 +146,9 @@ static void tsdbApplyRepoConfig(STsdbRepo *pRepo) {
if
(
oldCfg
.
cacheLastRow
!=
pRepo
->
config
.
cacheLastRow
)
{
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
;
tsdbCacheLastData
(
pRepo
,
&
oldCfg
);
// tsdbCacheLastData(pRepo, &oldCfg);
// lazy load last cache when query or update
pRepo
->
cacheLastConfigVersion
+=
1
;
tsdbUnlockRepo
(
pRepo
);
}
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
f48a1f1f
...
...
@@ -562,7 +562,7 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
return
NULL
;
}
pRepo
->
config_changed
=
false
;
atomic_store_8
(
&
pRepo
->
hasCachedLastColumn
,
0
)
;
pRepo
->
cacheLastConfigVersion
=
0
;
code
=
tsem_init
(
&
(
pRepo
->
readyToCommit
),
0
,
1
);
if
(
code
!=
0
)
{
...
...
@@ -788,21 +788,30 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh,
// Get the data in row
STSchema
*
pSchema
=
tsdbGetTableSchema
(
pTable
);
pTable
->
lastRow
=
taosTMalloc
(
memRowMaxBytesFromSchema
(
pSchema
));
if
(
pTable
->
lastRow
==
NULL
)
{
SMemRow
lastRow
=
taosTMalloc
(
memRowMaxBytesFromSchema
(
pSchema
));
if
(
lastRow
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
memRowSetType
(
pTable
->
lastRow
,
SMEM_ROW_DATA
);
tdInitDataRow
(
memRowDataBody
(
pTable
->
lastRow
),
pSchema
);
memRowSetType
(
lastRow
,
SMEM_ROW_DATA
);
tdInitDataRow
(
memRowDataBody
(
lastRow
),
pSchema
);
for
(
int
icol
=
0
;
icol
<
schemaNCols
(
pSchema
);
icol
++
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
icol
);
SDataCol
*
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
icol
;
tdAppendColVal
(
memRowDataBody
(
pTable
->
lastRow
),
tdGetColDataOfRow
(
pDataCol
,
pBlock
->
numOfRows
-
1
),
pCol
->
type
,
tdAppendColVal
(
memRowDataBody
(
lastRow
),
tdGetColDataOfRow
(
pDataCol
,
pBlock
->
numOfRows
-
1
),
pCol
->
type
,
pCol
->
offset
);
}
TSKEY
lastKey
=
memRowKey
(
lastRow
);
pTable
->
lastKey
=
memRowKey
(
pTable
->
lastRow
);
// during the load data in file, new data would be inserted and last row has been updated
if
(
tsdbGetTableLastKeyImpl
(
pTable
)
<=
lastKey
)
{
TSDB_WLOCK_TABLE
(
pTable
);
pTable
->
lastRow
=
lastRow
;
pTable
->
lastKey
=
lastKey
;
TSDB_WUNLOCK_TABLE
(
pTable
);
}
else
{
taosTZfree
(
lastRow
);
}
return
0
;
}
...
...
@@ -874,14 +883,99 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) {
tsdbDestroyReadH
(
&
readh
);
if
(
CACHE_LAST_NULL_COLUMN
(
pCfg
))
{
atomic_store_8
(
&
pRepo
->
hasCachedLastColumn
,
1
);
// if (CACHE_LAST_NULL_COLUMN(pCfg)) {
// atomic_store_8(&pRepo->hasCachedLastColumn, 1);
// }
return
0
;
}
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
)
{
bool
cacheLastRow
=
CACHE_LAST_ROW
(
&
(
pRepo
->
config
));
bool
cacheLastCol
=
CACHE_LAST_NULL_COLUMN
(
&
(
pRepo
->
config
));
SFSIter
fsiter
;
SReadH
readh
;
SDFileSet
*
pSet
;
int
cacheLastRowTableNum
=
0
;
int
cacheLastColTableNum
=
0
;
tsdbDebug
(
"tsdbLoadLastCache for %s, cacheLastRow:%d, cacheLastCol:%d"
,
pTable
->
name
->
data
,
cacheLastRow
,
cacheLastCol
);
pTable
->
cacheLastConfigVersion
=
pRepo
->
cacheLastConfigVersion
;
if
(
!
cacheLastRow
&&
pTable
->
lastRow
!=
NULL
)
{
taosTZfree
(
pTable
->
lastRow
);
pTable
->
lastRow
=
NULL
;
}
if
(
!
cacheLastCol
&&
pTable
->
lastCols
!=
NULL
)
{
tsdbFreeLastColumns
(
pTable
);
}
if
(
!
cacheLastRow
&&
!
cacheLastCol
)
{
return
0
;
}
cacheLastRowTableNum
=
(
cacheLastRow
&&
pTable
->
lastRow
==
NULL
)
?
1
:
0
;
cacheLastColTableNum
=
(
cacheLastCol
&&
pTable
->
lastCols
==
NULL
)
?
1
:
0
;
if
(
cacheLastRowTableNum
==
0
&&
cacheLastColTableNum
==
0
)
{
return
0
;
}
if
(
tsdbInitReadH
(
&
readh
,
pRepo
)
<
0
)
{
return
-
1
;
}
tsdbFSIterInit
(
&
fsiter
,
REPO_FS
(
pRepo
),
TSDB_FS_ITER_BACKWARD
);
while
((
pSet
=
tsdbFSIterNext
(
&
fsiter
))
!=
NULL
&&
(
cacheLastRowTableNum
>
0
||
cacheLastColTableNum
>
0
))
{
if
(
tsdbSetAndOpenReadFSet
(
&
readh
,
pSet
)
<
0
)
{
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
if
(
tsdbLoadBlockIdx
(
&
readh
)
<
0
)
{
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
//tsdbInfo("tsdbRestoreInfo restore vgId:%d,table:%s", REPO_ID(pRepo), pTable->name->data);
if
(
tsdbSetReadTable
(
&
readh
,
pTable
)
<
0
)
{
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
SBlockIdx
*
pIdx
=
readh
.
pBlkIdx
;
if
(
cacheLastRow
&&
pIdx
&&
pTable
->
lastRow
==
NULL
&&
cacheLastRowTableNum
>
0
)
{
pTable
->
lastKey
=
pIdx
->
maxKey
;
if
(
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
)
!=
0
)
{
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
cacheLastRowTableNum
-=
1
;
}
// restore NULL columns
if
(
pIdx
&&
cacheLastColTableNum
>
0
&&
!
pTable
->
hasRestoreLastColumn
)
{
if
(
tsdbRestoreLastColumns
(
pRepo
,
pTable
,
&
readh
)
!=
0
)
{
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
if
(
pTable
->
hasRestoreLastColumn
)
{
cacheLastColTableNum
-=
1
;
}
}
}
tsdbDestroyReadH
(
&
readh
);
return
0
;
}
int
tsdbCacheLastData
(
STsdbRepo
*
pRepo
,
STsdbCfg
*
oldCfg
)
{
UNUSED_FUNC
int
tsdbCacheLastData
(
STsdbRepo
*
pRepo
,
STsdbCfg
*
oldCfg
)
{
bool
cacheLastRow
=
false
,
cacheLastCol
=
false
;
SFSIter
fsiter
;
SReadH
readh
;
...
...
@@ -915,9 +1009,9 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) {
// if close last option,need to free data
if
(
need_free_last_row
||
need_free_last_col
)
{
if
(
need_free_last_col
)
{
atomic_store_8
(
&
pRepo
->
hasCachedLastColumn
,
0
);
}
//
if (need_free_last_col) {
//
atomic_store_8(&pRepo->hasCachedLastColumn, 0);
//
}
tsdbInfo
(
"free cache last data since cacheLast option changed"
);
for
(
int
i
=
1
;
i
<=
maxTableIdx
;
i
++
)
{
STable
*
pTable
=
pMeta
->
tables
[
i
];
...
...
@@ -995,9 +1089,9 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) {
tsdbDestroyReadH
(
&
readh
);
if
(
cacheLastCol
)
{
atomic_store_8
(
&
pRepo
->
hasCachedLastColumn
,
1
);
}
//
if (cacheLastCol) {
//
atomic_store_8(&pRepo->hasCachedLastColumn, 1);
//
}
return
0
;
}
src/tsdb/src/tsdbMemTable.c
浏览文件 @
f48a1f1f
...
...
@@ -1058,5 +1058,8 @@ static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SMemRow r
updateTableLatestColumn
(
pRepo
,
pTable
,
row
);
}
}
pTable
->
cacheLastConfigVersion
=
pRepo
->
cacheLastConfigVersion
;
return
0
;
}
src/tsdb/src/tsdbMeta.c
浏览文件 @
f48a1f1f
...
...
@@ -797,6 +797,7 @@ static STable *tsdbNewTable() {
pTable
->
lastCols
=
NULL
;
pTable
->
restoreColumnNum
=
0
;
pTable
->
cacheLastConfigVersion
=
0
;
pTable
->
maxColNum
=
0
;
pTable
->
hasRestoreLastColumn
=
false
;
pTable
->
lastColSVersion
=
-
1
;
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
f48a1f1f
...
...
@@ -156,6 +156,7 @@ typedef struct STableGroupSupporter {
static
STimeWindow
updateLastrowForEachGroup
(
STableGroupInfo
*
groupList
);
static
int32_t
checkForCachedLastRow
(
STsdbQueryHandle
*
pQueryHandle
,
STableGroupInfo
*
groupList
);
static
int32_t
checkForCachedLast
(
STsdbQueryHandle
*
pQueryHandle
);
static
int32_t
lazyLoadCacheLast
(
STsdbQueryHandle
*
pQueryHandle
);
static
int32_t
tsdbGetCachedLastRow
(
STable
*
pTable
,
SMemRow
*
pRes
,
TSKEY
*
lastKey
);
static
void
changeQueryHandleForInterpQuery
(
TsdbQueryHandleT
pHandle
);
...
...
@@ -602,6 +603,8 @@ TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STable
return
NULL
;
}
lazyLoadCacheLast
(
pQueryHandle
);
int32_t
code
=
checkForCachedLastRow
(
pQueryHandle
,
groupList
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// set the numOfTables to be 0
terrno
=
code
;
...
...
@@ -616,6 +619,29 @@ TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STable
return
pQueryHandle
;
}
static
int32_t
lazyLoadCacheLast
(
STsdbQueryHandle
*
pQueryHandle
)
{
STsdbRepo
*
pRepo
=
pQueryHandle
->
pTsdb
;
size_t
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
size_t
i
=
0
;
int32_t
code
=
0
;
for
(
i
=
0
;
i
<
numOfTables
;
++
i
)
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
STable
*
pTable
=
pCheckInfo
->
pTableObj
;
if
(
pTable
->
cacheLastConfigVersion
==
pRepo
->
cacheLastConfigVersion
)
{
continue
;
}
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
-
1
;
code
=
tsdbLoadLastCache
(
pRepo
,
pTable
);
if
(
tsdbUnlockRepo
(
pRepo
)
!=
0
)
return
-
1
;
if
(
code
!=
0
)
{
break
;
}
}
return
code
;
}
TsdbQueryHandleT
tsdbQueryCacheLast
(
STsdbRepo
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
uint64_t
qId
,
SMemRef
*
pMemRef
)
{
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
tsdbQueryTables
(
tsdb
,
pCond
,
groupList
,
qId
,
pMemRef
);
...
...
@@ -623,6 +649,8 @@ TsdbQueryHandleT tsdbQueryCacheLast(STsdbRepo *tsdb, STsdbQueryCond *pCond, STab
return
NULL
;
}
lazyLoadCacheLast
(
pQueryHandle
);
int32_t
code
=
checkForCachedLast
(
pQueryHandle
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// set the numOfTables to be 0
terrno
=
code
;
...
...
@@ -3198,7 +3226,9 @@ int32_t checkForCachedLast(STsdbQueryHandle* pQueryHandle) {
int32_t
code
=
0
;
if
(
pQueryHandle
->
pTsdb
&&
atomic_load_8
(
&
pQueryHandle
->
pTsdb
->
hasCachedLastColumn
)){
STsdbRepo
*
pRepo
=
pQueryHandle
->
pTsdb
;
if
(
pRepo
&&
CACHE_LAST_NULL_COLUMN
(
&
(
pRepo
->
config
)))
{
pQueryHandle
->
cachelastrow
=
TSDB_CACHED_TYPE_LAST
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录