Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c27d01a5
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看板
提交
c27d01a5
编写于
5月 04, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'enh/addTtlToStream' into enh/rocksdbSstateMerge
上级
dda1c880
84cae91f
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
913 addition
and
669 deletion
+913
-669
include/libs/stream/streamState.h
include/libs/stream/streamState.h
+9
-19
source/libs/stream/inc/streamBackendRocksdb.h
source/libs/stream/inc/streamBackendRocksdb.h
+63
-27
source/libs/stream/src/streamBackendRocksdb.c
source/libs/stream/src/streamBackendRocksdb.c
+840
-541
source/libs/stream/src/streamMeta.c
source/libs/stream/src/streamMeta.c
+1
-0
source/libs/stream/src/streamState.c
source/libs/stream/src/streamState.c
+0
-82
未找到文件。
include/libs/stream/streamState.h
浏览文件 @
c27d01a5
...
...
@@ -27,21 +27,10 @@ extern "C" {
#ifndef _STREAM_STATE_H_
#define _STREAM_STATE_H_
typedef
struct
{
rocksdb_t
*
db
;
rocksdb_writeoptions_t
*
writeOpts
;
rocksdb_readoptions_t
*
readOpts
;
rocksdb_options_t
*
dbOpt
;
void
*
param
;
void
*
env
;
rocksdb_cache_t
*
cache
;
TdThreadMutex
mutex
;
SList
*
list
;
}
SBackendHandle
;
void
*
streamBackendInit
(
const
char
*
path
);
void
streamBackendCleanup
(
void
*
arg
);
SListNode
*
streamBackendAddCompare
(
void
*
backend
,
void
*
arg
);
void
streamBackendDelCompare
(
void
*
backend
,
void
*
arg
);
// void* streamBackendInit(const char* path);
// void streamBackendCleanup(void* arg);
// SListNode* streamBackendAddCompare(void* backend, void* arg);
// void streamBackendDelCompare(void* backend, void* arg);
typedef
bool
(
*
state_key_cmpr_fn
)(
void
*
pKey1
,
void
*
pKey2
);
typedef
struct
STdbState
{
...
...
@@ -55,8 +44,9 @@ typedef struct STdbState {
void
*
param
;
void
*
env
;
SListNode
*
pComparNode
;
SBackendHandle
*
pBackendHandle
;
void
*
pBackendHandle
;
char
idstr
[
48
];
void
*
compactFactory
;
TDB
*
db
;
TTB
*
pStateDb
;
...
...
@@ -168,11 +158,11 @@ typedef struct SStateSessionKey {
int64_t
opNum
;
}
SStateSessionKey
;
typedef
struct
s
treamValue
{
typedef
struct
SS
treamValue
{
int64_t
unixTimestamp
;
int32_t
len
;
char
data
[
0
]
;
}
s
treamValue
;
char
*
data
;
}
SS
treamValue
;
int
sessionRangeKeyCmpr
(
const
SSessionKey
*
pWin1
,
const
SSessionKey
*
pWin2
);
int
sessionWinKeyCmpr
(
const
SSessionKey
*
pWin1
,
const
SSessionKey
*
pWin2
);
...
...
source/libs/stream/inc/streamBackendRocksdb.h
浏览文件 @
c27d01a5
...
...
@@ -17,7 +17,9 @@
#define _STREAM_BACKEDN_ROCKSDB_H_
#include "executor.h"
#include "streamInc.h"
#include "rocksdb/c.h"
// #include "streamInc.h"
#include "streamState.h"
#include "tcoding.h"
#include "tcommon.h"
...
...
@@ -28,58 +30,84 @@ typedef struct SCfComparator {
rocksdb_comparator_t
**
comp
;
int32_t
numOfComp
;
}
SCfComparator
;
typedef
struct
{
rocksdb_t
*
db
;
rocksdb_writeoptions_t
*
writeOpts
;
rocksdb_readoptions_t
*
readOpts
;
rocksdb_options_t
*
dbOpt
;
void
*
param
;
void
*
env
;
rocksdb_cache_t
*
cache
;
TdThreadMutex
mutex
;
rocksdb_compactionfilterfactory_t
*
filterFactory
;
SList
*
list
;
}
SBackendHandle
;
void
*
streamBackendInit
(
const
char
*
path
);
void
streamBackendCleanup
(
void
*
arg
);
SListNode
*
streamBackendAddCompare
(
void
*
backend
,
void
*
arg
);
void
streamBackendDelCompare
(
void
*
backend
,
void
*
arg
);
int
streamStateOpenBackend
(
void
*
backend
,
SStreamState
*
pState
);
void
streamStateCloseBackend
(
SStreamState
*
pState
,
bool
remove
);
void
streamStateDestroyCompar
(
void
*
arg
);
// void streamStateRemoveBackend(SStreamState* pState);
int32_t
streamStateFuncPut_rocksdb
(
SStreamState
*
pState
,
const
STupleKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateFuncGet_rocksdb
(
SStreamState
*
pState
,
const
STupleKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateFuncDel_rocksdb
(
SStreamState
*
pState
,
const
STupleKey
*
key
);
// state cf
int32_t
streamStatePut_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateGet_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateDel_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
int32_t
streamStateFillPut_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateFillGet_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateFillDel_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
int32_t
streamStateClear_rocksdb
(
SStreamState
*
pState
);
int32_t
streamStateCurNext_rocksdb
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
);
int32_t
streamStateGetFirst_rocksdb
(
SStreamState
*
pState
,
SWinKey
*
key
);
int32_t
streamStateGetGroupKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateAddIfNotExist_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateCurPrev_rocksdb
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
);
int32_t
streamStateGetKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
);
SStreamStateCur
*
streamStateGetAndCheckCur_rocksdb
(
SStreamState
*
pState
,
SWinKey
*
key
);
SStreamStateCur
*
streamStateSeekKeyNext_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateSeekToLast_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateGetCur_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
// func cf
int32_t
streamStateFuncPut_rocksdb
(
SStreamState
*
pState
,
const
STupleKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateFuncGet_rocksdb
(
SStreamState
*
pState
,
const
STupleKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateFuncDel_rocksdb
(
SStreamState
*
pState
,
const
STupleKey
*
key
);
// session cf
int32_t
streamStateSessionPut_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateSessionGet_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateSessionDel_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
);
SStreamStateCur
*
streamStateSessionSeekKeyCurrentPrev_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
);
SStreamStateCur
*
streamStateSessionSeekKeyCurrentNext_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
);
SStreamStateCur
*
streamStateSessionSeekKeyNext_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
);
int32_t
streamStateSessionGetKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SSessionKey
*
pKey
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateCurNext_rocksdb
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
);
int32_t
streamStateSessionGetKeyByRange_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
,
SSessionKey
*
curKey
);
int32_t
streamStateSessionGet_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateSessionDel_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
);
int32_t
streamStateSessionAddIfNotExist_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
TSKEY
gap
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateSessionClear_rocksdb
(
SStreamState
*
pState
);
int32_t
streamStateStateAddIfNotExist_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
char
*
pKeyData
,
int32_t
keyDataLen
,
state_key_cmpr_fn
fn
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateGetFirst_rocksdb
(
SStreamState
*
pState
,
SWinKey
*
key
);
int32_t
streamStateSessionClear_rocksdb
(
SStreamState
*
pState
);
int32_t
streamStateCurPrev_rocksdb
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
);
SStreamStateCur
*
streamStateSeekToLast_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
int32_t
streamStateGetGroupKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateAddIfNotExist_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
SStreamStateCur
*
streamStateGetCur_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
// fill cf
int32_t
streamStateFillPut_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateFillGet_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateFillDel_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateFillGetCur_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateGetAndCheckCur_rocksdb
(
SStreamState
*
pState
,
SWinKey
*
key
);
int32_t
streamStateGetKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateFillGetKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
);
SStreamStateCur
*
streamStateSeekKeyNext_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateFillSeekKeyPrev_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
SStreamStateCur
*
streamStateFillSeekKeyNext_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
int32_t
streamStatePutParTag_rocksdb
(
SStreamState
*
pState
,
int64_t
groupId
,
const
void
*
tag
,
int32_t
tagLen
);
int32_t
streamStateGetParTag_rocksdb
(
SStreamState
*
pState
,
int64_t
groupId
,
void
**
tagVal
,
int32_t
*
tagLen
);
// partag cf
int32_t
streamStatePutParTag_rocksdb
(
SStreamState
*
pState
,
int64_t
groupId
,
const
void
*
tag
,
int32_t
tagLen
);
int32_t
streamStateGetParTag_rocksdb
(
SStreamState
*
pState
,
int64_t
groupId
,
void
**
tagVal
,
int32_t
*
tagLen
);
// parname cf
int32_t
streamStatePutParName_rocksdb
(
SStreamState
*
pState
,
int64_t
groupId
,
const
char
tbname
[
TSDB_TABLE_NAME_LEN
]);
int32_t
streamStateGetParName_rocksdb
(
SStreamState
*
pState
,
int64_t
groupId
,
void
**
pVal
);
void
streamStateDestroy_rocksdb
(
SStreamState
*
pState
,
bool
remove
);
void
streamStateDestroy_rocksdb
(
SStreamState
*
pState
,
bool
remove
);
void
*
streamStateCreateBatch
();
int32_t
streamStateGetBatchSize
(
void
*
pBatch
);
...
...
@@ -89,10 +117,10 @@ int32_t streamStatePutBatch(SStreamState* pState, const char* cfName, rocksdb_wr
void
*
val
,
int32_t
vlen
);
int32_t
streamStatePutBatch_rocksdb
(
SStreamState
*
pState
,
void
*
pBatch
);
// default cf
int32_t
streamDefaultPut_rocksdb
(
SStreamState
*
pState
,
const
void
*
key
,
void
*
pVal
,
int32_t
pVLen
);
int32_t
streamDefaultGet_rocksdb
(
SStreamState
*
pState
,
const
void
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamDefaultDel_rocksdb
(
SStreamState
*
pState
,
const
void
*
key
);
int32_t
streamDefaultIterGet_rocksdb
(
SStreamState
*
pState
,
const
void
*
start
,
const
void
*
end
,
SArray
*
result
);
void
*
streamDefaultIterCreate_rocksdb
(
SStreamState
*
pState
);
int32_t
streamDefaultIterValid_rocksdb
(
void
*
iter
);
...
...
@@ -101,5 +129,13 @@ void streamDefaultIterNext_rocksdb(void* iter);
char
*
streamDefaultIterKey_rocksdb
(
void
*
iter
,
int32_t
*
len
);
char
*
streamDefaultIterVal_rocksdb
(
void
*
iter
,
int32_t
*
len
);
// batch func
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
);
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/stream
State
Rocksdb.c
→
source/libs/stream/src/stream
Backend
Rocksdb.c
浏览文件 @
c27d01a5
此差异已折叠。
点击以展开。
source/libs/stream/src/streamMeta.c
浏览文件 @
c27d01a5
...
...
@@ -14,6 +14,7 @@
*/
#include "executor.h"
#include "streamBackendRocksdb.h"
#include "streamInc.h"
#include "ttimer.h"
...
...
source/libs/stream/src/streamState.c
浏览文件 @
c27d01a5
...
...
@@ -26,88 +26,6 @@
#define MAX_TABLE_NAME_NUM 100000
void
*
streamBackendInit
(
const
char
*
path
)
{
SBackendHandle
*
pHandle
=
calloc
(
1
,
sizeof
(
SBackendHandle
));
pHandle
->
list
=
tdListNew
(
sizeof
(
SCfComparator
));
taosThreadMutexInit
(
&
pHandle
->
mutex
,
NULL
);
rocksdb_env_t
*
env
=
rocksdb_create_default_env
();
// rocksdb_envoptions_create();
rocksdb_env_set_low_priority_background_threads
(
env
,
4
);
rocksdb_env_set_high_priority_background_threads
(
env
,
2
);
rocksdb_cache_t
*
cache
=
rocksdb_cache_create_lru
(
128
<<
20
);
rocksdb_options_t
*
opts
=
rocksdb_options_create
();
rocksdb_options_set_env
(
opts
,
env
);
rocksdb_options_set_create_if_missing
(
opts
,
1
);
rocksdb_options_set_create_missing_column_families
(
opts
,
1
);
rocksdb_options_set_write_buffer_size
(
opts
,
128
<<
20
);
rocksdb_options_set_max_total_wal_size
(
opts
,
128
<<
20
);
rocksdb_options_set_recycle_log_file_num
(
opts
,
6
);
rocksdb_options_set_max_write_buffer_number
(
opts
,
3
);
pHandle
->
env
=
env
;
pHandle
->
dbOpt
=
opts
;
pHandle
->
cache
=
cache
;
char
*
err
=
NULL
;
pHandle
->
db
=
rocksdb_open
(
opts
,
path
,
&
err
);
if
(
err
!=
NULL
)
{
qError
(
"failed to open rocksdb, path:%s, reason:%s"
,
path
,
err
);
taosMemoryFreeClear
(
err
);
goto
_EXIT
;
}
return
pHandle
;
_EXIT:
rocksdb_options_destroy
(
opts
);
rocksdb_cache_destroy
(
cache
);
rocksdb_env_destroy
(
env
);
taosThreadMutexDestroy
(
&
pHandle
->
mutex
);
tdListFree
(
pHandle
->
list
);
free
(
pHandle
);
return
NULL
;
}
void
streamBackendCleanup
(
void
*
arg
)
{
SBackendHandle
*
pHandle
=
(
SBackendHandle
*
)
arg
;
rocksdb_close
(
pHandle
->
db
);
rocksdb_options_destroy
(
pHandle
->
dbOpt
);
rocksdb_env_destroy
(
pHandle
->
env
);
rocksdb_cache_destroy
(
pHandle
->
cache
);
taosThreadMutexDestroy
(
&
pHandle
->
mutex
);
SListNode
*
head
=
tdListPopHead
(
pHandle
->
list
);
while
(
head
!=
NULL
)
{
streamStateDestroyCompar
(
head
->
data
);
taosMemoryFree
(
head
);
head
=
tdListPopHead
(
pHandle
->
list
);
}
tdListFree
(
pHandle
->
list
);
taosMemoryFree
(
pHandle
);
return
;
}
SListNode
*
streamBackendAddCompare
(
void
*
backend
,
void
*
arg
)
{
SBackendHandle
*
pHandle
=
(
SBackendHandle
*
)
backend
;
SListNode
*
node
=
NULL
;
taosThreadMutexLock
(
&
pHandle
->
mutex
);
node
=
tdListAdd
(
pHandle
->
list
,
arg
);
taosThreadMutexUnlock
(
&
pHandle
->
mutex
);
return
node
;
}
void
streamBackendDelCompare
(
void
*
backend
,
void
*
arg
)
{
SBackendHandle
*
pHandle
=
(
SBackendHandle
*
)
backend
;
SListNode
*
node
=
NULL
;
taosThreadMutexLock
(
&
pHandle
->
mutex
);
node
=
tdListPopNode
(
pHandle
->
list
,
arg
);
taosThreadMutexUnlock
(
&
pHandle
->
mutex
);
if
(
node
)
{
streamStateDestroyCompar
(
node
->
data
);
taosMemoryFree
(
node
);
}
}
int
sessionRangeKeyCmpr
(
const
SSessionKey
*
pWin1
,
const
SSessionKey
*
pWin2
)
{
if
(
pWin1
->
groupId
>
pWin2
->
groupId
)
{
return
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录