Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
203444f6
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,发现更多精彩内容 >>
提交
203444f6
编写于
8月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of
https://github.com/taosdata/TDengine
into refact/meta_3.0
上级
5d1cbb54
f558feca
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
182 addition
and
2 deletion
+182
-2
docs/zh/07-develop/07-tmq.mdx
docs/zh/07-develop/07-tmq.mdx
+105
-0
include/libs/sync/sync.h
include/libs/sync/sync.h
+4
-0
source/dnode/vnode/src/inc/vnd.h
source/dnode/vnode/src/inc/vnd.h
+1
-0
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+2
-2
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+14
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+56
-0
未找到文件。
docs/zh/07-develop/07-tmq.mdx
浏览文件 @
203444f6
...
...
@@ -87,6 +87,25 @@ void commitSync() throws SQLException;
void close() throws SQLException;
```
</TabItem>
<TabItem label="Go" value="Go">
```go
func NewConsumer(conf *Config) (*Consumer, error)
func (c *Consumer) Close() error
func (c *Consumer) Commit(ctx context.Context, message unsafe.Pointer) error
func (c *Consumer) FreeMessage(message unsafe.Pointer)
func (c *Consumer) Poll(timeout time.Duration) (*Result, error)
func (c *Consumer) Subscribe(topics []string) error
func (c *Consumer) Unsubscribe() error
```
</TabItem>
</Tabs>
...
...
@@ -229,6 +248,56 @@ public class MetersDeserializer extends ReferenceDeserializer<Meters> {
}
```
</TabItem>
<TabItem label="Go" value="Go">
```go
config := tmq.NewConfig()
defer config.Destroy()
err = config.SetGroupID("test")
if err != nil {
panic(err)
}
err = config.SetAutoOffsetReset("earliest")
if err != nil {
panic(err)
}
err = config.SetConnectIP("127.0.0.1")
if err != nil {
panic(err)
}
err = config.SetConnectUser("root")
if err != nil {
panic(err)
}
err = config.SetConnectPass("taosdata")
if err != nil {
panic(err)
}
err = config.SetConnectPort("6030")
if err != nil {
panic(err)
}
err = config.SetMsgWithTableName(true)
if err != nil {
panic(err)
}
err = config.EnableHeartBeat()
if err != nil {
panic(err)
}
err = config.EnableAutoCommit(func(result *wrapper.TMQCommitCallbackResult) {
if result.ErrCode != 0 {
errStr := wrapper.TMQErr2Str(result.ErrCode)
err := errors.NewError(int(result.ErrCode), errStr)
panic(err)
}
})
if err != nil {
panic(err)
}
```
</TabItem>
</Tabs>
...
...
@@ -260,6 +329,20 @@ topics.add("tmq_topic");
consumer.subscribe(topics);
```
</TabItem>
<TabItem value="Go" label="Go">
```go
consumer, err := tmq.NewConsumer(config)
if err != nil {
panic(err)
}
err = consumer.Subscribe([]string{"example_tmq_topic"})
if err != nil {
panic(err)
}
```
</TabItem>
</Tabs>
...
...
@@ -293,6 +376,21 @@ while(running){
}
```
</TabItem>
<TabItem value="Go" label="Go">
```go
for {
result, err := consumer.Poll(time.Second)
if err != nil {
panic(err)
}
fmt.Println(result)
consumer.Commit(context.Background(), result.Message)
consumer.FreeMessage(result.Message)
}
```
</TabItem>
</Tabs>
...
...
@@ -322,6 +420,13 @@ consumer.unsubscribe();
consumer.close();
```
</TabItem>
<TabItem value="Go" label="Go">
```go
consumer.Close()
```
</TabItem>
</Tabs>
...
...
include/libs/sync/sync.h
浏览文件 @
203444f6
...
...
@@ -30,6 +30,7 @@ extern bool gRaftDetailLog;
#define SYNC_SPEED_UP_HB_TIMER 400
#define SYNC_SPEED_UP_AFTER_MS (1000 * 20)
#define SYNC_SLOW_DOWN_RANGE 100
#define SYNC_MAX_READ_RANGE 10
#define SYNC_MAX_BATCH_SIZE 1
#define SYNC_INDEX_BEGIN 0
...
...
@@ -210,9 +211,12 @@ void syncStop(int64_t rid);
int32_t
syncSetStandby
(
int64_t
rid
);
ESyncState
syncGetMyRole
(
int64_t
rid
);
bool
syncIsReady
(
int64_t
rid
);
bool
syncIsReadyForRead
(
int64_t
rid
);
const
char
*
syncGetMyRoleStr
(
int64_t
rid
);
bool
syncRestoreFinish
(
int64_t
rid
);
SyncTerm
syncGetMyTerm
(
int64_t
rid
);
SyncIndex
syncGetLastIndex
(
int64_t
rid
);
SyncIndex
syncGetCommitIndex
(
int64_t
rid
);
SyncGroupId
syncGetVgId
(
int64_t
rid
);
void
syncGetEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetRetryEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
...
...
source/dnode/vnode/src/inc/vnd.h
浏览文件 @
203444f6
...
...
@@ -98,6 +98,7 @@ void vnodeSyncStart(SVnode* pVnode);
void
vnodeSyncClose
(
SVnode
*
pVnode
);
void
vnodeRedirectRpcMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
bool
vnodeIsLeader
(
SVnode
*
pVnode
);
bool
vnodeIsReadyForRead
(
SVnode
*
pVnode
);
bool
vnodeIsRoleLeader
(
SVnode
*
pVnode
);
#ifdef __cplusplus
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
203444f6
...
...
@@ -283,7 +283,7 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
int32_t
vnodeProcessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
vTrace
(
"message in vnode query queue is processing"
);
if
((
pMsg
->
msgType
==
TDMT_SCH_QUERY
)
&&
!
vnodeIs
Leader
(
pVnode
))
{
if
((
pMsg
->
msgType
==
TDMT_SCH_QUERY
)
&&
!
vnodeIs
ReadyForRead
(
pVnode
))
{
vnodeRedirectRpcMsg
(
pVnode
,
pMsg
);
return
0
;
}
...
...
@@ -307,7 +307,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
vTrace
(
"vgId:%d, msg:%p in fetch queue is processing"
,
pVnode
->
config
.
vgId
,
pMsg
);
if
((
pMsg
->
msgType
==
TDMT_SCH_FETCH
||
pMsg
->
msgType
==
TDMT_VND_TABLE_META
||
pMsg
->
msgType
==
TDMT_VND_TABLE_CFG
||
pMsg
->
msgType
==
TDMT_VND_BATCH_META
)
&&
!
vnodeIs
Leader
(
pVnode
))
{
!
vnodeIs
ReadyForRead
(
pVnode
))
{
vnodeRedirectRpcMsg
(
pVnode
,
pMsg
);
return
0
;
}
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
203444f6
...
...
@@ -781,3 +781,17 @@ bool vnodeIsLeader(SVnode *pVnode) {
return
true
;
}
bool
vnodeIsReadyForRead
(
SVnode
*
pVnode
)
{
if
(
syncIsReady
(
pVnode
->
sync
))
{
return
true
;
}
if
(
syncIsReadyForRead
(
pVnode
->
sync
))
{
return
true
;
}
vDebug
(
"vgId:%d, vnode not ready for read, state:%s, last:%ld, cmt:%ld"
,
pVnode
->
config
.
vgId
,
syncGetMyRoleStr
(
pVnode
->
sync
),
syncGetLastIndex
(
pVnode
->
sync
),
syncGetCommitIndex
(
pVnode
->
sync
));
return
false
;
}
source/libs/sync/src/syncMain.c
浏览文件 @
203444f6
...
...
@@ -392,6 +392,29 @@ bool syncIsReady(int64_t rid) {
return
b
;
}
bool
syncIsReadyForRead
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
false
;
}
ASSERT
(
rid
==
pSyncNode
->
rid
);
// TODO: last not noop?
SyncIndex
lastIndex
=
syncNodeGetLastIndex
(
pSyncNode
);
bool
b
=
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
&&
(
pSyncNode
->
commitIndex
>=
lastIndex
-
SYNC_MAX_READ_RANGE
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
// if false, set error code
if
(
false
==
b
)
{
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
terrno
=
TSDB_CODE_SYN_NOT_LEADER
;
}
else
{
terrno
=
TSDB_CODE_APP_NOT_READY
;
}
}
return
b
;
}
bool
syncIsRestoreFinish
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
...
...
@@ -519,6 +542,30 @@ SyncTerm syncGetMyTerm(int64_t rid) {
return
term
;
}
SyncIndex
syncGetLastIndex
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
SYNC_INDEX_INVALID
;
}
ASSERT
(
rid
==
pSyncNode
->
rid
);
SyncIndex
lastIndex
=
syncNodeGetLastIndex
(
pSyncNode
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
lastIndex
;
}
SyncIndex
syncGetCommitIndex
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
SYNC_INDEX_INVALID
;
}
ASSERT
(
rid
==
pSyncNode
->
rid
);
SyncIndex
cmtIndex
=
pSyncNode
->
commitIndex
;
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
cmtIndex
;
}
SyncGroupId
syncGetVgId
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
...
...
@@ -828,6 +875,15 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
pSyncNode
->
changing
=
true
;
}
// not restored, vnode enable
if
(
!
pSyncNode
->
restoreFinish
&&
pSyncNode
->
vgId
!=
1
)
{
ret
=
-
1
;
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
sError
(
"vgId:%d, failed to sync propose since not ready, type:%s, last:%ld, cmt:%ld"
,
pSyncNode
->
vgId
,
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeGetLastIndex
(
pSyncNode
),
pSyncNode
->
commitIndex
);
goto
_END
;
}
SRespStub
stub
;
stub
.
createTime
=
taosGetTimestampMs
();
stub
.
rpcMsg
=
*
pMsg
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录