Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
671d06ef
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看板
未验证
提交
671d06ef
编写于
6月 01, 2022
作者:
L
Liu Jicong
提交者:
GitHub
6月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13394 from taosdata/feature/tq
refactor(tmq): push mode
上级
adc10301
f3b680f6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
136 addition
and
47 deletion
+136
-47
examples/c/tmq.c
examples/c/tmq.c
+2
-2
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+31
-0
source/dnode/vnode/src/inc/tq.h
source/dnode/vnode/src/inc/tq.h
+5
-10
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+35
-25
source/dnode/vnode/src/tq/tqPush.c
source/dnode/vnode/src/tq/tqPush.c
+63
-10
未找到文件。
examples/c/tmq.c
浏览文件 @
671d06ef
...
...
@@ -176,8 +176,8 @@ tmq_t* build_consumer() {
tmq_list_t
*
build_topic_list
()
{
tmq_list_t
*
topic_list
=
tmq_list_new
();
/*tmq_list_append(topic_list, "topic_ctb_column");*/
tmq_list_append
(
topic_list
,
"tmq_test_db_multi_insert_topic"
);
tmq_list_append
(
topic_list
,
"topic_ctb_column"
);
/*tmq_list_append(topic_list, "tmq_test_db_multi_insert_topic");*/
return
topic_list
;
}
...
...
include/libs/stream/tstream.h
浏览文件 @
671d06ef
...
...
@@ -80,6 +80,37 @@ typedef struct {
int8_t
type
;
}
SStreamCheckpoint
;
typedef
struct
{
STaosQueue
*
queue
;
STaosQall
*
qall
;
void
*
qItem
;
int8_t
failed
;
}
SStreamQ
;
static
FORCE_INLINE
void
*
streamQCurItem
(
SStreamQ
*
queue
)
{
//
return
queue
->
qItem
;
}
static
FORCE_INLINE
void
*
streamQNextItem
(
SStreamQ
*
queue
)
{
int8_t
failed
=
atomic_load_8
(
&
queue
->
failed
);
if
(
failed
)
{
ASSERT
(
queue
->
qItem
!=
NULL
);
return
streamQCurItem
(
queue
);
}
else
{
taosGetQitem
(
queue
->
qall
,
&
queue
->
qItem
);
if
(
queue
->
qItem
==
NULL
)
{
taosReadAllQitems
(
queue
->
queue
,
queue
->
qall
);
taosGetQitem
(
queue
->
qall
,
&
queue
->
qItem
);
}
return
streamQCurItem
(
queue
);
}
}
static
FORCE_INLINE
void
streamQSetFail
(
SStreamQ
*
queue
)
{
atomic_store_8
(
&
queue
->
failed
,
1
);
}
static
FORCE_INLINE
void
streamQSetSuccess
(
SStreamQ
*
queue
)
{
atomic_store_8
(
&
queue
->
failed
,
0
);
}
static
FORCE_INLINE
SStreamDataSubmit
*
streamDataSubmitNew
(
SSubmitReq
*
pReq
)
{
SStreamDataSubmit
*
pDataSubmit
=
(
SStreamDataSubmit
*
)
taosAllocateQitem
(
sizeof
(
SStreamDataSubmit
),
DEF_QITEM
);
if
(
pDataSubmit
==
NULL
)
return
NULL
;
...
...
source/dnode/vnode/src/inc/tq.h
浏览文件 @
671d06ef
...
...
@@ -65,12 +65,6 @@ struct STqReadHandle {
// tqPush
typedef
struct
{
STaosQueue
*
queue
;
STaosQall
*
qall
;
void
*
qItem
;
}
STqInputQ
;
typedef
struct
{
// msg info
int64_t
consumerId
;
...
...
@@ -84,10 +78,10 @@ typedef struct {
tmr_h
timerId
;
int8_t
tmrStopped
;
// exec
int8_t
inputStatus
;
int8_t
execStatus
;
S
TqInput
Q
inputQ
;
SRWLatch
lock
;
int8_t
inputStatus
;
int8_t
execStatus
;
S
Stream
Q
inputQ
;
SRWLatch
lock
;
}
STqPushHandle
;
// tqExec
...
...
@@ -155,6 +149,7 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
// tqExec
int32_t
tqDataExec
(
STQ
*
pTq
,
STqExecHandle
*
pExec
,
SSubmitReq
*
pReq
,
SMqDataBlkRsp
*
pRsp
,
int32_t
workerId
);
int32_t
tqSendPollRsp
(
STQ
*
pTq
,
const
SRpcMsg
*
pMsg
,
const
SMqPollReq
*
pReq
,
const
SMqDataBlkRsp
*
pRsp
);
// tqMeta
int32_t
tqMetaOpen
(
STQ
*
pTq
);
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
671d06ef
...
...
@@ -81,12 +81,41 @@ void tqClose(STQ* pTq) {
// TODO
}
int32_t
tqSendPollRsp
(
STQ
*
pTq
,
const
SRpcMsg
*
pMsg
,
const
SMqPollReq
*
pReq
,
const
SMqDataBlkRsp
*
pRsp
)
{
int32_t
tlen
=
sizeof
(
SMqRspHead
)
+
tEncodeSMqDataBlkRsp
(
NULL
,
pRsp
);
void
*
buf
=
rpcMallocCont
(
tlen
);
if
(
buf
==
NULL
)
{
return
-
1
;
}
((
SMqRspHead
*
)
buf
)
->
mqMsgType
=
TMQ_MSG_TYPE__POLL_RSP
;
((
SMqRspHead
*
)
buf
)
->
epoch
=
pReq
->
epoch
;
((
SMqRspHead
*
)
buf
)
->
consumerId
=
pReq
->
consumerId
;
void
*
abuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMqRspHead
));
tEncodeSMqDataBlkRsp
(
&
abuf
,
pRsp
);
SRpcMsg
resp
=
{
.
info
=
pMsg
->
info
,
.
pCont
=
buf
,
.
contLen
=
tlen
,
.
code
=
0
,
};
tmsgSendRsp
(
&
resp
);
tqDebug
(
"vg %d from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %ld, rspOffset: %ld"
,
TD_VID
(
pTq
->
pVnode
),
pReq
->
consumerId
,
pReq
->
epoch
,
pRsp
->
blockNum
,
pRsp
->
reqOffset
,
pRsp
->
rspOffset
);
return
0
;
}
int32_t
tqProcessPollReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
,
int32_t
workerId
)
{
SMqPollReq
*
pReq
=
pMsg
->
pCont
;
int64_t
consumerId
=
pReq
->
consumerId
;
int64_t
timeout
=
pReq
->
timeout
;
int32_t
reqEpoch
=
pReq
->
epoch
;
int64_t
fetchOffset
;
int32_t
code
=
0
;
// get offset to fetch message
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__EARLIEAST
)
{
...
...
@@ -155,7 +184,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
if
(
pHead
->
msgType
==
TDMT_VND_SUBMIT
)
{
SSubmitReq
*
pCont
=
(
SSubmitReq
*
)
&
pHead
->
body
;
tqDataExec
(
pTq
,
&
pHandle
->
execHandle
,
pCont
,
&
rsp
,
workerId
);
if
(
tqDataExec
(
pTq
,
&
pHandle
->
execHandle
,
pCont
,
&
rsp
,
workerId
)
<
0
)
{
/*ASSERT(0);*/
}
}
else
{
// TODO
ASSERT
(
0
);
...
...
@@ -180,31 +211,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
rsp
.
rspOffset
=
fetchOffset
;
int32_t
tlen
=
sizeof
(
SMqRspHead
)
+
tEncodeSMqDataBlkRsp
(
NULL
,
&
rsp
);
void
*
buf
=
rpcMallocCont
(
tlen
);
if
(
buf
==
NULL
)
{
pMsg
->
code
=
-
1
;
return
-
1
;
if
(
tqSendPollRsp
(
pTq
,
pMsg
,
pReq
,
&
rsp
)
<
0
)
{
code
=
-
1
;
}
((
SMqRspHead
*
)
buf
)
->
mqMsgType
=
TMQ_MSG_TYPE__POLL_RSP
;
((
SMqRspHead
*
)
buf
)
->
epoch
=
pReq
->
epoch
;
((
SMqRspHead
*
)
buf
)
->
consumerId
=
consumerId
;
void
*
abuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMqRspHead
));
tEncodeSMqDataBlkRsp
(
&
abuf
,
&
rsp
);
SRpcMsg
resp
=
{
.
info
=
pMsg
->
info
,
.
pCont
=
buf
,
.
contLen
=
tlen
,
.
code
=
0
,
};
tmsgSendRsp
(
&
resp
);
tqDebug
(
"vg %d offset %ld from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %ld, rspOffset: %ld"
,
TD_VID
(
pTq
->
pVnode
),
fetchOffset
,
consumerId
,
pReq
->
epoch
,
rsp
.
blockNum
,
rsp
.
reqOffset
,
rsp
.
rspOffset
);
// TODO wrap in destroy func
taosArrayDestroy
(
rsp
.
blockData
);
taosArrayDestroy
(
rsp
.
blockDataLen
);
...
...
@@ -217,7 +227,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
taosArrayDestroyP
(
rsp
.
blockTbName
,
(
FDelete
)
taosMemoryFree
);
}
return
0
;
return
code
;
}
int32_t
tqProcessVgDeleteReq
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
)
{
...
...
source/dnode/vnode/src/tq/tqPush.c
浏览文件 @
671d06ef
...
...
@@ -21,21 +21,74 @@ void tqTmrRspFunc(void* param, void* tmrId) {
}
int32_t
tqExecFromInputQ
(
STQ
*
pTq
,
STqHandle
*
pHandle
)
{
SMqDataBlkRsp
rsp
=
{
0
};
// 1. guard and set status executing
// 2. check processedVer
// 2.1. if not missed, get msg from queue
// 2.2. if missed, scan wal
//
// 3. exec, after each success, update processed ver
// first run
// set exec status closing
// second run
// set exec status idle
//
int8_t
execStatus
=
atomic_val_compare_exchange_8
(
&
pHandle
->
pushHandle
.
execStatus
,
TASK_STATUS__IDLE
,
TASK_STATUS__EXECUTING
);
if
(
execStatus
==
TASK_STATUS__IDLE
)
{
SStreamDataSubmit
*
pSubmit
=
NULL
;
// 2. check processedVer
// 2.1. if not missed, get msg from queue
// 2.2. if missed, scan wal
pSubmit
=
streamQNextItem
(
&
pHandle
->
pushHandle
.
inputQ
);
while
(
pHandle
->
pushHandle
.
processedVer
<=
pSubmit
->
ver
)
{
// read from wal
}
while
(
pHandle
->
pushHandle
.
processedVer
>
pSubmit
->
ver
+
1
)
{
streamQSetSuccess
(
&
pHandle
->
pushHandle
.
inputQ
);
streamDataSubmitRefDec
(
pSubmit
);
pSubmit
=
streamQNextItem
(
&
pHandle
->
pushHandle
.
inputQ
);
if
(
pSubmit
==
NULL
)
break
;
}
// 3. exec, after each success, update processed ver
// first run
while
(
pSubmit
!=
NULL
)
{
ASSERT
(
pSubmit
->
ver
==
pHandle
->
pushHandle
.
processedVer
+
1
);
if
(
tqDataExec
(
pTq
,
&
pHandle
->
execHandle
,
pSubmit
->
data
,
&
rsp
,
0
)
<
0
)
{
/*ASSERT(0);*/
}
// update processed
atomic_store_64
(
&
pHandle
->
pushHandle
.
processedVer
,
pSubmit
->
ver
);
streamQSetSuccess
(
&
pHandle
->
pushHandle
.
inputQ
);
streamDataSubmitRefDec
(
pSubmit
);
if
(
rsp
.
blockNum
>
0
)
{
goto
SEND_RSP
;
}
else
{
pSubmit
=
streamQNextItem
(
&
pHandle
->
pushHandle
.
inputQ
);
}
}
// set exec status closing
atomic_store_8
(
&
pHandle
->
pushHandle
.
execStatus
,
TASK_STATUS__CLOSING
);
// second run
while
(
pSubmit
!=
NULL
)
{
ASSERT
(
pSubmit
->
ver
==
pHandle
->
pushHandle
.
processedVer
+
1
);
if
(
tqDataExec
(
pTq
,
&
pHandle
->
execHandle
,
pSubmit
->
data
,
&
rsp
,
0
)
<
0
)
{
/*ASSERT(0);*/
}
// update processed
atomic_store_64
(
&
pHandle
->
pushHandle
.
processedVer
,
pSubmit
->
ver
);
streamQSetSuccess
(
&
pHandle
->
pushHandle
.
inputQ
);
streamDataSubmitRefDec
(
pSubmit
);
if
(
rsp
.
blockNum
>
0
)
{
goto
SEND_RSP
;
}
else
{
pSubmit
=
streamQNextItem
(
&
pHandle
->
pushHandle
.
inputQ
);
}
}
// set exec status idle
atomic_store_8
(
&
pHandle
->
pushHandle
.
execStatus
,
TASK_STATUS__IDLE
);
}
SEND_RSP:
// 4. if get result
// 4.1 set exec input status blocked and exec status idle
atomic_store_8
(
&
pHandle
->
pushHandle
.
execStatus
,
TASK_STATUS__IDLE
);
// 4.2 rpc send
rsp
.
rspOffset
=
pHandle
->
pushHandle
.
processedVer
;
/*if (tqSendPollRsp(pTq, pMsg, pReq, &rsp) < 0) {*/
/*return -1;*/
/*}*/
// 4.3 clear rpc info
memset
(
&
pHandle
->
pushHandle
.
rpcInfo
,
0
,
sizeof
(
SRpcHandleInfo
));
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录