Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c95e2d89
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c95e2d89
编写于
10月 29, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code optimization
上级
76721f8a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
77 addition
and
62 deletion
+77
-62
src/tsdb/src/tsdbCommitQueue.c
src/tsdb/src/tsdbCommitQueue.c
+1
-1
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+26
-19
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+4
-1
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+20
-17
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+26
-24
未找到文件。
src/tsdb/src/tsdbCommitQueue.c
浏览文件 @
c95e2d89
...
...
@@ -148,7 +148,7 @@ static void tsdbApplyRepoConfig(STsdbRepo *pRepo) {
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
;
// tsdbCacheLastData(pRepo, &oldCfg);
// lazy load last cache when query or update
pRepo
->
cacheLastConfigVersion
+=
1
;
++
pRepo
->
cacheLastConfigVersion
;
tsdbUnlockRepo
(
pRepo
);
}
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
c95e2d89
...
...
@@ -658,6 +658,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
}
if
(
pTable
->
lastColSVersion
!=
schemaVersion
(
pSchema
))
{
if
(
tsdbInitColIdCacheWithSchema
(
pTable
,
pSchema
)
<
0
)
{
TSDB_WUNLOCK_TABLE
(
pTable
);
return
-
1
;
}
}
...
...
@@ -711,7 +712,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
tsdbGetBlockStatis
(
pReadh
,
pBlockStatis
,
(
int
)
numColumns
);
loadStatisData
=
true
;
}
TSDB_WLOCK_TABLE
(
pTable
);
// lock when update pTable->lastCols[]
for
(
int16_t
i
=
0
;
i
<
numColumns
&&
numColumns
>
pTable
->
restoreColumnNum
;
++
i
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
// ignore loaded columns
...
...
@@ -760,6 +761,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
break
;
}
}
TSDB_WUNLOCK_TABLE
(
pTable
);
}
out:
...
...
@@ -800,23 +802,17 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh,
tdAppendColVal
(
memRowDataBody
(
lastRow
),
tdGetColDataOfRow
(
pDataCol
,
pBlock
->
numOfRows
-
1
),
pCol
->
type
,
pCol
->
offset
);
}
TSKEY
lastKey
=
memRowKey
(
lastRow
);
if
(
!
pCfg
->
cacheLastRow
&&
pTable
->
lastRow
!=
NULL
)
{
SMemRow
cachedLastRow
=
pTable
->
lastRow
;
TSDB_WLOCK_TABLE
(
pTable
);
pTable
->
lastRow
=
NULL
;
TSDB_WUNLOCK_TABLE
(
pTable
);
taosTZfree
(
cachedLastRow
);
}
// 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
;
TSDB_WLOCK_TABLE
(
pTable
);
if
(
tsdbGetTableLastKeyImpl
(
pTable
)
<
lastKey
)
{
pTable
->
lastKey
=
lastKey
;
pTable
->
lastRow
=
lastRow
;
TSDB_WUNLOCK_TABLE
(
pTable
);
}
else
{
TSDB_WUNLOCK_TABLE
(
pTable
);
taosTZfree
(
lastRow
);
}
...
...
@@ -897,15 +893,16 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) {
return
0
;
}
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
)
{
bool
cacheLastRow
=
CACHE_LAST_ROW
(
&
(
pRepo
->
config
));
bool
cacheLastCol
=
CACHE_LAST_NULL_COLUMN
(
&
(
pRepo
->
config
));
int32_t
tsdbLoadLastCache
(
STsdbRepo
*
pRepo
,
STable
*
pTable
)
{
SFSIter
fsiter
;
SReadH
readh
;
SDFileSet
*
pSet
;
int
cacheLastRowTableNum
=
0
;
int
cacheLastColTableNum
=
0
;
bool
cacheLastRow
=
CACHE_LAST_ROW
(
&
(
pRepo
->
config
));
bool
cacheLastCol
=
CACHE_LAST_NULL_COLUMN
(
&
(
pRepo
->
config
));
tsdbDebug
(
"tsdbLoadLastCache for %s, cacheLastRow:%d, cacheLastCol:%d"
,
pTable
->
name
->
data
,
cacheLastRow
,
cacheLastCol
);
pTable
->
cacheLastConfigVersion
=
pRepo
->
cacheLastConfigVersion
;
...
...
@@ -933,10 +930,12 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable* pTable) {
return
-
1
;
}
tsdbRLockFS
(
REPO_FS
(
pRepo
));
tsdbFSIterInit
(
&
fsiter
,
REPO_FS
(
pRepo
),
TSDB_FS_ITER_BACKWARD
);
while
((
pSet
=
tsdbFSIterNext
(
&
fsiter
))
!=
NULL
&&
(
cacheLastRowTableNum
>
0
||
cacheLastColTableNum
>
0
)
)
{
while
((
cacheLastRowTableNum
>
0
||
cacheLastColTableNum
>
0
)
&&
(
pSet
=
tsdbFSIterNext
(
&
fsiter
))
!=
NULL
)
{
if
(
tsdbSetAndOpenReadFSet
(
&
readh
,
pSet
)
<
0
)
{
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
...
...
@@ -946,19 +945,25 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable* pTable) {
return
-
1
;
}
//tsdbInfo
("tsdbRestoreInfo restore vgId:%d,table:%s", REPO_ID(pRepo), pTable->name->data);
// tsdbDebug
("tsdbRestoreInfo restore vgId:%d,table:%s", REPO_ID(pRepo), pTable->name->data);
if
(
tsdbSetReadTable
(
&
readh
,
pTable
)
<
0
)
{
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
SBlockIdx
*
pIdx
=
readh
.
pBlkIdx
;
if
(
cacheLastRow
&&
pIdx
&&
pTable
->
lastRow
==
NULL
&&
cacheLastRowTableNum
>
0
)
{
if
(
pIdx
&&
(
cacheLastRowTableNum
>
0
)
&&
(
pTable
->
lastRow
==
NULL
))
{
if
(
tsdbGetTableLastKeyImpl
(
pTable
)
<
pTable
->
lastKey
)
{
TSDB_WLOCK_TABLE
(
pTable
);
pTable
->
lastKey
=
pIdx
->
maxKey
;
TSDB_WUNLOCK_TABLE
(
pTable
);
}
if
(
tsdbRestoreLastRow
(
pRepo
,
pTable
,
&
readh
,
pIdx
)
!=
0
)
{
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
...
...
@@ -966,8 +971,9 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable* pTable) {
}
// restore NULL columns
if
(
pIdx
&&
cacheLastColTableNum
>
0
&&
!
pTable
->
hasRestoreLastColumn
)
{
if
(
pIdx
&&
(
cacheLastColTableNum
>
0
)
&&
!
pTable
->
hasRestoreLastColumn
)
{
if
(
tsdbRestoreLastColumns
(
pRepo
,
pTable
,
&
readh
)
!=
0
)
{
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbDestroyReadH
(
&
readh
);
return
-
1
;
}
...
...
@@ -977,6 +983,7 @@ int32_t tsdbLoadLastCache(STsdbRepo *pRepo, STable* pTable) {
}
}
tsdbUnLockFS
(
REPO_FS
(
pRepo
));
tsdbDestroyReadH
(
&
readh
);
return
0
;
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
c95e2d89
...
...
@@ -996,7 +996,8 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SMemRow ro
if
((
value
==
NULL
)
||
isNull
(
value
,
pTCol
->
type
))
{
continue
;
}
// lock
TSDB_WLOCK_TABLE
(
pTable
);
SDataCol
*
pDataCol
=
&
(
pLatestCols
[
idx
]);
if
(
pDataCol
->
pData
==
NULL
)
{
pDataCol
->
pData
=
malloc
(
pTCol
->
bytes
);
...
...
@@ -1012,6 +1013,8 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SMemRow ro
memcpy
(
pDataCol
->
pData
,
value
,
bytes
);
//tsdbInfo("updateTableLatestColumn vgId:%d cache column %d for %d,%s", REPO_ID(pRepo), j, pDataCol->bytes, (char*)pDataCol->pData);
pDataCol
->
ts
=
memRowKey
(
row
);
// unlock
TSDB_WUNLOCK_TABLE
(
pTable
);
}
}
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
c95e2d89
...
...
@@ -627,27 +627,30 @@ int16_t tsdbGetLastColumnsIndexByColId(STable* pTable, int16_t colId) {
}
int
tsdbInitColIdCacheWithSchema
(
STable
*
pTable
,
STSchema
*
pSchema
)
{
ASSERT
(
pTable
->
lastCols
==
NULL
);
TSDB_WLOCK_TABLE
(
pTable
);
if
(
pTable
->
lastCols
==
NULL
)
{
int16_t
numOfColumn
=
pSchema
->
numOfCols
;
int16_t
numOfColumn
=
pSchema
->
numOfCols
;
pTable
->
lastCols
=
(
SDataCol
*
)
malloc
(
numOfColumn
*
sizeof
(
SDataCol
));
if
(
pTable
->
lastCols
==
NULL
)
{
TSDB_WUNLOCK_TABLE
(
pTable
);
return
-
1
;
}
pTable
->
lastCols
=
(
SDataCol
*
)
malloc
(
numOfColumn
*
sizeof
(
SDataCol
));
if
(
pTable
->
lastCols
==
NULL
)
{
return
-
1
;
}
for
(
int16_t
i
=
0
;
i
<
numOfColumn
;
++
i
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
SDataCol
*
pDataCol
=
&
(
pTable
->
lastCols
[
i
]);
pDataCol
->
bytes
=
0
;
pDataCol
->
pData
=
NULL
;
pDataCol
->
colId
=
pCol
->
colId
;
}
for
(
int16_t
i
=
0
;
i
<
numOfColumn
;
++
i
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
i
);
SDataCol
*
pDataCol
=
&
(
pTable
->
lastCols
[
i
]);
pDataCol
->
bytes
=
0
;
pDataCol
->
pData
=
NULL
;
pDataCol
->
colId
=
pCol
->
colId
;
pTable
->
lastColSVersion
=
schemaVersion
(
pSchema
);
pTable
->
maxColNum
=
numOfColumn
;
pTable
->
restoreColumnNum
=
0
;
pTable
->
hasRestoreLastColumn
=
false
;
}
pTable
->
lastColSVersion
=
schemaVersion
(
pSchema
);
pTable
->
maxColNum
=
numOfColumn
;
pTable
->
restoreColumnNum
=
0
;
pTable
->
hasRestoreLastColumn
=
false
;
TSDB_WUNLOCK_TABLE
(
pTable
);
return
0
;
}
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
c95e2d89
...
...
@@ -590,6 +590,28 @@ void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCon
pQueryHandle
->
next
=
doFreeColumnInfoData
(
pQueryHandle
->
next
);
}
static
int32_t
lazyLoadCacheLast
(
STsdbQueryHandle
*
pQueryHandle
)
{
STsdbRepo
*
pRepo
=
pQueryHandle
->
pTsdb
;
size_t
numOfTables
=
taosArrayGetSize
(
pQueryHandle
->
pTableCheckInfo
);
int32_t
code
=
0
;
for
(
size_t
i
=
0
;
i
<
numOfTables
;
++
i
)
{
STableCheckInfo
*
pCheckInfo
=
taosArrayGet
(
pQueryHandle
->
pTableCheckInfo
,
i
);
STable
*
pTable
=
pCheckInfo
->
pTableObj
;
if
(
pTable
->
cacheLastConfigVersion
==
pRepo
->
cacheLastConfigVersion
)
{
continue
;
}
code
=
tsdbLoadLastCache
(
pRepo
,
pTable
);
if
(
code
!=
0
)
{
tsdbError
(
"%p uid:%"
PRId64
", tid:%d, failed to load last cache since %s"
,
pQueryHandle
,
pTable
->
tableId
.
uid
,
pTable
->
tableId
.
tid
,
tstrerror
(
terrno
));
break
;
}
}
return
code
;
}
TsdbQueryHandleT
tsdbQueryLastRow
(
STsdbRepo
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
uint64_t
qId
,
SMemRef
*
pMemRef
)
{
pCond
->
twindow
=
updateLastrowForEachGroup
(
groupList
);
...
...
@@ -619,30 +641,6 @@ 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
);
if
(
pQueryHandle
==
NULL
)
{
...
...
@@ -2809,6 +2807,9 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
}
int32_t
i
=
0
,
j
=
0
;
// lock pTable->lastCols[i] as it would be released when schema update(tsdbUpdateLastColSchema)
TSDB_RLOCK_TABLE
(
pTable
);
while
(
i
<
tgNumOfCols
&&
j
<
numOfCols
)
{
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
if
(
pTable
->
lastCols
[
j
].
colId
<
pColInfo
->
info
.
colId
)
{
...
...
@@ -2895,6 +2896,7 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
i
++
;
j
++
;
}
TSDB_RUNLOCK_TABLE
(
pTable
);
// leave the real ts column as the last row, because last function only (not stable) use the last row as res
if
(
priKey
!=
TSKEY_INITIAL_VAL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录