Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d5c0ca31
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d5c0ca31
编写于
6月 08, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opt batch write
上级
a3b8ca27
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
18 deletion
+52
-18
source/libs/stream/inc/streamBackendRocksdb.h
source/libs/stream/inc/streamBackendRocksdb.h
+5
-0
source/libs/stream/src/streamBackendRocksdb.c
source/libs/stream/src/streamBackendRocksdb.c
+37
-17
source/libs/stream/src/tstreamFileState.c
source/libs/stream/src/tstreamFileState.c
+10
-1
未找到文件。
source/libs/stream/inc/streamBackendRocksdb.h
浏览文件 @
d5c0ca31
...
...
@@ -122,12 +122,17 @@ char* streamDefaultIterKey_rocksdb(void* iter, int32_t* len);
char
*
streamDefaultIterVal_rocksdb
(
void
*
iter
,
int32_t
*
len
);
// batch func
int
streamStateGetCfIdx
(
SStreamState
*
pState
,
const
char
*
funcName
);
void
*
streamStateCreateBatch
();
int32_t
streamStateGetBatchSize
(
void
*
pBatch
);
void
streamStateClearBatch
(
void
*
pBatch
);
void
streamStateDestroyBatch
(
void
*
pBatch
);
int32_t
streamStatePutBatch
(
SStreamState
*
pState
,
const
char
*
cfName
,
rocksdb_writebatch_t
*
pBatch
,
void
*
key
,
void
*
val
,
int32_t
vlen
,
int64_t
ttl
);
int32_t
streamStatePutBatchOptimize
(
SStreamState
*
pState
,
int32_t
cfIdx
,
rocksdb_writebatch_t
*
pBatch
,
void
*
key
,
void
*
val
,
int32_t
vlen
,
int64_t
ttl
,
void
*
tmpBuf
);
int32_t
streamStatePutBatch_rocksdb
(
SStreamState
*
pState
,
void
*
pBatch
);
// int32_t streamDefaultIter_rocksdb(SStreamState* pState, const void* start, const void* end, SArray* result);
#endif
\ No newline at end of file
source/libs/stream/src/streamBackendRocksdb.c
浏览文件 @
d5c0ca31
...
...
@@ -210,7 +210,6 @@ void streamBackendDelCompare(void* backend, void* arg) {
}
void
streamStateDestroy_rocksdb
(
SStreamState
*
pState
,
bool
remove
)
{
streamStateCloseBackend
(
pState
,
remove
);
}
static
bool
streamStateIterSeekAndValid
(
rocksdb_iterator_t
*
iter
,
char
*
buf
,
size_t
len
);
int
streamGetInit
(
SStreamState
*
pState
,
const
char
*
funcName
);
// |key|-----value------|
// |key|ttl|len|userData|
...
...
@@ -557,14 +556,20 @@ typedef struct {
int32_t
encodeValueFunc
(
void
*
value
,
int32_t
vlen
,
int64_t
ttl
,
char
**
dest
)
{
SStreamValue
key
=
{.
unixTimestamp
=
ttl
,
.
len
=
vlen
,
.
data
=
(
char
*
)(
value
)};
char
*
p
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
sizeof
(
int32_t
)
+
key
.
len
);
char
*
buf
=
p
;
int32_t
len
=
0
;
len
+=
taosEncodeFixedI64
((
void
**
)
&
buf
,
key
.
unixTimestamp
);
len
+=
taosEncodeFixedI32
((
void
**
)
&
buf
,
key
.
len
);
len
+=
taosEncodeBinary
((
void
**
)
&
buf
,
(
char
*
)
value
,
vlen
);
*
dest
=
p
;
int32_t
len
=
0
;
if
(
*
dest
==
NULL
)
{
char
*
p
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
)
+
sizeof
(
int32_t
)
+
key
.
len
);
char
*
buf
=
p
;
len
+=
taosEncodeFixedI64
((
void
**
)
&
buf
,
key
.
unixTimestamp
);
len
+=
taosEncodeFixedI32
((
void
**
)
&
buf
,
key
.
len
);
len
+=
taosEncodeBinary
((
void
**
)
&
buf
,
(
char
*
)
value
,
vlen
);
*
dest
=
p
;
}
else
{
char
*
buf
=
*
dest
;
len
+=
taosEncodeFixedI64
((
void
**
)
&
buf
,
key
.
unixTimestamp
);
len
+=
taosEncodeFixedI32
((
void
**
)
&
buf
,
key
.
len
);
len
+=
taosEncodeBinary
((
void
**
)
&
buf
,
(
char
*
)
value
,
vlen
);
}
return
len
;
}
/*
...
...
@@ -713,7 +718,7 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
rocksdb_options_set_block_based_table_factory
((
rocksdb_options_t
*
)
cfOpts
[
i
],
tableOpt
);
params
[
i
].
tableOpt
=
tableOpt
;
int
idx
=
stream
GetInit
(
NULL
,
funcname
);
int
idx
=
stream
StateGetCfIdx
(
NULL
,
funcname
);
SCfInit
*
cfPara
=
&
ginitDict
[
idx
];
rocksdb_comparator_t
*
compare
=
...
...
@@ -744,7 +749,7 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
char
idstr
[
128
]
=
{
0
};
sprintf
(
idstr
,
"0x%"
PRIx64
"-%d"
,
streamId
,
taskId
);
int
idx
=
stream
GetInit
(
NULL
,
funcname
);
int
idx
=
stream
StateGetCfIdx
(
NULL
,
funcname
);
RocksdbCfInst
*
inst
=
NULL
;
RocksdbCfInst
**
pInst
=
taosHashGet
(
handle
->
cfInst
,
idstr
,
strlen
(
idstr
)
+
1
);
...
...
@@ -955,7 +960,7 @@ void streamStateDestroyCompar(void* arg) {
taosMemoryFree
(
comp
->
comp
);
}
int
stream
GetInit
(
SStreamState
*
pState
,
const
char
*
funcName
)
{
int
stream
StateGetCfIdx
(
SStreamState
*
pState
,
const
char
*
funcName
)
{
int
idx
=
-
1
;
size_t
len
=
strlen
(
funcName
);
for
(
int
i
=
0
;
i
<
sizeof
(
ginitDict
)
/
sizeof
(
ginitDict
[
0
]);
i
++
)
{
...
...
@@ -1002,7 +1007,7 @@ bool streamStateIterSeekAndValid(rocksdb_iterator_t* iter, char* buf, size_t len
}
rocksdb_iterator_t
*
streamStateIterCreate
(
SStreamState
*
pState
,
const
char
*
cfName
,
rocksdb_snapshot_t
**
snapshot
,
rocksdb_readoptions_t
**
readOpt
)
{
int
idx
=
stream
GetInit
(
pState
,
cfName
);
int
idx
=
stream
StateGetCfIdx
(
pState
,
cfName
);
if
(
snapshot
!=
NULL
)
{
*
snapshot
=
(
rocksdb_snapshot_t
*
)
rocksdb_create_snapshot
(
pState
->
pTdbState
->
rocksdb
);
...
...
@@ -1022,7 +1027,7 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
code = 0; \
char buf[128] = {0}; \
char* err = NULL; \
int i = stream
GetInit(pState, funcname);
\
int i = stream
StateGetCfIdx(pState, funcname);
\
if (i < 0) { \
qWarn("streamState failed to get cf name: %s", funcname); \
code = -1; \
...
...
@@ -1053,7 +1058,7 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
code = 0; \
char buf[128] = {0}; \
char* err = NULL; \
int i = stream
GetInit(pState, funcname);
\
int i = stream
StateGetCfIdx(pState, funcname);
\
if (i < 0) { \
qWarn("streamState failed to get cf name: %s", funcname); \
code = -1; \
...
...
@@ -1101,7 +1106,7 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfNa
code = 0; \
char buf[128] = {0}; \
char* err = NULL; \
int i = stream
GetInit(pState, funcname);
\
int i = stream
StateGetCfIdx(pState, funcname);
\
if (i < 0) { \
qWarn("streamState failed to get cf name: %s_%s", pState->pTdbState->idstr, funcname); \
code = -1; \
...
...
@@ -2041,7 +2046,7 @@ void streamStateClearBatch(void* pBatch) { rocksdb_writebatch_clear((rocksdb_
void
streamStateDestroyBatch
(
void
*
pBatch
)
{
rocksdb_writebatch_destroy
((
rocksdb_writebatch_t
*
)
pBatch
);
}
int32_t
streamStatePutBatch
(
SStreamState
*
pState
,
const
char
*
cfName
,
rocksdb_writebatch_t
*
pBatch
,
void
*
key
,
void
*
val
,
int32_t
vlen
,
int64_t
ttl
)
{
int
i
=
stream
GetInit
(
pState
,
cfName
);
int
i
=
stream
StateGetCfIdx
(
pState
,
cfName
);
if
(
i
<
0
)
{
qError
(
"streamState failed to put to cf name:%s"
,
cfName
);
...
...
@@ -2057,6 +2062,21 @@ int32_t streamStatePutBatch(SStreamState* pState, const char* cfName, rocksdb_wr
taosMemoryFree
(
ttlV
);
return
0
;
}
int32_t
streamStatePutBatchOptimize
(
SStreamState
*
pState
,
int32_t
cfIdx
,
rocksdb_writebatch_t
*
pBatch
,
void
*
key
,
void
*
val
,
int32_t
vlen
,
int64_t
ttl
,
void
*
tmpBuf
)
{
char
buf
[
128
]
=
{
0
};
int32_t
klen
=
ginitDict
[
cfIdx
].
enFunc
((
void
*
)
key
,
buf
);
char
*
ttlV
=
tmpBuf
;
int32_t
ttlVLen
=
ginitDict
[
cfIdx
].
enValueFunc
(
val
,
vlen
,
ttl
,
&
ttlV
);
rocksdb_column_family_handle_t
*
pCf
=
pState
->
pTdbState
->
pHandle
[
ginitDict
[
cfIdx
].
idx
];
rocksdb_writebatch_put_cf
((
rocksdb_writebatch_t
*
)
pBatch
,
pCf
,
buf
,
(
size_t
)
klen
,
ttlV
,
(
size_t
)
ttlVLen
);
if
(
tmpBuf
==
NULL
)
{
taosMemoryFree
(
ttlV
);
}
return
0
;
}
int32_t
streamStatePutBatch_rocksdb
(
SStreamState
*
pState
,
void
*
pBatch
)
{
char
*
err
=
NULL
;
rocksdb_write
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
writeOpts
,
(
rocksdb_writebatch_t
*
)
pBatch
,
&
err
);
...
...
source/libs/stream/src/tstreamFileState.c
浏览文件 @
d5c0ca31
...
...
@@ -350,6 +350,11 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
const
int32_t
BATCH_LIMIT
=
256
;
SListNode
*
pNode
=
NULL
;
int
idx
=
streamStateGetCfIdx
(
pFileState
->
pFileStore
,
"state"
);
int32_t
len
=
pFileState
->
rowSize
+
sizeof
(
uint64_t
)
+
sizeof
(
int32_t
)
+
1
;
char
*
buf
=
taosMemoryCalloc
(
1
,
len
);
void
*
batch
=
streamStateCreateBatch
();
while
((
pNode
=
tdListNext
(
&
iter
))
!=
NULL
&&
code
==
TSDB_CODE_SUCCESS
)
{
SRowBuffPos
*
pPos
=
*
(
SRowBuffPos
**
)
pNode
->
data
;
...
...
@@ -360,9 +365,13 @@ int32_t flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot,
}
SStateKey
sKey
=
{.
key
=
*
((
SWinKey
*
)
pPos
->
pKey
),
.
opNum
=
((
SStreamState
*
)
pFileState
->
pFileStore
)
->
number
};
code
=
streamStatePutBatch
(
pFileState
->
pFileStore
,
"state"
,
batch
,
&
sKey
,
pPos
->
pRowBuff
,
pFileState
->
rowSize
,
0
);
code
=
streamStatePutBatchOptimize
(
pFileState
->
pFileStore
,
idx
,
batch
,
&
sKey
,
pPos
->
pRowBuff
,
pFileState
->
rowSize
,
0
,
buf
);
memset
(
buf
,
0
,
len
);
qDebug
(
"===stream===put %"
PRId64
" to disc, res %d"
,
sKey
.
key
.
ts
,
code
);
}
taosMemoryFree
(
buf
);
if
(
streamStateGetBatchSize
(
batch
)
>
0
)
{
code
=
streamStatePutBatch_rocksdb
(
pFileState
->
pFileStore
,
batch
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录