Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7e33e70a
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看板
提交
7e33e70a
编写于
3月 21, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add backend
上级
764a8129
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
189 addition
and
2 deletion
+189
-2
source/libs/stream/src/streamStateRocksdb.c
source/libs/stream/src/streamStateRocksdb.c
+189
-2
未找到文件。
source/libs/stream/src/streamStateRocksdb.c
浏览文件 @
7e33e70a
...
...
@@ -497,6 +497,36 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentNext_rocksdb(SStreamState* pSta
return
pCur
;
}
SStreamStateCur
*
streamStateSessionSeekKeyNext_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
)
{
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
{
return
NULL
;
}
pCur
->
iter
=
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
ropts
,
pState
->
pTdbState
->
pHandle
[
2
]);
pCur
->
number
=
pState
->
number
;
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
);
return
NULL
;
}
size_t
klen
;
const
char
*
iKey
=
rocksdb_iter_key
(
pCur
->
iter
,
&
klen
);
SStateSessionKey
curKey
=
{
0
};
stateSessionKeyDecode
(
&
curKey
,
(
char
*
)
iKey
);
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
;
}
int32_t
streamStateSessionGetKVByCur_rocksdb
(
SStreamStateCur
*
pCur
,
SSessionKey
*
pKey
,
void
**
pVal
,
int32_t
*
pVLen
)
{
if
(
!
pCur
)
{
return
-
1
;
...
...
@@ -512,8 +542,8 @@ int32_t streamStateSessionGetKVByCur_rocksdb(SStreamStateCur* pCur, SSessionKey*
stateSessionKeyDecode
((
void
*
)
&
ktmp
,
(
char
*
)
curKey
);
const
char
*
val
=
rocksdb_iter_value
(
pCur
->
iter
,
(
size_t
*
)
&
vLen
);
*
pVal
=
(
char
*
)
val
;
*
pVLen
=
vLen
;
if
(
pVal
!=
NULL
)
*
pVal
=
(
char
*
)
val
;
if
(
pVLen
!=
NULL
)
*
pVLen
=
vLen
;
if
(
pKTmp
->
opNum
!=
pCur
->
number
)
{
return
-
1
;
...
...
@@ -532,6 +562,62 @@ int32_t streamStateCurNext_rocksdb(SStreamState* pState, SStreamStateCur* pCur)
rocksdb_iter_next
(
pCur
->
iter
);
return
0
;
}
int32_t
streamStateSessionGetKeyByRange_rocksdb
(
SStreamState
*
pState
,
const
SSessionKey
*
key
,
SSessionKey
*
curKey
)
{
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
{
return
-
1
;
}
pCur
->
number
=
pState
->
number
;
pCur
->
iter
=
rocksdb_create_iterator_cf
(
pState
->
pTdbState
->
rocksdb
,
pState
->
pTdbState
->
ropts
,
pState
->
pTdbState
->
pHandle
[
2
]);
SStateSessionKey
sKey
=
{.
key
=
*
key
,
.
opNum
=
pState
->
number
};
int32_t
c
=
0
;
char
buf
[
128
]
=
{
0
};
stateSessionKeyEncode
(
&
sKey
,
buf
);
rocksdb_iter_seek
(
pCur
->
iter
,
buf
,
sizeof
(
sKey
));
if
(
!
rocksdb_iter_valid
(
pCur
->
iter
))
{
streamStateFreeCur
(
pCur
);
return
-
1
;
}
int32_t
kLen
;
const
char
*
iKeyStr
=
rocksdb_iter_key
(
pCur
->
iter
,
(
size_t
*
)
&
kLen
);
SStateSessionKey
iKey
=
{
0
};
stateSessionKeyDecode
(
&
iKey
,
(
char
*
)
iKeyStr
);
c
=
stateSessionKeyCmpr
(
&
sKey
,
sizeof
(
sKey
),
&
iKey
,
sizeof
(
iKey
));
SSessionKey
resKey
=
*
key
;
int32_t
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
&
resKey
,
NULL
,
0
);
if
(
code
==
0
&&
sessionRangeKeyCmpr
(
key
,
&
resKey
)
==
0
)
{
*
curKey
=
resKey
;
streamStateFreeCur
(
pCur
);
return
code
;
}
if
(
c
>
0
)
{
streamStateCurNext_rocksdb
(
pState
,
pCur
);
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
&
resKey
,
NULL
,
0
);
if
(
code
==
0
&&
sessionRangeKeyCmpr
(
key
,
&
resKey
)
==
0
)
{
*
curKey
=
resKey
;
streamStateFreeCur
(
pCur
);
return
code
;
}
}
else
if
(
c
<
0
)
{
streamStateCurPrev
(
pState
,
pCur
);
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
&
resKey
,
NULL
,
0
);
if
(
code
==
0
&&
sessionRangeKeyCmpr
(
key
,
&
resKey
)
==
0
)
{
*
curKey
=
resKey
;
streamStateFreeCur
(
pCur
);
return
code
;
}
}
streamStateFreeCur
(
pCur
);
return
-
1
;
}
int32_t
streamStateSessionGet_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
int
code
=
0
;
SStreamStateCur
*
pCur
=
streamStateSessionSeekKeyCurrentNext_rocksdb
(
pState
,
key
);
...
...
@@ -558,6 +644,107 @@ int32_t streamStateSessionDel_rocksdb(SStreamState* pState, const SSessionKey* k
STREAM_STATE_DEL_ROCKSDB
(
pState
,
"sess"
,
key
);
return
code
;
}
int32_t
streamStateSessionAddIfNotExist_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
TSKEY
gap
,
void
**
pVal
,
int32_t
*
pVLen
)
{
// todo refactor
int32_t
res
=
0
;
SSessionKey
originKey
=
*
key
;
SSessionKey
searchKey
=
*
key
;
searchKey
.
win
.
skey
=
key
->
win
.
skey
-
gap
;
searchKey
.
win
.
ekey
=
key
->
win
.
ekey
+
gap
;
int32_t
valSize
=
*
pVLen
;
void
*
tmp
=
taosMemoryMalloc
(
valSize
);
SStreamStateCur
*
pCur
=
streamStateSessionSeekKeyCurrentPrev_rocksdb
(
pState
,
key
);
int32_t
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
key
,
pVal
,
pVLen
);
if
(
code
==
0
)
{
if
(
sessionRangeKeyCmpr
(
&
searchKey
,
key
)
==
0
)
{
memcpy
(
tmp
,
*
pVal
,
valSize
);
streamStateSessionDel_rocksdb
(
pState
,
key
);
goto
_end
;
}
streamStateCurNext_rocksdb
(
pState
,
pCur
);
}
else
{
*
key
=
originKey
;
streamStateFreeCur
(
pCur
);
pCur
=
streamStateSessionSeekKeyNext_rocksdb
(
pState
,
key
);
}
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
key
,
pVal
,
pVLen
);
if
(
code
==
0
)
{
if
(
sessionRangeKeyCmpr
(
&
searchKey
,
key
)
==
0
)
{
memcpy
(
tmp
,
*
pVal
,
valSize
);
streamStateSessionDel_rocksdb
(
pState
,
key
);
goto
_end
;
}
}
*
key
=
originKey
;
res
=
1
;
memset
(
tmp
,
0
,
valSize
);
_end:
*
pVal
=
tmp
;
streamStateFreeCur
(
pCur
);
return
res
;
}
int32_t
streamStateStateAddIfNotExist_rocksdb
(
SStreamState
*
pState
,
SSessionKey
*
key
,
char
*
pKeyData
,
int32_t
keyDataLen
,
state_key_cmpr_fn
fn
,
void
**
pVal
,
int32_t
*
pVLen
)
{
// todo refactor
int32_t
res
=
0
;
SSessionKey
tmpKey
=
*
key
;
int32_t
valSize
=
*
pVLen
;
void
*
tmp
=
taosMemoryMalloc
(
valSize
);
// tdbRealloc(NULL, valSize);
if
(
!
tmp
)
{
return
-
1
;
}
SStreamStateCur
*
pCur
=
streamStateSessionSeekKeyCurrentPrev_rocksdb
(
pState
,
key
);
int32_t
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
key
,
pVal
,
pVLen
);
if
(
code
==
0
)
{
if
(
key
->
win
.
skey
<=
tmpKey
.
win
.
skey
&&
tmpKey
.
win
.
ekey
<=
key
->
win
.
ekey
)
{
memcpy
(
tmp
,
*
pVal
,
valSize
);
streamStateSessionDel
(
pState
,
key
);
goto
_end
;
}
void
*
stateKey
=
(
char
*
)(
*
pVal
)
+
(
valSize
-
keyDataLen
);
if
(
fn
(
pKeyData
,
stateKey
)
==
true
)
{
memcpy
(
tmp
,
*
pVal
,
valSize
);
streamStateSessionDel
(
pState
,
key
);
goto
_end
;
}
streamStateCurNext_rocksdb
(
pState
,
pCur
);
}
else
{
*
key
=
tmpKey
;
streamStateFreeCur
(
pCur
);
pCur
=
streamStateSessionSeekKeyNext_rocksdb
(
pState
,
key
);
}
code
=
streamStateSessionGetKVByCur_rocksdb
(
pCur
,
key
,
pVal
,
pVLen
);
if
(
code
==
0
)
{
void
*
stateKey
=
(
char
*
)(
*
pVal
)
+
(
valSize
-
keyDataLen
);
if
(
fn
(
pKeyData
,
stateKey
)
==
true
)
{
memcpy
(
tmp
,
*
pVal
,
valSize
);
streamStateSessionDel_rocksdb
(
pState
,
key
);
goto
_end
;
}
}
*
key
=
tmpKey
;
res
=
1
;
memset
(
tmp
,
0
,
valSize
);
_end:
*
pVal
=
tmp
;
streamStateFreeCur
(
pCur
);
return
res
;
}
int32_t
streamStateSessionClear
(
SStreamState
*
pState
)
{
SSessionKey
key
=
{.
win
.
skey
=
0
,
.
win
.
ekey
=
0
,
.
groupId
=
0
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录