Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
42da4f6f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
42da4f6f
编写于
2月 11, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rewrite rebalance
上级
f2bc0004
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
384 addition
and
111 deletion
+384
-111
example/src/tmq.c
example/src/tmq.c
+11
-11
include/common/tmsg.h
include/common/tmsg.h
+53
-2
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+1
-1
source/dnode/mnode/impl/inc/mndConsumer.h
source/dnode/mnode/impl/inc/mndConsumer.h
+10
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+28
-8
source/dnode/mnode/impl/inc/mndSubscribe.h
source/dnode/mnode/impl/inc/mndSubscribe.h
+2
-1
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+1
-0
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+276
-86
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+2
-2
未找到文件。
example/src/tmq.c
浏览文件 @
42da4f6f
...
@@ -44,11 +44,11 @@ int32_t init_env() {
...
@@ -44,11 +44,11 @@ int32_t init_env() {
}
}
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
pRes
=
taos_query
(
pConn
,
"create stable
if not exists
st1 (ts timestamp, k int) tags(a int)"
);
pRes
=
taos_query
(
pConn
,
"create stable st1 (ts timestamp, k int) tags(a int)"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
/*if (taos_errno(pRes) != 0) {*/
printf
(
"failed to create super table 123_$^), reason:%s
\n
"
,
taos_errstr
(
pRes
));
/*printf("failed to create super table 123_$^), reason:%s\n", taos_errstr(pRes));*/
return
-
1
;
/*return -1;*/
}
/*}*/
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
pRes
=
taos_query
(
pConn
,
"create table tu using st1 tags(1)"
);
pRes
=
taos_query
(
pConn
,
"create table tu using st1 tags(1)"
);
...
@@ -114,19 +114,19 @@ void basic_consume_loop(tmq_t *tmq,
...
@@ -114,19 +114,19 @@ void basic_consume_loop(tmq_t *tmq,
return
;
return
;
}
}
int32_t
cnt
=
0
;
int32_t
cnt
=
0
;
clock_t
startTime
=
clock
();
/*clock_t startTime = clock();*/
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
0
);
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
0
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
cnt
++
;
cnt
++
;
/*msg_process(tmqmessage);*/
msg_process
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
}
else
{
/*} else {*/
break
;
/*break;*/
}
}
}
}
clock_t
endTime
=
clock
();
/*clock_t endTime = clock();*/
printf
(
"log cnt: %d %f s
\n
"
,
cnt
,
(
double
)(
endTime
-
startTime
)
/
CLOCKS_PER_SEC
);
/*printf("log cnt: %d %f s\n", cnt, (double)(endTime - startTime) / CLOCKS_PER_SEC);*/
err
=
tmq_consumer_close
(
tmq
);
err
=
tmq_consumer_close
(
tmq
);
if
(
err
)
if
(
err
)
...
...
include/common/tmsg.h
浏览文件 @
42da4f6f
...
@@ -1055,7 +1055,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
...
@@ -1055,7 +1055,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
buf
=
taosDecodeString
(
buf
,
&
pReq
->
consumerGroup
);
buf
=
taosDecodeString
(
buf
,
&
pReq
->
consumerGroup
);
pReq
->
topicNames
=
taosArrayInit
(
pReq
->
topicNum
,
sizeof
(
void
*
));
pReq
->
topicNames
=
taosArrayInit
(
pReq
->
topicNum
,
sizeof
(
void
*
));
for
(
int
i
=
0
;
i
<
pReq
->
topicNum
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pReq
->
topicNum
;
i
++
)
{
char
*
name
=
NULL
;
char
*
name
;
buf
=
taosDecodeString
(
buf
,
&
name
);
buf
=
taosDecodeString
(
buf
,
&
name
);
taosArrayPush
(
pReq
->
topicNames
,
&
name
);
taosArrayPush
(
pReq
->
topicNames
,
&
name
);
}
}
...
@@ -1132,9 +1132,60 @@ typedef struct {
...
@@ -1132,9 +1132,60 @@ typedef struct {
}
SMqTmrMsg
;
}
SMqTmrMsg
;
typedef
struct
{
typedef
struct
{
int64_t
consumerId
;
const
char
*
key
;
SArray
*
lostConsumers
;
//SArray<int64_t>
SArray
*
removedConsumers
;
//SArray<int64_t>
SArray
*
newConsumers
;
//SArray<int64_t>
}
SMqRebSubscribe
;
static
FORCE_INLINE
SMqRebSubscribe
*
tNewSMqRebSubscribe
(
const
char
*
key
)
{
SMqRebSubscribe
*
pRebSub
=
(
SMqRebSubscribe
*
)
calloc
(
1
,
sizeof
(
SMqRebSubscribe
));
if
(
pRebSub
==
NULL
)
{
goto
_err
;
}
pRebSub
->
key
=
key
;
pRebSub
->
lostConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pRebSub
->
lostConsumers
==
NULL
)
{
goto
_err
;
}
pRebSub
->
removedConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pRebSub
->
removedConsumers
==
NULL
)
{
goto
_err
;
}
pRebSub
->
newConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pRebSub
->
newConsumers
==
NULL
)
{
goto
_err
;
}
return
pRebSub
;
_err:
taosArrayDestroy
(
pRebSub
->
lostConsumers
);
taosArrayDestroy
(
pRebSub
->
removedConsumers
);
taosArrayDestroy
(
pRebSub
->
newConsumers
);
tfree
(
pRebSub
);
return
NULL
;
}
// this message is sent from mnode to mnode(read thread to write thread), so there is no need for serialization / deserialization
typedef
struct
{
//SArray* rebSubscribes; //SArray<SMqRebSubscribe>
SHashObj
*
rebSubHash
;
// SHashObj<key, SMqRebSubscribe>
}
SMqDoRebalanceMsg
;
}
SMqDoRebalanceMsg
;
#if 0
static FORCE_INLINE SMqDoRebalanceMsg* tNewSMqDoRebalanceMsg() {
SMqDoRebalanceMsg *pMsg = malloc(sizeof(SMqDoRebalanceMsg));
if (pMsg == NULL) {
return NULL;
}
pMsg->rebSubscribes = taosArrayInit(0, sizeof(SMqRebSubscribe));
if (pMsg->rebSubscribes == NULL) {
free(pMsg);
return NULL;
}
return pMsg;
}
#endif
typedef
struct
{
typedef
struct
{
int64_t
status
;
int64_t
status
;
}
SMVSubscribeRsp
;
}
SMVSubscribeRsp
;
...
...
include/dnode/mnode/sdb/sdb.h
浏览文件 @
42da4f6f
...
@@ -222,7 +222,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw);
...
@@ -222,7 +222,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw);
* @param pKey The key value of the row.
* @param pKey The key value of the row.
* @return void* The object of the row.
* @return void* The object of the row.
*/
*/
void
*
sdbAcquire
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pKey
);
void
*
sdbAcquire
(
SSdb
*
pSdb
,
ESdbType
type
,
const
void
*
pKey
);
/**
/**
* @brief Release a row from sdb.
* @brief Release a row from sdb.
...
...
source/dnode/mnode/impl/inc/mndConsumer.h
浏览文件 @
42da4f6f
...
@@ -22,6 +22,16 @@
...
@@ -22,6 +22,16 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
enum
{
MQ_CONSUMER_STATUS__INIT
=
1
,
MQ_CONSUMER_STATUS__IDLE
,
MQ_CONSUMER_STATUS__ACTIVE
,
MQ_CONSUMER_STATUS__LOST
,
MQ_CONSUMER_STATUS__MODIFY
};
int32_t
mndInitConsumer
(
SMnode
*
pMnode
);
int32_t
mndInitConsumer
(
SMnode
*
pMnode
);
void
mndCleanupConsumer
(
SMnode
*
pMnode
);
void
mndCleanupConsumer
(
SMnode
*
pMnode
);
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
42da4f6f
...
@@ -388,6 +388,7 @@ static FORCE_INLINE int32_t tEncodeSMqSubConsumer(void** buf, const SMqSubConsum
...
@@ -388,6 +388,7 @@ static FORCE_INLINE int32_t tEncodeSMqSubConsumer(void** buf, const SMqSubConsum
int32_t
tlen
=
0
;
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
consumerId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
consumerId
);
int32_t
sz
=
taosArrayGetSize
(
pConsumer
->
vgInfo
);
int32_t
sz
=
taosArrayGetSize
(
pConsumer
->
vgInfo
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
*
pCEp
=
taosArrayGet
(
pConsumer
->
vgInfo
,
i
);
SMqConsumerEp
*
pCEp
=
taosArrayGet
(
pConsumer
->
vgInfo
,
i
);
tlen
+=
tEncodeSMqConsumerEp
(
buf
,
pCEp
);
tlen
+=
tEncodeSMqConsumerEp
(
buf
,
pCEp
);
...
@@ -498,9 +499,9 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub)
...
@@ -498,9 +499,9 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub)
return
NULL
;
return
NULL
;
}
}
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
cEp
=
{
0
};
SMqConsumerEp
c
onsumer
Ep
=
{
0
};
buf
=
tDecodeSMqConsumerEp
(
buf
,
&
cEp
);
buf
=
tDecodeSMqConsumerEp
(
buf
,
&
c
onsumer
Ep
);
taosArrayPush
(
pSub
->
unassignedVg
,
&
cEp
);
taosArrayPush
(
pSub
->
unassignedVg
,
&
c
onsumer
Ep
);
}
}
return
buf
;
return
buf
;
}
}
...
@@ -539,7 +540,8 @@ typedef struct {
...
@@ -539,7 +540,8 @@ typedef struct {
int64_t
connId
;
int64_t
connId
;
SRWLatch
lock
;
SRWLatch
lock
;
char
cgroup
[
TSDB_CONSUMER_GROUP_LEN
];
char
cgroup
[
TSDB_CONSUMER_GROUP_LEN
];
SArray
*
topics
;
// SArray<char*>
SArray
*
currentTopics
;
// SArray<char*>
SArray
*
recentRemovedTopics
;
// SArray<char*>
int64_t
epoch
;
int64_t
epoch
;
// stat
// stat
int64_t
pollCnt
;
int64_t
pollCnt
;
...
@@ -552,16 +554,25 @@ typedef struct {
...
@@ -552,16 +554,25 @@ typedef struct {
}
SMqConsumerObj
;
}
SMqConsumerObj
;
static
FORCE_INLINE
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
)
{
static
FORCE_INLINE
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
)
{
int32_t
sz
;
int32_t
tlen
=
0
;
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
consumerId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
consumerId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
connId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
connId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
epoch
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
epoch
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
pollCnt
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
pollCnt
);
tlen
+=
taosEncodeString
(
buf
,
pConsumer
->
cgroup
);
tlen
+=
taosEncodeString
(
buf
,
pConsumer
->
cgroup
);
int32_t
sz
=
taosArrayGetSize
(
pConsumer
->
topics
);
sz
=
taosArrayGetSize
(
pConsumer
->
currentTopics
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
currentTopics
,
i
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
}
sz
=
taosArrayGetSize
(
pConsumer
->
recentRemovedTopics
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
t
opics
,
i
);
char
*
topic
=
taosArrayGetP
(
pConsumer
->
recentRemovedT
opics
,
i
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
}
}
return
tlen
;
return
tlen
;
...
@@ -574,12 +585,21 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
...
@@ -574,12 +585,21 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
epoch
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
epoch
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
pollCnt
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
pollCnt
);
buf
=
taosDecodeStringTo
(
buf
,
pConsumer
->
cgroup
);
buf
=
taosDecodeStringTo
(
buf
,
pConsumer
->
cgroup
);
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
currentTopics
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerObj
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
;
buf
=
taosDecodeString
(
buf
,
&
topic
);
taosArrayPush
(
pConsumer
->
currentTopics
,
&
topic
);
}
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
t
opics
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerObj
));
pConsumer
->
recentRemovedT
opics
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerObj
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
;
char
*
topic
;
buf
=
taosDecodeString
(
buf
,
&
topic
);
buf
=
taosDecodeString
(
buf
,
&
topic
);
taosArrayPush
(
pConsumer
->
t
opics
,
&
topic
);
taosArrayPush
(
pConsumer
->
recentRemovedT
opics
,
&
topic
);
}
}
return
buf
;
return
buf
;
}
}
...
...
source/dnode/mnode/impl/inc/mndSubscribe.h
浏览文件 @
42da4f6f
...
@@ -25,7 +25,8 @@ extern "C" {
...
@@ -25,7 +25,8 @@ extern "C" {
int32_t
mndInitSubscribe
(
SMnode
*
pMnode
);
int32_t
mndInitSubscribe
(
SMnode
*
pMnode
);
void
mndCleanupSubscribe
(
SMnode
*
pMnode
);
void
mndCleanupSubscribe
(
SMnode
*
pMnode
);
SMqSubscribeObj
*
mndAcquireSubscribe
(
SMnode
*
pMnode
,
char
*
CGroup
,
char
*
topicName
);
SMqSubscribeObj
*
mndAcquireSubscribe
(
SMnode
*
pMnode
,
const
char
*
CGroup
,
const
char
*
topicName
);
SMqSubscribeObj
*
mndAcquireSubscribeByKey
(
SMnode
*
pMnode
,
const
char
*
key
);
void
mndReleaseSubscribe
(
SMnode
*
pMnode
,
SMqSubscribeObj
*
pSub
);
void
mndReleaseSubscribe
(
SMnode
*
pMnode
,
SMqSubscribeObj
*
pSub
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
source/dnode/mnode/impl/src/mndConsumer.c
浏览文件 @
42da4f6f
...
@@ -61,6 +61,7 @@ SMqConsumerObj* mndCreateConsumer(int64_t consumerId, const char* cgroup) {
...
@@ -61,6 +61,7 @@ SMqConsumerObj* mndCreateConsumer(int64_t consumerId, const char* cgroup) {
}
}
pConsumer
->
epoch
=
1
;
pConsumer
->
epoch
=
1
;
pConsumer
->
consumerId
=
consumerId
;
pConsumer
->
consumerId
=
consumerId
;
pConsumer
->
status
=
MQ_CONSUMER_STATUS__INIT
;
strcpy
(
pConsumer
->
cgroup
,
cgroup
);
strcpy
(
pConsumer
->
cgroup
,
cgroup
);
taosInitRWLatch
(
&
pConsumer
->
lock
);
taosInitRWLatch
(
&
pConsumer
->
lock
);
return
pConsumer
;
return
pConsumer
;
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
42da4f6f
此差异已折叠。
点击以展开。
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
42da4f6f
...
@@ -107,7 +107,7 @@ static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
...
@@ -107,7 +107,7 @@ static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
return
hash
;
return
hash
;
}
}
static
int32_t
sdbGetkeySize
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pKey
)
{
static
int32_t
sdbGetkeySize
(
SSdb
*
pSdb
,
ESdbType
type
,
const
void
*
pKey
)
{
int32_t
keySize
;
int32_t
keySize
;
EKeyType
keyType
=
pSdb
->
keyTypes
[
type
];
EKeyType
keyType
=
pSdb
->
keyTypes
[
type
];
...
@@ -263,7 +263,7 @@ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
...
@@ -263,7 +263,7 @@ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
return
code
;
return
code
;
}
}
void
*
sdbAcquire
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pKey
)
{
void
*
sdbAcquire
(
SSdb
*
pSdb
,
ESdbType
type
,
const
void
*
pKey
)
{
terrno
=
0
;
terrno
=
0
;
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
type
);
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
type
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录