Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5eb57f2e
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看板
提交
5eb57f2e
编写于
6月 26, 2023
作者:
M
Minglei Jin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(tsdb/cache): writebatch with rcache locked
上级
f9b97f7c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
83 deletion
+61
-83
source/dnode/vnode/src/tsdb/tsdbCache.c
source/dnode/vnode/src/tsdb/tsdbCache.c
+61
-83
未找到文件。
source/dnode/vnode/src/tsdb/tsdbCache.c
浏览文件 @
5eb57f2e
...
...
@@ -215,7 +215,7 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) {
}
static
void
rocksMayWrite
(
STsdb
*
pTsdb
,
bool
force
,
bool
read
,
bool
lock
)
{
rocksdb_writebatch_t
*
wb
=
NULL
;
rocksdb_writebatch_t
*
wb
=
pTsdb
->
rCache
.
writebatch
;
if
(
read
)
{
if
(
lock
)
{
taosThreadMutexLock
(
&
pTsdb
->
lruMutex
);
...
...
@@ -225,11 +225,12 @@ static void rocksMayWrite(STsdb *pTsdb, bool force, bool read, bool lock) {
if
(
lock
)
{
taosThreadMutexLock
(
&
pTsdb
->
rCache
.
rMutex
);
}
wb
=
pTsdb
->
rCache
.
writebatch
;
}
int
count
=
rocksdb_writebatch_count
(
wb
);
if
((
force
&&
count
>
0
)
||
count
>=
ROCKS_BATCH_SIZE
)
{
char
*
err
=
NULL
;
rocksdb_write
(
pTsdb
->
rCache
.
db
,
pTsdb
->
rCache
.
writeoptions
,
wb
,
&
err
);
if
(
NULL
!=
err
)
{
tsdbError
(
"vgId:%d, %s failed at line %d, count: %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
__LINE__
,
count
,
...
...
@@ -240,10 +241,13 @@ static void rocksMayWrite(STsdb *pTsdb, bool force, bool read, bool lock) {
rocksdb_writebatch_clear
(
wb
);
}
if
(
read
)
{
if
(
lock
)
taosThreadMutexUnlock
(
&
pTsdb
->
lruMutex
);
}
else
{
if
(
lock
)
taosThreadMutexUnlock
(
&
pTsdb
->
rCache
.
rMutex
);
if
(
lock
)
{
if
(
read
)
{
taosThreadMutexUnlock
(
&
pTsdb
->
lruMutex
);
}
else
{
taosThreadMutexUnlock
(
&
pTsdb
->
rCache
.
rMutex
);
}
}
}
...
...
@@ -287,36 +291,45 @@ static void tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size) {
*
size
=
length
;
}
int
tsdbCacheFlushDirty
(
const
void
*
key
,
size_t
klen
,
void
*
value
,
void
*
ud
)
{
SLastCol
*
pLastCol
=
(
SLastCol
*
)
value
;
static
void
tsdbCachePutBatch
(
SLastCol
*
pLastCol
,
const
void
*
key
,
size_t
klen
,
SCacheFlushState
*
state
)
{
STsdb
*
pTsdb
=
state
->
pTsdb
;
SRocksCache
*
rCache
=
&
pTsdb
->
rCache
;
rocksdb_writebatch_t
*
wb
=
rCache
->
writebatch
;
char
*
rocks_value
=
NULL
;
size_t
vlen
=
0
;
if
(
pLastCol
->
dirty
)
{
SCacheFlushState
*
state
=
(
SCacheFlushState
*
)
ud
;
STsdb
*
pTsdb
=
state
->
pTsdb
;
SRocksCache
*
rCache
=
&
pTsdb
->
rCache
;
rocksdb_writebatch_t
*
wb
=
rCache
->
writebatch
;
char
*
rocks_value
=
NULL
;
size_t
vlen
=
0
;
tsdbCacheSerialize
(
pLastCol
,
&
rocks_value
,
&
vlen
);
tsdbCacheSerialize
(
pLastCol
,
&
rocks_value
,
&
vlen
);
rocksdb_writebatch_put
(
wb
,
(
char
*
)
key
,
klen
,
rocks_value
,
vlen
);
taosThreadMutexLock
(
&
rCache
->
rMutex
);
taosMemoryFree
(
rocks_value
);
rocksdb_writebatch_put
(
wb
,
(
char
*
)
key
,
klen
,
rocks_value
,
vlen
);
if
(
++
state
->
flush_count
>=
ROCKS_BATCH_SIZE
)
{
char
*
err
=
NULL
;
rocksdb_write
(
rCache
->
db
,
rCache
->
writeoptions
,
wb
,
&
err
);
if
(
NULL
!=
err
)
{
tsdbError
(
"vgId:%d, %s failed at line %d, count: %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
__LINE__
,
state
->
flush_count
,
err
);
rocksdb_free
(
err
);
}
taosMemoryFree
(
rocks_value
);
rocksdb_writebatch_clear
(
wb
);
if
(
++
state
->
flush_count
>=
ROCKS_BATCH_SIZE
)
{
char
*
err
=
NULL
;
state
->
flush_count
=
0
;
rocksdb_write
(
rCache
->
db
,
rCache
->
writeoptions
,
wb
,
&
err
);
if
(
NULL
!=
err
)
{
tsdbError
(
"vgId:%d, %s failed at line %d, count: %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
__LINE__
,
state
->
flush_count
,
err
);
rocksdb_free
(
err
);
}
rocksdb_writebatch_clear
(
wb
);
state
->
flush_count
=
0
;
}
taosThreadMutexUnlock
(
&
rCache
->
rMutex
);
}
int
tsdbCacheFlushDirty
(
const
void
*
key
,
size_t
klen
,
void
*
value
,
void
*
ud
)
{
SLastCol
*
pLastCol
=
(
SLastCol
*
)
value
;
if
(
pLastCol
->
dirty
)
{
tsdbCachePutBatch
(
pLastCol
,
key
,
klen
,
(
SCacheFlushState
*
)
ud
);
pLastCol
->
dirty
=
0
;
}
...
...
@@ -379,36 +392,10 @@ static void reallocVarData(SColVal *pColVal) {
}
static
void
tsdbCacheDeleter
(
const
void
*
key
,
size_t
klen
,
void
*
value
,
void
*
ud
)
{
(
void
)
key
;
(
void
)
klen
;
SLastCol
*
pLastCol
=
(
SLastCol
*
)
value
;
if
(
pLastCol
->
dirty
)
{
SCacheFlushState
*
state
=
(
SCacheFlushState
*
)
ud
;
STsdb
*
pTsdb
=
state
->
pTsdb
;
SRocksCache
*
rCache
=
&
pTsdb
->
rCache
;
rocksdb_writebatch_t
*
wb
=
rCache
->
writebatch
;
char
*
rocks_value
=
NULL
;
size_t
vlen
=
0
;
tsdbCacheSerialize
(
pLastCol
,
&
rocks_value
,
&
vlen
);
rocksdb_writebatch_put
(
wb
,
(
char
*
)
key
,
klen
,
rocks_value
,
vlen
);
taosMemoryFree
(
rocks_value
);
if
(
++
state
->
flush_count
>=
ROCKS_BATCH_SIZE
)
{
char
*
err
=
NULL
;
rocksdb_write
(
rCache
->
db
,
rCache
->
writeoptions
,
wb
,
&
err
);
if
(
NULL
!=
err
)
{
tsdbError
(
"vgId:%d, %s failed at line %d, count: %d since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
__LINE__
,
state
->
flush_count
,
err
);
rocksdb_free
(
err
);
}
rocksdb_writebatch_clear
(
wb
);
state
->
flush_count
=
0
;
}
tsdbCachePutBatch
(
pLastCol
,
key
,
klen
,
(
SCacheFlushState
*
)
ud
);
}
if
(
IS_VAR_DATA_TYPE
(
pLastCol
->
colVal
.
type
)
/* && pLastCol->colVal.value.nData > 0*/
)
{
...
...
@@ -449,11 +436,10 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
tsdbRowClose
(
&
iter
);
// 3, build keys & multi get from rocks
int
num_keys
=
TARRAY_SIZE
(
aColVal
);
TSKEY
keyTs
=
TSDBROW_TS
(
pRow
);
rocksdb_writebatch_t
*
wb
=
pTsdb
->
rCache
.
writebatch
;
SArray
*
remainCols
=
NULL
;
SLRUCache
*
pCache
=
pTsdb
->
lruCache
;
int
num_keys
=
TARRAY_SIZE
(
aColVal
);
TSKEY
keyTs
=
TSDBROW_TS
(
pRow
);
SArray
*
remainCols
=
NULL
;
SLRUCache
*
pCache
=
pTsdb
->
lruCache
;
taosThreadMutexLock
(
&
pTsdb
->
lruMutex
);
for
(
int
i
=
0
;
i
<
num_keys
;
++
i
)
{
...
...
@@ -489,14 +475,6 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
if
(
!
pLastCol
->
dirty
)
{
pLastCol
->
dirty
=
1
;
}
/*
char *value = NULL;
size_t vlen = 0;
tsdbCacheSerialize(pLastCol, &value, &vlen);
// tsdbCacheSerialize(&(SLastCol){.ts = keyTs, .colVal = *pColVal}, &value, &vlen);
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
taosMemoryFree(value);
*/
}
taosLRUCacheRelease
(
pCache
,
h
,
false
);
...
...
@@ -536,13 +514,6 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
if
(
!
pLastCol
->
dirty
)
{
pLastCol
->
dirty
=
1
;
}
/*
char *value = NULL;
size_t vlen = 0;
tsdbCacheSerialize(pLastCol, &value, &vlen);
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
taosMemoryFree(value);
*/
}
taosLRUCacheRelease
(
pCache
,
h
,
false
);
...
...
@@ -580,6 +551,7 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
taosMemoryFree
(
keys_list_sizes
);
taosMemoryFree
(
values_list_sizes
);
rocksdb_writebatch_t
*
wb
=
pTsdb
->
rCache
.
writebatch
;
for
(
int
i
=
0
;
i
<
num_keys
;
++
i
)
{
SIdxKey
*
idxKey
=
&
((
SIdxKey
*
)
TARRAY_DATA
(
remainCols
))[
i
];
SColVal
*
pColVal
=
(
SColVal
*
)
TARRAY_DATA
(
aColVal
)
+
idxKey
->
idx
;
...
...
@@ -593,8 +565,12 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
size_t
vlen
=
0
;
tsdbCacheSerialize
(
&
(
SLastCol
){.
ts
=
keyTs
,
.
colVal
=
*
pColVal
},
&
value
,
&
vlen
);
// SLastKey key = (SLastKey){.ltype = 0, .uid = uid, .cid = pColVal->cid};
taosThreadMutexLock
(
&
pTsdb
->
rCache
.
rMutex
);
rocksdb_writebatch_put
(
wb
,
(
char
*
)
&
idxKey
->
key
,
ROCKS_KEY_LEN
,
value
,
vlen
);
taosThreadMutexUnlock
(
&
pTsdb
->
rCache
.
rMutex
);
pLastCol
=
(
SLastCol
*
)
value
;
SLastCol
*
pTmpLastCol
=
taosMemoryCalloc
(
1
,
sizeof
(
SLastCol
));
*
pTmpLastCol
=
*
pLastCol
;
...
...
@@ -621,8 +597,12 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
size_t
vlen
=
0
;
tsdbCacheSerialize
(
&
(
SLastCol
){.
ts
=
keyTs
,
.
colVal
=
*
pColVal
},
&
value
,
&
vlen
);
// SLastKey key = (SLastKey){.ltype = 1, .uid = uid, .cid = pColVal->cid};
taosThreadMutexLock
(
&
pTsdb
->
rCache
.
rMutex
);
rocksdb_writebatch_put
(
wb
,
(
char
*
)
&
idxKey
->
key
,
ROCKS_KEY_LEN
,
value
,
vlen
);
taosThreadMutexUnlock
(
&
pTsdb
->
rCache
.
rMutex
);
pLastCol
=
(
SLastCol
*
)
value
;
SLastCol
*
pTmpLastCol
=
taosMemoryCalloc
(
1
,
sizeof
(
SLastCol
));
*
pTmpLastCol
=
*
pLastCol
;
...
...
@@ -647,12 +627,14 @@ int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSDBROW *pRow
rocksdb_free
(
values_list
[
i
]);
}
rocksMayWrite
(
pTsdb
,
true
,
false
,
true
);
taosMemoryFree
(
values_list
);
taosArrayDestroy
(
remainCols
);
}
rocksMayWrite
(
pTsdb
,
true
,
false
,
false
);
taosThreadMutexUnlock
(
&
pTsdb
->
lruMutex
);
_exit:
...
...
@@ -1005,9 +987,7 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache
reallocVarData
(
&
lastCol
.
colVal
);
taosArrayPush
(
pLastArray
,
&
lastCol
);
if
(
h
)
{
taosLRUCacheRelease
(
pCache
,
h
,
false
);
}
taosLRUCacheRelease
(
pCache
,
h
,
false
);
}
else
{
SLastCol
noneCol
=
{.
ts
=
TSKEY_MIN
,
.
colVal
=
COL_VAL_NONE
(
cid
,
pr
->
pSchema
->
columns
[
pr
->
pSlotIds
[
i
]].
type
)};
...
...
@@ -1032,9 +1012,7 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache
reallocVarData
(
&
lastCol
.
colVal
);
taosArraySet
(
pLastArray
,
idxKey
->
idx
,
&
lastCol
);
if
(
h
)
{
taosLRUCacheRelease
(
pCache
,
h
,
false
);
}
taosLRUCacheRelease
(
pCache
,
h
,
false
);
taosArrayRemove
(
remainCols
,
i
);
}
else
{
...
...
@@ -1183,7 +1161,7 @@ int32_t tsdbOpenCache(STsdb *pTsdb) {
SLRUCache
*
pCache
=
NULL
;
size_t
cfgCapacity
=
pTsdb
->
pVnode
->
config
.
cacheLastSize
*
1024
*
1024
;
pCache
=
taosLRUCacheInit
(
cfgCapacity
,
1
,
.
5
);
pCache
=
taosLRUCacheInit
(
cfgCapacity
,
0
,
.
5
);
if
(
pCache
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录