Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b17f99de
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,发现更多精彩内容 >>
提交
b17f99de
编写于
3月 23, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add backend
上级
981466a0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
68 deletion
+70
-68
source/libs/stream/src/streamState.c
source/libs/stream/src/streamState.c
+29
-22
source/libs/stream/src/streamStateRocksdb.c
source/libs/stream/src/streamStateRocksdb.c
+41
-46
未找到文件。
source/libs/stream/src/streamState.c
浏览文件 @
b17f99de
...
...
@@ -313,21 +313,30 @@ int32_t streamStatePut(SStreamState* pState, const SWinKey* key, const void* val
}
// todo refactor
int32_t
streamState
FillPut
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
v
Len
)
{
int32_t
streamState
Get
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pV
Len
)
{
#ifdef USE_ROCKSDB
return
streamState
FillPut_rocksdb
(
pState
,
key
,
value
,
v
Len
);
return
streamState
Get_rocksdb
(
pState
,
key
,
pVal
,
pV
Len
);
#else
return
tdbTbUpsert
(
pState
->
pTdbState
->
pFillStateDb
,
key
,
sizeof
(
SWinKey
),
value
,
vLen
,
pState
->
pTdbState
->
txn
);
SStateKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
return
tdbTbGet
(
pState
->
pTdbState
->
pStateDb
,
&
sKey
,
sizeof
(
SStateKey
),
pVal
,
pVLen
);
#endif
}
// todo refactor
int32_t
streamState
Get
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
int32_t
streamState
Del
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
#ifdef USE_ROCKSDB
return
streamState
Get_rocksdb
(
pState
,
key
,
pVal
,
pVLen
);
return
streamState
Del_rocksdb
(
pState
,
key
);
#else
SStateKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
return
tdbTbGet
(
pState
->
pTdbState
->
pStateDb
,
&
sKey
,
sizeof
(
SStateKey
),
pVal
,
pVLen
);
return
tdbTbDelete
(
pState
->
pTdbState
->
pStateDb
,
&
sKey
,
sizeof
(
SStateKey
),
pState
->
pTdbState
->
txn
);
#endif
}
// todo refactor
int32_t
streamStateFillPut
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
)
{
#ifdef USE_ROCKSDB
return
streamStateFillPut_rocksdb
(
pState
,
key
,
value
,
vLen
);
#else
return
tdbTbUpsert
(
pState
->
pTdbState
->
pFillStateDb
,
key
,
sizeof
(
SWinKey
),
value
,
vLen
,
pState
->
pTdbState
->
txn
);
#endif
}
...
...
@@ -341,12 +350,11 @@ int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal
}
// todo refactor
int32_t
streamStateDel
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
int32_t
streamState
Fill
Del
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
#ifdef USE_ROCKSDB
return
streamStateDel_rocksdb
(
pState
,
key
);
return
streamState
Fill
Del_rocksdb
(
pState
,
key
);
#else
SStateKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
return
tdbTbDelete
(
pState
->
pTdbState
->
pStateDb
,
&
sKey
,
sizeof
(
SStateKey
),
pState
->
pTdbState
->
txn
);
return
tdbTbDelete
(
pState
->
pTdbState
->
pFillStateDb
,
key
,
sizeof
(
SWinKey
),
pState
->
pTdbState
->
txn
);
#endif
}
...
...
@@ -373,15 +381,6 @@ int32_t streamStateClear(SStreamState* pState) {
void
streamStateSetNumber
(
SStreamState
*
pState
,
int32_t
number
)
{
pState
->
number
=
number
;
}
// todo refactor
int32_t
streamStateFillDel
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
#ifdef USE_ROCKSDB
return
streamStateFillDel_rocksdb
(
pState
,
key
);
#else
return
tdbTbDelete
(
pState
->
pTdbState
->
pFillStateDb
,
key
,
sizeof
(
SWinKey
),
pState
->
pTdbState
->
txn
);
#endif
}
int32_t
streamStateAddIfNotExist
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
#ifdef USE_ROCKSDB
return
streamStateAddIfNotExist_rocksdb
(
pState
,
key
,
pVal
,
pVLen
);
...
...
@@ -535,13 +534,21 @@ int32_t streamStateGetFirst(SStreamState* pState, SWinKey* key) {
}
int32_t
streamStateSeekFirst
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
)
{
//
#ifdef USE_ROCKSDB
rocksdb_iter_seek_to_first
(
pCur
->
iter
);
return
0
;
#else
return
tdbTbcMoveToFirst
(
pCur
->
pCur
);
#endif
}
int32_t
streamStateSeekLast
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
)
{
//
#ifdef USE_ROCKSDB
rocksdb_iter_seek_to_last
(
pCur
->
iter
);
return
0
;
#else
return
tdbTbcMoveToLast
(
pCur
->
pCur
);
#endif
}
SStreamStateCur
*
streamStateSeekKeyNext
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
...
...
source/libs/stream/src/streamStateRocksdb.c
浏览文件 @
b17f99de
...
...
@@ -49,7 +49,7 @@ int stateKeyEncode(void* k, char* buf) {
int
len
=
0
;
len
+=
taosEncodeFixedU64
((
void
**
)
&
buf
,
key
->
key
.
groupId
);
len
+=
taosEncodeFixedI64
((
void
**
)
&
buf
,
key
->
key
.
ts
);
len
+=
taosEncodeFixed
U
64
((
void
**
)
&
buf
,
key
->
opNum
);
len
+=
taosEncodeFixed
I
64
((
void
**
)
&
buf
,
key
->
opNum
);
return
len
;
}
int
stateKeyDecode
(
void
*
k
,
char
*
buf
)
{
...
...
@@ -482,6 +482,17 @@ int32_t streamStateFillPut_rocksdb(SStreamState* pState, const SWinKey* key, con
return
code
;
}
int32_t
streamStateFillGet_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
int
code
=
0
;
STREAM_STATE_GET_ROCKSDB
(
pState
,
"fill"
,
key
,
pVal
,
pVLen
);
return
code
;
}
int32_t
streamStateFillDel_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
int
code
=
0
;
STREAM_STATE_DEL_ROCKSDB
(
pState
,
"fill"
,
key
);
return
code
;
}
// todo refactor
int32_t
streamStateClear_rocksdb
(
SStreamState
*
pState
)
{
...
...
@@ -502,16 +513,6 @@ int32_t streamStateClear_rocksdb(SStreamState* pState) {
}
return
0
;
}
int32_t
streamStateFillGet_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
int
code
=
0
;
STREAM_STATE_GET_ROCKSDB
(
pState
,
"fill"
,
key
,
pVal
,
pVLen
);
return
code
;
}
int32_t
streamStateFillDel_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
int
code
=
0
;
STREAM_STATE_DEL_ROCKSDB
(
pState
,
"fill"
,
key
);
return
code
;
}
int32_t
streamStateSessionPut_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
,
const
void
*
value
,
int32_t
vLen
)
{
int
code
=
0
;
...
...
@@ -545,10 +546,6 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev_rocksdb(SStreamState* pSta
if
(
stateSessionKeyCmpr
(
&
sKey
,
sizeof
(
sKey
),
&
curKey
,
sizeof
(
curKey
))
>=
0
)
return
pCur
;
rocksdb_iter_prev
(
pCur
->
iter
);
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
return
NULL
;
}
return
pCur
;
}
SStreamStateCur
*
streamStateSessionSeekKeyCurrentNext_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
)
{
...
...
@@ -560,9 +557,12 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentNext_rocksdb(SStreamState* pSta
pCur
->
iter
=
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
ropts
,
pState
->
pTdbState
->
pHandle
[
2
]);
pCur
->
number
=
pState
->
number
;
char
buf
[
128
]
=
{
0
};
SStateSessionKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
char
buf
[
128
]
=
{
0
};
stateSessionKeyEncode
(
&
sKey
,
buf
);
rocksdb_iter_seek
(
pCur
->
iter
,
(
const
char
*
)
buf
,
sizeof
(
sKey
));
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
...
...
@@ -575,10 +575,6 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentNext_rocksdb(SStreamState* pSta
if
(
stateSessionKeyCmpr
(
&
sKey
,
sizeof
(
sKey
),
&
curKey
,
sizeof
(
curKey
))
<=
0
)
return
pCur
;
rocksdb_iter_next
(
pCur
->
iter
);
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
return
NULL
;
}
return
pCur
;
}
...
...
@@ -606,10 +602,6 @@ SStreamStateCur* streamStateSessionSeekKeyNext_rocksdb(SStreamState* pState, con
if
(
stateSessionKeyCmpr
(
&
sKey
,
sizeof
(
sKey
),
&
curKey
,
sizeof
(
curKey
))
<
0
)
return
pCur
;
rocksdb_iter_next
(
pCur
->
iter
);
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
return
NULL
;
}
return
pCur
;
}
...
...
@@ -626,31 +618,43 @@ int32_t streamStateAddIfNotExist_rocksdb(SStreamState* pState, const SWinKey* ke
SStreamStateCur
*
streamStateGetCur_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
qWarn
(
"streamStateGetCur_rocksdb"
);
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
return
NULL
;
qWarn
(
"streamStateGetCur_rocksdb-->1"
);
pCur
->
iter
=
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
ropts
,
pState
->
pTdbState
->
pHandle
[
0
]);
int32_t
c
=
0
;
SStateKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
char
buf
[
128
]
=
{
0
};
stateKeyEncode
((
void
*
)
&
sKey
,
buf
);
char
sKeyStr
[
128
]
=
{
0
};
stateKeyToString
(
&
sKey
,
sKeyStr
);
rocksdb_iter_seek
(
pCur
->
iter
,
buf
,
sizeof
(
sKey
));
if
(
rocksdb_iter_valid
(
pCur
->
iter
))
{
qWarn
(
"streamStateGetCur_rocksdb-->2"
);
SStateKey
curKey
;
size_t
kLen
=
0
;
char
*
keyStr
=
(
char
*
)
rocksdb_iter_key
(
pCur
->
iter
,
&
kLen
);
stateKeyDecode
((
void
*
)
&
curKey
,
keyStr
);
char
tKeyStr
[
128
]
=
{
0
};
stateKeyToString
(
&
curKey
,
tKeyStr
);
qWarn
(
"streamStateGetCur_rocksdb-->src:%s, dst:%s"
,
sKeyStr
,
tKeyStr
);
if
(
stateKeyCmpr
(
&
sKey
,
sizeof
(
sKey
),
&
curKey
,
sizeof
(
curKey
))
==
0
)
{
pCur
->
number
=
pState
->
number
;
return
pCur
;
}
qWarn
(
"streamStateGetCur_rocksdb-->3"
);
}
qWarn
(
"streamStateGetCur_rocksdb-->4"
);
streamStateFreeCur
(
pCur
);
return
NULL
;
}
SStreamStateCur
*
streamStateFillGetCur_rocksdb
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
qWarn
(
"streamStateFillGetCur_rocksdb"
);
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
return
NULL
;
pCur
->
iter
=
...
...
@@ -688,15 +692,19 @@ int32_t streamStateGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, cons
SStateKey
*
pKtmp
=
&
tkey
;
if
(
rocksdb_iter_valid
(
pCur
->
iter
))
{
qWarn
(
"streamStateGetKVByCur_rocksdb-2"
);
size_t
tlen
;
char
*
keyStr
=
(
char
*
)
rocksdb_iter_key
(
pCur
->
iter
,
&
tlen
);
stateKeyDecode
((
void
*
)
pKtmp
,
keyStr
);
if
(
pKtmp
->
opNum
!=
pCur
->
number
)
{
qWarn
(
"streamStateGetKVByCur_rocksdb-3"
);
return
-
1
;
}
qWarn
(
"streamStateGetKVByCur_rocksdb-4"
);
*
pKey
=
pKtmp
->
key
;
return
0
;
}
qWarn
(
"streamStateGetKVByCur_rocksdb-5"
);
return
-
1
;
}
int32_t
streamStateFillGetKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SWinKey
*
pKey
,
const
void
**
pVal
,
int32_t
*
pVLen
)
{
...
...
@@ -779,10 +787,7 @@ SStreamStateCur* streamStateSeekKeyNext_rocksdb(SStreamState* pState, const SWin
pCur
->
number
=
pState
->
number
;
pCur
->
iter
=
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
ropts
,
pState
->
pTdbState
->
pHandle
[
0
]);
// if (!rocksdb_iter_valid(pCur->iter)) {
// streamStateFreeCur(pCur);
// return NULL;
// }
SStateKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
char
buf
[
128
]
=
{
0
};
stateKeyEncode
((
void
*
)
&
sKey
,
buf
);
...
...
@@ -796,9 +801,7 @@ SStreamStateCur* streamStateSeekKeyNext_rocksdb(SStreamState* pState, const SWin
return
pCur
;
}
rocksdb_iter_next
(
pCur
->
iter
);
if
(
rocksdb_iter_valid
(
pCur
->
iter
))
{
return
pCur
;
}
return
pCur
;
}
streamStateFreeCur
(
pCur
);
return
NULL
;
...
...
@@ -817,6 +820,7 @@ SStreamStateCur* streamStateFillSeekKeyNext_rocksdb(SStreamState* pState, const
rocksdb_iter_seek
(
pCur
->
iter
,
buf
,
sizeof
(
*
key
));
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
return
NULL
;
}
{
SWinKey
curKey
;
...
...
@@ -827,9 +831,7 @@ SStreamStateCur* streamStateFillSeekKeyNext_rocksdb(SStreamState* pState, const
return
pCur
;
}
rocksdb_iter_next
(
pCur
->
iter
);
if
(
rocksdb_iter_valid
(
pCur
->
iter
))
{
return
pCur
;
}
return
pCur
;
}
streamStateFreeCur
(
pCur
);
return
NULL
;
...
...
@@ -848,6 +850,7 @@ SStreamStateCur* streamStateFillSeekKeyPrev_rocksdb(SStreamState* pState, const
rocksdb_iter_seek
(
pCur
->
iter
,
buf
,
sizeof
(
*
key
));
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
return
NULL
;
}
{
...
...
@@ -859,9 +862,7 @@ SStreamStateCur* streamStateFillSeekKeyPrev_rocksdb(SStreamState* pState, const
return
pCur
;
}
rocksdb_iter_prev
(
pCur
->
iter
);
if
(
rocksdb_iter_valid
(
pCur
->
iter
))
{
return
pCur
;
}
return
pCur
;
}
streamStateFreeCur
(
pCur
);
return
NULL
;
...
...
@@ -869,10 +870,8 @@ SStreamStateCur* streamStateFillSeekKeyPrev_rocksdb(SStreamState* pState, const
int32_t
streamStateCurPrev_rocksdb
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
)
{
qWarn
(
"streamStateCurPrev_rocksdb"
);
if
(
!
pCur
)
return
-
1
;
rocksdb_iter_prev
(
pCur
->
iter
);
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
return
-
1
;
}
return
0
;
}
int32_t
streamStateCurNext_rocksdb
(
SStreamState
*
pState
,
SStreamStateCur
*
pCur
)
{
...
...
@@ -880,9 +879,6 @@ int32_t streamStateCurNext_rocksdb(SStreamState* pState, SStreamStateCur* pCur)
return
-
1
;
}
rocksdb_iter_next
(
pCur
->
iter
);
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
return
-
1
;
}
return
0
;
}
int32_t
streamStateSessionGetKeyByRange_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
,
SSessionKey
*
curKey
)
{
...
...
@@ -959,7 +955,6 @@ int32_t streamStateSessionGet_rocksdb(SStreamState* pState, SSessionKey* key, vo
}
}
streamStateFreeCur
(
pCur
);
// impl later
return
code
;
}
...
...
@@ -1085,7 +1080,7 @@ int32_t streamStateSessionClear_rocksdb(SStreamState* pState) {
int32_t
size
=
0
;
int32_t
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
&
delKey
,
&
buf
,
&
size
);
if
(
code
==
0
&&
size
>
0
)
{
//
memset(buf, 0, size);
memset
(
buf
,
0
,
size
);
streamStateSessionPut_rocksdb
(
pState
,
&
delKey
,
buf
,
size
);
}
else
{
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录