Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b62fa20b
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看板
提交
b62fa20b
编写于
10月 17, 2022
作者:
M
Minglei Jin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tsdb/cache: return last row as array of SLastCol
上级
977fc4b1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
91 addition
and
34 deletion
+91
-34
source/dnode/vnode/src/tsdb/tsdbCache.c
source/dnode/vnode/src/tsdb/tsdbCache.c
+89
-33
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
+2
-1
未找到文件。
source/dnode/vnode/src/tsdb/tsdbCache.c
浏览文件 @
b62fa20b
...
...
@@ -61,8 +61,6 @@ static void getTableCacheKey(tb_uid_t uid, int cacheType, char *key, int *len) {
*
len
=
sizeof
(
uint64_t
);
}
static
void
deleteTableCacheLastrow
(
const
void
*
key
,
size_t
keyLen
,
void
*
value
)
{
taosMemoryFree
(
value
);
}
static
void
deleteTableCacheLast
(
const
void
*
key
,
size_t
keyLen
,
void
*
value
)
{
taosArrayDestroy
(
value
);
}
int32_t
tsdbCacheDeleteLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
TSKEY
eKey
)
{
...
...
@@ -75,13 +73,23 @@ int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
getTableCacheKey
(
uid
,
0
,
key
,
&
keyLen
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
h
)
{
STSRow
*
pRow
=
(
STSRow
*
)
taosLRUCacheValue
(
pCache
,
h
);
if
(
pRow
->
ts
<=
eKey
)
{
SArray
*
pLast
=
(
SArray
*
)
taosLRUCacheValue
(
pCache
,
h
);
bool
invalidate
=
false
;
int16_t
nCol
=
taosArrayGetSize
(
pLast
);
for
(
int16_t
iCol
=
0
;
iCol
<
nCol
;
++
iCol
)
{
SLastCol
*
tTsVal
=
(
SLastCol
*
)
taosArrayGet
(
pLast
,
iCol
);
if
(
eKey
>=
tTsVal
->
ts
)
{
invalidate
=
true
;
break
;
}
}
if
(
invalidate
)
{
taosLRUCacheRelease
(
pCache
,
h
,
true
);
}
else
{
taosLRUCacheRelease
(
pCache
,
h
,
false
);
}
// void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
}
...
...
@@ -130,14 +138,23 @@ int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) {
getTableCacheKey
(
uid
,
0
,
key
,
&
keyLen
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
h
)
{
STSRow
*
pRow
=
(
STSRow
*
)
taosLRUCacheValue
(
pCache
,
h
);
if
(
pRow
->
ts
<=
eKey
)
{
SArray
*
pLast
=
(
SArray
*
)
taosLRUCacheValue
(
pCache
,
h
);
bool
invalidate
=
false
;
int16_t
nCol
=
taosArrayGetSize
(
pLast
);
for
(
int16_t
iCol
=
0
;
iCol
<
nCol
;
++
iCol
)
{
SLastCol
*
tTsVal
=
(
SLastCol
*
)
taosArrayGet
(
pLast
,
iCol
);
if
(
eKey
>=
tTsVal
->
ts
)
{
invalidate
=
true
;
break
;
}
}
if
(
invalidate
)
{
taosLRUCacheRelease
(
pCache
,
h
,
true
);
}
else
{
taosLRUCacheRelease
(
pCache
,
h
,
false
);
}
// void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
}
// getTableCacheKey(uid, "l", key, &keyLen);
...
...
@@ -177,6 +194,46 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
getTableCacheKey
(
uid
,
0
,
key
,
&
keyLen
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
h
)
{
STSchema
*
pTSchema
=
metaGetTbTSchema
(
pTsdb
->
pVnode
->
pMeta
,
uid
,
-
1
,
1
);
TSKEY
keyTs
=
row
->
ts
;
bool
invalidate
=
false
;
SArray
*
pLast
=
(
SArray
*
)
taosLRUCacheValue
(
pCache
,
h
);
int16_t
nCol
=
taosArrayGetSize
(
pLast
);
int16_t
iCol
=
0
;
SLastCol
*
tTsVal
=
(
SLastCol
*
)
taosArrayGet
(
pLast
,
iCol
);
if
(
keyTs
>
tTsVal
->
ts
)
{
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
0
];
SColVal
tColVal
=
COL_VAL_VALUE
(
pTColumn
->
colId
,
pTColumn
->
type
,
(
SValue
){.
val
=
keyTs
});
taosArraySet
(
pLast
,
iCol
,
&
(
SLastCol
){.
ts
=
keyTs
,
.
colVal
=
tColVal
});
}
for
(
++
iCol
;
iCol
<
nCol
;
++
iCol
)
{
SLastCol
*
tTsVal1
=
(
SLastCol
*
)
taosArrayGet
(
pLast
,
iCol
);
if
(
keyTs
>=
tTsVal1
->
ts
)
{
SColVal
*
tColVal
=
&
tTsVal1
->
colVal
;
SColVal
colVal
=
{
0
};
tTSRowGetVal
(
row
,
pTSchema
,
iCol
,
&
colVal
);
if
(
!
COL_VAL_IS_NONE
(
&
colVal
))
{
if
(
keyTs
==
tTsVal1
->
ts
&&
!
COL_VAL_IS_NONE
(
tColVal
))
{
invalidate
=
true
;
break
;
}
}
else
{
taosArraySet
(
pLast
,
iCol
,
&
(
SLastCol
){.
ts
=
keyTs
,
.
colVal
=
colVal
});
}
}
}
_invalidate:
taosMemoryFreeClear
(
pTSchema
);
taosLRUCacheRelease
(
pCache
,
h
,
invalidate
);
/*
cacheRow = (STSRow *)taosLRUCacheValue(pCache, h);
if (row->ts >= cacheRow->ts) {
if (row->ts == cacheRow->ts) {
...
...
@@ -218,9 +275,9 @@ int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, STsdb *pTsdb, tb_uid_t uid, ST
if (status != TAOS_LRU_STATUS_OK) {
code = -1;
}
/
* tsdbCacheInsertLastrow(pCache, uid, row, dup); */
/
/ tsdbCacheInsertLastrow(pCache, uid, row, dup);
}
}
}
*/
}
/*else {
if (dup) {
cacheRow = tdRowDup(row);
...
...
@@ -1031,7 +1088,7 @@ _err:
return
code
;
}
static
int32_t
mergeLastRow
(
tb_uid_t
uid
,
STsdb
*
pTsdb
,
bool
*
dup
,
S
TSRow
**
ppRow
)
{
static
int32_t
mergeLastRow
(
tb_uid_t
uid
,
STsdb
*
pTsdb
,
bool
*
dup
,
S
Array
**
ppColArray
)
{
int32_t
code
=
0
;
STSchema
*
pTSchema
=
metaGetTbTSchema
(
pTsdb
->
pVnode
->
pMeta
,
uid
,
-
1
,
1
);
...
...
@@ -1055,12 +1112,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo
break
;
}
TSKEY
rowTs
=
TSDBROW_TS
(
pRow
);
if
(
lastRowTs
==
TSKEY_MAX
)
{
lastRowTs
=
TSDBROW_TS
(
pRow
)
;
lastRowTs
=
rowTs
;
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
0
];
*
pColVal
=
COL_VAL_VALUE
(
pTColumn
->
colId
,
pTColumn
->
type
,
(
SValue
){.
val
=
lastRowTs
});
if
(
taosArrayPush
(
pColArray
,
pColVal
)
==
NULL
)
{
if
(
taosArrayPush
(
pColArray
,
&
(
SLastCol
){.
ts
=
lastRowTs
,
.
colVal
=
*
pColVal
}
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -1068,7 +1127,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo
for
(
iCol
=
1
;
iCol
<
nCol
;
++
iCol
)
{
tsdbRowGetColVal
(
pRow
,
pTSchema
,
iCol
,
pColVal
);
if
(
taosArrayPush
(
pColArray
,
pColVal
)
==
NULL
)
{
if
(
taosArrayPush
(
pColArray
,
&
(
SLastCol
){.
ts
=
lastRowTs
,
.
colVal
=
*
pColVal
}
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
...
...
@@ -1079,15 +1138,15 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo
}
}
if
(
!
setNoneCol
)
{
//
goto build the result ts row
//
done, goto return pColArray
break
;
}
else
{
continue
;
}
}
if
((
TSDBROW_TS
(
pRow
)
<
lastRowTs
))
{
//
goto build the result ts row
if
((
rowTs
<
lastRowTs
))
{
//
done, goto return pColArray
break
;
}
...
...
@@ -1099,7 +1158,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo
tsdbRowGetColVal
(
pRow
,
pTSchema
,
iCol
,
pColVal
);
if
(
COL_VAL_IS_NONE
(
tColVal
)
&&
!
COL_VAL_IS_NONE
(
pColVal
))
{
taosArraySet
(
pColArray
,
iCol
,
pColVal
);
taosArraySet
(
pColArray
,
iCol
,
&
(
SLastCol
){.
ts
=
rowTs
,
.
colVal
=
*
pColVal
}
);
}
else
if
(
COL_VAL_IS_NONE
(
tColVal
)
&&
COL_VAL_IS_NONE
(
pColVal
)
&&
!
setNoneCol
)
{
noneCol
=
iCol
;
setNoneCol
=
true
;
...
...
@@ -1110,14 +1169,13 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, STSRow **ppRo
// build the result ts row here
*
dup
=
false
;
if
(
taosArrayGetSize
(
pColArray
)
==
nCol
)
{
code
=
tdSTSRowNew
(
pColArray
,
pTSchema
,
ppRow
)
;
if
(
code
)
goto
_err
;
*
ppColArray
=
NULL
;
taosArrayDestroy
(
pColArray
)
;
}
else
{
*
pp
Row
=
NULL
;
*
pp
ColArray
=
pColArray
;
}
nextRowIterClose
(
&
iter
);
taosArrayDestroy
(
pColArray
);
taosMemoryFreeClear
(
pTSchema
);
return
code
;
...
...
@@ -1178,7 +1236,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) {
}
}
if
(
!
setNoneCol
)
{
//
goto build the result ts row
//
done, goto return pColArray
break
;
}
else
{
continue
;
...
...
@@ -1202,7 +1260,6 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray) {
}
}
while
(
setNoneCol
);
// build the result ts row here
if
(
taosArrayGetSize
(
pColArray
)
<=
0
)
{
*
ppLastArray
=
NULL
;
taosArrayDestroy
(
pColArray
);
...
...
@@ -1233,13 +1290,13 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
!
h
)
{
S
TSRow
*
pRow
=
NULL
;
S
Array
*
pArray
=
NULL
;
bool
dup
=
false
;
// which is always false for now
code
=
mergeLastRow
(
uid
,
pTsdb
,
&
dup
,
&
p
Row
);
code
=
mergeLastRow
(
uid
,
pTsdb
,
&
dup
,
&
p
Array
);
// if table's empty or error, return code of -1
if
(
code
<
0
||
p
Row
==
NULL
)
{
if
(
!
dup
&&
p
Row
)
{
taos
MemoryFree
(
pRow
);
if
(
code
<
0
||
p
Array
==
NULL
)
{
if
(
!
dup
&&
p
Array
)
{
taos
ArrayDestroy
(
pArray
);
}
taosThreadMutexUnlock
(
&
pTsdb
->
lruMutex
);
...
...
@@ -1249,9 +1306,9 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH
return
0
;
}
_taos_lru_deleter_t
deleter
=
deleteTableCacheLast
row
;
_taos_lru_deleter_t
deleter
=
deleteTableCacheLast
;
LRUStatus
status
=
taosLRUCacheInsert
(
pCache
,
key
,
keyLen
,
p
Row
,
TD_ROW_LEN
(
pRow
)
,
deleter
,
NULL
,
TAOS_LRU_PRIORITY_LOW
);
taosLRUCacheInsert
(
pCache
,
key
,
keyLen
,
p
Array
,
pArray
->
capacity
,
deleter
,
NULL
,
TAOS_LRU_PRIORITY_LOW
);
if
(
status
!=
TAOS_LRU_STATUS_OK
)
{
code
=
-
1
;
}
...
...
@@ -1309,7 +1366,6 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand
SArray
*
pLastArray
=
NULL
;
code
=
mergeLast
(
uid
,
pTsdb
,
&
pLastArray
);
// if table's empty or error, return code of -1
// if (code < 0 || pRow == NULL) {
if
(
code
<
0
||
pLastArray
==
NULL
)
{
taosThreadMutexUnlock
(
&
pTsdb
->
lruMutex
);
...
...
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
浏览文件 @
b62fa20b
...
...
@@ -128,7 +128,8 @@ static int32_t doExtractCacheRow(SCacheRowsReader* pr, SLRUCache* lruCache, uint
// no data in the table of Uid
if
(
*
h
!=
NULL
)
{
*
pRow
=
(
STSRow
*
)
taosLRUCacheValue
(
lruCache
,
*
h
);
//*pRow = (STSRow*)taosLRUCacheValue(lruCache, *h);
SArray
*
pLastrow
=
(
SArray
*
)
taosLRUCacheValue
(
lruCache
,
*
h
);
}
}
else
{
code
=
tsdbCacheGetLastH
(
lruCache
,
uid
,
pr
->
pVnode
->
pTsdb
,
h
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录