Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9e78a4c5
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看板
未验证
提交
9e78a4c5
编写于
6月 15, 2023
作者:
H
Haojun Liao
提交者:
GitHub
6月 15, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21741 from taosdata/fix/TS-3540
fix:control memory size if consumer group is too much
上级
f1edb498
a17a8cc1
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
406 addition
and
319 deletion
+406
-319
include/common/tmsg.h
include/common/tmsg.h
+11
-0
include/libs/wal/wal.h
include/libs/wal/wal.h
+0
-1
include/util/talgo.h
include/util/talgo.h
+1
-1
include/util/tarray.h
include/util/tarray.h
+1
-1
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+28
-25
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+1
-1
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+158
-73
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+10
-14
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+38
-11
source/dnode/vnode/src/inc/tq.h
source/dnode/vnode/src/inc/tq.h
+3
-0
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+16
-86
source/dnode/vnode/src/tq/tqMeta.c
source/dnode/vnode/src/tq/tqMeta.c
+137
-80
source/libs/wal/src/walRef.c
source/libs/wal/src/walRef.c
+0
-24
source/util/src/tarray.c
source/util/src/tarray.c
+2
-2
未找到文件。
include/common/tmsg.h
浏览文件 @
9e78a4c5
...
...
@@ -3354,6 +3354,17 @@ static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
taosArrayDestroyEx
(
pRsp
->
topics
,
(
FDelete
)
tDeleteMqSubTopicEp
);
}
typedef
struct
{
int32_t
vgId
;
STqOffsetVal
offset
;
int64_t
rows
;
}
OffsetRows
;
typedef
struct
{
char
topicName
[
TSDB_TOPIC_FNAME_LEN
];
SArray
*
offsetRows
;
}
TopicOffsetRows
;
#define TD_AUTO_CREATE_TABLE 0x1
typedef
struct
{
int64_t
suid
;
...
...
include/libs/wal/wal.h
浏览文件 @
9e78a4c5
...
...
@@ -214,7 +214,6 @@ int32_t walSkipFetchBody(SWalReader *pRead, const SWalCkHead *pHead);
void
walRefFirstVer
(
SWal
*
,
SWalRef
*
);
void
walRefLastVer
(
SWal
*
,
SWalRef
*
);
SWalRef
*
walRefCommittedVer
(
SWal
*
);
SWalRef
*
walOpenRef
(
SWal
*
);
void
walCloseRef
(
SWal
*
pWal
,
int64_t
refId
);
...
...
include/util/talgo.h
浏览文件 @
9e78a4c5
...
...
@@ -31,7 +31,7 @@ typedef void *(*__array_item_dup_fn_t)(void *);
typedef
void
(
*
FDelete
)(
void
*
);
typedef
int32_t
(
*
FEncode
)(
void
**
buf
,
const
void
*
dst
);
typedef
void
*
(
*
FDecode
)(
const
void
*
buf
,
void
*
dst
);
typedef
void
*
(
*
FDecode
)(
const
void
*
buf
,
void
*
dst
,
int8_t
sver
);
#define TD_EQ 0x1
#define TD_GT 0x2
...
...
include/util/tarray.h
浏览文件 @
9e78a4c5
...
...
@@ -244,7 +244,7 @@ int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t
void
taosArraySortPWithExt
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
);
int32_t
taosEncodeArray
(
void
**
buf
,
const
SArray
*
pArray
,
FEncode
encode
);
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
);
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
,
int8_t
sver
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
9e78a4c5
...
...
@@ -559,24 +559,25 @@ void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer
typedef
struct
{
int32_t
vgId
;
char
*
qmsg
;
// SubPlanToString
//
char* qmsg; // SubPlanToString
SEpSet
epSet
;
}
SMqVgEp
;
SMqVgEp
*
tCloneSMqVgEp
(
const
SMqVgEp
*
pVgEp
);
void
tDeleteSMqVgEp
(
SMqVgEp
*
pVgEp
);
int32_t
tEncodeSMqVgEp
(
void
**
buf
,
const
SMqVgEp
*
pVgEp
);
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
);
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
,
int8_t
sver
);
typedef
struct
{
int64_t
consumerId
;
// -1 for unassigned
SArray
*
vgs
;
// SArray<SMqVgEp*>
SArray
*
offsetRows
;
// SArray<OffsetRows*>
}
SMqConsumerEp
;
SMqConsumerEp
*
tCloneSMqConsumerEp
(
const
SMqConsumerEp
*
pEp
);
void
tDeleteSMqConsumerEp
(
void
*
pEp
);
int32_t
tEncodeSMqConsumerEp
(
void
**
buf
,
const
SMqConsumerEp
*
pEp
);
void
*
tDecodeSMqConsumerEp
(
const
void
*
buf
,
SMqConsumerEp
*
pEp
);
void
*
tDecodeSMqConsumerEp
(
const
void
*
buf
,
SMqConsumerEp
*
pEp
,
int8_t
sver
);
typedef
struct
{
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
...
...
@@ -588,34 +589,36 @@ typedef struct {
int64_t
stbUid
;
SHashObj
*
consumerHash
;
// consumerId -> SMqConsumerEp
SArray
*
unassignedVgs
;
// SArray<SMqVgEp*>
SArray
*
offsetRows
;
char
dbName
[
TSDB_DB_FNAME_LEN
];
char
*
qmsg
;
// SubPlanToString
}
SMqSubscribeObj
;
SMqSubscribeObj
*
tNewSubscribeObj
(
const
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
]);
SMqSubscribeObj
*
tCloneSubscribeObj
(
const
SMqSubscribeObj
*
pSub
);
void
tDeleteSubscribeObj
(
SMqSubscribeObj
*
pSub
);
int32_t
tEncodeSubscribeObj
(
void
**
buf
,
const
SMqSubscribeObj
*
pSub
);
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
);
typedef
struct
{
int32_t
epoch
;
SArray
*
consumers
;
// SArray<SMqConsumerEp*>
}
SMqSubActionLogEntry
;
SMqSubActionLogEntry
*
tCloneSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
);
void
tDeleteSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
);
int32_t
tEncodeSMqSubActionLogEntry
(
void
**
buf
,
const
SMqSubActionLogEntry
*
pEntry
);
void
*
tDecodeSMqSubActionLogEntry
(
const
void
*
buf
,
SMqSubActionLogEntry
*
pEntry
);
typedef
struct
{
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
SArray
*
logs
;
// SArray<SMqSubActionLogEntry*>
}
SMqSubActionLogObj
;
SMqSubActionLogObj
*
tCloneSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
);
void
tDeleteSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
);
int32_t
tEncodeSMqSubActionLogObj
(
void
**
buf
,
const
SMqSubActionLogObj
*
pLog
);
void
*
tDecodeSMqSubActionLogObj
(
const
void
*
buf
,
SMqSubActionLogObj
*
pLog
);
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
,
int8_t
sver
);
//
typedef struct {
//
int32_t epoch;
//
SArray* consumers; // SArray<SMqConsumerEp*>
//
} SMqSubActionLogEntry;
//
SMqSubActionLogEntry* tCloneSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry);
//
void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry);
//
int32_t tEncodeSMqSubActionLogEntry(void** buf, const SMqSubActionLogEntry* pEntry);
//
void* tDecodeSMqSubActionLogEntry(const void* buf, SMqSubActionLogEntry* pEntry);
//
//
typedef struct {
//
char key[TSDB_SUBSCRIBE_KEY_LEN];
//
SArray* logs; // SArray<SMqSubActionLogEntry*>
//
} SMqSubActionLogObj;
//
//
SMqSubActionLogObj* tCloneSMqSubActionLogObj(SMqSubActionLogObj* pLog);
//
void tDeleteSMqSubActionLogObj(SMqSubActionLogObj* pLog);
//
int32_t tEncodeSMqSubActionLogObj(void** buf, const SMqSubActionLogObj* pLog);
//
void* tDecodeSMqSubActionLogObj(const void* buf, SMqSubActionLogObj* pLog);
typedef
struct
{
int32_t
oldConsumerNum
;
...
...
@@ -634,7 +637,7 @@ typedef struct {
SArray
*
removedConsumers
;
// SArray<int64_t>
SArray
*
modifyConsumers
;
// SArray<int64_t>
SMqSubscribeObj
*
pSub
;
SMqSubActionLogEntry
*
pLogEntry
;
//
SMqSubActionLogEntry* pLogEntry;
}
SMqRebOutputObj
;
typedef
struct
{
...
...
source/dnode/mnode/impl/src/mndConsumer.c
浏览文件 @
9e78a4c5
...
...
@@ -644,7 +644,7 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
SCMSubscribeReq
subscribe
=
{
0
};
tDeserializeSCMSubscribeReq
(
msgStr
,
&
subscribe
);
u
int64_t
consumerId
=
subscribe
.
consumerId
;
int64_t
consumerId
=
subscribe
.
consumerId
;
char
*
cgroup
=
subscribe
.
cgroup
;
SMqConsumerObj
*
pExistedConsumer
=
NULL
;
SMqConsumerObj
*
pConsumerNew
=
NULL
;
...
...
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
9e78a4c5
...
...
@@ -187,14 +187,14 @@ SMqVgEp *tCloneSMqVgEp(const SMqVgEp *pVgEp) {
SMqVgEp
*
pVgEpNew
=
taosMemoryMalloc
(
sizeof
(
SMqVgEp
));
if
(
pVgEpNew
==
NULL
)
return
NULL
;
pVgEpNew
->
vgId
=
pVgEp
->
vgId
;
pVgEpNew
->
qmsg
=
taosStrdup
(
pVgEp
->
qmsg
);
//
pVgEpNew->qmsg = taosStrdup(pVgEp->qmsg);
pVgEpNew
->
epSet
=
pVgEp
->
epSet
;
return
pVgEpNew
;
}
void
tDeleteSMqVgEp
(
SMqVgEp
*
pVgEp
)
{
if
(
pVgEp
)
{
taosMemoryFreeClear
(
pVgEp
->
qmsg
);
//
taosMemoryFreeClear(pVgEp->qmsg);
taosMemoryFree
(
pVgEp
);
}
}
...
...
@@ -202,14 +202,18 @@ void tDeleteSMqVgEp(SMqVgEp *pVgEp) {
int32_t
tEncodeSMqVgEp
(
void
**
buf
,
const
SMqVgEp
*
pVgEp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pVgEp
->
vgId
);
tlen
+=
taosEncodeString
(
buf
,
pVgEp
->
qmsg
);
//
tlen += taosEncodeString(buf, pVgEp->qmsg);
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
tlen
;
}
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
)
{
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
,
int8_t
sver
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pVgEp
->
vgId
);
buf
=
taosDecodeString
(
buf
,
&
pVgEp
->
qmsg
);
if
(
sver
==
1
){
uint64_t
size
=
0
;
buf
=
taosDecodeVariantU64
(
buf
,
&
size
);
buf
=
POINTER_SHIFT
(
buf
,
size
);
}
buf
=
taosDecodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
(
void
*
)
buf
;
}
...
...
@@ -395,6 +399,22 @@ int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumerEp
->
consumerId
);
tlen
+=
taosEncodeArray
(
buf
,
pConsumerEp
->
vgs
,
(
FEncode
)
tEncodeSMqVgEp
);
int32_t
szVgs
=
taosArrayGetSize
(
pConsumerEp
->
offsetRows
);
tlen
+=
taosEncodeFixedI32
(
buf
,
szVgs
);
for
(
int32_t
j
=
0
;
j
<
szVgs
;
++
j
)
{
OffsetRows
*
offRows
=
taosArrayGet
(
pConsumerEp
->
offsetRows
,
j
);
tlen
+=
taosEncodeFixedI32
(
buf
,
offRows
->
vgId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
rows
);
tlen
+=
taosEncodeFixedI8
(
buf
,
offRows
->
offset
.
type
);
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_DATA
||
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_META
)
{
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
offset
.
uid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
offset
.
ts
);
}
else
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__LOG
)
{
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
offset
.
version
);
}
else
{
// do nothing
}
}
#if 0
int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
tlen += taosEncodeFixedI32(buf, sz);
...
...
@@ -406,9 +426,9 @@ int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
return
tlen
;
}
void
*
tDecodeSMqConsumerEp
(
const
void
*
buf
,
SMqConsumerEp
*
pConsumerEp
)
{
void
*
tDecodeSMqConsumerEp
(
const
void
*
buf
,
SMqConsumerEp
*
pConsumerEp
,
int8_t
sver
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumerEp
->
consumerId
);
buf
=
taosDecodeArray
(
buf
,
&
pConsumerEp
->
vgs
,
(
FDecode
)
tDecodeSMqVgEp
,
sizeof
(
SMqVgEp
));
buf
=
taosDecodeArray
(
buf
,
&
pConsumerEp
->
vgs
,
(
FDecode
)
tDecodeSMqVgEp
,
sizeof
(
SMqVgEp
)
,
sver
);
#if 0
int32_t sz;
buf = taosDecodeFixedI32(buf, &sz);
...
...
@@ -419,7 +439,28 @@ void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp) {
taosArrayPush(pConsumerEp->vgs, &pVgEp);
}
#endif
if
(
sver
>
1
){
int32_t
szVgs
=
0
;
buf
=
taosDecodeFixedI32
(
buf
,
&
szVgs
);
if
(
szVgs
>
0
){
pConsumerEp
->
offsetRows
=
taosArrayInit
(
szVgs
,
sizeof
(
OffsetRows
));
if
(
NULL
==
pConsumerEp
->
offsetRows
)
return
NULL
;
for
(
int32_t
j
=
0
;
j
<
szVgs
;
++
j
)
{
OffsetRows
*
offRows
=
taosArrayReserve
(
pConsumerEp
->
offsetRows
,
1
);
buf
=
taosDecodeFixedI32
(
buf
,
&
offRows
->
vgId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
rows
);
buf
=
taosDecodeFixedI8
(
buf
,
&
offRows
->
offset
.
type
);
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_DATA
||
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_META
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
offset
.
uid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
offset
.
ts
);
}
else
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__LOG
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
offset
.
version
);
}
else
{
// do nothing
}
}
}
}
return
(
void
*
)
buf
;
}
...
...
@@ -468,7 +509,9 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
taosHashPut
(
pSubNew
->
consumerHash
,
&
newEp
.
consumerId
,
sizeof
(
int64_t
),
&
newEp
,
sizeof
(
SMqConsumerEp
));
}
pSubNew
->
unassignedVgs
=
taosArrayDup
(
pSub
->
unassignedVgs
,
(
__array_item_dup_fn_t
)
tCloneSMqVgEp
);
pSubNew
->
offsetRows
=
taosArrayDup
(
pSub
->
offsetRows
,
NULL
);
memcpy
(
pSubNew
->
dbName
,
pSub
->
dbName
,
TSDB_DB_FNAME_LEN
);
pSubNew
->
qmsg
=
taosStrdup
(
pSub
->
qmsg
);
return
pSubNew
;
}
...
...
@@ -482,6 +525,8 @@ void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
}
taosHashCleanup
(
pSub
->
consumerHash
);
taosArrayDestroyP
(
pSub
->
unassignedVgs
,
(
FDelete
)
tDeleteSMqVgEp
);
taosMemoryFreeClear
(
pSub
->
qmsg
);
taosArrayDestroy
(
pSub
->
offsetRows
);
}
int32_t
tEncodeSubscribeObj
(
void
**
buf
,
const
SMqSubscribeObj
*
pSub
)
{
...
...
@@ -508,10 +553,27 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
if
(
cnt
!=
sz
)
return
-
1
;
tlen
+=
taosEncodeArray
(
buf
,
pSub
->
unassignedVgs
,
(
FEncode
)
tEncodeSMqVgEp
);
tlen
+=
taosEncodeString
(
buf
,
pSub
->
dbName
);
int32_t
szVgs
=
taosArrayGetSize
(
pSub
->
offsetRows
);
tlen
+=
taosEncodeFixedI32
(
buf
,
szVgs
);
for
(
int32_t
j
=
0
;
j
<
szVgs
;
++
j
)
{
OffsetRows
*
offRows
=
taosArrayGet
(
pSub
->
offsetRows
,
j
);
tlen
+=
taosEncodeFixedI32
(
buf
,
offRows
->
vgId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
rows
);
tlen
+=
taosEncodeFixedI8
(
buf
,
offRows
->
offset
.
type
);
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_DATA
||
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_META
)
{
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
offset
.
uid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
offset
.
ts
);
}
else
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__LOG
)
{
tlen
+=
taosEncodeFixedI64
(
buf
,
offRows
->
offset
.
version
);
}
else
{
// do nothing
}
}
tlen
+=
taosEncodeString
(
buf
,
pSub
->
qmsg
);
return
tlen
;
}
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
)
{
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
,
int8_t
sver
)
{
//
buf
=
taosDecodeStringTo
(
buf
,
pSub
->
key
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSub
->
dbUid
);
...
...
@@ -526,74 +588,97 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) {
pSub
->
consumerHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_NO_LOCK
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
consumerEp
=
{
0
};
buf
=
tDecodeSMqConsumerEp
(
buf
,
&
consumerEp
);
buf
=
tDecodeSMqConsumerEp
(
buf
,
&
consumerEp
,
sver
);
taosHashPut
(
pSub
->
consumerHash
,
&
consumerEp
.
consumerId
,
sizeof
(
int64_t
),
&
consumerEp
,
sizeof
(
SMqConsumerEp
));
}
buf
=
taosDecodeArray
(
buf
,
&
pSub
->
unassignedVgs
,
(
FDecode
)
tDecodeSMqVgEp
,
sizeof
(
SMqVgEp
));
buf
=
taosDecodeArray
(
buf
,
&
pSub
->
unassignedVgs
,
(
FDecode
)
tDecodeSMqVgEp
,
sizeof
(
SMqVgEp
)
,
sver
);
buf
=
taosDecodeStringTo
(
buf
,
pSub
->
dbName
);
if
(
sver
>
1
){
int32_t
szVgs
=
0
;
buf
=
taosDecodeFixedI32
(
buf
,
&
szVgs
);
if
(
szVgs
>
0
){
pSub
->
offsetRows
=
taosArrayInit
(
szVgs
,
sizeof
(
OffsetRows
));
if
(
NULL
==
pSub
->
offsetRows
)
return
NULL
;
for
(
int32_t
j
=
0
;
j
<
szVgs
;
++
j
)
{
OffsetRows
*
offRows
=
taosArrayReserve
(
pSub
->
offsetRows
,
1
);
buf
=
taosDecodeFixedI32
(
buf
,
&
offRows
->
vgId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
rows
);
buf
=
taosDecodeFixedI8
(
buf
,
&
offRows
->
offset
.
type
);
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_DATA
||
offRows
->
offset
.
type
==
TMQ_OFFSET__SNAPSHOT_META
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
offset
.
uid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
offset
.
ts
);
}
else
if
(
offRows
->
offset
.
type
==
TMQ_OFFSET__LOG
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
offRows
->
offset
.
version
);
}
else
{
// do nothing
}
}
}
buf
=
taosDecodeString
(
buf
,
&
pSub
->
qmsg
);
}
return
(
void
*
)
buf
;
}
SMqSubActionLogEntry
*
tCloneSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
)
{
SMqSubActionLogEntry
*
pEntryNew
=
taosMemoryMalloc
(
sizeof
(
SMqSubActionLogEntry
));
if
(
pEntryNew
==
NULL
)
return
NULL
;
pEntryNew
->
epoch
=
pEntry
->
epoch
;
pEntryNew
->
consumers
=
taosArrayDup
(
pEntry
->
consumers
,
(
__array_item_dup_fn_t
)
tCloneSMqConsumerEp
);
return
pEntryNew
;
}
void
tDeleteSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
)
{
taosArrayDestroyEx
(
pEntry
->
consumers
,
(
FDelete
)
tDeleteSMqConsumerEp
);
}
int32_t
tEncodeSMqSubActionLogEntry
(
void
**
buf
,
const
SMqSubActionLogEntry
*
pEntry
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pEntry
->
epoch
);
tlen
+=
taosEncodeArray
(
buf
,
pEntry
->
consumers
,
(
FEncode
)
tEncodeSMqSubActionLogEntry
);
return
tlen
;
}
void
*
tDecodeSMqSubActionLogEntry
(
const
void
*
buf
,
SMqSubActionLogEntry
*
pEntry
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pEntry
->
epoch
);
buf
=
taosDecodeArray
(
buf
,
&
pEntry
->
consumers
,
(
FDecode
)
tDecodeSMqSubActionLogEntry
,
sizeof
(
SMqSubActionLogEntry
));
return
(
void
*
)
buf
;
}
SMqSubActionLogObj
*
tCloneSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
)
{
SMqSubActionLogObj
*
pLogNew
=
taosMemoryMalloc
(
sizeof
(
SMqSubActionLogObj
));
if
(
pLogNew
==
NULL
)
return
pLogNew
;
memcpy
(
pLogNew
->
key
,
pLog
->
key
,
TSDB_SUBSCRIBE_KEY_LEN
);
pLogNew
->
logs
=
taosArrayDup
(
pLog
->
logs
,
(
__array_item_dup_fn_t
)
tCloneSMqConsumerEp
);
return
pLogNew
;
}
void
tDeleteSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
)
{
taosArrayDestroyEx
(
pLog
->
logs
,
(
FDelete
)
tDeleteSMqConsumerEp
);
}
int32_t
tEncodeSMqSubActionLogObj
(
void
**
buf
,
const
SMqSubActionLogObj
*
pLog
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pLog
->
key
);
tlen
+=
taosEncodeArray
(
buf
,
pLog
->
logs
,
(
FEncode
)
tEncodeSMqSubActionLogEntry
);
return
tlen
;
}
void
*
tDecodeSMqSubActionLogObj
(
const
void
*
buf
,
SMqSubActionLogObj
*
pLog
)
{
buf
=
taosDecodeStringTo
(
buf
,
pLog
->
key
);
buf
=
taosDecodeArray
(
buf
,
&
pLog
->
logs
,
(
FDecode
)
tDecodeSMqSubActionLogEntry
,
sizeof
(
SMqSubActionLogEntry
));
return
(
void
*
)
buf
;
}
int32_t
tEncodeSMqOffsetObj
(
void
**
buf
,
const
SMqOffsetObj
*
pOffset
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pOffset
->
key
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pOffset
->
offset
);
return
tlen
;
}
void
*
tDecodeSMqOffsetObj
(
void
*
buf
,
SMqOffsetObj
*
pOffset
)
{
buf
=
taosDecodeStringTo
(
buf
,
pOffset
->
key
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pOffset
->
offset
);
return
buf
;
}
//
SMqSubActionLogEntry *tCloneSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
//
SMqSubActionLogEntry *pEntryNew = taosMemoryMalloc(sizeof(SMqSubActionLogEntry));
//
if (pEntryNew == NULL) return NULL;
//
pEntryNew->epoch = pEntry->epoch;
//
pEntryNew->consumers = taosArrayDup(pEntry->consumers, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
//
return pEntryNew;
//
}
//
//
void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
//
taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEp);
//
}
//
//
int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) {
//
int32_t tlen = 0;
//
tlen += taosEncodeFixedI32(buf, pEntry->epoch);
//
tlen += taosEncodeArray(buf, pEntry->consumers, (FEncode)tEncodeSMqSubActionLogEntry);
//
return tlen;
//
}
//
//
void *tDecodeSMqSubActionLogEntry(const void *buf, SMqSubActionLogEntry *pEntry) {
//
buf = taosDecodeFixedI32(buf, &pEntry->epoch);
//
buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
//
return (void *)buf;
//
}
//
//
SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
//
SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj));
//
if (pLogNew == NULL) return pLogNew;
//
memcpy(pLogNew->key, pLog->key, TSDB_SUBSCRIBE_KEY_LEN);
//
pLogNew->logs = taosArrayDup(pLog->logs, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
//
return pLogNew;
//
}
//
//
void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
//
taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEp);
//
}
//
//
int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) {
//
int32_t tlen = 0;
//
tlen += taosEncodeString(buf, pLog->key);
//
tlen += taosEncodeArray(buf, pLog->logs, (FEncode)tEncodeSMqSubActionLogEntry);
//
return tlen;
//
}
//
//
void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) {
//
buf = taosDecodeStringTo(buf, pLog->key);
//
buf = taosDecodeArray(buf, &pLog->logs, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
//
return (void *)buf;
//
}
//
//
int32_t tEncodeSMqOffsetObj(void **buf, const SMqOffsetObj *pOffset) {
//
int32_t tlen = 0;
//
tlen += taosEncodeString(buf, pOffset->key);
//
tlen += taosEncodeFixedI64(buf, pOffset->offset);
//
return tlen;
//
}
//
//
void *tDecodeSMqOffsetObj(void *buf, SMqOffsetObj *pOffset) {
//
buf = taosDecodeStringTo(buf, pOffset->key);
//
buf = taosDecodeFixedI64(buf, &pOffset->offset);
//
return buf;
//
}
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
9e78a4c5
...
...
@@ -570,23 +570,19 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
mDebug
(
"init subscription %s for topic:%s assign vgId:%d"
,
pSub
->
key
,
pTopic
->
name
,
pVgEp
->
vgId
);
sdbRelease
(
pSdb
,
pVgroup
);
}
if
(
pSubplan
)
{
int32_t
msgLen
;
pSubplan
->
execNode
.
epSet
=
pVgEp
->
epSet
;
pSubplan
->
execNode
.
nodeId
=
pVgEp
->
vgId
;
if
(
qSubPlanToString
(
pSubplan
,
&
pVgEp
->
qmsg
,
&
msgLen
)
<
0
)
{
sdbRelease
(
pSdb
,
pVgroup
);
if
(
qSubPlanToString
(
pSubplan
,
&
pSub
->
qmsg
,
&
msgLen
)
<
0
)
{
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
-
1
;
}
}
else
{
pVgEp
->
qmsg
=
taosStrdup
(
""
);
}
sdbRelease
(
pSdb
,
pVgroup
);
pSub
->
qmsg
=
taosStrdup
(
""
);
}
qDestroyQueryPlan
(
pPlan
);
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
9e78a4c5
...
...
@@ -24,7 +24,7 @@
#include "tcompare.h"
#include "tname.h"
#define MND_SUBSCRIBE_VER_NUMBER
1
#define MND_SUBSCRIBE_VER_NUMBER
2
#define MND_SUBSCRIBE_RESERVE_SIZE 64
#define MND_SUBSCRIBE_REBALANCE_CNT 3
...
...
@@ -99,13 +99,23 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj
return
pSub
;
}
static
int32_t
mndBuildSubChangeReq
(
void
**
pBuf
,
int32_t
*
pLen
,
const
SMqSubscribeObj
*
pSub
,
const
SMqRebOutputVg
*
pRebVg
)
{
static
int32_t
mndBuildSubChangeReq
(
void
**
pBuf
,
int32_t
*
pLen
,
SMqSubscribeObj
*
pSub
,
const
SMqRebOutputVg
*
pRebVg
,
SSubplan
*
pPlan
)
{
SMqRebVgReq
req
=
{
0
};
req
.
oldConsumerId
=
pRebVg
->
oldConsumerId
;
req
.
newConsumerId
=
pRebVg
->
newConsumerId
;
req
.
vgId
=
pRebVg
->
pVgEp
->
vgId
;
req
.
qmsg
=
pRebVg
->
pVgEp
->
qmsg
;
if
(
pPlan
){
pPlan
->
execNode
.
epSet
=
pRebVg
->
pVgEp
->
epSet
;
pPlan
->
execNode
.
nodeId
=
pRebVg
->
pVgEp
->
vgId
;
int32_t
msgLen
;
if
(
qSubPlanToString
(
pPlan
,
&
req
.
qmsg
,
&
msgLen
)
<
0
)
{
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
-
1
;
}
}
else
{
req
.
qmsg
=
taosStrdup
(
""
);
}
req
.
subType
=
pSub
->
subType
;
req
.
withMeta
=
pSub
->
withMeta
;
req
.
suid
=
pSub
->
stbUid
;
...
...
@@ -115,6 +125,7 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
int32_t
ret
=
0
;
tEncodeSize
(
tEncodeSMqRebVgReq
,
&
req
,
tlen
,
ret
);
if
(
ret
<
0
)
{
taosMemoryFree
(
req
.
qmsg
);
return
-
1
;
}
...
...
@@ -122,6 +133,7 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
void
*
buf
=
taosMemoryMalloc
(
tlen
);
if
(
buf
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
taosMemoryFree
(
req
.
qmsg
);
return
-
1
;
}
...
...
@@ -135,17 +147,19 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
if
(
tEncodeSMqRebVgReq
(
&
encoder
,
&
req
)
<
0
)
{
taosMemoryFreeClear
(
buf
);
tEncoderClear
(
&
encoder
);
taosMemoryFree
(
req
.
qmsg
);
return
-
1
;
}
tEncoderClear
(
&
encoder
);
*
pBuf
=
buf
;
*
pLen
=
tlen
;
taosMemoryFree
(
req
.
qmsg
);
return
0
;
}
static
int32_t
mndPersistSubChangeVgReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqSubscribeObj
*
pSub
,
const
SMqRebOutputVg
*
pRebVg
)
{
static
int32_t
mndPersistSubChangeVgReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMqSubscribeObj
*
pSub
,
const
SMqRebOutputVg
*
pRebVg
,
SSubplan
*
pPlan
)
{
// if (pRebVg->oldConsumerId == pRebVg->newConsumerId) {
// terrno = TSDB_CODE_MND_INVALID_SUB_OPTION;
// return -1;
...
...
@@ -153,7 +167,7 @@ static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SM
void
*
buf
;
int32_t
tlen
;
if
(
mndBuildSubChangeReq
(
&
buf
,
&
tlen
,
pSub
,
pRebVg
)
<
0
)
{
if
(
mndBuildSubChangeReq
(
&
buf
,
&
tlen
,
pSub
,
pRebVg
,
pPlan
)
<
0
)
{
return
-
1
;
}
...
...
@@ -255,7 +269,7 @@ static void doAddNewConsumers(SMqRebOutputObj *pOutput, const SMqRebInputObj *pI
for
(
int32_t
i
=
0
;
i
<
numOfNewConsumers
;
i
++
)
{
int64_t
consumerId
=
*
(
int64_t
*
)
taosArrayGet
(
pInput
->
pRebInfo
->
newConsumers
,
i
);
SMqConsumerEp
newConsumerEp
;
SMqConsumerEp
newConsumerEp
=
{
0
}
;
newConsumerEp
.
consumerId
=
consumerId
;
newConsumerEp
.
vgs
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
...
...
@@ -483,14 +497,25 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
}
static
int32_t
mndPersistRebResult
(
SMnode
*
pMnode
,
SRpcMsg
*
pMsg
,
const
SMqRebOutputObj
*
pOutput
)
{
struct
SSubplan
*
pPlan
=
NULL
;
if
(
strcmp
(
pOutput
->
pSub
->
qmsg
,
""
)
!=
0
){
int32_t
code
=
qStringToSubplan
(
pOutput
->
pSub
->
qmsg
,
&
pPlan
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
return
-
1
;
}
}
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_CONFLICT_DB_INSIDE
,
pMsg
,
"tmq-reb"
);
if
(
pTrans
==
NULL
)
{
nodesDestroyNode
((
SNode
*
)
pPlan
);
return
-
1
;
}
mndTransSetDbName
(
pTrans
,
pOutput
->
pSub
->
dbName
,
NULL
);
if
(
mndTrancCheckConflict
(
pMnode
,
pTrans
)
!=
0
)
{
mndTransDrop
(
pTrans
);
nodesDestroyNode
((
SNode
*
)
pPlan
);
return
-
1
;
}
...
...
@@ -500,11 +525,13 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
int32_t
vgNum
=
taosArrayGetSize
(
rebVgs
);
for
(
int32_t
i
=
0
;
i
<
vgNum
;
i
++
)
{
SMqRebOutputVg
*
pRebVg
=
taosArrayGet
(
rebVgs
,
i
);
if
(
mndPersistSubChangeVgReq
(
pMnode
,
pTrans
,
pOutput
->
pSub
,
pRebVg
)
<
0
)
{
if
(
mndPersistSubChangeVgReq
(
pMnode
,
pTrans
,
pOutput
->
pSub
,
pRebVg
,
pPlan
)
<
0
)
{
mndTransDrop
(
pTrans
);
nodesDestroyNode
((
SNode
*
)
pPlan
);
return
-
1
;
}
}
nodesDestroyNode
((
SNode
*
)
pPlan
);
// 2. redo log: subscribe and vg assignment
// subscribe
...
...
@@ -809,7 +836,7 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
goto
SUB_DECODE_OVER
;
if
(
sver
!=
MND_SUBSCRIBE_VER_NUMBER
)
{
if
(
sver
>
MND_SUBSCRIBE_VER_NUMBER
||
sver
<
1
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
goto
SUB_DECODE_OVER
;
}
...
...
@@ -828,7 +855,7 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) {
SDB_GET_BINARY
(
pRaw
,
dataPos
,
buf
,
tlen
,
SUB_DECODE_OVER
);
SDB_GET_RESERVE
(
pRaw
,
dataPos
,
MND_SUBSCRIBE_RESERVE_SIZE
,
SUB_DECODE_OVER
);
if
(
tDecodeSubscribeObj
(
buf
,
pSub
)
==
NULL
)
{
if
(
tDecodeSubscribeObj
(
buf
,
pSub
,
sver
)
==
NULL
)
{
goto
SUB_DECODE_OVER
;
}
...
...
source/dnode/vnode/src/inc/tq.h
浏览文件 @
9e78a4c5
...
...
@@ -139,6 +139,7 @@ static STqMgmt tqMgmt = {0};
int32_t
tEncodeSTqHandle
(
SEncoder
*
pEncoder
,
const
STqHandle
*
pHandle
);
int32_t
tDecodeSTqHandle
(
SDecoder
*
pDecoder
,
STqHandle
*
pHandle
);
void
tqDestroyTqHandle
(
void
*
data
);
// tqRead
int32_t
tqScanTaosx
(
STQ
*
pTq
,
const
STqHandle
*
pHandle
,
STaosxRsp
*
pRsp
,
SMqMetaRsp
*
pMetaRsp
,
STqOffsetVal
*
offset
);
...
...
@@ -161,6 +162,8 @@ int32_t tqMetaRestoreHandle(STQ* pTq);
int32_t
tqMetaSaveCheckInfo
(
STQ
*
pTq
,
const
char
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
tqMetaDeleteCheckInfo
(
STQ
*
pTq
,
const
char
*
key
);
int32_t
tqMetaRestoreCheckInfo
(
STQ
*
pTq
);
int32_t
tqMetaGetHandle
(
STQ
*
pTq
,
const
char
*
key
);
int32_t
tqCreateHandle
(
STQ
*
pTq
,
SMqRebVgReq
*
req
,
STqHandle
*
handle
);
STqOffsetStore
*
tqOffsetOpen
(
STQ
*
pTq
);
void
tqOffsetClose
(
STqOffsetStore
*
);
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
9e78a4c5
...
...
@@ -62,7 +62,7 @@ void tqCleanUp() {
}
}
static
void
d
estroyTqHandle
(
void
*
data
)
{
void
tqD
estroyTqHandle
(
void
*
data
)
{
STqHandle
*
pData
=
(
STqHandle
*
)
data
;
qDestroyTask
(
pData
->
execHandle
.
task
);
...
...
@@ -102,7 +102,7 @@ STQ* tqOpen(const char* path, SVnode* pVnode) {
pTq
->
walLogLastVer
=
pVnode
->
pWal
->
vers
.
lastVer
;
pTq
->
pHandle
=
taosHashInit
(
64
,
MurmurHash3_32
,
true
,
HASH_ENTRY_LOCK
);
taosHashSetFreeFp
(
pTq
->
pHandle
,
d
estroyTqHandle
);
taosHashSetFreeFp
(
pTq
->
pHandle
,
tqD
estroyTqHandle
);
taosInitRWLatch
(
&
pTq
->
lock
);
pTq
->
pPushMgr
=
taosHashInit
(
64
,
MurmurHash3_32
,
false
,
HASH_NO_LOCK
);
...
...
@@ -690,103 +690,33 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
return
-
1
;
}
SVnode
*
pVnode
=
pTq
->
pVnode
;
int32_t
vgId
=
TD_VID
(
pVnode
);
tqDebug
(
"vgId:%d, tq process sub req:%s, Id:0x%"
PRIx64
" -> Id:0x%"
PRIx64
,
pVnode
->
config
.
vgId
,
req
.
subKey
,
tqDebug
(
"vgId:%d, tq process sub req:%s, Id:0x%"
PRIx64
" -> Id:0x%"
PRIx64
,
pTq
->
pVnode
->
config
.
vgId
,
req
.
subKey
,
req
.
oldConsumerId
,
req
.
newConsumerId
);
STqHandle
*
pHandle
=
taosHashGet
(
pTq
->
pHandle
,
req
.
subKey
,
strlen
(
req
.
subKey
));
STqHandle
*
pHandle
=
NULL
;
while
(
1
){
pHandle
=
taosHashGet
(
pTq
->
pHandle
,
req
.
subKey
,
strlen
(
req
.
subKey
));
if
(
pHandle
||
tqMetaGetHandle
(
pTq
,
req
.
subKey
)
<
0
){
break
;
}
}
if
(
pHandle
==
NULL
)
{
if
(
req
.
oldConsumerId
!=
-
1
)
{
tqError
(
"vgId:%d, build new consumer handle %s for consumer:0x%"
PRIx64
", but old consumerId:0x%"
PRIx64
,
req
.
vgId
,
req
.
subKey
,
req
.
newConsumerId
,
req
.
oldConsumerId
);
}
if
(
req
.
newConsumerId
==
-
1
)
{
tqError
(
"vgId:%d, tq invalid re-balance request, new consumerId %"
PRId64
""
,
req
.
vgId
,
req
.
newConsumerId
);
goto
end
;
}
STqHandle
tqHandle
=
{
0
};
pHandle
=
&
tqHandle
;
memcpy
(
pHandle
->
subKey
,
req
.
subKey
,
TSDB_SUBSCRIBE_KEY_LEN
);
pHandle
->
consumerId
=
req
.
newConsumerId
;
pHandle
->
epoch
=
-
1
;
pHandle
->
execHandle
.
subType
=
req
.
subType
;
pHandle
->
fetchMeta
=
req
.
withMeta
;
// TODO version should be assigned and refed during preprocess
SWalRef
*
pRef
=
walRefCommittedVer
(
pVnode
->
pWal
);
if
(
pRef
==
NULL
)
{
ret
=
-
1
;
goto
end
;
}
int64_t
ver
=
pRef
->
refVer
;
pHandle
->
pRef
=
pRef
;
SReadHandle
handle
=
{.
vnode
=
pVnode
,
.
initTableReader
=
true
,
.
initTqReader
=
true
,
.
version
=
ver
};
initStorageAPI
(
&
handle
.
api
);
pHandle
->
snapshotVer
=
ver
;
if
(
pHandle
->
execHandle
.
subType
==
TOPIC_SUB_TYPE__COLUMN
)
{
pHandle
->
execHandle
.
execCol
.
qmsg
=
taosStrdup
(
req
.
qmsg
);
pHandle
->
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
pHandle
->
execHandle
.
execCol
.
qmsg
,
&
handle
,
vgId
,
&
pHandle
->
execHandle
.
numOfCols
,
req
.
newConsumerId
);
void
*
scanner
=
NULL
;
qExtractStreamScanner
(
pHandle
->
execHandle
.
task
,
&
scanner
);
pHandle
->
execHandle
.
pTqReader
=
qExtractReaderFromStreamScanner
(
scanner
);
}
else
if
(
pHandle
->
execHandle
.
subType
==
TOPIC_SUB_TYPE__DB
)
{
pHandle
->
pWalReader
=
walOpenReader
(
pVnode
->
pWal
,
NULL
);
pHandle
->
execHandle
.
pTqReader
=
tqReaderOpen
(
pVnode
);
pHandle
->
execHandle
.
execDb
.
pFilterOutTbUid
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_ENTRY_LOCK
);
buildSnapContext
(
handle
.
vnode
,
handle
.
version
,
0
,
pHandle
->
execHandle
.
subType
,
pHandle
->
fetchMeta
,
(
SSnapContext
**
)(
&
handle
.
sContext
));
pHandle
->
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
NULL
,
&
handle
,
vgId
,
NULL
,
req
.
newConsumerId
);
}
else
if
(
pHandle
->
execHandle
.
subType
==
TOPIC_SUB_TYPE__TABLE
)
{
pHandle
->
pWalReader
=
walOpenReader
(
pVnode
->
pWal
,
NULL
);
pHandle
->
execHandle
.
execTb
.
suid
=
req
.
suid
;
pHandle
->
execHandle
.
execTb
.
qmsg
=
taosStrdup
(
req
.
qmsg
);
if
(
strcmp
(
pHandle
->
execHandle
.
execTb
.
qmsg
,
""
)
!=
0
)
{
if
(
nodesStringToNode
(
pHandle
->
execHandle
.
execTb
.
qmsg
,
&
pHandle
->
execHandle
.
execTb
.
node
)
!=
0
)
{
tqError
(
"nodesStringToNode error in sub stable, since %s, vgId:%d, subkey:%s consumer:0x%"
PRIx64
,
terrstr
(),
pVnode
->
config
.
vgId
,
req
.
subKey
,
pHandle
->
consumerId
);
return
-
1
;
}
}
buildSnapContext
(
handle
.
vnode
,
handle
.
version
,
req
.
suid
,
pHandle
->
execHandle
.
subType
,
pHandle
->
fetchMeta
,
(
SSnapContext
**
)(
&
handle
.
sContext
));
pHandle
->
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
NULL
,
&
handle
,
vgId
,
NULL
,
req
.
newConsumerId
);
SArray
*
tbUidList
=
NULL
;
ret
=
qGetTableList
(
req
.
suid
,
pVnode
,
pHandle
->
execHandle
.
execTb
.
node
,
&
tbUidList
,
pHandle
->
execHandle
.
task
);
if
(
ret
!=
TDB_CODE_SUCCESS
)
{
tqError
(
"qGetTableList error:%d vgId:%d, subkey:%s consumer:0x%"
PRIx64
,
ret
,
pVnode
->
config
.
vgId
,
req
.
subKey
,
pHandle
->
consumerId
);
taosArrayDestroy
(
tbUidList
);
STqHandle
handle
=
{
0
};
ret
=
tqCreateHandle
(
pTq
,
&
req
,
&
handle
);
if
(
ret
<
0
){
tqDestroyTqHandle
(
&
handle
);
goto
end
;
}
tqDebug
(
"tq try to get ctb for stb subscribe, vgId:%d, subkey:%s consumer:0x%"
PRIx64
" suid:%"
PRId64
,
pVnode
->
config
.
vgId
,
req
.
subKey
,
pHandle
->
consumerId
,
req
.
suid
);
pHandle
->
execHandle
.
pTqReader
=
tqReaderOpen
(
pVnode
);
tqReaderSetTbUidList
(
pHandle
->
execHandle
.
pTqReader
,
tbUidList
,
NULL
);
taosArrayDestroy
(
tbUidList
);
}
taosHashPut
(
pTq
->
pHandle
,
req
.
subKey
,
strlen
(
req
.
subKey
),
pHandle
,
sizeof
(
STqHandle
));
tqDebug
(
"try to persist handle %s consumer:0x%"
PRIx64
,
req
.
subKey
,
pHandle
->
consumerId
);
ret
=
tqMetaSaveHandle
(
pTq
,
req
.
subKey
,
pHandle
);
goto
end
;
ret
=
tqMetaSaveHandle
(
pTq
,
req
.
subKey
,
&
handle
);
}
else
{
taosWLockLatch
(
&
pTq
->
lock
);
...
...
source/dnode/vnode/src/tq/tqMeta.c
浏览文件 @
9e78a4c5
...
...
@@ -88,9 +88,9 @@ int32_t tqMetaOpen(STQ* pTq) {
return
-
1
;
}
if
(
tqMetaRestoreHandle
(
pTq
)
<
0
)
{
return
-
1
;
}
//
if (tqMetaRestoreHandle(pTq) < 0) {
//
return -1;
//
}
if
(
tqMetaRestoreCheckInfo
(
pTq
)
<
0
)
{
return
-
1
;
...
...
@@ -274,104 +274,161 @@ int32_t tqMetaDeleteHandle(STQ* pTq, const char* key) {
return
0
;
}
int32_t
tqMetaRestoreHandle
(
STQ
*
pTq
)
{
int
code
=
0
;
TBC
*
pCur
=
NULL
;
if
(
tdbTbcOpen
(
pTq
->
pExecStore
,
&
pCur
,
NULL
)
<
0
)
{
return
-
1
;
}
int32_t
vgId
=
TD_VID
(
pTq
->
pVnode
);
void
*
pKey
=
NULL
;
int
kLen
=
0
;
void
*
pVal
=
NULL
;
int
vLen
=
0
;
SDecoder
decoder
;
tdbTbcMoveToFirst
(
pCur
);
while
(
tdbTbcNext
(
pCur
,
&
pKey
,
&
kLen
,
&
pVal
,
&
vLen
)
==
0
)
{
STqHandle
handle
=
{
0
};
tDecoderInit
(
&
decoder
,
(
uint8_t
*
)
pVal
,
vLen
);
tDecodeSTqHandle
(
&
decoder
,
&
handle
);
tDecoderClear
(
&
decoder
);
static
int
buildHandle
(
STQ
*
pTq
,
STqHandle
*
handle
){
SVnode
*
pVnode
=
pTq
->
pVnode
;
int32_t
vgId
=
TD_VID
(
pVnode
);
handle
.
pRef
=
walOpenRef
(
pTq
->
pVnode
->
pWal
);
if
(
handle
.
pRef
==
NULL
)
{
code
=
-
1
;
goto
end
;
handle
->
pRef
=
walOpenRef
(
pVnode
->
pWal
);
if
(
handle
->
pRef
==
NULL
)
{
return
-
1
;
}
walSetRefVer
(
handle
.
pRef
,
handle
.
snapshotVer
);
walSetRefVer
(
handle
->
pRef
,
handle
->
snapshotVer
);
SReadHandle
reader
=
{
.
vnode
=
pTq
->
pVnode
,
.
vnode
=
pVnode
,
.
initTableReader
=
true
,
.
initTqReader
=
true
,
.
version
=
handle
.
snapshotVer
.
version
=
handle
->
snapshotVer
,
};
initStorageAPI
(
&
reader
.
api
);
if
(
handle
.
execHandle
.
subType
==
TOPIC_SUB_TYPE__COLUMN
)
{
handle
.
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
handle
.
execHandle
.
execCol
.
qmsg
,
&
reader
,
vgId
,
&
handle
.
execHandle
.
numOfCols
,
0
);
if
(
handle
.
execHandle
.
task
==
NULL
)
{
tqError
(
"cannot create exec task for %s"
,
handle
.
subKey
);
code
=
-
1
;
goto
end
;
if
(
handle
->
execHandle
.
subType
==
TOPIC_SUB_TYPE__COLUMN
)
{
handle
->
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
handle
->
execHandle
.
execCol
.
qmsg
,
&
reader
,
vgId
,
&
handle
->
execHandle
.
numOfCols
,
handle
->
consumerId
);
if
(
handle
->
execHandle
.
task
==
NULL
)
{
tqError
(
"cannot create exec task for %s"
,
handle
->
subKey
);
return
-
1
;
}
void
*
scanner
=
NULL
;
qExtractStreamScanner
(
handle
.
execHandle
.
task
,
&
scanner
);
qExtractStreamScanner
(
handle
->
execHandle
.
task
,
&
scanner
);
if
(
scanner
==
NULL
)
{
tqError
(
"cannot extract stream scanner for %s"
,
handle
.
subKey
);
code
=
-
1
;
goto
end
;
tqError
(
"cannot extract stream scanner for %s"
,
handle
->
subKey
);
return
-
1
;
}
handle
.
execHandle
.
pTqReader
=
qExtractReaderFromStreamScanner
(
scanner
);
if
(
handle
.
execHandle
.
pTqReader
==
NULL
)
{
tqError
(
"cannot extract exec reader for %s"
,
handle
.
subKey
);
code
=
-
1
;
goto
end
;
handle
->
execHandle
.
pTqReader
=
qExtractReaderFromStreamScanner
(
scanner
);
if
(
handle
->
execHandle
.
pTqReader
==
NULL
)
{
tqError
(
"cannot extract exec reader for %s"
,
handle
->
subKey
);
return
-
1
;
}
}
else
if
(
handle
.
execHandle
.
subType
==
TOPIC_SUB_TYPE__DB
)
{
handle
.
pWalReader
=
walOpenReader
(
pTq
->
pVnode
->
pWal
,
NULL
);
handle
.
execHandle
.
pTqReader
=
tqReaderOpen
(
pTq
->
pVnode
);
}
else
if
(
handle
->
execHandle
.
subType
==
TOPIC_SUB_TYPE__DB
)
{
handle
->
pWalReader
=
walOpenReader
(
pVnode
->
pWal
,
NULL
);
handle
->
execHandle
.
pTqReader
=
tqReaderOpen
(
pVnode
);
buildSnapContext
(
reader
.
vnode
,
reader
.
version
,
0
,
handle
.
execHandle
.
subType
,
handle
.
fetchMeta
,
buildSnapContext
(
reader
.
vnode
,
reader
.
version
,
0
,
handle
->
execHandle
.
subType
,
handle
->
fetchMeta
,
(
SSnapContext
**
)(
&
reader
.
sContext
));
handle
.
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
NULL
,
&
reader
,
vgId
,
NULL
,
0
);
}
else
if
(
handle
.
execHandle
.
subType
==
TOPIC_SUB_TYPE__TABLE
)
{
handle
.
pWalReader
=
walOpenReader
(
pTq
->
pVnode
->
pWal
,
NULL
);
handle
->
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
NULL
,
&
reader
,
vgId
,
NULL
,
handle
->
consumerId
);
}
else
if
(
handle
->
execHandle
.
subType
==
TOPIC_SUB_TYPE__TABLE
)
{
handle
->
pWalReader
=
walOpenReader
(
pVnode
->
pWal
,
NULL
);
if
(
handle
.
execHandle
.
execTb
.
qmsg
!=
NULL
&&
strcmp
(
handle
.
execHandle
.
execTb
.
qmsg
,
""
)
!=
0
)
{
if
(
nodesStringToNode
(
handle
.
execHandle
.
execTb
.
qmsg
,
&
handle
.
execHandle
.
execTb
.
node
)
!=
0
)
{
if
(
handle
->
execHandle
.
execTb
.
qmsg
!=
NULL
&&
strcmp
(
handle
->
execHandle
.
execTb
.
qmsg
,
""
)
!=
0
)
{
if
(
nodesStringToNode
(
handle
->
execHandle
.
execTb
.
qmsg
,
&
handle
->
execHandle
.
execTb
.
node
)
!=
0
)
{
tqError
(
"nodesStringToNode error in sub stable, since %s"
,
terrstr
());
return
-
1
;
}
}
buildSnapContext
(
reader
.
vnode
,
reader
.
version
,
handle
.
execHandle
.
execTb
.
suid
,
handle
.
execHandle
.
subType
,
handle
.
fetchMeta
,
(
SSnapContext
**
)(
&
reader
.
sContext
));
handle
.
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
NULL
,
&
reader
,
vgId
,
NULL
,
0
);
buildSnapContext
(
reader
.
vnode
,
reader
.
version
,
handle
->
execHandle
.
execTb
.
suid
,
handle
->
execHandle
.
subType
,
handle
->
fetchMeta
,
(
SSnapContext
**
)(
&
reader
.
sContext
));
handle
->
execHandle
.
task
=
qCreateQueueExecTaskInfo
(
NULL
,
&
reader
,
vgId
,
NULL
,
handle
->
consumerId
);
SArray
*
tbUidList
=
NULL
;
int
ret
=
qGetTableList
(
handle
.
execHandle
.
execTb
.
suid
,
pTq
->
pVnode
,
handle
.
execHandle
.
execTb
.
node
,
&
tbUidList
,
handle
.
execHandle
.
task
);
int
ret
=
qGetTableList
(
handle
->
execHandle
.
execTb
.
suid
,
pVnode
,
handle
->
execHandle
.
execTb
.
node
,
&
tbUidList
,
handle
->
execHandle
.
task
);
if
(
ret
!=
TDB_CODE_SUCCESS
)
{
tqError
(
"qGetTableList error:%d handle %s consumer:0x%"
PRIx64
,
ret
,
handle
.
subKey
,
handle
.
consumerId
);
tqError
(
"qGetTableList error:%d handle %s consumer:0x%"
PRIx64
,
ret
,
handle
->
subKey
,
handle
->
consumerId
);
taosArrayDestroy
(
tbUidList
);
goto
end
;
return
-
1
;
}
tqDebug
(
"vgId:%d, tq try to get ctb for stb subscribe, suid:%"
PRId64
,
pTq
->
pVnode
->
config
.
vgId
,
handle
.
execHandle
.
execTb
.
suid
);
handle
.
execHandle
.
pTqReader
=
tqReaderOpen
(
pTq
->
pVnode
);
tqReaderSetTbUidList
(
handle
.
execHandle
.
pTqReader
,
tbUidList
,
NULL
);
tqDebug
(
"vgId:%d, tq try to get ctb for stb subscribe, suid:%"
PRId64
,
pVnode
->
config
.
vgId
,
handle
->
execHandle
.
execTb
.
suid
);
handle
->
execHandle
.
pTqReader
=
tqReaderOpen
(
pVnode
);
tqReaderSetTbUidList
(
handle
->
execHandle
.
pTqReader
,
tbUidList
,
NULL
);
taosArrayDestroy
(
tbUidList
);
}
tqDebug
(
"tq restore %s consumer %"
PRId64
" vgId:%d"
,
handle
.
subKey
,
handle
.
consumerId
,
vgId
);
taosHashPut
(
pTq
->
pHandle
,
pKey
,
kLen
,
&
handle
,
sizeof
(
STqHandle
));
return
0
;
}
static
int
restoreHandle
(
STQ
*
pTq
,
void
*
pVal
,
int
vLen
,
STqHandle
*
handle
){
int32_t
vgId
=
TD_VID
(
pTq
->
pVnode
);
SDecoder
decoder
;
tDecoderInit
(
&
decoder
,
(
uint8_t
*
)
pVal
,
vLen
);
tDecodeSTqHandle
(
&
decoder
,
handle
);
tDecoderClear
(
&
decoder
);
if
(
buildHandle
(
pTq
,
handle
)
<
0
){
return
-
1
;
}
tqDebug
(
"tq restore %s consumer %"
PRId64
" vgId:%d"
,
handle
->
subKey
,
handle
->
consumerId
,
vgId
);
return
taosHashPut
(
pTq
->
pHandle
,
handle
->
subKey
,
strlen
(
handle
->
subKey
),
handle
,
sizeof
(
STqHandle
));
}
int32_t
tqCreateHandle
(
STQ
*
pTq
,
SMqRebVgReq
*
req
,
STqHandle
*
handle
){
int32_t
vgId
=
TD_VID
(
pTq
->
pVnode
);
memcpy
(
handle
->
subKey
,
req
->
subKey
,
TSDB_SUBSCRIBE_KEY_LEN
);
handle
->
consumerId
=
req
->
newConsumerId
;
handle
->
epoch
=
-
1
;
handle
->
execHandle
.
subType
=
req
->
subType
;
handle
->
fetchMeta
=
req
->
withMeta
;
if
(
req
->
subType
==
TOPIC_SUB_TYPE__COLUMN
){
handle
->
execHandle
.
execCol
.
qmsg
=
taosStrdup
(
req
->
qmsg
);
}
else
if
(
req
->
subType
==
TOPIC_SUB_TYPE__DB
){
handle
->
execHandle
.
execDb
.
pFilterOutTbUid
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_ENTRY_LOCK
);
}
else
if
(
req
->
subType
==
TOPIC_SUB_TYPE__TABLE
){
handle
->
execHandle
.
execTb
.
suid
=
req
->
suid
;
handle
->
execHandle
.
execTb
.
qmsg
=
taosStrdup
(
req
->
qmsg
);
}
handle
->
snapshotVer
=
walGetCommittedVer
(
pTq
->
pVnode
->
pWal
);
if
(
buildHandle
(
pTq
,
handle
)
<
0
){
return
-
1
;
}
tqDebug
(
"tq restore %s consumer %"
PRId64
" vgId:%d"
,
handle
->
subKey
,
handle
->
consumerId
,
vgId
);
return
taosHashPut
(
pTq
->
pHandle
,
handle
->
subKey
,
strlen
(
handle
->
subKey
),
handle
,
sizeof
(
STqHandle
));
}
int32_t
tqMetaRestoreHandle
(
STQ
*
pTq
)
{
int
code
=
0
;
TBC
*
pCur
=
NULL
;
if
(
tdbTbcOpen
(
pTq
->
pExecStore
,
&
pCur
,
NULL
)
<
0
)
{
return
-
1
;
}
void
*
pKey
=
NULL
;
int
kLen
=
0
;
void
*
pVal
=
NULL
;
int
vLen
=
0
;
tdbTbcMoveToFirst
(
pCur
);
while
(
tdbTbcNext
(
pCur
,
&
pKey
,
&
kLen
,
&
pVal
,
&
vLen
)
==
0
)
{
STqHandle
handle
=
{
0
};
code
=
restoreHandle
(
pTq
,
pVal
,
vLen
,
&
handle
);
if
(
code
<
0
)
{
tqDestroyTqHandle
(
&
handle
);
break
;
}
}
end:
tdbFree
(
pKey
);
tdbFree
(
pVal
);
tdbTbcClose
(
pCur
);
return
code
;
}
int32_t
tqMetaGetHandle
(
STQ
*
pTq
,
const
char
*
key
)
{
void
*
pVal
=
NULL
;
int
vLen
=
0
;
if
(
tdbTbGet
(
pTq
->
pExecStore
,
key
,
(
int
)
strlen
(
key
),
&
pVal
,
&
vLen
)
<
0
)
{
return
-
1
;
}
STqHandle
handle
=
{
0
};
int
code
=
restoreHandle
(
pTq
,
pVal
,
vLen
,
&
handle
);
if
(
code
<
0
){
tqDestroyTqHandle
(
&
handle
);
}
tdbFree
(
pVal
);
return
code
;
}
source/libs/wal/src/walRef.c
浏览文件 @
9e78a4c5
...
...
@@ -80,27 +80,3 @@ void walRefLastVer(SWal *pWal, SWalRef *pRef) {
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
wDebug
(
"vgId:%d, wal ref version %"
PRId64
" for last"
,
pWal
->
cfg
.
vgId
,
ver
);
}
SWalRef
*
walRefCommittedVer
(
SWal
*
pWal
)
{
SWalRef
*
pRef
=
walOpenRef
(
pWal
);
if
(
pRef
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
taosThreadMutexLock
(
&
pWal
->
mutex
);
int64_t
ver
=
walGetCommittedVer
(
pWal
);
wDebug
(
"vgId:%d, wal ref version %"
PRId64
" for committed"
,
pWal
->
cfg
.
vgId
,
ver
);
pRef
->
refVer
=
ver
;
// bsearch in fileSet
SWalFileInfo
tmpInfo
;
tmpInfo
.
firstVer
=
ver
;
SWalFileInfo
*
pRet
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmpInfo
,
compareWalFileInfo
,
TD_LE
);
ASSERT
(
pRet
!=
NULL
);
// pRef->refFile = pRet->firstVer;
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
return
pRef
;
}
source/util/src/tarray.c
浏览文件 @
9e78a4c5
...
...
@@ -476,13 +476,13 @@ int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode) {
return
tlen
;
}
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
)
{
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
,
int8_t
sver
)
{
int32_t
sz
;
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
*
pArray
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
void
*
data
=
taosMemoryCalloc
(
1
,
dataSz
);
buf
=
decode
(
buf
,
data
);
buf
=
decode
(
buf
,
data
,
sver
);
taosArrayPush
(
*
pArray
,
&
data
);
}
return
(
void
*
)
buf
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录