Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a55f40a1
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看板
提交
a55f40a1
编写于
6月 21, 2022
作者:
M
Minglei Jin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat/tsdbCache: the first round tsdbCache
上级
4cacd72f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
146 addition
and
2 deletion
+146
-2
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+1
-0
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+9
-1
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-0
source/dnode/vnode/src/tsdb/tsdbCache.c
source/dnode/vnode/src/tsdb/tsdbCache.c
+115
-0
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+14
-0
source/dnode/vnode/src/tsdb/tsdbOpen.c
source/dnode/vnode/src/tsdb/tsdbOpen.c
+6
-1
未找到文件。
source/dnode/vnode/CMakeLists.txt
浏览文件 @
a55f40a1
...
...
@@ -41,6 +41,7 @@ target_sources(
"src/tsdb/tsdbMemTable.c"
"src/tsdb/tsdbRead.c"
"src/tsdb/tsdbReadImpl.c"
"src/tsdb/tsdbCache.c"
"src/tsdb/tsdbWrite.c"
"src/tsdb/tsdbReaderWriter.c"
"src/tsdb/tsdbUtil.c"
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
a55f40a1
...
...
@@ -198,6 +198,13 @@ int32_t tsdbDelFReaderClose(SDelFReader *pReader);
int32_t
tsdbReadDelData
(
SDelFReader
*
pReader
,
SDelIdx
*
pDelIdx
,
SMapData
*
pDelDataMap
,
uint8_t
**
ppBuf
);
int32_t
tsdbReadDelIdx
(
SDelFReader
*
pReader
,
SMapData
*
pDelIdxMap
,
uint8_t
**
ppBuf
);
// tsdbCache
int32_t
tsdbOpenCache
(
STsdb
*
pTsdb
);
void
tsdbCloseCache
(
SLRUCache
*
pCache
);
int32_t
tsdbCacheInsertLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
STSRow
*
row
);
int32_t
tsdbCacheGetLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
STSRow
**
ppRow
);
int32_t
tsdbCacheDeleteLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
);
// structs =======================
typedef
struct
{
int
minFid
;
...
...
@@ -218,6 +225,7 @@ struct STsdb {
SMemTable
*
imem
;
SRtn
rtn
;
STsdbFS
*
fs
;
SLRUCache
*
lruCache
;
};
struct
STable
{
...
...
@@ -466,4 +474,4 @@ struct SDFileSet {
}
#endif
#endif
/*_TD_VNODE_TSDB_H_*/
\ No newline at end of file
#endif
/*_TD_VNODE_TSDB_H_*/
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
a55f40a1
...
...
@@ -36,6 +36,7 @@
#include "tmallocator.h"
#include "tmsgcb.h"
#include "tskiplist.h"
#include "tlrucache.h"
#include "tstream.h"
#include "ttime.h"
#include "ttimer.h"
...
...
source/dnode/vnode/src/tsdb/tsdbCache.c
0 → 100644
浏览文件 @
a55f40a1
/*
* 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 "tsdb.h"
int32_t
tsdbOpenCache
(
STsdb
*
pTsdb
)
{
int32_t
code
=
0
;
SLRUCache
*
pCache
=
NULL
;
size_t
cfgCapacity
=
1024
*
1024
;
// TODO: get cfg from tsdb config
pCache
=
taosLRUCacheInit
(
cfgCapacity
,
-
1
,
.
5
);
if
(
pCache
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
taosLRUCacheSetStrictCapacity
(
pCache
,
true
);
_err:
pTsdb
->
lruCache
=
pCache
;
return
code
;
}
void
tsdbCloseCache
(
SLRUCache
*
pCache
)
{
if
(
pCache
)
{
taosLRUCacheEraseUnrefEntries
(
pCache
);
taosLRUCacheCleanup
(
pCache
);
}
}
static
void
getTableCacheKey
(
tb_uid_t
uid
,
const
char
*
cacheType
,
char
*
key
,
int
*
len
)
{
int
keyLen
=
0
;
snprintf
(
key
,
30
,
"%"
PRIi64
"%s"
,
uid
,
cacheType
);
*
len
=
strlen
(
key
);
}
static
void
deleteTableCacheLastrow
(
const
void
*
key
,
size_t
keyLen
,
void
*
value
)
{
taosMemoryFree
(
value
);
}
int32_t
tsdbCacheInsertLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
STSRow
*
row
)
{
int32_t
code
=
0
;
STSRow
*
cacheRow
=
NULL
;
char
key
[
32
]
=
{
0
};
int
keyLen
=
0
;
getTableCacheKey
(
uid
,
"lr"
,
key
,
&
keyLen
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
h
)
{
cacheRow
=
(
STSRow
*
)
taosLRUCacheValue
(
pCache
,
h
);
if
(
row
->
ts
>=
cacheRow
->
ts
)
{
if
(
row
->
ts
>
cacheRow
->
ts
)
{
tdRowCpy
(
cacheRow
,
row
);
}
}
}
else
{
cacheRow
=
tdRowDup
(
row
);
_taos_lru_deleter_t
deleter
=
deleteTableCacheLastrow
;
LRUStatus
status
=
taosLRUCacheInsert
(
pCache
,
key
,
keyLen
,
cacheRow
,
TD_ROW_LEN
(
cacheRow
),
deleter
,
NULL
,
TAOS_LRU_PRIORITY_LOW
);
if
(
status
!=
TAOS_LRU_STATUS_OK
)
{
code
=
-
1
;
}
}
return
code
;
}
int32_t
tsdbCacheGetLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
STSRow
**
ppRow
)
{
int32_t
code
=
0
;
char
key
[
32
]
=
{
0
};
int
keyLen
=
0
;
getTableCacheKey
(
uid
,
"lr"
,
key
,
&
keyLen
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
h
)
{
*
ppRow
=
(
STSRow
*
)
taosLRUCacheValue
(
pCache
,
h
);
}
else
{
// TODO: load lastrow from mem, imem, and files
// if table's empty, return code of -1
code
=
-
1
;
}
return
code
;
}
int32_t
tsdbCacheDeleteLastrow
(
SLRUCache
*
pCache
,
tb_uid_t
uid
)
{
int32_t
code
=
0
;
char
key
[
32
]
=
{
0
};
int
keyLen
=
0
;
getTableCacheKey
(
uid
,
"lr"
,
key
,
&
keyLen
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
pCache
,
key
,
keyLen
);
if
(
h
)
{
taosLRUCacheRelease
(
pCache
,
h
,
true
);
//void taosLRUCacheErase(SLRUCache * cache, const void *key, size_t keyLen);
}
return
code
;
}
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
a55f40a1
...
...
@@ -143,6 +143,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
SMemTable
*
pMemTable
=
pTsdb
->
mem
;
STbData
*
pTbData
=
NULL
;
SVBufPool
*
pPool
=
pTsdb
->
pVnode
->
inUse
;
TSDBKEY
lastKey
=
{.
version
=
version
,
.
ts
=
eKey
};
// check if table exists (todo)
...
...
@@ -173,6 +174,10 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
pMemTable
->
nDel
++
;
if
(
tsdbKeyCmprFn
(
&
lastKey
,
&
pTbData
->
info
.
maxKey
)
>=
0
)
{
tsdbCacheDeleteLastrow
(
pTsdb
->
lruCache
,
pTbData
->
uid
);
}
tsdbError
(
"vgId:%d, delete data from table suid:%"
PRId64
" uid:%"
PRId64
" skey:%"
PRId64
" eKey:%"
PRId64
" since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
...
...
@@ -496,6 +501,7 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
SMemSkipListNode
*
pos
[
SL_MAX_LEVEL
];
TSDBROW
row
=
tsdbRowFromTSRow
(
version
,
NULL
);
int32_t
nRow
=
0
;
STSRow
*
pLastRow
=
NULL
;
tInitSubmitBlkIter
(
pMsgIter
,
pBlock
,
&
blkIter
);
...
...
@@ -517,6 +523,8 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
pMemTable
->
info
.
minKey
=
key
;
}
pLastRow
=
row
.
pTSRow
;
// forward put rest data
row
.
pTSRow
=
tGetSubmitBlkNext
(
&
blkIter
);
if
(
row
.
pTSRow
)
{
...
...
@@ -532,12 +540,18 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
goto
_err
;
}
pLastRow
=
row
.
pTSRow
;
row
.
pTSRow
=
tGetSubmitBlkNext
(
&
blkIter
);
}
while
(
row
.
pTSRow
);
}
if
(
tsdbKeyCmprFn
(
&
key
,
&
pTbData
->
info
.
maxKey
)
>
0
)
{
pTbData
->
info
.
maxKey
=
key
;
if
(
pLastRow
)
{
tsdbCacheInsertLastrow
(
pMemTable
->
pTsdb
->
lruCache
,
pTbData
->
uid
,
pLastRow
);
}
}
if
(
tsdbKeyCmprFn
(
&
key
,
&
pMemTable
->
info
.
maxKey
)
>
0
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbOpen.c
浏览文件 @
a55f40a1
...
...
@@ -73,6 +73,10 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
goto
_err
;
}
if
(
tsdbOpenCache
(
pTsdb
)
<
0
)
{
goto
_err
;
}
tsdbDebug
(
"vgId:%d, tsdb is opened for %s, days:%d, keep:%d,%d,%d"
,
TD_VID
(
pVnode
),
pTsdb
->
path
,
pTsdb
->
keepCfg
.
days
,
pTsdb
->
keepCfg
.
keep0
,
pTsdb
->
keepCfg
.
keep1
,
pTsdb
->
keepCfg
.
keep2
);
...
...
@@ -91,6 +95,7 @@ int tsdbClose(STsdb **pTsdb) {
tsdbFSClose
((
*
pTsdb
)
->
fs
);
// tsdbFreeFS((*pTsdb)->fs);
taosMemoryFreeClear
(
*
pTsdb
);
tsdbCloseCache
((
*
pTsdb
)
->
lruCache
);
}
return
0
;
}
...
...
@@ -116,4 +121,4 @@ int tsdbUnlockRepo(STsdb *pTsdb) {
return
-
1
;
}
return
0
;
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录