Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8f0ecd46
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看板
未验证
提交
8f0ecd46
编写于
11月 08, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 08, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17961 from taosdata/feature/stream
enh(tmq): offset commit only when needed
上级
920fc400
118e5bf5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
2 deletion
+14
-2
source/dnode/vnode/src/tq/tqOffset.c
source/dnode/vnode/src/tq/tqOffset.c
+14
-2
未找到文件。
source/dnode/vnode/src/tq/tqOffset.c
浏览文件 @
8f0ecd46
...
@@ -17,9 +17,9 @@
...
@@ -17,9 +17,9 @@
#include "tq.h"
#include "tq.h"
struct
STqOffsetStore
{
struct
STqOffsetStore
{
char
*
fname
;
STQ
*
pTq
;
STQ
*
pTq
;
SHashObj
*
pHash
;
// SHashObj<subscribeKey, offset>
SHashObj
*
pHash
;
// SHashObj<subscribeKey, offset>
int8_t
needCommit
;
};
};
char
*
tqOffsetBuildFName
(
const
char
*
path
,
int32_t
fVer
)
{
char
*
tqOffsetBuildFName
(
const
char
*
path
,
int32_t
fVer
)
{
...
@@ -74,6 +74,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) {
...
@@ -74,6 +74,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) {
return
NULL
;
return
NULL
;
}
}
pStore
->
pTq
=
pTq
;
pStore
->
pTq
=
pTq
;
pStore
->
needCommit
=
0
;
pTq
->
pOffsetStore
=
pStore
;
pTq
->
pOffsetStore
=
pStore
;
pStore
->
pHash
=
taosHashInit
(
64
,
MurmurHash3_32
,
true
,
HASH_NO_LOCK
);
pStore
->
pHash
=
taosHashInit
(
64
,
MurmurHash3_32
,
true
,
HASH_NO_LOCK
);
...
@@ -100,6 +101,7 @@ STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey) {
...
@@ -100,6 +101,7 @@ STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey) {
}
}
int32_t
tqOffsetWrite
(
STqOffsetStore
*
pStore
,
const
STqOffset
*
pOffset
)
{
int32_t
tqOffsetWrite
(
STqOffsetStore
*
pStore
,
const
STqOffset
*
pOffset
)
{
pStore
->
needCommit
=
1
;
return
taosHashPut
(
pStore
->
pHash
,
pOffset
->
subKey
,
strlen
(
pOffset
->
subKey
),
pOffset
,
sizeof
(
STqOffset
));
return
taosHashPut
(
pStore
->
pHash
,
pOffset
->
subKey
,
strlen
(
pOffset
->
subKey
),
pOffset
,
sizeof
(
STqOffset
));
}
}
...
@@ -108,14 +110,23 @@ int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey) {
...
@@ -108,14 +110,23 @@ int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey) {
}
}
int32_t
tqOffsetCommitFile
(
STqOffsetStore
*
pStore
)
{
int32_t
tqOffsetCommitFile
(
STqOffsetStore
*
pStore
)
{
if
(
!
pStore
->
needCommit
)
return
0
;
// TODO file name should be with a newer version
// TODO file name should be with a newer version
char
*
fname
=
tqOffsetBuildFName
(
pStore
->
pTq
->
path
,
0
);
char
*
fname
=
tqOffsetBuildFName
(
pStore
->
pTq
->
path
,
0
);
TdFilePtr
pFile
=
taosOpenFile
(
fname
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
TdFilePtr
pFile
=
taosOpenFile
(
fname
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
taosMemoryFree
(
fname
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
int32_t
err
=
terrno
;
const
char
*
errStr
=
tstrerror
(
err
);
int32_t
sysErr
=
errno
;
const
char
*
sysErrStr
=
strerror
(
errno
);
tqError
(
"vgId:%d, cannot open file %s when commit offset since %s"
,
pStore
->
pTq
->
pVnode
->
config
.
vgId
,
fname
,
sysErrStr
);
ASSERT
(
0
);
ASSERT
(
0
);
return
-
1
;
return
-
1
;
}
}
taosMemoryFree
(
fname
);
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
while
(
1
)
{
pIter
=
taosHashIterate
(
pStore
->
pHash
,
pIter
);
pIter
=
taosHashIterate
(
pStore
->
pHash
,
pIter
);
...
@@ -152,5 +163,6 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
...
@@ -152,5 +163,6 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
}
}
// close and rename file
// close and rename file
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
pStore
->
needCommit
=
0
;
return
0
;
return
0
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录