Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ec4ea9cf
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看板
提交
ec4ea9cf
编写于
4月 14, 2023
作者:
M
Minglei Jin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(cache/rocks): base for rocks put/get
上级
c1412648
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
150 addition
and
15 deletion
+150
-15
contrib/CMakeLists.txt
contrib/CMakeLists.txt
+1
-0
contrib/test/CMakeLists.txt
contrib/test/CMakeLists.txt
+2
-0
contrib/test/rocksdb/CMakeLists.txt
contrib/test/rocksdb/CMakeLists.txt
+3
-1
contrib/test/rocksdb/main.c
contrib/test/rocksdb/main.c
+5
-3
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+2
-0
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+10
-0
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
+111
-0
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+15
-11
未找到文件。
contrib/CMakeLists.txt
浏览文件 @
ec4ea9cf
...
...
@@ -438,6 +438,7 @@ endif(${BUILD_ADDR2LINE})
# ================================================================================================
# Build test
# ================================================================================================
message
(
"contrib tests:"
${
BUILD_DEPENDENCY_TESTS
}
)
if
(
${
BUILD_DEPENDENCY_TESTS
}
)
add_subdirectory
(
test EXCLUDE_FROM_ALL
)
endif
(
${
BUILD_DEPENDENCY_TESTS
}
)
contrib/test/CMakeLists.txt
浏览文件 @
ec4ea9cf
# rocksdb
message
(
"contrib test dir:"
${
BUILD_WITH_ROCKSDB
}
)
if
(
${
BUILD_WITH_ROCKSDB
}
)
add_subdirectory
(
rocksdb
)
endif
(
${
BUILD_WITH_ROCKSDB
}
)
...
...
contrib/test/rocksdb/CMakeLists.txt
浏览文件 @
ec4ea9cf
message
(
"contrib test/rocksdb:"
${
BUILD_DEPENDENCY_TESTS
}
)
add_executable
(
rocksdbTest
""
)
target_sources
(
rocksdbTest
PRIVATE
...
...
contrib/test/rocksdb/main.c
浏览文件 @
ec4ea9cf
...
...
@@ -25,10 +25,12 @@ int main(int argc, char const *argv[]) {
// Read
rocksdb_readoptions_t
*
readoptions
=
rocksdb_readoptions_create
();
rocksdb_readoptions_set_snapshot
(
readoptions
,
rocksdb_create_snapshot
(
db
));
//rocksdb_readoptions_set_snapshot(readoptions, rocksdb_create_snapshot(db));
char
buf
[
256
]
=
{
0
};
size_t
vallen
=
0
;
char
*
val
=
rocksdb_get
(
db
,
readoptions
,
"key"
,
3
,
&
vallen
,
&
err
);
printf
(
"val:%s
\n
"
,
val
);
snprintf
(
buf
,
vallen
+
5
,
"val:%s"
,
val
);
printf
(
"%ld %ld %s
\n
"
,
strlen
(
val
),
vallen
,
buf
);
// Update
// rocksdb_put(db, writeoptions, "key", 3, "eulav", 5, &err);
...
...
source/dnode/vnode/CMakeLists.txt
浏览文件 @
ec4ea9cf
...
...
@@ -82,6 +82,7 @@ target_include_directories(
PUBLIC
"inc"
PUBLIC
"src/inc"
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/scalar"
PUBLIC
"
${
TD_SOURCE_DIR
}
/contrib/rocksdb/include"
)
target_link_libraries
(
vnode
...
...
@@ -98,6 +99,7 @@ target_link_libraries(
# PUBLIC bdb
# PUBLIC scalar
PUBLIC rocksdb
PUBLIC transport
PUBLIC stream
PUBLIC index
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
ec4ea9cf
...
...
@@ -343,6 +343,14 @@ struct STsdbFS {
SArray
*
aDFileSet
;
// SArray<SDFileSet>
};
typedef
struct
{
rocksdb_t
*
db
;
rocksdb_options_t
*
options
;
rocksdb_writeoptions_t
*
writeoptions
;
rocksdb_readoptions_t
*
readoptions
;
TdThreadMutex
rMutex
;
}
SRocksCache
;
struct
STsdb
{
char
*
path
;
SVnode
*
pVnode
;
...
...
@@ -355,6 +363,7 @@ struct STsdb {
TdThreadMutex
lruMutex
;
SLRUCache
*
biCache
;
TdThreadMutex
biMutex
;
SRocksCache
rCache
;
};
struct
TSDBKEY
{
...
...
@@ -796,6 +805,7 @@ typedef struct {
int32_t
tsdbOpenCache
(
STsdb
*
pTsdb
);
void
tsdbCloseCache
(
STsdb
*
pTsdb
);
int32_t
tsdbCacheUpdate
(
STsdb
*
pTsdb
,
tb_uid_t
uid
,
TSDBROW
*
row
);
int32_t
tsdbCacheInsertLast
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
TSDBROW
*
row
,
STsdb
*
pTsdb
);
int32_t
tsdbCacheInsertLastrow
(
SLRUCache
*
pCache
,
STsdb
*
pTsdb
,
tb_uid_t
uid
,
TSDBROW
*
row
,
bool
dup
);
int32_t
tsdbCacheGetLastH
(
SLRUCache
*
pCache
,
tb_uid_t
uid
,
SCacheRowsReader
*
pr
,
LRUHandle
**
h
);
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
ec4ea9cf
...
...
@@ -19,6 +19,7 @@
#include "executor.h"
#include "filter.h"
#include "qworker.h"
#include "rocksdb/c.h"
#include "sync.h"
#include "tRealloc.h"
#include "tchecksum.h"
...
...
source/dnode/vnode/src/tsdb/tsdbCache.c
浏览文件 @
ec4ea9cf
...
...
@@ -43,6 +43,110 @@ static void tsdbCloseBICache(STsdb *pTsdb) {
}
}
static
void
tsdbGetRocksPath
(
STsdb
*
pTsdb
,
char
*
path
)
{
SVnode
*
pVnode
=
pTsdb
->
pVnode
;
if
(
pVnode
->
pTfs
)
{
if
(
path
)
{
snprintf
(
path
,
TSDB_FILENAME_LEN
,
"%s%s%s%scache.rdb"
,
tfsGetPrimaryPath
(
pTsdb
->
pVnode
->
pTfs
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
);
}
}
else
{
if
(
path
)
{
snprintf
(
path
,
TSDB_FILENAME_LEN
,
"%s%scache.rdb"
,
pTsdb
->
path
,
TD_DIRSEP
);
}
}
}
static
int32_t
tsdbOpenRocksCache
(
STsdb
*
pTsdb
)
{
int32_t
code
=
0
;
rocksdb_options_t
*
options
=
rocksdb_options_create
();
if
(
NULL
==
options
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
rocksdb_options_set_create_if_missing
(
options
,
1
);
rocksdb_options_set_inplace_update_support
(
options
,
1
);
rocksdb_options_set_allow_concurrent_memtable_write
(
options
,
0
);
rocksdb_writeoptions_t
*
writeoptions
=
rocksdb_writeoptions_create
();
if
(
NULL
==
writeoptions
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err2
;
}
rocksdb_readoptions_t
*
readoptions
=
rocksdb_readoptions_create
();
if
(
NULL
==
readoptions
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err2
;
}
char
*
err
=
NULL
;
char
cachePath
[
TSDB_FILENAME_LEN
]
=
{
0
};
tsdbGetRocksPath
(
pTsdb
,
cachePath
);
rocksdb_t
*
db
=
rocksdb_open
(
options
,
cachePath
,
&
err
);
if
(
NULL
==
db
)
{
code
=
-
1
;
goto
_err3
;
}
taosThreadMutexInit
(
&
pTsdb
->
rCache
.
rMutex
,
NULL
);
pTsdb
->
rCache
.
options
=
options
;
pTsdb
->
rCache
.
writeoptions
=
writeoptions
;
pTsdb
->
rCache
.
readoptions
=
readoptions
;
pTsdb
->
rCache
.
db
=
db
;
return
code
;
_err4:
rocksdb_readoptions_destroy
(
readoptions
);
_err3:
rocksdb_writeoptions_destroy
(
writeoptions
);
_err2:
rocksdb_options_destroy
(
options
);
_err:
return
code
;
}
static
void
tsdbCloseRocksCache
(
STsdb
*
pTsdb
)
{
rocksdb_close
(
pTsdb
->
rCache
.
db
);
rocksdb_readoptions_destroy
(
pTsdb
->
rCache
.
readoptions
);
rocksdb_writeoptions_destroy
(
pTsdb
->
rCache
.
writeoptions
);
rocksdb_options_destroy
(
pTsdb
->
rCache
.
options
);
}
int32_t
tsdbCacheUpdate
(
STsdb
*
pTsdb
,
tb_uid_t
uid
,
TSDBROW
*
pRow
)
{
int32_t
code
=
0
;
STSDBRowIter
iter
=
{
0
};
tsdbRowIterOpen
(
&
iter
,
pRow
,
pTSchema
);
for
(
SColVal
*
pColVal
=
tsdbRowIterNext
(
&
iter
);
pColVal
;
pColVal
=
tsdbRowIterNext
(
&
iter
))
{
SColVal
*
pRColVal
=
tsdbCacheGetRColVal
(
pTsdb
);
if
(
pRColVal
)
{
// merge pColVal with pRColVal
}
tsdbCachePutRColVal
(
pColVal
);
}
tsdbRowClose
(
&
iter
);
char
*
err
=
NULL
;
char
buf
[
256
]
=
{
0
};
size_t
vallen
=
0
;
char
*
val
=
rocksdb_get
(
pTsdb
->
rCache
.
db
,
pTsdb
->
rCache
.
readoptions
,
"key"
,
3
,
&
vallen
,
&
err
);
if
(
val
)
{
}
else
{
}
rocksdb_put
(
pTsdb
->
rCache
.
db
,
pTsdb
->
rCache
.
writeoptions
,
"key"
,
3
,
"value"
,
5
,
&
err
);
return
code
;
}
int32_t
tsdbOpenCache
(
STsdb
*
pTsdb
)
{
int32_t
code
=
0
;
SLRUCache
*
pCache
=
NULL
;
...
...
@@ -60,6 +164,12 @@ int32_t tsdbOpenCache(STsdb *pTsdb) {
goto
_err
;
}
code
=
tsdbOpenRocksCache
(
pTsdb
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
taosLRUCacheSetStrictCapacity
(
pCache
,
false
);
taosThreadMutexInit
(
&
pTsdb
->
lruMutex
,
NULL
);
...
...
@@ -80,6 +190,7 @@ void tsdbCloseCache(STsdb *pTsdb) {
}
tsdbCloseBICache
(
pTsdb
);
tsdbCloseRocksCache
(
pTsdb
);
}
static
void
getTableCacheKey
(
tb_uid_t
uid
,
int
cacheType
,
char
*
key
,
int
*
len
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
ec4ea9cf
...
...
@@ -298,12 +298,12 @@ int64_t tsdbCountTbDataRows(STbData *pTbData) {
return
rowsNum
;
}
void
tsdbMemTableCountRows
(
SMemTable
*
pMemTable
,
SHashObj
*
pTableMap
,
int64_t
*
rowsNum
)
{
void
tsdbMemTableCountRows
(
SMemTable
*
pMemTable
,
SHashObj
*
pTableMap
,
int64_t
*
rowsNum
)
{
taosRLockLatch
(
&
pMemTable
->
latch
);
for
(
int32_t
i
=
0
;
i
<
pMemTable
->
nBucket
;
++
i
)
{
STbData
*
pTbData
=
pMemTable
->
aBucket
[
i
];
while
(
pTbData
)
{
void
*
p
=
taosHashGet
(
pTableMap
,
&
pTbData
->
uid
,
sizeof
(
pTbData
->
uid
));
void
*
p
=
taosHashGet
(
pTableMap
,
&
pTbData
->
uid
,
sizeof
(
pTbData
->
uid
));
if
(
p
==
NULL
)
{
pTbData
=
pTbData
->
next
;
continue
;
...
...
@@ -668,15 +668,17 @@ static int32_t tsdbInsertColDataToTable(SMemTable *pMemTable, STbData *pTbData,
if
(
key
.
ts
>=
pTbData
->
maxKey
)
{
pTbData
->
maxKey
=
key
.
ts
;
/*
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config)) {
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, &lRow, true);
}*/
}
}
/*
if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) {
tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, &lRow, pMemTable->pTsdb);
}
*/
tsdbCacheUpdate
(
pMemTable
->
pTsdb
,
pTbData
->
uid
,
&
lRow
);
// SMemTable
pMemTable
->
minKey
=
TMIN
(
pMemTable
->
minKey
,
pTbData
->
minKey
);
...
...
@@ -736,15 +738,17 @@ static int32_t tsdbInsertRowDataToTable(SMemTable *pMemTable, STbData *pTbData,
if
(
key
.
ts
>=
pTbData
->
maxKey
)
{
pTbData
->
maxKey
=
key
.
ts
;
/*
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config)) {
tsdbCacheInsertLastrow(pMemTable->pTsdb->lruCache, pMemTable->pTsdb, pTbData->uid, &lRow, true);
}*/
}
}
/*
if (TSDB_CACHE_LAST(pMemTable->pTsdb->pVnode->config)) {
tsdbCacheInsertLast(pMemTable->pTsdb->lruCache, pTbData->uid, &lRow, pMemTable->pTsdb);
}
*/
tsdbCacheUpdate
(
pMemTable
->
pTsdb
,
pTbData
->
uid
,
&
lRow
);
// SMemTable
pMemTable
->
minKey
=
TMIN
(
pMemTable
->
minKey
,
pTbData
->
minKey
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录