Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8ecd7a56
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
8ecd7a56
编写于
12月 30, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
差异文件
[td-11818] merge 3.0
上级
a1f65e9c
0656624d
变更
78
展开全部
显示空白变更内容
内联
并排
Showing
78 changed file
with
3746 addition
and
1202 deletion
+3746
-1202
include/common/tmsg.h
include/common/tmsg.h
+116
-31
include/common/tmsgdef.h
include/common/tmsgdef.h
+26
-2
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+22
-17
include/dnode/vnode/vnode.h
include/dnode/vnode/vnode.h
+0
-10
include/libs/catalog/catalog.h
include/libs/catalog/catalog.h
+12
-0
include/libs/qcom/query.h
include/libs/qcom/query.h
+1
-0
include/util/taoserror.h
include/util/taoserror.h
+7
-2
include/util/thash.h
include/util/thash.h
+30
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+15
-5
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+2
-0
source/dnode/mgmt/daemon/src/daemon.c
source/dnode/mgmt/daemon/src/daemon.c
+1
-1
source/dnode/mgmt/impl/src/dndBnode.c
source/dnode/mgmt/impl/src/dndBnode.c
+2
-2
source/dnode/mgmt/impl/src/dndDnode.c
source/dnode/mgmt/impl/src/dndDnode.c
+35
-11
source/dnode/mgmt/impl/src/dndMnode.c
source/dnode/mgmt/impl/src/dndMnode.c
+6
-6
source/dnode/mgmt/impl/src/dndQnode.c
source/dnode/mgmt/impl/src/dndQnode.c
+2
-2
source/dnode/mgmt/impl/src/dndSnode.c
source/dnode/mgmt/impl/src/dndSnode.c
+2
-2
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+19
-0
source/dnode/mgmt/impl/test/CMakeLists.txt
source/dnode/mgmt/impl/test/CMakeLists.txt
+3
-0
source/dnode/mgmt/impl/test/bnode/CMakeLists.txt
source/dnode/mgmt/impl/test/bnode/CMakeLists.txt
+11
-0
source/dnode/mgmt/impl/test/bnode/bnode.cpp
source/dnode/mgmt/impl/test/bnode/bnode.cpp
+154
-0
source/dnode/mgmt/impl/test/dnode/dnode.cpp
source/dnode/mgmt/impl/test/dnode/dnode.cpp
+12
-12
source/dnode/mgmt/impl/test/mnode/mnode.cpp
source/dnode/mgmt/impl/test/mnode/mnode.cpp
+8
-8
source/dnode/mgmt/impl/test/qnode/CMakeLists.txt
source/dnode/mgmt/impl/test/qnode/CMakeLists.txt
+11
-0
source/dnode/mgmt/impl/test/qnode/qnode.cpp
source/dnode/mgmt/impl/test/qnode/qnode.cpp
+154
-0
source/dnode/mgmt/impl/test/snode/CMakeLists.txt
source/dnode/mgmt/impl/test/snode/CMakeLists.txt
+11
-0
source/dnode/mgmt/impl/test/snode/snode.cpp
source/dnode/mgmt/impl/test/snode/snode.cpp
+154
-0
source/dnode/mgmt/impl/test/stb/stb.cpp
source/dnode/mgmt/impl/test/stb/stb.cpp
+2
-2
source/dnode/mgmt/impl/test/sut/src/server.cpp
source/dnode/mgmt/impl/test/sut/src/server.cpp
+1
-1
source/dnode/mnode/impl/inc/mndBnode.h
source/dnode/mnode/impl/inc/mndBnode.h
+5
-5
source/dnode/mnode/impl/inc/mndConsumer.h
source/dnode/mnode/impl/inc/mndConsumer.h
+38
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+47
-4
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+1
-0
source/dnode/mnode/impl/inc/mndQnode.h
source/dnode/mnode/impl/inc/mndQnode.h
+15
-4
source/dnode/mnode/impl/inc/mndSnode.h
source/dnode/mnode/impl/inc/mndSnode.h
+32
-0
source/dnode/mnode/impl/inc/mndVgroup.h
source/dnode/mnode/impl/inc/mndVgroup.h
+1
-0
source/dnode/mnode/impl/src/mndBnode.c
source/dnode/mnode/impl/src/mndBnode.c
+446
-0
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+373
-0
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+2
-4
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+18
-18
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+5
-5
source/dnode/mnode/impl/src/mndQnode.c
source/dnode/mnode/impl/src/mndQnode.c
+446
-0
source/dnode/mnode/impl/src/mndShow.c
source/dnode/mnode/impl/src/mndShow.c
+33
-35
source/dnode/mnode/impl/src/mndSnode.c
source/dnode/mnode/impl/src/mndSnode.c
+446
-0
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+5
-37
source/dnode/mnode/impl/src/mndTopic.c
source/dnode/mnode/impl/src/mndTopic.c
+15
-376
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+9
-9
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+85
-26
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+11
-7
source/dnode/mnode/sdb/inc/sdbInt.h
source/dnode/mnode/sdb/inc/sdbInt.h
+1
-0
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+2
-6
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+3
-3
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+66
-20
source/dnode/mnode/sdb/src/sdbRaw.c
source/dnode/mnode/sdb/src/sdbRaw.c
+2
-2
source/dnode/mnode/sdb/src/sdbRow.c
source/dnode/mnode/sdb/src/sdbRow.c
+10
-1
source/dnode/qnode/src/qnode.c
source/dnode/qnode/src/qnode.c
+1
-5
source/dnode/snode/src/snode.c
source/dnode/snode/src/snode.c
+1
-1
source/dnode/vnode/impl/src/vnodeInt.c
source/dnode/vnode/impl/src/vnodeInt.c
+0
-5
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+31
-0
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+212
-97
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+2
-1
source/libs/index/inc/index_tfile.h
source/libs/index/inc/index_tfile.h
+3
-2
source/libs/index/src/index.c
source/libs/index/src/index.c
+88
-52
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+92
-89
source/libs/index/src/index_fst_automation.c
source/libs/index/src/index_fst_automation.c
+44
-55
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+9
-6
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+112
-121
source/libs/index/test/fstTest.cc
source/libs/index/test/fstTest.cc
+3
-5
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+80
-56
source/libs/qworker/inc/qworkerInt.h
source/libs/qworker/inc/qworkerInt.h
+4
-4
source/util/CMakeLists.txt
source/util/CMakeLists.txt
+3
-1
source/util/src/terror.c
source/util/src/terror.c
+7
-2
source/util/src/thash.c
source/util/src/thash.c
+20
-1
source/util/test/CMakeLists.txt
source/util/test/CMakeLists.txt
+8
-3
source/util/test/hashTest.cpp
source/util/test/hashTest.cpp
+53
-1
tests/script/general/db/basic1.sim
tests/script/general/db/basic1.sim
+21
-1
tests/script/general/table/basic1.sim
tests/script/general/table/basic1.sim
+3
-4
tests/script/sh/exec.sh
tests/script/sh/exec.sh
+2
-2
tests/script/tmp/dnodes.sim
tests/script/tmp/dnodes.sim
+11
-12
未找到文件。
include/common/tmsg.h
浏览文件 @
8ecd7a56
...
@@ -71,6 +71,9 @@ typedef enum _mgmt_table {
...
@@ -71,6 +71,9 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_TABLE
,
TSDB_MGMT_TABLE_TABLE
,
TSDB_MGMT_TABLE_DNODE
,
TSDB_MGMT_TABLE_DNODE
,
TSDB_MGMT_TABLE_MNODE
,
TSDB_MGMT_TABLE_MNODE
,
TSDB_MGMT_TABLE_QNODE
,
TSDB_MGMT_TABLE_SNODE
,
TSDB_MGMT_TABLE_BNODE
,
TSDB_MGMT_TABLE_VGROUP
,
TSDB_MGMT_TABLE_VGROUP
,
TSDB_MGMT_TABLE_STB
,
TSDB_MGMT_TABLE_STB
,
TSDB_MGMT_TABLE_MODULE
,
TSDB_MGMT_TABLE_MODULE
,
...
@@ -219,6 +222,26 @@ typedef struct {
...
@@ -219,6 +222,26 @@ typedef struct {
char
data
[];
char
data
[];
}
SMDCreateTableMsg
;
}
SMDCreateTableMsg
;
// typedef struct {
// int32_t len; // one create table message
// char tableName[TSDB_TABLE_FNAME_LEN];
// int16_t numOfColumns;
// int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string
// int8_t igExists;
// int8_t rspMeta;
// int8_t reserved[16];
// char schema[];
//} SCreateTableMsg;
typedef
struct
{
char
tableName
[
TSDB_TABLE_FNAME_LEN
];
int16_t
numOfColumns
;
int16_t
numOfTags
;
int8_t
igExists
;
int8_t
rspMeta
;
char
schema
[];
}
SCreateCTableMsg
;
typedef
struct
{
typedef
struct
{
char
name
[
TSDB_TABLE_FNAME_LEN
];
char
name
[
TSDB_TABLE_FNAME_LEN
];
int8_t
igExists
;
int8_t
igExists
;
...
@@ -242,19 +265,7 @@ typedef struct {
...
@@ -242,19 +265,7 @@ typedef struct {
SMsgHead
head
;
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
char
name
[
TSDB_TABLE_FNAME_LEN
];
uint64_t
suid
;
uint64_t
suid
;
int32_t
sverson
;
}
SVDropStbReq
;
uint32_t
ttl
;
uint32_t
keep
;
int32_t
numOfTags
;
int32_t
numOfColumns
;
SSchema
pSchema
[];
}
SCreateStbInternalMsg
;
typedef
struct
{
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
uint64_t
suid
;
}
SDropStbInternalMsg
;
typedef
struct
{
typedef
struct
{
SMsgHead
head
;
SMsgHead
head
;
...
@@ -299,6 +310,18 @@ typedef struct SEpSet {
...
@@ -299,6 +310,18 @@ typedef struct SEpSet {
char
fqdn
[
TSDB_MAX_REPLICA
][
TSDB_FQDN_LEN
];
char
fqdn
[
TSDB_MAX_REPLICA
][
TSDB_FQDN_LEN
];
}
SEpSet
;
}
SEpSet
;
static
FORCE_INLINE
int
taosEncodeSEpSet
(
void
**
buf
,
const
SEpSet
*
pEp
)
{
if
(
buf
==
NULL
)
return
sizeof
(
SEpSet
);
memcpy
(
buf
,
pEp
,
sizeof
(
SEpSet
));
//TODO: endian conversion
return
sizeof
(
SEpSet
);
}
static
FORCE_INLINE
void
*
taosDecodeSEpSet
(
void
*
buf
,
SEpSet
*
pEpSet
)
{
memcpy
(
pEpSet
,
buf
,
sizeof
(
SEpSet
));
return
buf
;
}
typedef
struct
{
typedef
struct
{
int32_t
acctId
;
int32_t
acctId
;
int64_t
clusterId
;
int64_t
clusterId
;
...
@@ -642,8 +665,6 @@ typedef struct {
...
@@ -642,8 +665,6 @@ typedef struct {
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
int64_t
clusterId
;
int64_t
clusterId
;
int8_t
dropped
;
char
reserved
[
7
];
}
SDnodeCfg
;
}
SDnodeCfg
;
typedef
struct
{
typedef
struct
{
...
@@ -822,29 +843,25 @@ typedef struct {
...
@@ -822,29 +843,25 @@ typedef struct {
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
}
S
CreateMnodeMsg
,
S
DropMnodeMsg
;
}
S
MCreateMnodeMsg
,
SMDropMnodeMsg
,
SD
DropMnodeMsg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
int8_t
replica
;
int8_t
replica
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
SReplica
replicas
[
TSDB_MAX_REPLICA
];
}
S
CreateMnodeInMsg
,
SAlterMnodeIn
Msg
;
}
S
DCreateMnodeMsg
,
SDAlterMnode
Msg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
}
S
DropMnodeIn
Msg
;
}
S
MCreateQnodeMsg
,
SMDropQnodeMsg
,
SDCreateQnodeMsg
,
SDDropQnode
Msg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
}
S
CreateQnodeInMsg
,
SDropQnodeIn
Msg
;
}
S
MCreateSnodeMsg
,
SMDropSnodeMsg
,
SDCreateSnodeMsg
,
SDDropSnode
Msg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
}
SCreateSnodeInMsg
,
SDropSnodeInMsg
;
}
SMCreateBnodeMsg
,
SMDropBnodeMsg
,
SDCreateBnodeMsg
,
SDDropBnodeMsg
;
typedef
struct
{
int32_t
dnodeId
;
}
SCreateBnodeInMsg
,
SDropBnodeInMsg
;
typedef
struct
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
...
@@ -1060,24 +1077,92 @@ typedef struct STaskDropRsp {
...
@@ -1060,24 +1077,92 @@ typedef struct STaskDropRsp {
typedef
struct
{
typedef
struct
{
int8_t
igExists
;
int8_t
igExists
;
char
*
name
;
char
*
name
;
char
*
phyPlan
;
char
*
physicalPlan
;
char
*
logicalPlan
;
}
SCMCreateTopicReq
;
}
SCMCreateTopicReq
;
static
FORCE_INLINE
int
tSerializeSCMCreateTopicReq
(
void
**
buf
,
const
SCMCreateTopicReq
*
pReq
)
{
static
FORCE_INLINE
int
tSerializeSCMCreateTopicReq
(
void
**
buf
,
const
SCMCreateTopicReq
*
pReq
)
{
int
tlen
=
0
;
int
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pReq
->
name
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
name
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
igExists
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
igExists
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
phyPlan
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
physicalPlan
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
logicalPlan
);
return
tlen
;
return
tlen
;
}
}
static
FORCE_INLINE
void
*
tDeserializeSCMCreateTopicReq
(
void
*
buf
,
SCMCreateTopicReq
*
pReq
)
{
static
FORCE_INLINE
void
*
tDeserializeSCMCreateTopicReq
(
void
*
buf
,
SCMCreateTopicReq
*
pReq
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
igExists
));
buf
=
taosDecodeFixedI8
(
buf
,
&
(
pReq
->
igExists
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
name
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
name
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
phyPlan
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
physicalPlan
));
buf
=
taosDecodeString
(
buf
,
&
(
pReq
->
logicalPlan
));
return
buf
;
}
typedef
struct
{
int64_t
topicId
;
}
SCMCreateTopicRsp
;
static
FORCE_INLINE
int
tSerializeSCMCreateTopicRsp
(
void
**
buf
,
const
SCMCreateTopicRsp
*
pRsp
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pRsp
->
topicId
);
return
tlen
;
}
static
FORCE_INLINE
void
*
tDeserializeSCMCreateTopicRsp
(
void
*
buf
,
SCMCreateTopicRsp
*
pRsp
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pRsp
->
topicId
);
return
buf
;
return
buf
;
}
}
typedef
struct
{
char
*
topicName
;
char
*
consumerGroup
;
int64_t
consumerId
;
}
SCMSubscribeReq
;
static
FORCE_INLINE
int
tSerializeSCMSubscribeReq
(
void
**
buf
,
const
SCMSubscribeReq
*
pReq
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pReq
->
topicName
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
consumerGroup
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
consumerId
);
return
tlen
;
}
static
FORCE_INLINE
void
*
tDeserializeSCMSubscribeReq
(
void
*
buf
,
SCMSubscribeReq
*
pReq
)
{
buf
=
taosDecodeString
(
buf
,
&
pReq
->
topicName
);
buf
=
taosDecodeString
(
buf
,
&
pReq
->
consumerGroup
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
consumerId
);
return
buf
;
}
typedef
struct
{
int32_t
vgId
;
SEpSet
pEpSet
;
}
SCMSubscribeRsp
;
static
FORCE_INLINE
int
tSerializeSCMSubscribeRsp
(
void
**
buf
,
const
SCMSubscribeRsp
*
pRsp
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
vgId
);
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pRsp
->
pEpSet
);
return
tlen
;
}
static
FORCE_INLINE
void
*
tDeserializeSCMSubscribeRsp
(
void
*
buf
,
SCMSubscribeRsp
*
pRsp
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
vgId
);
buf
=
taosDecodeSEpSet
(
buf
,
&
pRsp
->
pEpSet
);
return
buf
;
}
typedef
struct
{
int64_t
topicId
;
int64_t
consumerId
;
int64_t
consumerGroupId
;
int64_t
offset
;
}
SMVSubscribeReq
;
typedef
struct
{
int64_t
newOffset
;
}
SMVSubscribeRsp
;
typedef
struct
{
typedef
struct
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
char
name
[
TSDB_TOPIC_FNAME_LEN
];
int8_t
igExists
;
int8_t
igExists
;
...
@@ -1107,13 +1192,13 @@ typedef struct {
...
@@ -1107,13 +1192,13 @@ typedef struct {
char
*
executor
;
char
*
executor
;
int32_t
sqlLen
;
int32_t
sqlLen
;
char
*
sql
;
char
*
sql
;
}
S
CreateTopicInternal
Msg
;
}
S
DCreateTopic
Msg
;
typedef
struct
{
typedef
struct
{
SMsgHead
head
;
SMsgHead
head
;
char
name
[
TSDB_TABLE_FNAME_LEN
];
char
name
[
TSDB_TABLE_FNAME_LEN
];
uint64_t
tuid
;
uint64_t
tuid
;
}
SD
ropTopicInternal
Msg
;
}
SD
DropTopic
Msg
;
typedef
struct
SVCreateTbReq
{
typedef
struct
SVCreateTbReq
{
uint64_t
ver
;
// use a general definition
uint64_t
ver
;
// use a general definition
...
...
include/common/tmsgdef.h
浏览文件 @
8ecd7a56
...
@@ -70,6 +70,15 @@ enum {
...
@@ -70,6 +70,15 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_MNODE
,
"dnode-create-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_MNODE
,
"dnode-create-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_MNODE
,
"dnode-alter-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_MNODE
,
"dnode-alter-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_MNODE
,
"dnode-drop-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_MNODE
,
"dnode-drop-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_QNODE
,
"dnode-create-qnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_QNODE
,
"dnode-alter-qnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_QNODE
,
"dnode-drop-qnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_SNODE
,
"dnode-create-snode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_SNODE
,
"dnode-alter-snode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_SNODE
,
"dnode-drop-snode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_BNODE
,
"dnode-create-bnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_BNODE
,
"dnode-alter-bnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_BNODE
,
"dnode-drop-bnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_VNODE
,
"dnode-create-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CREATE_VNODE
,
"dnode-create-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_VNODE
,
"dnode-alter-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_ALTER_VNODE
,
"dnode-alter-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_VNODE
,
"dnode-drop-vnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_DROP_VNODE
,
"dnode-drop-vnode"
,
NULL
,
NULL
)
...
@@ -90,9 +99,20 @@ enum {
...
@@ -90,9 +99,20 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_USER
,
"mnode-drop-user"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_USER
,
"mnode-drop-user"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_DNODE
,
"mnode-create-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_DNODE
,
"mnode-create-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CONFIG_DNODE
,
"mnode-config-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CONFIG_DNODE
,
"mnode-config-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_DNODE
,
"mnode-alter-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_DNODE
,
"mnode-drop-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_DNODE
,
"mnode-drop-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_MNODE
,
"mnode-create-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_MNODE
,
"mnode-create-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_MNODE
,
"mnode-alter-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_MNODE
,
"mnode-drop-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_MNODE
,
"mnode-drop-mnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_QNODE
,
"mnode-create-qnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_QNODE
,
"mnode-alter-qnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_QNODE
,
"mnode-drop-qnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_SNODE
,
"mnode-create-snode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_SNODE
,
"mnode-alter-snode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_SNODE
,
"mnode-drop-snode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_BNODE
,
"mnode-create-bnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_BNODE
,
"mnode-alter-bnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_BNODE
,
"mnode-drop-bnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_DB
,
"mnode-create-db"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_DB
,
"mnode-create-db"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_DB
,
"mnode-drop-db"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_DB
,
"mnode-drop-db"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_USE_DB
,
"mnode-use-db"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_USE_DB
,
"mnode-use-db"
,
NULL
,
NULL
)
...
@@ -116,9 +136,10 @@ enum {
...
@@ -116,9 +136,10 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_TRANS
,
"mnode-trans"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_TRANS
,
"mnode-trans"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_GRANT
,
"mnode-grant"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_GRANT
,
"mnode-grant"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_AUTH
,
"mnode-auth"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_AUTH
,
"mnode-auth"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_TOPIC
,
"mnode-create-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_TOPIC
,
"mnode-create-topic"
,
SCMCreateTopicReq
,
SCMCreateTopicRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_TOPIC
,
"mnode-alter-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_TOPIC
,
"mnode-alter-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_TOPIC
,
"mnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_TOPIC
,
"mnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SUBSCRIBE
,
"mnode-subscribe"
,
SCMSubscribeReq
,
SCMSubscribeRsp
)
// Requests handled by VNODE
// Requests handled by VNODE
TD_NEW_MSG_SEG
(
TDMT_VND_MSG
)
TD_NEW_MSG_SEG
(
TDMT_VND_MSG
)
...
@@ -149,6 +170,9 @@ enum {
...
@@ -149,6 +170,9 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES
,
"vnode-show-tables"
,
SVShowTablesReq
,
SVShowTablesRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES
,
"vnode-show-tables"
,
SVShowTablesReq
,
SVShowTablesRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES_FETCH
,
"vnode-show-tables-fetch"
,
SVShowTablesFetchReq
,
SVShowTablesFetchRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES_FETCH
,
"vnode-show-tables-fetch"
,
SVShowTablesFetchReq
,
SVShowTablesFetchRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBSCRIBE
,
"vnode-subscribe"
,
SMVSubscribeReq
,
SMVSubscribeRsp
)
// Requests handled by QNODE
// Requests handled by QNODE
TD_NEW_MSG_SEG
(
TDMT_QND_MSG
)
TD_NEW_MSG_SEG
(
TDMT_QND_MSG
)
...
...
include/dnode/mnode/sdb/sdb.h
浏览文件 @
8ecd7a56
...
@@ -25,7 +25,7 @@ extern "C" {
...
@@ -25,7 +25,7 @@ extern "C" {
#define SDB_GET_INT64(pData, pRow, dataPos, val) \
#define SDB_GET_INT64(pData, pRow, dataPos, val) \
{ \
{ \
if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \
if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \
sdbFreeRow(pRow);
\
tfree(pRow);
\
return NULL; \
return NULL; \
} \
} \
dataPos += sizeof(int64_t); \
dataPos += sizeof(int64_t); \
...
@@ -34,7 +34,7 @@ extern "C" {
...
@@ -34,7 +34,7 @@ extern "C" {
#define SDB_GET_INT32(pData, pRow, dataPos, val) \
#define SDB_GET_INT32(pData, pRow, dataPos, val) \
{ \
{ \
if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \
if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \
sdbFreeRow(pRow);
\
tfree(pRow);
\
return NULL; \
return NULL; \
} \
} \
dataPos += sizeof(int32_t); \
dataPos += sizeof(int32_t); \
...
@@ -43,7 +43,7 @@ extern "C" {
...
@@ -43,7 +43,7 @@ extern "C" {
#define SDB_GET_INT16(pData, pRow, dataPos, val) \
#define SDB_GET_INT16(pData, pRow, dataPos, val) \
{ \
{ \
if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \
if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \
sdbFreeRow(pRow);
\
tfree(pRow);
\
return NULL; \
return NULL; \
} \
} \
dataPos += sizeof(int16_t); \
dataPos += sizeof(int16_t); \
...
@@ -52,7 +52,7 @@ extern "C" {
...
@@ -52,7 +52,7 @@ extern "C" {
#define SDB_GET_INT8(pData, pRow, dataPos, val) \
#define SDB_GET_INT8(pData, pRow, dataPos, val) \
{ \
{ \
if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \
if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \
sdbFreeRow(pRow);
\
tfree(pRow);
\
return NULL; \
return NULL; \
} \
} \
dataPos += sizeof(int8_t); \
dataPos += sizeof(int8_t); \
...
@@ -61,7 +61,7 @@ extern "C" {
...
@@ -61,7 +61,7 @@ extern "C" {
#define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \
#define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \
{ \
{ \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
sdbFreeRow(pRow);
\
tfree(pRow);
\
return NULL; \
return NULL; \
} \
} \
dataPos += valLen; \
dataPos += valLen; \
...
@@ -71,7 +71,7 @@ extern "C" {
...
@@ -71,7 +71,7 @@ extern "C" {
{ \
{ \
char val[valLen] = {0}; \
char val[valLen] = {0}; \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
sdbFreeRow(pRow);
\
tfree(pRow);
\
return NULL; \
return NULL; \
} \
} \
dataPos += valLen; \
dataPos += valLen; \
...
@@ -157,16 +157,21 @@ typedef enum {
...
@@ -157,16 +157,21 @@ typedef enum {
SDB_TRANS
=
1
,
SDB_TRANS
=
1
,
SDB_CLUSTER
=
2
,
SDB_CLUSTER
=
2
,
SDB_MNODE
=
3
,
SDB_MNODE
=
3
,
SDB_DNODE
=
4
,
SDB_QNODE
=
4
,
SDB_USER
=
5
,
SDB_SNODE
=
5
,
SDB_AUTH
=
6
,
SDB_BNODE
=
6
,
SDB_ACCT
=
7
,
SDB_DNODE
=
7
,
SDB_TOPIC
=
8
,
SDB_USER
=
8
,
SDB_VGROUP
=
9
,
SDB_AUTH
=
9
,
SDB_STB
=
10
,
SDB_ACCT
=
10
,
SDB_DB
=
11
,
SDB_CONSUMER
=
11
,
SDB_FUNC
=
12
,
SDB_CGROUP
=
12
,
SDB_MAX
=
13
SDB_TOPIC
=
13
,
SDB_VGROUP
=
14
,
SDB_STB
=
15
,
SDB_DB
=
16
,
SDB_FUNC
=
17
,
SDB_MAX
=
18
}
ESdbType
;
}
ESdbType
;
typedef
struct
SSdb
SSdb
;
typedef
struct
SSdb
SSdb
;
...
@@ -325,7 +330,7 @@ int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver);
...
@@ -325,7 +330,7 @@ int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver);
int32_t
sdbGetRawTotalSize
(
SSdbRaw
*
pRaw
);
int32_t
sdbGetRawTotalSize
(
SSdbRaw
*
pRaw
);
SSdbRow
*
sdbAllocRow
(
int32_t
objSize
);
SSdbRow
*
sdbAllocRow
(
int32_t
objSize
);
void
sdbFreeRow
(
SSdbRow
*
pRow
);
void
sdbFreeRow
(
SSdb
*
pSdb
,
SSdb
Row
*
pRow
);
void
*
sdbGetRowObj
(
SSdbRow
*
pRow
);
void
*
sdbGetRowObj
(
SSdbRow
*
pRow
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
include/dnode/vnode/vnode.h
浏览文件 @
8ecd7a56
...
@@ -162,16 +162,6 @@ int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
...
@@ -162,16 +162,6 @@ int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
*/
*/
int
vnodeProcessFetchReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int
vnodeProcessFetchReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
/**
* @brief Process a consume message.
*
* @param pVnode The vnode object.
* @param pMsg The request message
* @param pRsp The response message
* @return int 0 for success, -1 for failure
*/
int
vnodeProcessConsumeReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
/* ------------------------ SVnodeCfg ------------------------ */
/* ------------------------ SVnodeCfg ------------------------ */
/**
/**
* @brief Initialize VNODE options.
* @brief Initialize VNODE options.
...
...
include/libs/catalog/catalog.h
浏览文件 @
8ecd7a56
...
@@ -62,6 +62,18 @@ int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle)
...
@@ -62,6 +62,18 @@ int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle)
int32_t
catalogGetDBVgroupVersion
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
int32_t
*
version
);
int32_t
catalogGetDBVgroupVersion
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
int32_t
*
version
);
/**
* Get a DB's all vgroup info.
* @param pCatalog (input, got with catalogGetHandle)
* @param pRpc (input, rpc object)
* @param pMgmtEps (input, mnode EPs)
* @param pDBName (input, full db name)
* @param forceUpdate (input, force update db vgroup info from mnode)
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
* @return error code
*/
int32_t
catalogGetDBVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
int32_t
forceUpdate
,
SArray
**
pVgroupList
);
int32_t
catalogUpdateDBVgroup
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
dbInfo
);
int32_t
catalogUpdateDBVgroup
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
dbInfo
);
/**
/**
...
...
include/libs/qcom/query.h
浏览文件 @
8ecd7a56
...
@@ -75,6 +75,7 @@ typedef struct STableMeta {
...
@@ -75,6 +75,7 @@ typedef struct STableMeta {
}
STableMeta
;
}
STableMeta
;
typedef
struct
SDBVgroupInfo
{
typedef
struct
SDBVgroupInfo
{
int32_t
lock
;
int32_t
vgVersion
;
int32_t
vgVersion
;
int8_t
hashMethod
;
int8_t
hashMethod
;
SHashObj
*
vgInfo
;
//key:vgId, value:SVgroupInfo
SHashObj
*
vgInfo
;
//key:vgId, value:SVgroupInfo
...
...
include/util/taoserror.h
浏览文件 @
8ecd7a56
...
@@ -172,10 +172,15 @@ int32_t* taosGetErrno();
...
@@ -172,10 +172,15 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347)
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347)
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348)
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348)
// mnode-
m
node
// mnode-node
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351)
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351)
#define TSDB_CODE_MND_TOO_MANY_MNODES TAOS_DEF_ERROR_CODE(0, 0x0352)
#define TSDB_CODE_MND_QNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0352)
#define TSDB_CODE_MND_QNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0353)
#define TSDB_CODE_MND_SNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0354)
#define TSDB_CODE_MND_SNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0355)
#define TSDB_CODE_MND_BNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0356)
#define TSDB_CODE_MND_BNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0357)
// mnode-acct
// mnode-acct
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
...
...
include/util/thash.h
浏览文件 @
8ecd7a56
...
@@ -144,6 +144,16 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
...
@@ -144,6 +144,16 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
*/
*/
void
*
taosHashGetClone
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
destBuf
);
void
*
taosHashGetClone
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
destBuf
);
/**
* Clone the result to interval allocated buffer
* @param pHashObj
* @param key
* @param keyLen
* @param destBuf
* @return
*/
void
*
taosHashGetCloneExt
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
(
*
fp
)(
void
*
),
void
**
d
,
size_t
*
sz
);
/**
/**
* remove item with the specified key
* remove item with the specified key
* @param pHashObj
* @param pHashObj
...
@@ -200,6 +210,26 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
...
@@ -200,6 +210,26 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
*/
*/
int32_t
taosHashGetKey
(
void
*
data
,
void
**
key
,
size_t
*
keyLen
);
int32_t
taosHashGetKey
(
void
*
data
,
void
**
key
,
size_t
*
keyLen
);
/**
* return the payload data with the specified key(reference number added)
*
* @param pHashObj
* @param key
* @param keyLen
* @return
*/
void
*
taosHashAcquire
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
);
/**
* release the prevous acquired obj
*
* @param pHashObj
* @param data
* @return
*/
void
taosHashRelease
(
SHashObj
*
pHashObj
,
void
*
p
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/client/src/clientImpl.c
浏览文件 @
8ecd7a56
...
@@ -210,6 +210,9 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
...
@@ -210,6 +210,9 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
terrno
=
TSDB_CODE_SUCCESS
;
terrno
=
TSDB_CODE_SUCCESS
;
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
//temporary disabled until planner ready
#if 0
CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return);
CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return);
//TODO: check sql valid
//TODO: check sql valid
...
@@ -219,15 +222,24 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
...
@@ -219,15 +222,24 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
if(dagStr == NULL) {
if(dagStr == NULL) {
//TODO
//TODO
}
}
#endif
SCMCreateTopicReq
req
=
{
SCMCreateTopicReq
req
=
{
.
name
=
(
char
*
)
name
,
.
name
=
(
char
*
)
name
,
.
igExists
=
0
,
.
igExists
=
0
,
.
phyPlan
=
dagStr
,
/*.physicalPlan = dagStr,*/
.
physicalPlan
=
(
char
*
)
sql
,
.
logicalPlan
=
""
,
};
};
void
*
buf
=
NULL
;
int
tlen
=
tSerializeSCMCreateTopicReq
(
NULL
,
&
req
);
int
tlen
=
tSerializeSCMCreateTopicReq
(
&
buf
,
&
req
);
void
*
buf
=
malloc
(
tlen
);
if
(
buf
==
NULL
)
{
goto
_return
;
}
void
*
abuf
=
buf
;
tSerializeSCMCreateTopicReq
(
&
abuf
,
&
req
);
/*printf("formatted: %s\n", dagStr);*/
pRequest
->
body
.
requestMsg
=
(
SDataBuf
){
.
pData
=
buf
,
.
len
=
tlen
};
pRequest
->
body
.
requestMsg
=
(
SDataBuf
){
.
pData
=
buf
,
.
len
=
tlen
};
...
@@ -239,8 +251,6 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
...
@@ -239,8 +251,6 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
destroySendMsgInfo
(
body
);
_return:
_return:
qDestroyQuery
(
pQuery
);
qDestroyQuery
(
pQuery
);
qDestroyQueryDag
(
pDag
);
qDestroyQueryDag
(
pDag
);
...
...
source/client/test/clientTests.cpp
浏览文件 @
8ecd7a56
...
@@ -49,6 +49,7 @@ int main(int argc, char** argv) {
...
@@ -49,6 +49,7 @@ int main(int argc, char** argv) {
TEST
(
testCase
,
driverInit_Test
)
{
taos_init
();
}
TEST
(
testCase
,
driverInit_Test
)
{
taos_init
();
}
#if 0
TEST(testCase, connect_Test) {
TEST(testCase, connect_Test) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
assert(pConn != NULL);
assert(pConn != NULL);
...
@@ -398,6 +399,7 @@ TEST(testCase, drop_stable_Test) {
...
@@ -398,6 +399,7 @@ TEST(testCase, drop_stable_Test) {
taos_free_result(pRes);
taos_free_result(pRes);
taos_close(pConn);
taos_close(pConn);
}
}
#endif
//TEST(testCase, create_topic_Test) {
//TEST(testCase, create_topic_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
...
...
source/dnode/mgmt/daemon/src/daemon.c
浏览文件 @
8ecd7a56
...
@@ -139,7 +139,7 @@ void dmnWaitSignal() {
...
@@ -139,7 +139,7 @@ void dmnWaitSignal() {
void
dmnInitOption
(
SDnodeOpt
*
pOption
)
{
void
dmnInitOption
(
SDnodeOpt
*
pOption
)
{
pOption
->
sver
=
30000000
;
//3.0.0.0
pOption
->
sver
=
30000000
;
//3.0.0.0
pOption
->
numOfCores
=
tsNumOfCores
;
pOption
->
numOfCores
=
tsNumOfCores
;
pOption
->
numOfSupportVnodes
=
1
;
pOption
->
numOfSupportVnodes
=
1
6
;
pOption
->
numOfCommitThreads
=
1
;
pOption
->
numOfCommitThreads
=
1
;
pOption
->
statusInterval
=
tsStatusInterval
;
pOption
->
statusInterval
=
tsStatusInterval
;
pOption
->
numOfThreadsPerCore
=
tsNumOfThreadsPerCore
;
pOption
->
numOfThreadsPerCore
=
tsNumOfThreadsPerCore
;
...
...
source/dnode/mgmt/impl/src/dndBnode.c
浏览文件 @
8ecd7a56
...
@@ -256,7 +256,7 @@ static int32_t dndDropBnode(SDnode *pDnode) {
...
@@ -256,7 +256,7 @@ static int32_t dndDropBnode(SDnode *pDnode) {
}
}
int32_t
dndProcessCreateBnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessCreateBnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
S
CreateBnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
S
DCreateBnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
@@ -268,7 +268,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -268,7 +268,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessDropBnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessDropBnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SD
ropBnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
SD
DropBnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
...
source/dnode/mgmt/impl/src/dndDnode.c
浏览文件 @
8ecd7a56
...
@@ -15,9 +15,12 @@
...
@@ -15,9 +15,12 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "dndDnode.h"
#include "dndDnode.h"
#include "dndBnode.h"
#include "dndMnode.h"
#include "dndQnode.h"
#include "dndSnode.h"
#include "dndTransport.h"
#include "dndTransport.h"
#include "dndVnodes.h"
#include "dndVnodes.h"
#include "dndMnode.h"
static
int32_t
dndInitMgmtWorker
(
SDnode
*
pDnode
);
static
int32_t
dndInitMgmtWorker
(
SDnode
*
pDnode
);
static
void
dndCleanupMgmtWorker
(
SDnode
*
pDnode
);
static
void
dndCleanupMgmtWorker
(
SDnode
*
pDnode
);
...
@@ -393,13 +396,11 @@ void dndSendStatusMsg(SDnode *pDnode) {
...
@@ -393,13 +396,11 @@ void dndSendStatusMsg(SDnode *pDnode) {
static
void
dndUpdateDnodeCfg
(
SDnode
*
pDnode
,
SDnodeCfg
*
pCfg
)
{
static
void
dndUpdateDnodeCfg
(
SDnode
*
pDnode
,
SDnodeCfg
*
pCfg
)
{
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
if
(
pMgmt
->
dnodeId
==
0
||
pMgmt
->
dropped
!=
pCfg
->
dropped
)
{
if
(
pMgmt
->
dnodeId
==
0
)
{
dInfo
(
"set dnodeId:%d clusterId:% "
PRId64
" dropped:%d"
,
pCfg
->
dnodeId
,
pCfg
->
clusterId
,
pCfg
->
dropped
);
dInfo
(
"set dnodeId:%d clusterId:% "
PRId64
,
pCfg
->
dnodeId
,
pCfg
->
clusterId
);
taosWLockLatch
(
&
pMgmt
->
latch
);
taosWLockLatch
(
&
pMgmt
->
latch
);
pMgmt
->
dnodeId
=
pCfg
->
dnodeId
;
pMgmt
->
dnodeId
=
pCfg
->
dnodeId
;
pMgmt
->
clusterId
=
pCfg
->
clusterId
;
pMgmt
->
clusterId
=
pCfg
->
clusterId
;
pMgmt
->
dropped
=
pCfg
->
dropped
;
dndWriteDnodes
(
pDnode
);
dndWriteDnodes
(
pDnode
);
taosWUnLockLatch
(
&
pMgmt
->
latch
);
taosWUnLockLatch
(
&
pMgmt
->
latch
);
}
}
...
@@ -430,6 +431,11 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
...
@@ -430,6 +431,11 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
if
(
pMsg
->
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pMsg
->
code
!=
TSDB_CODE_SUCCESS
)
{
pMgmt
->
statusSent
=
0
;
pMgmt
->
statusSent
=
0
;
if
(
pMsg
->
code
==
TSDB_CODE_MND_DNODE_NOT_EXIST
&&
!
pMgmt
->
dropped
&&
pMgmt
->
dnodeId
>
0
)
{
dInfo
(
"dnode:%d, set to dropped since not exist in mnode"
,
pMgmt
->
dnodeId
);
pMgmt
->
dropped
=
1
;
dndWriteDnodes
(
pDnode
);
}
return
;
return
;
}
}
...
@@ -439,11 +445,6 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
...
@@ -439,11 +445,6 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
pCfg
->
clusterId
=
htobe64
(
pCfg
->
clusterId
);
pCfg
->
clusterId
=
htobe64
(
pCfg
->
clusterId
);
dndUpdateDnodeCfg
(
pDnode
,
pCfg
);
dndUpdateDnodeCfg
(
pDnode
,
pCfg
);
if
(
pCfg
->
dropped
)
{
pMgmt
->
statusSent
=
0
;
return
;
}
SDnodeEps
*
pDnodeEps
=
&
pRsp
->
dnodeEps
;
SDnodeEps
*
pDnodeEps
=
&
pRsp
->
dnodeEps
;
pDnodeEps
->
num
=
htonl
(
pDnodeEps
->
num
);
pDnodeEps
->
num
=
htonl
(
pDnodeEps
->
num
);
for
(
int32_t
i
=
0
;
i
<
pDnodeEps
->
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pDnodeEps
->
num
;
++
i
)
{
...
@@ -487,7 +488,7 @@ static void *dnodeThreadRoutine(void *param) {
...
@@ -487,7 +488,7 @@ static void *dnodeThreadRoutine(void *param) {
pthread_testcancel
();
pthread_testcancel
();
taosMsleep
(
ms
);
taosMsleep
(
ms
);
if
(
dndGetStat
(
pDnode
)
==
DND_STAT_RUNNING
&&
!
pMgmt
->
statusSent
)
{
if
(
dndGetStat
(
pDnode
)
==
DND_STAT_RUNNING
&&
!
pMgmt
->
statusSent
&&
!
pMgmt
->
dropped
)
{
dndSendStatusMsg
(
pDnode
);
dndSendStatusMsg
(
pDnode
);
}
}
}
}
...
@@ -522,6 +523,11 @@ int32_t dndInitDnode(SDnode *pDnode) {
...
@@ -522,6 +523,11 @@ int32_t dndInitDnode(SDnode *pDnode) {
return
-
1
;
return
-
1
;
}
}
if
(
pMgmt
->
dropped
)
{
dError
(
"dnode will not start for its already dropped"
);
return
-
1
;
}
if
(
dndInitMgmtWorker
(
pDnode
)
!=
0
)
{
if
(
dndInitMgmtWorker
(
pDnode
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
...
@@ -645,6 +651,24 @@ static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
...
@@ -645,6 +651,24 @@ static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
case
TDMT_DND_DROP_MNODE
:
case
TDMT_DND_DROP_MNODE
:
code
=
dndProcessDropMnodeReq
(
pDnode
,
pMsg
);
code
=
dndProcessDropMnodeReq
(
pDnode
,
pMsg
);
break
;
break
;
case
TDMT_DND_CREATE_QNODE
:
code
=
dndProcessCreateQnodeReq
(
pDnode
,
pMsg
);
break
;
case
TDMT_DND_DROP_QNODE
:
code
=
dndProcessDropQnodeReq
(
pDnode
,
pMsg
);
break
;
case
TDMT_DND_CREATE_SNODE
:
code
=
dndProcessCreateSnodeReq
(
pDnode
,
pMsg
);
break
;
case
TDMT_DND_DROP_SNODE
:
code
=
dndProcessDropSnodeReq
(
pDnode
,
pMsg
);
break
;
case
TDMT_DND_CREATE_BNODE
:
code
=
dndProcessCreateBnodeReq
(
pDnode
,
pMsg
);
break
;
case
TDMT_DND_DROP_BNODE
:
code
=
dndProcessDropBnodeReq
(
pDnode
,
pMsg
);
break
;
case
TDMT_DND_CONFIG_DNODE
:
case
TDMT_DND_CONFIG_DNODE
:
code
=
dndProcessConfigDnodeReq
(
pDnode
,
pMsg
);
code
=
dndProcessConfigDnodeReq
(
pDnode
,
pMsg
);
break
;
break
;
...
...
source/dnode/mgmt/impl/src/dndMnode.c
浏览文件 @
8ecd7a56
...
@@ -299,7 +299,7 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
...
@@ -299,7 +299,7 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
memcpy
(
&
pOption
->
replicas
,
pMgmt
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
memcpy
(
&
pOption
->
replicas
,
pMgmt
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
}
}
static
int32_t
dndBuildMnodeOptionFromMsg
(
SDnode
*
pDnode
,
SMnodeOpt
*
pOption
,
S
CreateMnodeIn
Msg
*
pMsg
)
{
static
int32_t
dndBuildMnodeOptionFromMsg
(
SDnode
*
pDnode
,
SMnodeOpt
*
pOption
,
S
DCreateMnode
Msg
*
pMsg
)
{
dndInitMnodeOption
(
pDnode
,
pOption
);
dndInitMnodeOption
(
pDnode
,
pOption
);
pOption
->
dnodeId
=
dndGetDnodeId
(
pDnode
);
pOption
->
dnodeId
=
dndGetDnodeId
(
pDnode
);
pOption
->
clusterId
=
dndGetClusterId
(
pDnode
);
pOption
->
clusterId
=
dndGetClusterId
(
pDnode
);
...
@@ -417,8 +417,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
...
@@ -417,8 +417,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
return
0
;
return
0
;
}
}
static
S
CreateMnodeIn
Msg
*
dndParseCreateMnodeMsg
(
SRpcMsg
*
pRpcMsg
)
{
static
S
DCreateMnode
Msg
*
dndParseCreateMnodeMsg
(
SRpcMsg
*
pRpcMsg
)
{
S
CreateMnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
S
DCreateMnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
for
(
int32_t
i
=
0
;
i
<
pMsg
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pMsg
->
replica
;
++
i
)
{
pMsg
->
replicas
[
i
].
id
=
htonl
(
pMsg
->
replicas
[
i
].
id
);
pMsg
->
replicas
[
i
].
id
=
htonl
(
pMsg
->
replicas
[
i
].
id
);
...
@@ -429,7 +429,7 @@ static SCreateMnodeInMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
...
@@ -429,7 +429,7 @@ static SCreateMnodeInMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessCreateMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessCreateMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
S
CreateMnodeIn
Msg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
);
S
DCreateMnode
Msg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
...
@@ -445,7 +445,7 @@ int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -445,7 +445,7 @@ int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessAlterMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessAlterMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
S
AlterMnodeIn
Msg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
);
S
DAlterMnode
Msg
*
pMsg
=
dndParseCreateMnodeMsg
(
pRpcMsg
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
...
@@ -465,7 +465,7 @@ int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -465,7 +465,7 @@ int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessDropMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessDropMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SD
ropMnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
SD
DropMnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
...
source/dnode/mgmt/impl/src/dndQnode.c
浏览文件 @
8ecd7a56
...
@@ -261,7 +261,7 @@ static int32_t dndDropQnode(SDnode *pDnode) {
...
@@ -261,7 +261,7 @@ static int32_t dndDropQnode(SDnode *pDnode) {
}
}
int32_t
dndProcessCreateQnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessCreateQnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
S
CreateQnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
S
DCreateQnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
@@ -273,7 +273,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -273,7 +273,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessDropQnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessDropQnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SD
ropQnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
SD
DropQnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
...
source/dnode/mgmt/impl/src/dndSnode.c
浏览文件 @
8ecd7a56
...
@@ -256,7 +256,7 @@ static int32_t dndDropSnode(SDnode *pDnode) {
...
@@ -256,7 +256,7 @@ static int32_t dndDropSnode(SDnode *pDnode) {
}
}
int32_t
dndProcessCreateSnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessCreateSnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
S
CreateSnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
S
DCreateSnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
@@ -268,7 +268,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
...
@@ -268,7 +268,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessDropSnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
dndProcessDropSnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpcMsg
)
{
SD
ropSnodeIn
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
SD
DropSnode
Msg
*
pMsg
=
pRpcMsg
->
pCont
;
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
pMsg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
pMsg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
8ecd7a56
...
@@ -37,6 +37,18 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
...
@@ -37,6 +37,18 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_ALTER_MNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_ALTER_MNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_MNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_MNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_MNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_MNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_QNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_QNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_QNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_QNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_SNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_SNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_SNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_SNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_BNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_BNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_BNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_DROP_BNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_VNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_VNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_VNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_CREATE_VNODE_RSP
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_ALTER_VNODE
)]
=
dndProcessMgmtMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_DND_ALTER_VNODE
)]
=
dndProcessMgmtMsg
;
...
@@ -66,6 +78,12 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
...
@@ -66,6 +78,12 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_MNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_MNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_MNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_MNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_QNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_QNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_SNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_SNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_BNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_BNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_DB
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_DB
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DB
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DB
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_USE_DB
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_USE_DB
)]
=
dndProcessMnodeWriteMsg
;
...
@@ -367,6 +385,7 @@ void dndCleanupTrans(SDnode *pDnode) {
...
@@ -367,6 +385,7 @@ void dndCleanupTrans(SDnode *pDnode) {
void
dndSendMsgToDnode
(
SDnode
*
pDnode
,
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
void
dndSendMsgToDnode
(
SDnode
*
pDnode
,
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
STransMgmt
*
pMgmt
=
&
pDnode
->
tmgmt
;
STransMgmt
*
pMgmt
=
&
pDnode
->
tmgmt
;
if
(
pMgmt
->
clientRpc
==
NULL
)
return
;
rpcSendRequest
(
pMgmt
->
clientRpc
,
pEpSet
,
pMsg
,
NULL
);
rpcSendRequest
(
pMgmt
->
clientRpc
,
pEpSet
,
pMsg
,
NULL
);
}
}
...
...
source/dnode/mgmt/impl/test/CMakeLists.txt
浏览文件 @
8ecd7a56
...
@@ -8,6 +8,9 @@ add_subdirectory(db)
...
@@ -8,6 +8,9 @@ add_subdirectory(db)
add_subdirectory
(
dnode
)
add_subdirectory
(
dnode
)
# add_subdirectory(func)
# add_subdirectory(func)
add_subdirectory
(
mnode
)
add_subdirectory
(
mnode
)
add_subdirectory
(
qnode
)
add_subdirectory
(
snode
)
add_subdirectory
(
bnode
)
add_subdirectory
(
profile
)
add_subdirectory
(
profile
)
add_subdirectory
(
show
)
add_subdirectory
(
show
)
add_subdirectory
(
stb
)
add_subdirectory
(
stb
)
...
...
source/dnode/mgmt/impl/test/bnode/CMakeLists.txt
0 → 100644
浏览文件 @
8ecd7a56
aux_source_directory
(
. STEST_SRC
)
add_executable
(
dnode_test_bnode
${
STEST_SRC
}
)
target_link_libraries
(
dnode_test_bnode
PUBLIC sut
)
add_test
(
NAME dnode_test_bnode
COMMAND dnode_test_bnode
)
source/dnode/mgmt/impl/test/bnode/bnode.cpp
0 → 100644
浏览文件 @
8ecd7a56
/**
* @file dnode.cpp
* @author slguan (slguan@taosdata.com)
* @brief DNODE module dnode-msg tests
* @version 0.1
* @date 2021-12-15
*
* @copyright Copyright (c) 2021
*
*/
#include "base.h"
class
DndTestBnode
:
public
::
testing
::
Test
{
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
public:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_bnode1"
,
9068
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9068"
;
server2
.
Start
(
"/tmp/dnode_test_bnode2"
,
fqdn
,
9069
,
firstEp
);
taosMsleep
(
300
);
}
static
void
TearDownTestSuite
()
{
server2
.
Stop
();
test
.
Cleanup
();
}
static
Testbase
test
;
static
TestServer
server2
;
};
Testbase
DndTestBnode
::
test
;
TestServer
DndTestBnode
::
server2
;
TEST_F
(
DndTestBnode
,
01
_ShowBnode
)
{
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_BNODE
,
""
);
CHECK_META
(
"show bnodes"
,
3
);
CHECK_SCHEMA
(
0
,
TSDB_DATA_TYPE_SMALLINT
,
2
,
"id"
);
CHECK_SCHEMA
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
"endpoint"
);
CHECK_SCHEMA
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
0
);
}
TEST_F
(
DndTestBnode
,
02
_Create_Bnode_Invalid_Id
)
{
{
int32_t
contLen
=
sizeof
(
SMCreateBnodeMsg
);
SMCreateBnodeMsg
*
pReq
=
(
SMCreateBnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_BNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_BNODE
,
""
);
CHECK_META
(
"show bnodes"
,
3
);
CHECK_SCHEMA
(
0
,
TSDB_DATA_TYPE_SMALLINT
,
2
,
"id"
);
CHECK_SCHEMA
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
"endpoint"
);
CHECK_SCHEMA
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9068"
,
TSDB_EP_LEN
);
CheckTimestamp
();
}
}
TEST_F
(
DndTestBnode
,
03
_Create_Bnode_Invalid_Id
)
{
{
int32_t
contLen
=
sizeof
(
SMCreateBnodeMsg
);
SMCreateBnodeMsg
*
pReq
=
(
SMCreateBnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_BNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_DNODE_NOT_EXIST
);
}
}
TEST_F
(
DndTestBnode
,
04
_Create_Bnode
)
{
{
// create dnode
int32_t
contLen
=
sizeof
(
SCreateDnodeMsg
);
SCreateDnodeMsg
*
pReq
=
(
SCreateDnodeMsg
*
)
rpcMallocCont
(
contLen
);
strcpy
(
pReq
->
fqdn
,
"localhost"
);
pReq
->
port
=
htonl
(
9069
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_DNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
taosMsleep
(
1300
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_DNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
}
{
// create bnode
int32_t
contLen
=
sizeof
(
SMCreateBnodeMsg
);
SMCreateBnodeMsg
*
pReq
=
(
SMCreateBnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_BNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_BNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
CheckInt16
(
1
);
CheckInt16
(
2
);
CheckBinary
(
"localhost:9068"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:9069"
,
TSDB_EP_LEN
);
CheckTimestamp
();
CheckTimestamp
();
}
{
// drop bnode
int32_t
contLen
=
sizeof
(
SMDropBnodeMsg
);
SMDropBnodeMsg
*
pReq
=
(
SMDropBnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_DROP_BNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_BNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9068"
,
TSDB_EP_LEN
);
CheckTimestamp
();
}
}
\ No newline at end of file
source/dnode/mgmt/impl/test/dnode/dnode.cpp
浏览文件 @
8ecd7a56
...
@@ -68,7 +68,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
...
@@ -68,7 +68,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
CheckInt16
(
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9041"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:9041"
,
TSDB_EP_LEN
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckTimestamp
();
CheckTimestamp
();
CheckBinary
(
""
,
24
);
CheckBinary
(
""
,
24
);
...
@@ -112,8 +112,8 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
...
@@ -112,8 +112,8 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
CheckBinary
(
"localhost:9042"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:9042"
,
TSDB_EP_LEN
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckTimestamp
();
CheckTimestamp
();
...
@@ -140,7 +140,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
...
@@ -140,7 +140,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
CheckInt16
(
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9041"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:9041"
,
TSDB_EP_LEN
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckTimestamp
();
CheckTimestamp
();
CheckBinary
(
""
,
24
);
CheckBinary
(
""
,
24
);
...
@@ -199,10 +199,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
...
@@ -199,10 +199,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
...
@@ -242,10 +242,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
...
@@ -242,10 +242,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
0
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckInt16
(
1
);
CheckInt16
(
1
6
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
CheckBinary
(
"ready"
,
10
);
...
...
source/dnode/mgmt/impl/test/mnode/mnode.cpp
浏览文件 @
8ecd7a56
...
@@ -72,9 +72,9 @@ TEST_F(DndTestMnode, 01_ShowDnode) {
...
@@ -72,9 +72,9 @@ TEST_F(DndTestMnode, 01_ShowDnode) {
TEST_F
(
DndTestMnode
,
02
_Create_Mnode_Invalid_Id
)
{
TEST_F
(
DndTestMnode
,
02
_Create_Mnode_Invalid_Id
)
{
{
{
int32_t
contLen
=
sizeof
(
SCreateMnodeMsg
);
int32_t
contLen
=
sizeof
(
S
M
CreateMnodeMsg
);
S
CreateMnodeMsg
*
pReq
=
(
S
CreateMnodeMsg
*
)
rpcMallocCont
(
contLen
);
S
MCreateMnodeMsg
*
pReq
=
(
SM
CreateMnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
pReq
->
dnodeId
=
htonl
(
1
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
...
@@ -85,9 +85,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
...
@@ -85,9 +85,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
TEST_F
(
DndTestMnode
,
03
_Create_Mnode_Invalid_Id
)
{
TEST_F
(
DndTestMnode
,
03
_Create_Mnode_Invalid_Id
)
{
{
{
int32_t
contLen
=
sizeof
(
SCreateMnodeMsg
);
int32_t
contLen
=
sizeof
(
S
M
CreateMnodeMsg
);
S
CreateMnodeMsg
*
pReq
=
(
S
CreateMnodeMsg
*
)
rpcMallocCont
(
contLen
);
S
MCreateMnodeMsg
*
pReq
=
(
SM
CreateMnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
...
@@ -117,9 +117,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
...
@@ -117,9 +117,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
{
{
// create mnode
// create mnode
int32_t
contLen
=
sizeof
(
SCreateMnodeMsg
);
int32_t
contLen
=
sizeof
(
S
M
CreateMnodeMsg
);
S
CreateMnodeMsg
*
pReq
=
(
S
CreateMnodeMsg
*
)
rpcMallocCont
(
contLen
);
S
MCreateMnodeMsg
*
pReq
=
(
SM
CreateMnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_MNODE
,
pReq
,
contLen
);
...
@@ -144,9 +144,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
...
@@ -144,9 +144,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
{
{
// drop mnode
// drop mnode
int32_t
contLen
=
sizeof
(
SDropMnodeMsg
);
int32_t
contLen
=
sizeof
(
S
M
DropMnodeMsg
);
S
DropMnodeMsg
*
pReq
=
(
S
DropMnodeMsg
*
)
rpcMallocCont
(
contLen
);
S
MDropMnodeMsg
*
pReq
=
(
SM
DropMnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_DROP_MNODE
,
pReq
,
contLen
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_DROP_MNODE
,
pReq
,
contLen
);
...
...
source/dnode/mgmt/impl/test/qnode/CMakeLists.txt
0 → 100644
浏览文件 @
8ecd7a56
aux_source_directory
(
. QTEST_SRC
)
add_executable
(
dnode_test_qnode
${
QTEST_SRC
}
)
target_link_libraries
(
dnode_test_qnode
PUBLIC sut
)
add_test
(
NAME dnode_test_qnode
COMMAND dnode_test_qnode
)
source/dnode/mgmt/impl/test/qnode/qnode.cpp
0 → 100644
浏览文件 @
8ecd7a56
/**
* @file dnode.cpp
* @author slguan (slguan@taosdata.com)
* @brief DNODE module dnode-msg tests
* @version 0.1
* @date 2021-12-15
*
* @copyright Copyright (c) 2021
*
*/
#include "base.h"
class
DndTestQnode
:
public
::
testing
::
Test
{
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
public:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_qnode1"
,
9064
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9064"
;
server2
.
Start
(
"/tmp/dnode_test_qnode2"
,
fqdn
,
9065
,
firstEp
);
taosMsleep
(
300
);
}
static
void
TearDownTestSuite
()
{
server2
.
Stop
();
test
.
Cleanup
();
}
static
Testbase
test
;
static
TestServer
server2
;
};
Testbase
DndTestQnode
::
test
;
TestServer
DndTestQnode
::
server2
;
TEST_F
(
DndTestQnode
,
01
_ShowQnode
)
{
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_QNODE
,
""
);
CHECK_META
(
"show qnodes"
,
3
);
CHECK_SCHEMA
(
0
,
TSDB_DATA_TYPE_SMALLINT
,
2
,
"id"
);
CHECK_SCHEMA
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
"endpoint"
);
CHECK_SCHEMA
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
0
);
}
TEST_F
(
DndTestQnode
,
02
_Create_Qnode_Invalid_Id
)
{
{
int32_t
contLen
=
sizeof
(
SMCreateQnodeMsg
);
SMCreateQnodeMsg
*
pReq
=
(
SMCreateQnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_QNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_QNODE
,
""
);
CHECK_META
(
"show qnodes"
,
3
);
CHECK_SCHEMA
(
0
,
TSDB_DATA_TYPE_SMALLINT
,
2
,
"id"
);
CHECK_SCHEMA
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
"endpoint"
);
CHECK_SCHEMA
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9064"
,
TSDB_EP_LEN
);
CheckTimestamp
();
}
}
TEST_F
(
DndTestQnode
,
03
_Create_Qnode_Invalid_Id
)
{
{
int32_t
contLen
=
sizeof
(
SMCreateQnodeMsg
);
SMCreateQnodeMsg
*
pReq
=
(
SMCreateQnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_QNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_DNODE_NOT_EXIST
);
}
}
TEST_F
(
DndTestQnode
,
04
_Create_Qnode
)
{
{
// create dnode
int32_t
contLen
=
sizeof
(
SCreateDnodeMsg
);
SCreateDnodeMsg
*
pReq
=
(
SCreateDnodeMsg
*
)
rpcMallocCont
(
contLen
);
strcpy
(
pReq
->
fqdn
,
"localhost"
);
pReq
->
port
=
htonl
(
9065
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_DNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
taosMsleep
(
1300
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_DNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
}
{
// create qnode
int32_t
contLen
=
sizeof
(
SMCreateQnodeMsg
);
SMCreateQnodeMsg
*
pReq
=
(
SMCreateQnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_QNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_QNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
CheckInt16
(
1
);
CheckInt16
(
2
);
CheckBinary
(
"localhost:9064"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:9065"
,
TSDB_EP_LEN
);
CheckTimestamp
();
CheckTimestamp
();
}
{
// drop qnode
int32_t
contLen
=
sizeof
(
SMDropQnodeMsg
);
SMDropQnodeMsg
*
pReq
=
(
SMDropQnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_DROP_QNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_QNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9064"
,
TSDB_EP_LEN
);
CheckTimestamp
();
}
}
\ No newline at end of file
source/dnode/mgmt/impl/test/snode/CMakeLists.txt
0 → 100644
浏览文件 @
8ecd7a56
aux_source_directory
(
. STEST_SRC
)
add_executable
(
dnode_test_snode
${
STEST_SRC
}
)
target_link_libraries
(
dnode_test_snode
PUBLIC sut
)
add_test
(
NAME dnode_test_snode
COMMAND dnode_test_snode
)
source/dnode/mgmt/impl/test/snode/snode.cpp
0 → 100644
浏览文件 @
8ecd7a56
/**
* @file dnode.cpp
* @author slguan (slguan@taosdata.com)
* @brief DNODE module dnode-msg tests
* @version 0.1
* @date 2021-12-15
*
* @copyright Copyright (c) 2021
*
*/
#include "base.h"
class
DndTestSnode
:
public
::
testing
::
Test
{
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
public:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_snode1"
,
9066
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9066"
;
server2
.
Start
(
"/tmp/dnode_test_snode2"
,
fqdn
,
9067
,
firstEp
);
taosMsleep
(
300
);
}
static
void
TearDownTestSuite
()
{
server2
.
Stop
();
test
.
Cleanup
();
}
static
Testbase
test
;
static
TestServer
server2
;
};
Testbase
DndTestSnode
::
test
;
TestServer
DndTestSnode
::
server2
;
TEST_F
(
DndTestSnode
,
01
_ShowSnode
)
{
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_SNODE
,
""
);
CHECK_META
(
"show snodes"
,
3
);
CHECK_SCHEMA
(
0
,
TSDB_DATA_TYPE_SMALLINT
,
2
,
"id"
);
CHECK_SCHEMA
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
"endpoint"
);
CHECK_SCHEMA
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
0
);
}
TEST_F
(
DndTestSnode
,
02
_Create_Snode_Invalid_Id
)
{
{
int32_t
contLen
=
sizeof
(
SMCreateSnodeMsg
);
SMCreateSnodeMsg
*
pReq
=
(
SMCreateSnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
1
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_SNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_SNODE
,
""
);
CHECK_META
(
"show snodes"
,
3
);
CHECK_SCHEMA
(
0
,
TSDB_DATA_TYPE_SMALLINT
,
2
,
"id"
);
CHECK_SCHEMA
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
"endpoint"
);
CHECK_SCHEMA
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9066"
,
TSDB_EP_LEN
);
CheckTimestamp
();
}
}
TEST_F
(
DndTestSnode
,
03
_Create_Snode_Invalid_Id
)
{
{
int32_t
contLen
=
sizeof
(
SMCreateSnodeMsg
);
SMCreateSnodeMsg
*
pReq
=
(
SMCreateSnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_SNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_DNODE_NOT_EXIST
);
}
}
TEST_F
(
DndTestSnode
,
04
_Create_Snode
)
{
{
// create dnode
int32_t
contLen
=
sizeof
(
SCreateDnodeMsg
);
SCreateDnodeMsg
*
pReq
=
(
SCreateDnodeMsg
*
)
rpcMallocCont
(
contLen
);
strcpy
(
pReq
->
fqdn
,
"localhost"
);
pReq
->
port
=
htonl
(
9067
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_DNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
taosMsleep
(
1300
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_DNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
}
{
// create snode
int32_t
contLen
=
sizeof
(
SMCreateSnodeMsg
);
SMCreateSnodeMsg
*
pReq
=
(
SMCreateSnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_CREATE_SNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_SNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
2
);
CheckInt16
(
1
);
CheckInt16
(
2
);
CheckBinary
(
"localhost:9066"
,
TSDB_EP_LEN
);
CheckBinary
(
"localhost:9067"
,
TSDB_EP_LEN
);
CheckTimestamp
();
CheckTimestamp
();
}
{
// drop snode
int32_t
contLen
=
sizeof
(
SMDropSnodeMsg
);
SMDropSnodeMsg
*
pReq
=
(
SMDropSnodeMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
dnodeId
=
htonl
(
2
);
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TDMT_MND_DROP_SNODE
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_SNODE
,
""
);
test
.
SendShowRetrieveMsg
();
EXPECT_EQ
(
test
.
GetShowRows
(),
1
);
CheckInt16
(
1
);
CheckBinary
(
"localhost:9066"
,
TSDB_EP_LEN
);
CheckTimestamp
();
}
}
\ No newline at end of file
source/dnode/mgmt/impl/test/stb/stb.cpp
浏览文件 @
8ecd7a56
...
@@ -146,8 +146,8 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
...
@@ -146,8 +146,8 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
}
}
EXPECT_STREQ
(
pRsp
->
tbFname
,
""
);
EXPECT_STREQ
(
pRsp
->
tbFname
,
"
1.d1.stb
"
);
EXPECT_STREQ
(
pRsp
->
stbFname
,
"
1.d1.stb
"
);
EXPECT_STREQ
(
pRsp
->
stbFname
,
""
);
EXPECT_EQ
(
pRsp
->
numOfColumns
,
2
);
EXPECT_EQ
(
pRsp
->
numOfColumns
,
2
);
EXPECT_EQ
(
pRsp
->
numOfTags
,
3
);
EXPECT_EQ
(
pRsp
->
numOfTags
,
3
);
EXPECT_EQ
(
pRsp
->
precision
,
TSDB_TIME_PRECISION_MILLI
);
EXPECT_EQ
(
pRsp
->
precision
,
TSDB_TIME_PRECISION_MILLI
);
...
...
source/dnode/mgmt/impl/test/sut/src/server.cpp
浏览文件 @
8ecd7a56
...
@@ -26,7 +26,7 @@ SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t p
...
@@ -26,7 +26,7 @@ SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t p
SDnodeOpt
option
=
{
0
};
SDnodeOpt
option
=
{
0
};
option
.
sver
=
1
;
option
.
sver
=
1
;
option
.
numOfCores
=
1
;
option
.
numOfCores
=
1
;
option
.
numOfSupportVnodes
=
1
;
option
.
numOfSupportVnodes
=
1
6
;
option
.
numOfCommitThreads
=
1
;
option
.
numOfCommitThreads
=
1
;
option
.
statusInterval
=
1
;
option
.
statusInterval
=
1
;
option
.
numOfThreadsPerCore
=
1
;
option
.
numOfThreadsPerCore
=
1
;
...
...
source/dnode/mnode/impl/inc/mndB
alanc
e.h
→
source/dnode/mnode/impl/inc/mndB
nod
e.h
浏览文件 @
8ecd7a56
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef _TD_MND_B
ALANC
E_H_
#ifndef _TD_MND_B
NOD
E_H_
#define _TD_MND_B
ALANC
E_H_
#define _TD_MND_B
NOD
E_H_
#include "mndInt.h"
#include "mndInt.h"
...
@@ -22,11 +22,11 @@
...
@@ -22,11 +22,11 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
int32_t
mndInitB
alanc
e
(
SMnode
*
pMnode
);
int32_t
mndInitB
nod
e
(
SMnode
*
pMnode
);
void
mndCleanupB
alanc
e
(
SMnode
*
pMnode
);
void
mndCleanupB
nod
e
(
SMnode
*
pMnode
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
#endif
/*_TD_MND_B
ALANC
E_H_*/
#endif
/*_TD_MND_B
NOD
E_H_*/
source/dnode/mnode/impl/inc/mndConsumer.h
0 → 100644
浏览文件 @
8ecd7a56
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_CONSUMER_H_
#define _TD_MND_CONSUMER_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitConsumer
(
SMnode
*
pMnode
);
void
mndCleanupConsumer
(
SMnode
*
pMnode
);
SConsumerObj
*
mndAcquireConsumer
(
SMnode
*
pMnode
,
int32_t
consumerId
);
void
mndReleaseConsumer
(
SMnode
*
pMnode
,
SConsumerObj
*
pConsumer
);
SCGroupObj
*
mndAcquireCGroup
(
SMnode
*
pMnode
,
char
*
consumerGroup
);
void
mndReleaseCGroup
(
SMnode
*
pMnode
,
SCGroupObj
*
pCGroup
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_CONSUMER_H_*/
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
8ecd7a56
...
@@ -124,12 +124,8 @@ typedef struct {
...
@@ -124,12 +124,8 @@ typedef struct {
int64_t
rebootTime
;
int64_t
rebootTime
;
int64_t
lastAccessTime
;
int64_t
lastAccessTime
;
int32_t
accessTimes
;
int32_t
accessTimes
;
int16_t
numOfMnodes
;
int16_t
numOfVnodes
;
int16_t
numOfVnodes
;
int16_t
numOfQnodes
;
int16_t
numOfSupportMnodes
;
int16_t
numOfSupportVnodes
;
int16_t
numOfSupportVnodes
;
int16_t
numOfSupportQnodes
;
int16_t
numOfCores
;
int16_t
numOfCores
;
EDndStatus
status
;
EDndStatus
status
;
EDndReason
offlineReason
;
EDndReason
offlineReason
;
...
@@ -148,6 +144,27 @@ typedef struct {
...
@@ -148,6 +144,27 @@ typedef struct {
SDnodeObj
*
pDnode
;
SDnodeObj
*
pDnode
;
}
SMnodeObj
;
}
SMnodeObj
;
typedef
struct
{
int32_t
id
;
int64_t
createdTime
;
int64_t
updateTime
;
SDnodeObj
*
pDnode
;
}
SQnodeObj
;
typedef
struct
{
int32_t
id
;
int64_t
createdTime
;
int64_t
updateTime
;
SDnodeObj
*
pDnode
;
}
SSnodeObj
;
typedef
struct
{
int32_t
id
;
int64_t
createdTime
;
int64_t
updateTime
;
SDnodeObj
*
pDnode
;
}
SBnodeObj
;
typedef
struct
{
typedef
struct
{
int32_t
maxUsers
;
int32_t
maxUsers
;
int32_t
maxDbs
;
int32_t
maxDbs
;
...
@@ -305,8 +322,34 @@ typedef struct {
...
@@ -305,8 +322,34 @@ typedef struct {
void
*
executor
;
void
*
executor
;
int32_t
sqlLen
;
int32_t
sqlLen
;
char
*
sql
;
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
}
STopicObj
;
}
STopicObj
;
typedef
struct
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
int64_t
createTime
;
int64_t
updateTime
;
uint64_t
uid
;
//uint64_t dbUid;
int32_t
version
;
SRWLatch
lock
;
}
SConsumerObj
;
typedef
struct
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
int64_t
createTime
;
int64_t
updateTime
;
uint64_t
uid
;
//uint64_t dbUid;
int32_t
version
;
SRWLatch
lock
;
}
SCGroupObj
;
typedef
struct
SMnodeMsg
{
typedef
struct
SMnodeMsg
{
char
user
[
TSDB_USER_LEN
];
char
user
[
TSDB_USER_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
...
...
source/dnode/mnode/impl/inc/mndInt.h
浏览文件 @
8ecd7a56
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "mndDef.h"
#include "mndDef.h"
#include "sdb.h"
#include "sdb.h"
#include "tcache.h"
#include "tcache.h"
#include "tep.h"
#include "tqueue.h"
#include "tqueue.h"
#include "ttime.h"
#include "ttime.h"
...
...
source/dnode/mnode/impl/
src/mndBalance.c
→
source/dnode/mnode/impl/
inc/mndQnode.h
浏览文件 @
8ecd7a56
...
@@ -13,9 +13,20 @@
...
@@ -13,9 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#define _DEFAULT_SOURCE
#ifndef _TD_MND_QNODE_H_
#include "os.h"
#define _TD_MND_QNODE_H_
#include "mndInt.h"
#include "mndInt.h"
int32_t
mndInitBalance
(
SMnode
*
pMnode
)
{
return
0
;
}
#ifdef __cplusplus
void
mndCleanupBalance
(
SMnode
*
pMnode
)
{}
extern
"C"
{
\ No newline at end of file
#endif
int32_t
mndInitQnode
(
SMnode
*
pMnode
);
void
mndCleanupQnode
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_QNODE_H_*/
source/dnode/mnode/impl/inc/mndSnode.h
0 → 100644
浏览文件 @
8ecd7a56
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_SNODE_H_
#define _TD_MND_SNODE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitSnode
(
SMnode
*
pMnode
);
void
mndCleanupSnode
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_SNODE_H_*/
source/dnode/mnode/impl/inc/mndVgroup.h
浏览文件 @
8ecd7a56
...
@@ -29,6 +29,7 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
...
@@ -29,6 +29,7 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
SSdbRaw
*
mndVgroupActionEncode
(
SVgObj
*
pVgroup
);
SSdbRaw
*
mndVgroupActionEncode
(
SVgObj
*
pVgroup
);
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
);
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
);
SEpSet
mndGetVgroupEpset
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
);
SEpSet
mndGetVgroupEpset
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
);
int32_t
mndGetVnodesNum
(
SMnode
*
pMnode
,
int32_t
dnodeId
);
SCreateVnodeMsg
*
mndBuildCreateVnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
);
SCreateVnodeMsg
*
mndBuildCreateVnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
);
SDropVnodeMsg
*
mndBuildDropVnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
);
SDropVnodeMsg
*
mndBuildDropVnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
);
...
...
source/dnode/mnode/impl/src/mndBnode.c
0 → 100644
浏览文件 @
8ecd7a56
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "mndBnode.h"
#include "mndDnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#define TSDB_BNODE_VER_NUMBER 1
#define TSDB_BNODE_RESERVE_SIZE 64
static
SSdbRaw
*
mndBnodeActionEncode
(
SBnodeObj
*
pObj
);
static
SSdbRow
*
mndBnodeActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndBnodeActionInsert
(
SSdb
*
pSdb
,
SBnodeObj
*
pObj
);
static
int32_t
mndBnodeActionDelete
(
SSdb
*
pSdb
,
SBnodeObj
*
pObj
);
static
int32_t
mndBnodeActionUpdate
(
SSdb
*
pSdb
,
SBnodeObj
*
pOldBnode
,
SBnodeObj
*
pNewBnode
);
static
int32_t
mndProcessCreateBnodeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropBnodeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateBnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropBnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetBnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveBnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextBnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitBnode
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_BNODE
,
.
keyType
=
SDB_KEY_INT32
,
.
encodeFp
=
(
SdbEncodeFp
)
mndBnodeActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndBnodeActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndBnodeActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndBnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndBnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_BNODE
,
mndProcessCreateBnodeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DROP_BNODE
,
mndProcessDropBnodeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_CREATE_BNODE_RSP
,
mndProcessCreateBnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_DROP_BNODE_RSP
,
mndProcessDropBnodeRsp
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_BNODE
,
mndGetBnodeMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_BNODE
,
mndRetrieveBnodes
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_BNODE
,
mndCancelGetNextBnode
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupBnode
(
SMnode
*
pMnode
)
{}
static
SBnodeObj
*
mndAcquireBnode
(
SMnode
*
pMnode
,
int32_t
snodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SBnodeObj
*
pObj
=
sdbAcquire
(
pSdb
,
SDB_BNODE
,
&
snodeId
);
if
(
pObj
==
NULL
)
{
terrno
=
TSDB_CODE_MND_BNODE_NOT_EXIST
;
}
return
pObj
;
}
static
void
mndReleaseBnode
(
SMnode
*
pMnode
,
SBnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pObj
);
}
static
SSdbRaw
*
mndBnodeActionEncode
(
SBnodeObj
*
pObj
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_BNODE
,
TSDB_BNODE_VER_NUMBER
,
sizeof
(
SBnodeObj
)
+
TSDB_BNODE_RESERVE_SIZE
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_INT32
(
pRaw
,
dataPos
,
pObj
->
id
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pObj
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pObj
->
updateTime
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_BNODE_RESERVE_SIZE
)
return
pRaw
;
}
static
SSdbRow
*
mndBnodeActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_BNODE_VER_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode snode since %s"
,
terrstr
());
return
NULL
;
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SBnodeObj
));
SBnodeObj
*
pObj
=
sdbGetRowObj
(
pRow
);
if
(
pObj
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
id
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
updateTime
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_BNODE_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndBnodeActionInsert
(
SSdb
*
pSdb
,
SBnodeObj
*
pObj
)
{
mTrace
(
"snode:%d, perform insert action"
,
pObj
->
id
);
pObj
->
pDnode
=
sdbAcquire
(
pSdb
,
SDB_DNODE
,
&
pObj
->
id
);
if
(
pObj
->
pDnode
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
mError
(
"snode:%d, failed to perform insert action since %s"
,
pObj
->
id
,
terrstr
());
return
-
1
;
}
return
0
;
}
static
int32_t
mndBnodeActionDelete
(
SSdb
*
pSdb
,
SBnodeObj
*
pObj
)
{
mTrace
(
"snode:%d, perform delete action"
,
pObj
->
id
);
if
(
pObj
->
pDnode
!=
NULL
)
{
sdbRelease
(
pSdb
,
pObj
->
pDnode
);
pObj
->
pDnode
=
NULL
;
}
return
0
;
}
static
int32_t
mndBnodeActionUpdate
(
SSdb
*
pSdb
,
SBnodeObj
*
pOldBnode
,
SBnodeObj
*
pNewBnode
)
{
mTrace
(
"snode:%d, perform update action"
,
pOldBnode
->
id
);
pOldBnode
->
updateTime
=
pNewBnode
->
updateTime
;
return
0
;
}
static
int32_t
mndSetCreateBnodeRedoLogs
(
STrans
*
pTrans
,
SBnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndBnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateBnodeCommitLogs
(
STrans
*
pTrans
,
SBnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndBnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateBnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SBnodeObj
*
pObj
)
{
SDCreateBnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDCreateBnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pDnode
->
id
);
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDCreateBnodeMsg
);
action
.
msgType
=
TDMT_DND_CREATE_BNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndCreateBnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
,
SMCreateBnodeMsg
*
pCreate
)
{
SBnodeObj
snodeObj
=
{
0
};
snodeObj
.
id
=
pDnode
->
id
;
snodeObj
.
createdTime
=
taosGetTimestampMs
();
snodeObj
.
updateTime
=
snodeObj
.
createdTime
;
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"snode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
goto
CREATE_BNODE_OVER
;
}
mDebug
(
"trans:%d, used to create snode:%d"
,
pTrans
->
id
,
pCreate
->
dnodeId
);
if
(
mndSetCreateBnodeRedoLogs
(
pTrans
,
&
snodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_BNODE_OVER
;
}
if
(
mndSetCreateBnodeCommitLogs
(
pTrans
,
&
snodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_BNODE_OVER
;
}
if
(
mndSetCreateBnodeRedoActions
(
pTrans
,
pDnode
,
&
snodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_BNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_BNODE_OVER
;
}
code
=
0
;
CREATE_BNODE_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndProcessCreateBnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMCreateBnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
mDebug
(
"snode:%d, start to create"
,
pCreate
->
dnodeId
);
SBnodeObj
*
pObj
=
mndAcquireBnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pObj
!=
NULL
)
{
mError
(
"snode:%d, snode already exist"
,
pObj
->
id
);
mndReleaseBnode
(
pMnode
,
pObj
);
return
-
1
;
}
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"snode:%d, dnode not exist"
,
pCreate
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateBnode
(
pMnode
,
pMsg
,
pDnode
,
pCreate
);
mndReleaseDnode
(
pMnode
,
pDnode
);
if
(
code
!=
0
)
{
mError
(
"snode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndSetDropBnodeRedoLogs
(
STrans
*
pTrans
,
SBnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndBnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropBnodeCommitLogs
(
STrans
*
pTrans
,
SBnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndBnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropBnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SBnodeObj
*
pObj
)
{
SDDropBnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDDropBnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pDnode
->
id
);
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDDropBnodeMsg
);
action
.
msgType
=
TDMT_DND_DROP_BNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndDropBnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SBnodeObj
*
pObj
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"snode:%d, failed to drop since %s"
,
pObj
->
id
,
terrstr
());
goto
DROP_BNODE_OVER
;
}
mDebug
(
"trans:%d, used to drop snode:%d"
,
pTrans
->
id
,
pObj
->
id
);
if
(
mndSetDropBnodeRedoLogs
(
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_BNODE_OVER
;
}
if
(
mndSetDropBnodeCommitLogs
(
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_BNODE_OVER
;
}
if
(
mndSetDropBnodeRedoActions
(
pTrans
,
pObj
->
pDnode
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_BNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_BNODE_OVER
;
}
code
=
0
;
DROP_BNODE_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndProcessDropBnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMDropBnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"snode:%d, start to drop"
,
pDrop
->
dnodeId
);
if
(
pDrop
->
dnodeId
<=
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"snode:%d, failed to drop since %s"
,
pDrop
->
dnodeId
,
terrstr
());
return
-
1
;
}
SBnodeObj
*
pObj
=
mndAcquireBnode
(
pMnode
,
pDrop
->
dnodeId
);
if
(
pObj
==
NULL
)
{
mError
(
"snode:%d, not exist"
,
pDrop
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndDropBnode
(
pMnode
,
pMsg
,
pObj
);
if
(
code
!=
0
)
{
mError
(
"snode:%d, failed to drop since %s"
,
pMnode
->
dnodeId
,
terrstr
());
return
-
1
;
}
sdbRelease
(
pMnode
->
pSdb
,
pMnode
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessCreateBnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndProcessDropBnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndGetBnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"endpoint"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htonl
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_BNODE
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tbFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveBnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SBnodeObj
*
pObj
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_BNODE
,
pShow
->
pIter
,
(
void
**
)
&
pObj
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pObj
->
id
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pObj
->
pDnode
->
ep
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pObj
->
createdTime
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pObj
);
}
mndVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextBnode
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
source/dnode/mnode/impl/src/mndConsumer.c
0 → 100644
浏览文件 @
8ecd7a56
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "mndConsumer.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndShow.h"
#include "mndStb.h"
#include "mndTopic.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "tname.h"
#define MND_CONSUMER_VER_NUMBER 1
#define MND_CONSUMER_RESERVE_SIZE 64
static
SSdbRaw
*
mndConsumerActionEncode
(
SConsumerObj
*
pConsumer
);
static
SSdbRow
*
mndConsumerActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndConsumerActionInsert
(
SSdb
*
pSdb
,
SConsumerObj
*
pConsumer
);
static
int32_t
mndConsumerActionDelete
(
SSdb
*
pSdb
,
SConsumerObj
*
pConsumer
);
static
int32_t
mndConsumerActionUpdate
(
SSdb
*
pSdb
,
SConsumerObj
*
pConsumer
,
SConsumerObj
*
pNewConsumer
);
static
int32_t
mndProcessCreateConsumerMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropConsumerMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropConsumerInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessConsumerMetaMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetConsumerMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveConsumer
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextConsumer
(
SMnode
*
pMnode
,
void
*
pIter
);
static
int32_t
mndProcessSubscribeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessSubscribeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessSubscribeInternalReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessSubscribeInternalRsp
(
SMnodeMsg
*
pMsg
);
int32_t
mndInitConsumer
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_CONSUMER
,
.
keyType
=
SDB_KEY_BINARY
,
.
encodeFp
=
(
SdbEncodeFp
)
mndConsumerActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndConsumerActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndConsumerActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndConsumerActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndConsumerActionDelete
};
mndSetMsgHandle
(
pMnode
,
TDMT_MND_SUBSCRIBE
,
mndProcessSubscribeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_SUBSCRIBE_RSP
,
mndProcessSubscribeRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_SUBSCRIBE
,
mndProcessSubscribeInternalReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_SUBSCRIBE_RSP
,
mndProcessSubscribeInternalRsp
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupConsumer
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndConsumerActionEncode
(
SConsumerObj
*
pConsumer
)
{
int32_t
size
=
sizeof
(
SConsumerObj
)
+
MND_CONSUMER_RESERVE_SIZE
;
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_CONSUMER
,
MND_CONSUMER_VER_NUMBER
,
size
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pConsumer
->
name
,
TSDB_TABLE_FNAME_LEN
);
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pConsumer
->
db
,
TSDB_DB_FNAME_LEN
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pConsumer
->
createTime
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pConsumer
->
updateTime
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pConsumer
->
uid
);
/*SDB_SET_INT64(pRaw, dataPos, pConsumer->dbUid);*/
SDB_SET_INT32
(
pRaw
,
dataPos
,
pConsumer
->
version
);
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
MND_CONSUMER_RESERVE_SIZE
);
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
return
pRaw
;
}
static
SSdbRow
*
mndConsumerActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
MND_CONSUMER_VER_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode consumer since %s"
,
terrstr
());
return
NULL
;
}
int32_t
size
=
sizeof
(
SConsumerObj
)
+
TSDB_MAX_COLUMNS
*
sizeof
(
SSchema
);
SSdbRow
*
pRow
=
sdbAllocRow
(
size
);
SConsumerObj
*
pConsumer
=
sdbGetRowObj
(
pRow
);
if
(
pConsumer
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pConsumer
->
name
,
TSDB_TABLE_FNAME_LEN
);
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pConsumer
->
db
,
TSDB_DB_FNAME_LEN
);
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pConsumer
->
createTime
);
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pConsumer
->
updateTime
);
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pConsumer
->
uid
);
/*SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->dbUid);*/
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pConsumer
->
version
);
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
MND_CONSUMER_RESERVE_SIZE
);
return
pRow
;
}
static
int32_t
mndConsumerActionInsert
(
SSdb
*
pSdb
,
SConsumerObj
*
pConsumer
)
{
mTrace
(
"consumer:%s, perform insert action"
,
pConsumer
->
name
);
return
0
;
}
static
int32_t
mndConsumerActionDelete
(
SSdb
*
pSdb
,
SConsumerObj
*
pConsumer
)
{
mTrace
(
"consumer:%s, perform delete action"
,
pConsumer
->
name
);
return
0
;
}
static
int32_t
mndConsumerActionUpdate
(
SSdb
*
pSdb
,
SConsumerObj
*
pOldConsumer
,
SConsumerObj
*
pNewConsumer
)
{
mTrace
(
"consumer:%s, perform update action"
,
pOldConsumer
->
name
);
atomic_exchange_32
(
&
pOldConsumer
->
updateTime
,
pNewConsumer
->
updateTime
);
atomic_exchange_32
(
&
pOldConsumer
->
version
,
pNewConsumer
->
version
);
taosWLockLatch
(
&
pOldConsumer
->
lock
);
// TODO handle update
taosWUnLockLatch
(
&
pOldConsumer
->
lock
);
return
0
;
}
SConsumerObj
*
mndAcquireConsumer
(
SMnode
*
pMnode
,
int32_t
consumerId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SConsumerObj
*
pConsumer
=
sdbAcquire
(
pSdb
,
SDB_CONSUMER
,
&
consumerId
);
if
(
pConsumer
==
NULL
)
{
/*terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST;*/
}
return
pConsumer
;
}
void
mndReleaseConsumer
(
SMnode
*
pMnode
,
SConsumerObj
*
pConsumer
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pConsumer
);
}
static
int32_t
mndProcessSubscribeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
char
*
msgStr
=
pMsg
->
rpcMsg
.
pCont
;
SCMSubscribeReq
*
pSubscribe
;
tDeserializeSCMSubscribeReq
(
msgStr
,
pSubscribe
);
// add consumerGroupId -> list<consumerId> to sdb
// add consumerId -> list<consumer> to sdb
// add consumer -> list<consumerId> to sdb
return
0
;
}
static
int32_t
mndProcessSubscribeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessSubscribeInternalReq
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessSubscribeInternalRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropConsumerInRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndProcessConsumerMetaMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
STableInfoMsg
*
pInfo
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"consumer:%s, start to retrieve meta"
,
pInfo
->
tableFname
);
#if 0
SDbObj *pDb = mndAcquireDbByConsumer(pMnode, pInfo->tableFname);
if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
mError("consumer:%s, failed to retrieve meta since %s", pInfo->tableFname, terrstr());
return -1;
}
SConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pInfo->tableFname);
if (pConsumer == NULL) {
mndReleaseDb(pMnode, pDb);
terrno = TSDB_CODE_MND_INVALID_CONSUMER;
mError("consumer:%s, failed to get meta since %s", pInfo->tableFname, terrstr());
return -1;
}
taosRLockLatch(&pConsumer->lock);
int32_t totalCols = pConsumer->numOfColumns + pConsumer->numOfTags;
int32_t contLen = sizeof(STableMetaMsg) + totalCols * sizeof(SSchema);
STableMetaMsg *pMeta = rpcMallocCont(contLen);
if (pMeta == NULL) {
taosRUnLockLatch(&pConsumer->lock);
mndReleaseDb(pMnode, pDb);
mndReleaseConsumer(pMnode, pConsumer);
terrno = TSDB_CODE_OUT_OF_MEMORY;
mError("consumer:%s, failed to get meta since %s", pInfo->tableFname, terrstr());
return -1;
}
memcpy(pMeta->consumerFname, pConsumer->name, TSDB_TABLE_FNAME_LEN);
pMeta->numOfTags = htonl(pConsumer->numOfTags);
pMeta->numOfColumns = htonl(pConsumer->numOfColumns);
pMeta->precision = pDb->cfg.precision;
pMeta->tableType = TSDB_SUPER_TABLE;
pMeta->update = pDb->cfg.update;
pMeta->sversion = htonl(pConsumer->version);
pMeta->tuid = htonl(pConsumer->uid);
for (int32_t i = 0; i < totalCols; ++i) {
SSchema *pSchema = &pMeta->pSchema[i];
SSchema *pSrcSchema = &pConsumer->pSchema[i];
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
pSchema->type = pSrcSchema->type;
pSchema->colId = htonl(pSrcSchema->colId);
pSchema->bytes = htonl(pSrcSchema->bytes);
}
taosRUnLockLatch(&pConsumer->lock);
mndReleaseDb(pMnode, pDb);
mndReleaseConsumer(pMnode, pConsumer);
pMsg->pCont = pMeta;
pMsg->contLen = contLen;
mDebug("consumer:%s, meta is retrieved, cols:%d tags:%d", pInfo->tableFname, pConsumer->numOfColumns, pConsumer->numOfTags);
#endif
return
0
;
}
static
int32_t
mndGetNumOfConsumers
(
SMnode
*
pMnode
,
char
*
dbName
,
int32_t
*
pNumOfConsumers
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
dbName
);
if
(
pDb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
return
-
1
;
}
int32_t
numOfConsumers
=
0
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SConsumerObj
*
pConsumer
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_CONSUMER
,
pIter
,
(
void
**
)
&
pConsumer
);
if
(
pIter
==
NULL
)
break
;
if
(
strcmp
(
pConsumer
->
db
,
dbName
)
==
0
)
{
numOfConsumers
++
;
}
sdbRelease
(
pSdb
,
pConsumer
);
}
*
pNumOfConsumers
=
numOfConsumers
;
return
0
;
}
static
int32_t
mndGetConsumerMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
if
(
mndGetNumOfConsumers
(
pMnode
,
pShow
->
db
,
&
pShow
->
numOfRows
)
!=
0
)
{
return
-
1
;
}
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"columns"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"tags"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htonl
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_CONSUMER
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tbFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveConsumer
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SConsumerObj
*
pConsumer
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
char
prefix
[
64
]
=
{
0
};
tstrncpy
(
prefix
,
pShow
->
db
,
64
);
strcat
(
prefix
,
TS_PATH_DELIMITER
);
int32_t
prefixLen
=
(
int32_t
)
strlen
(
prefix
);
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_CONSUMER
,
pShow
->
pIter
,
(
void
**
)
&
pConsumer
);
if
(
pShow
->
pIter
==
NULL
)
break
;
if
(
strncmp
(
pConsumer
->
name
,
prefix
,
prefixLen
)
!=
0
)
{
sdbRelease
(
pSdb
,
pConsumer
);
continue
;
}
cols
=
0
;
char
consumerName
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
tstrncpy
(
consumerName
,
pConsumer
->
name
+
prefixLen
,
TSDB_TABLE_NAME_LEN
);
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
consumerName
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pConsumer
->
createTime
;
cols
++
;
/*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/
/**(int32_t *)pWrite = pConsumer->numOfColumns;*/
/*cols++;*/
/*pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;*/
/**(int32_t *)pWrite = pConsumer->numOfTags;*/
/*cols++;*/
numOfRows
++
;
sdbRelease
(
pSdb
,
pConsumer
);
}
pShow
->
numOfReads
+=
numOfRows
;
mndVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
return
numOfRows
;
}
static
void
mndCancelGetNextConsumer
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
source/dnode/mnode/impl/src/mndDnode.c
浏览文件 @
8ecd7a56
...
@@ -18,8 +18,7 @@
...
@@ -18,8 +18,7 @@
#include "mndMnode.h"
#include "mndMnode.h"
#include "mndShow.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndTrans.h"
#include "tep.h"
#include "mndVgroup.h"
#include "ttime.h"
#define TSDB_DNODE_VER_NUMBER 1
#define TSDB_DNODE_VER_NUMBER 1
#define TSDB_DNODE_RESERVE_SIZE 64
#define TSDB_DNODE_RESERVE_SIZE 64
...
@@ -370,7 +369,6 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
...
@@ -370,7 +369,6 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
}
}
pRsp
->
dnodeCfg
.
dnodeId
=
htonl
(
pDnode
->
id
);
pRsp
->
dnodeCfg
.
dnodeId
=
htonl
(
pDnode
->
id
);
pRsp
->
dnodeCfg
.
dropped
=
0
;
pRsp
->
dnodeCfg
.
clusterId
=
htobe64
(
pMnode
->
clusterId
);
pRsp
->
dnodeCfg
.
clusterId
=
htobe64
(
pMnode
->
clusterId
);
mndGetDnodeData
(
pMnode
,
&
pRsp
->
dnodeEps
,
numOfEps
);
mndGetDnodeData
(
pMnode
,
&
pRsp
->
dnodeEps
,
numOfEps
);
...
@@ -700,7 +698,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
...
@@ -700,7 +698,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
numOfVnodes
;
*
(
int16_t
*
)
pWrite
=
mndGetVnodesNum
(
pMnode
,
pDnode
->
id
)
;
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
...
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
8ecd7a56
...
@@ -251,7 +251,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
...
@@ -251,7 +251,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
int32_t
numOfReplicas
=
0
;
int32_t
numOfReplicas
=
0
;
S
CreateMnodeIn
Msg
createMsg
=
{
0
};
S
DCreateMnode
Msg
createMsg
=
{
0
};
while
(
1
)
{
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
...
@@ -281,18 +281,18 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
...
@@ -281,18 +281,18 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
STransAction
action
=
{
0
};
STransAction
action
=
{
0
};
S
AlterMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SAlterMnodeIn
Msg
));
S
DAlterMnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDAlterMnode
Msg
));
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
return
-
1
;
}
}
memcpy
(
pMsg
,
&
createMsg
,
sizeof
(
S
AlterMnodeIn
Msg
));
memcpy
(
pMsg
,
&
createMsg
,
sizeof
(
S
DAlterMnode
Msg
));
pMsg
->
dnodeId
=
htonl
(
pMObj
->
id
);
pMsg
->
dnodeId
=
htonl
(
pMObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
pCont
=
pMsg
;
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
S
AlterMnodeIn
Msg
);
action
.
contLen
=
sizeof
(
S
DAlterMnode
Msg
);
action
.
msgType
=
TDMT_DND_ALTER_MNODE
;
action
.
msgType
=
TDMT_DND_ALTER_MNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
...
@@ -309,14 +309,14 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
...
@@ -309,14 +309,14 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
STransAction
action
=
{
0
};
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
S
CreateMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SCreateMnodeIn
Msg
));
S
DCreateMnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDCreateMnode
Msg
));
if
(
pMsg
==
NULL
)
return
-
1
;
if
(
pMsg
==
NULL
)
return
-
1
;
memcpy
(
pMsg
,
&
createMsg
,
sizeof
(
S
AlterMnodeIn
Msg
));
memcpy
(
pMsg
,
&
createMsg
,
sizeof
(
S
DAlterMnode
Msg
));
pMsg
->
dnodeId
=
htonl
(
pObj
->
id
);
pMsg
->
dnodeId
=
htonl
(
pObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
S
CreateMnodeIn
Msg
);
action
.
contLen
=
sizeof
(
S
DCreateMnode
Msg
);
action
.
msgType
=
TDMT_DND_CREATE_MNODE
;
action
.
msgType
=
TDMT_DND_CREATE_MNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
free
(
pMsg
);
...
@@ -327,9 +327,9 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
...
@@ -327,9 +327,9 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
return
0
;
return
0
;
}
}
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
,
SCreateMnodeMsg
*
pCreate
)
{
static
int32_t
mndCreateMnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
,
S
M
CreateMnodeMsg
*
pCreate
)
{
SMnodeObj
mnodeObj
=
{
0
};
SMnodeObj
mnodeObj
=
{
0
};
mnodeObj
.
id
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_MNODE
)
;
mnodeObj
.
id
=
pDnode
->
id
;
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
mnodeObj
.
createdTime
=
taosGetTimestampMs
();
mnodeObj
.
updateTime
=
mnodeObj
.
createdTime
;
mnodeObj
.
updateTime
=
mnodeObj
.
createdTime
;
...
@@ -370,7 +370,7 @@ CREATE_MNODE_OVER:
...
@@ -370,7 +370,7 @@ CREATE_MNODE_OVER:
static
int32_t
mndProcessCreateMnodeReq
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mndProcessCreateMnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateMnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
S
M
CreateMnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
...
@@ -423,7 +423,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
...
@@ -423,7 +423,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
int32_t
numOfReplicas
=
0
;
int32_t
numOfReplicas
=
0
;
S
AlterMnodeIn
Msg
alterMsg
=
{
0
};
S
DAlterMnode
Msg
alterMsg
=
{
0
};
while
(
1
)
{
while
(
1
)
{
SMnodeObj
*
pMObj
=
NULL
;
SMnodeObj
*
pMObj
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
pIter
=
sdbFetch
(
pSdb
,
SDB_MNODE
,
pIter
,
(
void
**
)
&
pMObj
);
...
@@ -449,18 +449,18 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
...
@@ -449,18 +449,18 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
if
(
pMObj
->
id
!=
pObj
->
id
)
{
if
(
pMObj
->
id
!=
pObj
->
id
)
{
STransAction
action
=
{
0
};
STransAction
action
=
{
0
};
S
AlterMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SAlterMnodeIn
Msg
));
S
DAlterMnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDAlterMnode
Msg
));
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pMObj
);
sdbRelease
(
pSdb
,
pMObj
);
return
-
1
;
return
-
1
;
}
}
memcpy
(
pMsg
,
&
alterMsg
,
sizeof
(
S
AlterMnodeIn
Msg
));
memcpy
(
pMsg
,
&
alterMsg
,
sizeof
(
S
DAlterMnode
Msg
));
pMsg
->
dnodeId
=
htonl
(
pMObj
->
id
);
pMsg
->
dnodeId
=
htonl
(
pMObj
->
id
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
epSet
=
mndGetDnodeEpset
(
pMObj
->
pDnode
);
action
.
pCont
=
pMsg
;
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
S
AlterMnodeIn
Msg
);
action
.
contLen
=
sizeof
(
S
DAlterMnode
Msg
);
action
.
msgType
=
TDMT_DND_ALTER_MNODE
;
action
.
msgType
=
TDMT_DND_ALTER_MNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
...
@@ -478,7 +478,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
...
@@ -478,7 +478,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
STransAction
action
=
{
0
};
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
SD
ropMnodeInMsg
*
pMsg
=
malloc
(
sizeof
(
SDropMnodeIn
Msg
));
SD
DropMnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDDropMnode
Msg
));
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
...
@@ -487,7 +487,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
...
@@ -487,7 +487,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SD
ropMnodeIn
Msg
);
action
.
contLen
=
sizeof
(
SD
DropMnode
Msg
);
action
.
msgType
=
TDMT_DND_DROP_MNODE
;
action
.
msgType
=
TDMT_DND_DROP_MNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
free
(
pMsg
);
...
@@ -537,7 +537,7 @@ DROP_MNODE_OVER:
...
@@ -537,7 +537,7 @@ DROP_MNODE_OVER:
static
int32_t
mndProcessDropMnodeReq
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mndProcessDropMnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SDropMnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
S
M
DropMnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"mnode:%d, start to drop"
,
pDrop
->
dnodeId
);
mDebug
(
"mnode:%d, start to drop"
,
pDrop
->
dnodeId
);
...
@@ -562,7 +562,7 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
...
@@ -562,7 +562,7 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
return
-
1
;
return
-
1
;
}
}
sdbRelease
(
pMnode
->
pSdb
,
p
Mnode
);
sdbRelease
(
pMnode
->
pSdb
,
p
Obj
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
}
...
...
source/dnode/mnode/impl/src/mndProfile.c
浏览文件 @
8ecd7a56
...
@@ -118,17 +118,17 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid,
...
@@ -118,17 +118,17 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid,
SConnObj
*
pConn
=
taosCachePut
(
pMgmt
->
cache
,
&
connId
,
sizeof
(
int32_t
),
&
connObj
,
sizeof
(
connObj
),
keepTime
*
1000
);
SConnObj
*
pConn
=
taosCachePut
(
pMgmt
->
cache
,
&
connId
,
sizeof
(
int32_t
),
&
connObj
,
sizeof
(
connObj
),
keepTime
*
1000
);
if
(
pConn
==
NULL
)
{
if
(
pConn
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"conn:%d,
data:%p failed to put into cache since %s, user:%s"
,
connId
,
pConn
,
pInfo
->
user
,
terrstr
());
mError
(
"conn:%d,
failed to put into cache since %s, user:%s"
,
connId
,
pInfo
->
user
,
terrstr
());
return
NULL
;
return
NULL
;
}
else
{
}
else
{
mTrace
(
"conn:%d,
data:%p created,
user:%s"
,
pConn
->
id
,
pConn
,
pInfo
->
user
);
mTrace
(
"conn:%d,
is created, data:%p
user:%s"
,
pConn
->
id
,
pConn
,
pInfo
->
user
);
return
pConn
;
return
pConn
;
}
}
}
}
static
void
mndFreeConn
(
SConnObj
*
pConn
)
{
static
void
mndFreeConn
(
SConnObj
*
pConn
)
{
tfree
(
pConn
->
pQueries
);
tfree
(
pConn
->
pQueries
);
mTrace
(
"conn:%d,
data:%p destroyed
"
,
pConn
->
id
,
pConn
);
mTrace
(
"conn:%d,
is destroyed, data:%p
"
,
pConn
->
id
,
pConn
);
}
}
static
SConnObj
*
mndAcquireConn
(
SMnode
*
pMnode
,
int32_t
connId
)
{
static
SConnObj
*
mndAcquireConn
(
SMnode
*
pMnode
,
int32_t
connId
)
{
...
@@ -143,13 +143,13 @@ static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId) {
...
@@ -143,13 +143,13 @@ static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId) {
int32_t
keepTime
=
pMnode
->
cfg
.
shellActivityTimer
*
3
;
int32_t
keepTime
=
pMnode
->
cfg
.
shellActivityTimer
*
3
;
pConn
->
lastAccessTimeMs
=
keepTime
*
1000
+
(
uint64_t
)
taosGetTimestampMs
();
pConn
->
lastAccessTimeMs
=
keepTime
*
1000
+
(
uint64_t
)
taosGetTimestampMs
();
mTrace
(
"conn:%d,
data:%p acquired from cache
"
,
pConn
->
id
,
pConn
);
mTrace
(
"conn:%d,
acquired from cache, data:%p
"
,
pConn
->
id
,
pConn
);
return
pConn
;
return
pConn
;
}
}
static
void
mndReleaseConn
(
SMnode
*
pMnode
,
SConnObj
*
pConn
)
{
static
void
mndReleaseConn
(
SMnode
*
pMnode
,
SConnObj
*
pConn
)
{
if
(
pConn
==
NULL
)
return
;
if
(
pConn
==
NULL
)
return
;
mTrace
(
"conn:%d,
data:%p released from cache
"
,
pConn
->
id
,
pConn
);
mTrace
(
"conn:%d,
released from cache, data:%p
"
,
pConn
->
id
,
pConn
);
SProfileMgmt
*
pMgmt
=
&
pMnode
->
profileMgmt
;
SProfileMgmt
*
pMgmt
=
&
pMnode
->
profileMgmt
;
taosCacheRelease
(
pMgmt
->
cache
,
(
void
**
)
&
pConn
,
false
);
taosCacheRelease
(
pMgmt
->
cache
,
(
void
**
)
&
pConn
,
false
);
...
...
source/dnode/mnode/impl/src/mndQnode.c
0 → 100644
浏览文件 @
8ecd7a56
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "mndQnode.h"
#include "mndDnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#define TSDB_QNODE_VER_NUMBER 1
#define TSDB_QNODE_RESERVE_SIZE 64
static
SSdbRaw
*
mndQnodeActionEncode
(
SQnodeObj
*
pObj
);
static
SSdbRow
*
mndQnodeActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndQnodeActionInsert
(
SSdb
*
pSdb
,
SQnodeObj
*
pObj
);
static
int32_t
mndQnodeActionDelete
(
SSdb
*
pSdb
,
SQnodeObj
*
pObj
);
static
int32_t
mndQnodeActionUpdate
(
SSdb
*
pSdb
,
SQnodeObj
*
pOldQnode
,
SQnodeObj
*
pNewQnode
);
static
int32_t
mndProcessCreateQnodeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropQnodeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateQnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropQnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetQnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveQnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextQnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitQnode
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_QNODE
,
.
keyType
=
SDB_KEY_INT32
,
.
encodeFp
=
(
SdbEncodeFp
)
mndQnodeActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndQnodeActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndQnodeActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndQnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndQnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_QNODE
,
mndProcessCreateQnodeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DROP_QNODE
,
mndProcessDropQnodeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_CREATE_QNODE_RSP
,
mndProcessCreateQnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_DROP_QNODE_RSP
,
mndProcessDropQnodeRsp
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_QNODE
,
mndGetQnodeMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_QNODE
,
mndRetrieveQnodes
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_QNODE
,
mndCancelGetNextQnode
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupQnode
(
SMnode
*
pMnode
)
{}
static
SQnodeObj
*
mndAcquireQnode
(
SMnode
*
pMnode
,
int32_t
qnodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SQnodeObj
*
pObj
=
sdbAcquire
(
pSdb
,
SDB_QNODE
,
&
qnodeId
);
if
(
pObj
==
NULL
)
{
terrno
=
TSDB_CODE_MND_QNODE_NOT_EXIST
;
}
return
pObj
;
}
static
void
mndReleaseQnode
(
SMnode
*
pMnode
,
SQnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pObj
);
}
static
SSdbRaw
*
mndQnodeActionEncode
(
SQnodeObj
*
pObj
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_QNODE
,
TSDB_QNODE_VER_NUMBER
,
sizeof
(
SQnodeObj
)
+
TSDB_QNODE_RESERVE_SIZE
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_INT32
(
pRaw
,
dataPos
,
pObj
->
id
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pObj
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pObj
->
updateTime
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_QNODE_RESERVE_SIZE
)
return
pRaw
;
}
static
SSdbRow
*
mndQnodeActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_QNODE_VER_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode qnode since %s"
,
terrstr
());
return
NULL
;
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SQnodeObj
));
SQnodeObj
*
pObj
=
sdbGetRowObj
(
pRow
);
if
(
pObj
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
id
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
updateTime
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_QNODE_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndQnodeActionInsert
(
SSdb
*
pSdb
,
SQnodeObj
*
pObj
)
{
mTrace
(
"qnode:%d, perform insert action"
,
pObj
->
id
);
pObj
->
pDnode
=
sdbAcquire
(
pSdb
,
SDB_DNODE
,
&
pObj
->
id
);
if
(
pObj
->
pDnode
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
mError
(
"qnode:%d, failed to perform insert action since %s"
,
pObj
->
id
,
terrstr
());
return
-
1
;
}
return
0
;
}
static
int32_t
mndQnodeActionDelete
(
SSdb
*
pSdb
,
SQnodeObj
*
pObj
)
{
mTrace
(
"qnode:%d, perform delete action"
,
pObj
->
id
);
if
(
pObj
->
pDnode
!=
NULL
)
{
sdbRelease
(
pSdb
,
pObj
->
pDnode
);
pObj
->
pDnode
=
NULL
;
}
return
0
;
}
static
int32_t
mndQnodeActionUpdate
(
SSdb
*
pSdb
,
SQnodeObj
*
pOldQnode
,
SQnodeObj
*
pNewQnode
)
{
mTrace
(
"qnode:%d, perform update action"
,
pOldQnode
->
id
);
pOldQnode
->
updateTime
=
pNewQnode
->
updateTime
;
return
0
;
}
static
int32_t
mndSetCreateQnodeRedoLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndQnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateQnodeCommitLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndQnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateQnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SQnodeObj
*
pObj
)
{
SDCreateQnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDCreateQnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pDnode
->
id
);
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDCreateQnodeMsg
);
action
.
msgType
=
TDMT_DND_CREATE_QNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndCreateQnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
,
SMCreateQnodeMsg
*
pCreate
)
{
SQnodeObj
qnodeObj
=
{
0
};
qnodeObj
.
id
=
pDnode
->
id
;
qnodeObj
.
createdTime
=
taosGetTimestampMs
();
qnodeObj
.
updateTime
=
qnodeObj
.
createdTime
;
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"qnode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
goto
CREATE_QNODE_OVER
;
}
mDebug
(
"trans:%d, used to create qnode:%d"
,
pTrans
->
id
,
pCreate
->
dnodeId
);
if
(
mndSetCreateQnodeRedoLogs
(
pTrans
,
&
qnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_QNODE_OVER
;
}
if
(
mndSetCreateQnodeCommitLogs
(
pTrans
,
&
qnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_QNODE_OVER
;
}
if
(
mndSetCreateQnodeRedoActions
(
pTrans
,
pDnode
,
&
qnodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_QNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_QNODE_OVER
;
}
code
=
0
;
CREATE_QNODE_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndProcessCreateQnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMCreateQnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
mDebug
(
"qnode:%d, start to create"
,
pCreate
->
dnodeId
);
SQnodeObj
*
pObj
=
mndAcquireQnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pObj
!=
NULL
)
{
mError
(
"qnode:%d, qnode already exist"
,
pObj
->
id
);
mndReleaseQnode
(
pMnode
,
pObj
);
return
-
1
;
}
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"qnode:%d, dnode not exist"
,
pCreate
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateQnode
(
pMnode
,
pMsg
,
pDnode
,
pCreate
);
mndReleaseDnode
(
pMnode
,
pDnode
);
if
(
code
!=
0
)
{
mError
(
"qnode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndSetDropQnodeRedoLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndQnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropQnodeCommitLogs
(
STrans
*
pTrans
,
SQnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndQnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropQnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SQnodeObj
*
pObj
)
{
SDDropQnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDDropQnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pDnode
->
id
);
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDDropQnodeMsg
);
action
.
msgType
=
TDMT_DND_DROP_QNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndDropQnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SQnodeObj
*
pObj
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"qnode:%d, failed to drop since %s"
,
pObj
->
id
,
terrstr
());
goto
DROP_QNODE_OVER
;
}
mDebug
(
"trans:%d, used to drop qnode:%d"
,
pTrans
->
id
,
pObj
->
id
);
if
(
mndSetDropQnodeRedoLogs
(
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_QNODE_OVER
;
}
if
(
mndSetDropQnodeCommitLogs
(
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_QNODE_OVER
;
}
if
(
mndSetDropQnodeRedoActions
(
pTrans
,
pObj
->
pDnode
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_QNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_QNODE_OVER
;
}
code
=
0
;
DROP_QNODE_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndProcessDropQnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMDropQnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"qnode:%d, start to drop"
,
pDrop
->
dnodeId
);
if
(
pDrop
->
dnodeId
<=
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"qnode:%d, failed to drop since %s"
,
pDrop
->
dnodeId
,
terrstr
());
return
-
1
;
}
SQnodeObj
*
pObj
=
mndAcquireQnode
(
pMnode
,
pDrop
->
dnodeId
);
if
(
pObj
==
NULL
)
{
mError
(
"qnode:%d, not exist"
,
pDrop
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndDropQnode
(
pMnode
,
pMsg
,
pObj
);
if
(
code
!=
0
)
{
mError
(
"qnode:%d, failed to drop since %s"
,
pMnode
->
dnodeId
,
terrstr
());
return
-
1
;
}
sdbRelease
(
pMnode
->
pSdb
,
pMnode
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessCreateQnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndProcessDropQnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndGetQnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"endpoint"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htonl
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_QNODE
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tbFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveQnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SQnodeObj
*
pObj
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_QNODE
,
pShow
->
pIter
,
(
void
**
)
&
pObj
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pObj
->
id
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pObj
->
pDnode
->
ep
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pObj
->
createdTime
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pObj
);
}
mndVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextQnode
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
source/dnode/mnode/impl/src/mndShow.c
浏览文件 @
8ecd7a56
...
@@ -56,31 +56,24 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) {
...
@@ -56,31 +56,24 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) {
if
(
showId
==
0
)
atomic_add_fetch_32
(
&
pMgmt
->
showId
,
1
);
if
(
showId
==
0
)
atomic_add_fetch_32
(
&
pMgmt
->
showId
,
1
);
int32_t
size
=
sizeof
(
SShowObj
)
+
pMsg
->
payloadLen
;
int32_t
size
=
sizeof
(
SShowObj
)
+
pMsg
->
payloadLen
;
SShowObj
*
pShow
=
calloc
(
1
,
size
);
SShowObj
showObj
=
{
0
};
if
(
pShow
!=
NULL
)
{
showObj
.
id
=
showId
;
pShow
->
id
=
showId
;
showObj
.
pMnode
=
pMnode
;
pShow
->
pMnode
=
pMnode
;
showObj
.
type
=
pMsg
->
type
;
pShow
->
type
=
pMsg
->
type
;
showObj
.
payloadLen
=
pMsg
->
payloadLen
;
pShow
->
payloadLen
=
pMsg
->
payloadLen
;
memcpy
(
showObj
.
db
,
pMsg
->
db
,
TSDB_DB_FNAME_LEN
);
memcpy
(
pShow
->
db
,
pMsg
->
db
,
TSDB_DB_FNAME_LEN
);
memcpy
(
showObj
.
payload
,
pMsg
->
payload
,
pMsg
->
payloadLen
);
memcpy
(
pShow
->
payload
,
pMsg
->
payload
,
pMsg
->
payloadLen
);
}
else
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed to process show-meta msg:%s since %s"
,
mndShowStr
(
pMsg
->
type
),
terrstr
());
return
NULL
;
}
int32_t
keepTime
=
pMnode
->
cfg
.
shellActivityTimer
*
6
*
1000
;
int32_t
keepTime
=
pMnode
->
cfg
.
shellActivityTimer
*
6
*
1000
;
SShowObj
*
pShowRet
=
taosCachePut
(
pMgmt
->
cache
,
&
showId
,
sizeof
(
int32_t
),
pShow
,
size
,
keepTime
);
SShowObj
*
pShow
=
taosCachePut
(
pMgmt
->
cache
,
&
showId
,
sizeof
(
int32_t
),
&
showObj
,
size
,
keepTime
);
free
(
pShow
);
if
(
pShow
==
NULL
)
{
if
(
pShowRet
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"show:%d, failed to put into cache since %s"
,
showId
,
terrstr
());
mError
(
"show:%d, failed to put into cache since %s"
,
showId
,
terrstr
());
return
NULL
;
return
NULL
;
}
else
{
mTrace
(
"show:%d, data:%p created"
,
showId
,
pShowRet
);
return
pShowRet
;
}
}
mTrace
(
"show:%d, is created, data:%p"
,
showId
,
pShow
);
return
pShow
;
}
}
static
void
mndFreeShowObj
(
SShowObj
*
pShow
)
{
static
void
mndFreeShowObj
(
SShowObj
*
pShow
)
{
...
@@ -94,7 +87,7 @@ static void mndFreeShowObj(SShowObj *pShow) {
...
@@ -94,7 +87,7 @@ static void mndFreeShowObj(SShowObj *pShow) {
}
}
}
}
mTrace
(
"show:%d,
data:%p destroyed
"
,
pShow
->
id
,
pShow
);
mTrace
(
"show:%d,
is destroyed, data:%p
"
,
pShow
->
id
,
pShow
);
}
}
static
SShowObj
*
mndAcquireShowObj
(
SMnode
*
pMnode
,
int32_t
showId
)
{
static
SShowObj
*
mndAcquireShowObj
(
SMnode
*
pMnode
,
int32_t
showId
)
{
...
@@ -106,13 +99,13 @@ static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId) {
...
@@ -106,13 +99,13 @@ static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId) {
return
NULL
;
return
NULL
;
}
}
mTrace
(
"show:%d,
data:%p acquired from cache
"
,
pShow
->
id
,
pShow
);
mTrace
(
"show:%d,
acquired from cache, data:%p
"
,
pShow
->
id
,
pShow
);
return
pShow
;
return
pShow
;
}
}
static
void
mndReleaseShowObj
(
SShowObj
*
pShow
,
bool
forceRemove
)
{
static
void
mndReleaseShowObj
(
SShowObj
*
pShow
,
bool
forceRemove
)
{
if
(
pShow
==
NULL
)
return
;
if
(
pShow
==
NULL
)
return
;
mTrace
(
"show:%d,
data:%p released from cache,
force:%d"
,
pShow
->
id
,
pShow
,
forceRemove
);
mTrace
(
"show:%d,
released from cache, data:%p
force:%d"
,
pShow
->
id
,
pShow
,
forceRemove
);
// A bug in tcache.c
// A bug in tcache.c
forceRemove
=
0
;
forceRemove
=
0
;
...
@@ -158,8 +151,8 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -158,8 +151,8 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
}
}
int32_t
code
=
(
*
metaFp
)(
pMnodeMsg
,
pShow
,
&
pRsp
->
tableMeta
);
int32_t
code
=
(
*
metaFp
)(
pMnodeMsg
,
pShow
,
&
pRsp
->
tableMeta
);
mDebug
(
"show:%d,
data:%p get meta finished, numOfRows:%d cols:%d type:%s result:%s"
,
pShow
->
id
,
pShow
,
mDebug
(
"show:%d,
get meta finished, numOfRows:%d cols:%d type:%s result:%s"
,
pShow
->
id
,
pShow
->
numOfRows
,
pShow
->
numOf
Rows
,
pShow
->
numOf
Columns
,
mndShowStr
(
type
),
tstrerror
(
code
));
pShow
->
numOfColumns
,
mndShowStr
(
type
),
tstrerror
(
code
));
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
code
==
TSDB_CODE_SUCCESS
)
{
pMnodeMsg
->
contLen
=
sizeof
(
SShowRsp
)
+
sizeof
(
SSchema
)
*
pShow
->
numOfColumns
;
pMnodeMsg
->
contLen
=
sizeof
(
SShowRsp
)
+
sizeof
(
SSchema
)
*
pShow
->
numOfColumns
;
...
@@ -195,16 +188,15 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -195,16 +188,15 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
if
(
retrieveFp
==
NULL
)
{
if
(
retrieveFp
==
NULL
)
{
mndReleaseShowObj
(
pShow
,
false
);
mndReleaseShowObj
(
pShow
,
false
);
terrno
=
TSDB_CODE_MSG_NOT_PROCESSED
;
terrno
=
TSDB_CODE_MSG_NOT_PROCESSED
;
mError
(
"show:%d,
data:%p failed to retrieve data since %s"
,
pShow
->
id
,
pShow
,
terrstr
());
mError
(
"show:%d,
failed to retrieve data since %s"
,
pShow
->
id
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
mDebug
(
"show:%d,
data:%p start retrieve data, numOfReads:%d numOfRows:%d type:%s"
,
pShow
->
id
,
pShow
,
mDebug
(
"show:%d,
start retrieve data, numOfReads:%d numOfRows:%d type:%s"
,
pShow
->
id
,
pShow
->
numOfReads
,
pShow
->
numOfR
eads
,
pShow
->
numOfR
ows
,
mndShowStr
(
pShow
->
type
));
pShow
->
numOfRows
,
mndShowStr
(
pShow
->
type
));
if
(
mndCheckRetrieveFinished
(
pShow
))
{
if
(
mndCheckRetrieveFinished
(
pShow
))
{
mDebug
(
"show:%d, data:%p read finished, numOfReads:%d numOfRows:%d"
,
pShow
->
id
,
pShow
,
pShow
->
numOfReads
,
mDebug
(
"show:%d, read finished, numOfReads:%d numOfRows:%d"
,
pShow
->
id
,
pShow
->
numOfReads
,
pShow
->
numOfRows
);
pShow
->
numOfRows
);
pShow
->
numOfReads
=
pShow
->
numOfRows
;
pShow
->
numOfReads
=
pShow
->
numOfRows
;
}
}
...
@@ -227,7 +219,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -227,7 +219,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
if
(
pRsp
==
NULL
)
{
if
(
pRsp
==
NULL
)
{
mndReleaseShowObj
(
pShow
,
false
);
mndReleaseShowObj
(
pShow
,
false
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"show:%d,
data:%p failed to retrieve data since %s"
,
pShow
->
id
,
pShow
,
terrstr
());
mError
(
"show:%d,
failed to retrieve data since %s"
,
pShow
->
id
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
...
@@ -236,7 +228,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -236,7 +228,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
rowsRead
=
(
*
retrieveFp
)(
pMnodeMsg
,
pShow
,
pRsp
->
data
,
rowsToRead
);
rowsRead
=
(
*
retrieveFp
)(
pMnodeMsg
,
pShow
,
pRsp
->
data
,
rowsToRead
);
}
}
mDebug
(
"show:%d,
data:%p stop retrieve data, rowsRead:%d rowsToRead:%d"
,
pShow
->
id
,
pShow
,
rowsRead
,
rowsToRead
);
mDebug
(
"show:%d,
stop retrieve data, rowsRead:%d rowsToRead:%d"
,
pShow
->
id
,
rowsRead
,
rowsToRead
);
pRsp
->
numOfRows
=
htonl
(
rowsRead
);
pRsp
->
numOfRows
=
htonl
(
rowsRead
);
pRsp
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
// millisecond time precision
pRsp
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
// millisecond time precision
...
@@ -246,10 +238,10 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -246,10 +238,10 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
if
(
rowsRead
==
0
||
rowsToRead
==
0
||
(
rowsRead
==
rowsToRead
&&
pShow
->
numOfRows
==
pShow
->
numOfReads
))
{
if
(
rowsRead
==
0
||
rowsToRead
==
0
||
(
rowsRead
==
rowsToRead
&&
pShow
->
numOfRows
==
pShow
->
numOfReads
))
{
pRsp
->
completed
=
1
;
pRsp
->
completed
=
1
;
mDebug
(
"show:%d,
data:%p retrieve completed"
,
pShow
->
id
,
pShow
);
mDebug
(
"show:%d,
retrieve completed"
,
pShow
->
id
);
mndReleaseShowObj
(
pShow
,
true
);
mndReleaseShowObj
(
pShow
,
true
);
}
else
{
}
else
{
mDebug
(
"show:%d,
data:%p retrieve not completed yet"
,
pShow
->
id
,
pShow
);
mDebug
(
"show:%d,
retrieve not completed yet"
,
pShow
->
id
);
mndReleaseShowObj
(
pShow
,
false
);
mndReleaseShowObj
(
pShow
,
false
);
}
}
...
@@ -270,6 +262,12 @@ char *mndShowStr(int32_t showType) {
...
@@ -270,6 +262,12 @@ char *mndShowStr(int32_t showType) {
return
"show dnodes"
;
return
"show dnodes"
;
case
TSDB_MGMT_TABLE_MNODE
:
case
TSDB_MGMT_TABLE_MNODE
:
return
"show mnodes"
;
return
"show mnodes"
;
case
TSDB_MGMT_TABLE_QNODE
:
return
"show qnodes"
;
case
TSDB_MGMT_TABLE_SNODE
:
return
"show snodes"
;
case
TSDB_MGMT_TABLE_BNODE
:
return
"show bnodes"
;
case
TSDB_MGMT_TABLE_VGROUP
:
case
TSDB_MGMT_TABLE_VGROUP
:
return
"show vgroups"
;
return
"show vgroups"
;
case
TSDB_MGMT_TABLE_STB
:
case
TSDB_MGMT_TABLE_STB
:
...
...
source/dnode/mnode/impl/src/mndSnode.c
0 → 100644
浏览文件 @
8ecd7a56
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "mndSnode.h"
#include "mndDnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#define TSDB_SNODE_VER_NUMBER 1
#define TSDB_SNODE_RESERVE_SIZE 64
static
SSdbRaw
*
mndSnodeActionEncode
(
SSnodeObj
*
pObj
);
static
SSdbRow
*
mndSnodeActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndSnodeActionInsert
(
SSdb
*
pSdb
,
SSnodeObj
*
pObj
);
static
int32_t
mndSnodeActionDelete
(
SSdb
*
pSdb
,
SSnodeObj
*
pObj
);
static
int32_t
mndSnodeActionUpdate
(
SSdb
*
pSdb
,
SSnodeObj
*
pOldSnode
,
SSnodeObj
*
pNewSnode
);
static
int32_t
mndProcessCreateSnodeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropSnodeReq
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateSnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropSnodeRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetSnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveSnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextSnode
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitSnode
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_SNODE
,
.
keyType
=
SDB_KEY_INT32
,
.
encodeFp
=
(
SdbEncodeFp
)
mndSnodeActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndSnodeActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndSnodeActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndSnodeActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndSnodeActionDelete
};
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_SNODE
,
mndProcessCreateSnodeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DROP_SNODE
,
mndProcessDropSnodeReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_CREATE_SNODE_RSP
,
mndProcessCreateSnodeRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_DROP_SNODE_RSP
,
mndProcessDropSnodeRsp
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_SNODE
,
mndGetSnodeMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_SNODE
,
mndRetrieveSnodes
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_SNODE
,
mndCancelGetNextSnode
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupSnode
(
SMnode
*
pMnode
)
{}
static
SSnodeObj
*
mndAcquireSnode
(
SMnode
*
pMnode
,
int32_t
snodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSnodeObj
*
pObj
=
sdbAcquire
(
pSdb
,
SDB_SNODE
,
&
snodeId
);
if
(
pObj
==
NULL
)
{
terrno
=
TSDB_CODE_MND_SNODE_NOT_EXIST
;
}
return
pObj
;
}
static
void
mndReleaseSnode
(
SMnode
*
pMnode
,
SSnodeObj
*
pObj
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pObj
);
}
static
SSdbRaw
*
mndSnodeActionEncode
(
SSnodeObj
*
pObj
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_SNODE
,
TSDB_SNODE_VER_NUMBER
,
sizeof
(
SSnodeObj
)
+
TSDB_SNODE_RESERVE_SIZE
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_INT32
(
pRaw
,
dataPos
,
pObj
->
id
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pObj
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pObj
->
updateTime
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_SNODE_RESERVE_SIZE
)
return
pRaw
;
}
static
SSdbRow
*
mndSnodeActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_SNODE_VER_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode snode since %s"
,
terrstr
());
return
NULL
;
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SSnodeObj
));
SSnodeObj
*
pObj
=
sdbGetRowObj
(
pRow
);
if
(
pObj
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
id
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pObj
->
updateTime
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_SNODE_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndSnodeActionInsert
(
SSdb
*
pSdb
,
SSnodeObj
*
pObj
)
{
mTrace
(
"snode:%d, perform insert action"
,
pObj
->
id
);
pObj
->
pDnode
=
sdbAcquire
(
pSdb
,
SDB_DNODE
,
&
pObj
->
id
);
if
(
pObj
->
pDnode
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
mError
(
"snode:%d, failed to perform insert action since %s"
,
pObj
->
id
,
terrstr
());
return
-
1
;
}
return
0
;
}
static
int32_t
mndSnodeActionDelete
(
SSdb
*
pSdb
,
SSnodeObj
*
pObj
)
{
mTrace
(
"snode:%d, perform delete action"
,
pObj
->
id
);
if
(
pObj
->
pDnode
!=
NULL
)
{
sdbRelease
(
pSdb
,
pObj
->
pDnode
);
pObj
->
pDnode
=
NULL
;
}
return
0
;
}
static
int32_t
mndSnodeActionUpdate
(
SSdb
*
pSdb
,
SSnodeObj
*
pOldSnode
,
SSnodeObj
*
pNewSnode
)
{
mTrace
(
"snode:%d, perform update action"
,
pOldSnode
->
id
);
pOldSnode
->
updateTime
=
pNewSnode
->
updateTime
;
return
0
;
}
static
int32_t
mndSetCreateSnodeRedoLogs
(
STrans
*
pTrans
,
SSnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndSnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateSnodeCommitLogs
(
STrans
*
pTrans
,
SSnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndSnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateSnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SSnodeObj
*
pObj
)
{
SDCreateSnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDCreateSnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pDnode
->
id
);
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDCreateSnodeMsg
);
action
.
msgType
=
TDMT_DND_CREATE_SNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndCreateSnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SDnodeObj
*
pDnode
,
SMCreateSnodeMsg
*
pCreate
)
{
SSnodeObj
snodeObj
=
{
0
};
snodeObj
.
id
=
pDnode
->
id
;
snodeObj
.
createdTime
=
taosGetTimestampMs
();
snodeObj
.
updateTime
=
snodeObj
.
createdTime
;
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"snode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
goto
CREATE_SNODE_OVER
;
}
mDebug
(
"trans:%d, used to create snode:%d"
,
pTrans
->
id
,
pCreate
->
dnodeId
);
if
(
mndSetCreateSnodeRedoLogs
(
pTrans
,
&
snodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_SNODE_OVER
;
}
if
(
mndSetCreateSnodeCommitLogs
(
pTrans
,
&
snodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_SNODE_OVER
;
}
if
(
mndSetCreateSnodeRedoActions
(
pTrans
,
pDnode
,
&
snodeObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_SNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_SNODE_OVER
;
}
code
=
0
;
CREATE_SNODE_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndProcessCreateSnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMCreateSnodeMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
mDebug
(
"snode:%d, start to create"
,
pCreate
->
dnodeId
);
SSnodeObj
*
pObj
=
mndAcquireSnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pObj
!=
NULL
)
{
mError
(
"snode:%d, snode already exist"
,
pObj
->
id
);
mndReleaseSnode
(
pMnode
,
pObj
);
return
-
1
;
}
SDnodeObj
*
pDnode
=
mndAcquireDnode
(
pMnode
,
pCreate
->
dnodeId
);
if
(
pDnode
==
NULL
)
{
mError
(
"snode:%d, dnode not exist"
,
pCreate
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndCreateSnode
(
pMnode
,
pMsg
,
pDnode
,
pCreate
);
mndReleaseDnode
(
pMnode
,
pDnode
);
if
(
code
!=
0
)
{
mError
(
"snode:%d, failed to create since %s"
,
pCreate
->
dnodeId
,
terrstr
());
return
-
1
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndSetDropSnodeRedoLogs
(
STrans
*
pTrans
,
SSnodeObj
*
pObj
)
{
SSdbRaw
*
pRedoRaw
=
mndSnodeActionEncode
(
pObj
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropSnodeCommitLogs
(
STrans
*
pTrans
,
SSnodeObj
*
pObj
)
{
SSdbRaw
*
pCommitRaw
=
mndSnodeActionEncode
(
pObj
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropSnodeRedoActions
(
STrans
*
pTrans
,
SDnodeObj
*
pDnode
,
SSnodeObj
*
pObj
)
{
SDDropSnodeMsg
*
pMsg
=
malloc
(
sizeof
(
SDDropSnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pMsg
->
dnodeId
=
htonl
(
pDnode
->
id
);
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetDnodeEpset
(
pDnode
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDDropSnodeMsg
);
action
.
msgType
=
TDMT_DND_DROP_SNODE
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndDropSnode
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SSnodeObj
*
pObj
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"snode:%d, failed to drop since %s"
,
pObj
->
id
,
terrstr
());
goto
DROP_SNODE_OVER
;
}
mDebug
(
"trans:%d, used to drop snode:%d"
,
pTrans
->
id
,
pObj
->
id
);
if
(
mndSetDropSnodeRedoLogs
(
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_SNODE_OVER
;
}
if
(
mndSetDropSnodeCommitLogs
(
pTrans
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_SNODE_OVER
;
}
if
(
mndSetDropSnodeRedoActions
(
pTrans
,
pObj
->
pDnode
,
pObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_SNODE_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_SNODE_OVER
;
}
code
=
0
;
DROP_SNODE_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
static
int32_t
mndProcessDropSnodeReq
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMDropSnodeMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
pDrop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
mDebug
(
"snode:%d, start to drop"
,
pDrop
->
dnodeId
);
if
(
pDrop
->
dnodeId
<=
0
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
mError
(
"snode:%d, failed to drop since %s"
,
pDrop
->
dnodeId
,
terrstr
());
return
-
1
;
}
SSnodeObj
*
pObj
=
mndAcquireSnode
(
pMnode
,
pDrop
->
dnodeId
);
if
(
pObj
==
NULL
)
{
mError
(
"snode:%d, not exist"
,
pDrop
->
dnodeId
);
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
-
1
;
}
int32_t
code
=
mndDropSnode
(
pMnode
,
pMsg
,
pObj
);
if
(
code
!=
0
)
{
mError
(
"snode:%d, failed to drop since %s"
,
pMnode
->
dnodeId
,
terrstr
());
return
-
1
;
}
sdbRelease
(
pMnode
->
pSdb
,
pMnode
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessCreateSnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndProcessDropSnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndGetSnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
pSchema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"endpoint"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htonl
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htonl
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
sdbGetSize
(
pSdb
,
SDB_SNODE
);
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tbFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
static
int32_t
mndRetrieveSnodes
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
SSnodeObj
*
pObj
=
NULL
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_SNODE
,
pShow
->
pIter
,
(
void
**
)
&
pObj
);
if
(
pShow
->
pIter
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pObj
->
id
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pObj
->
pDnode
->
ep
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pObj
->
createdTime
;
cols
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pObj
);
}
mndVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextSnode
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
8ecd7a56
...
@@ -201,7 +201,6 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) {
...
@@ -201,7 +201,6 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) {
}
}
static
void
*
mndBuildCreateStbMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SStbObj
*
pStb
,
int
*
pContLen
)
{
static
void
*
mndBuildCreateStbMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SStbObj
*
pStb
,
int
*
pContLen
)
{
#if 1
SVCreateTbReq
req
;
SVCreateTbReq
req
;
void
*
buf
;
void
*
buf
;
int
bsize
;
int
bsize
;
...
@@ -235,43 +234,12 @@ static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb
...
@@ -235,43 +234,12 @@ static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb
*
pContLen
=
sizeof
(
SMsgHead
)
+
bsize
;
*
pContLen
=
sizeof
(
SMsgHead
)
+
bsize
;
return
buf
;
return
buf
;
#else
int32_t
totalCols
=
pStb
->
numOfTags
+
pStb
->
numOfColumns
;
int32_t
contLen
=
totalCols
*
sizeof
(
SSchema
)
+
sizeof
(
SCreateStbInternalMsg
);
SCreateStbInternalMsg
*
pCreate
=
calloc
(
1
,
contLen
);
if
(
pCreate
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pCreate
->
head
.
contLen
=
htonl
(
contLen
);
pCreate
->
head
.
vgId
=
htonl
(
pVgroup
->
vgId
);
memcpy
(
pCreate
->
name
,
pStb
->
name
,
TSDB_TABLE_FNAME_LEN
);
pCreate
->
suid
=
htobe64
(
pStb
->
uid
);
pCreate
->
sverson
=
htonl
(
pStb
->
version
);
pCreate
->
ttl
=
0
;
pCreate
->
keep
=
0
;
pCreate
->
numOfTags
=
htonl
(
pStb
->
numOfTags
);
pCreate
->
numOfColumns
=
htonl
(
pStb
->
numOfColumns
);
memcpy
(
pCreate
->
pSchema
,
pStb
->
pSchema
,
totalCols
*
sizeof
(
SSchema
));
for
(
int32_t
t
=
0
;
t
<
totalCols
;
++
t
)
{
SSchema
*
pSchema
=
&
pCreate
->
pSchema
[
t
];
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
pSchema
->
colId
=
htonl
(
pSchema
->
colId
);
}
*
pContLen
=
contLen
;
return
pCreate
;
#endif
}
}
static
S
DropStbInternalMsg
*
mndBuildDropStbMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SStbObj
*
pStb
)
{
static
S
VDropStbReq
*
mndBuildDropStbMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SStbObj
*
pStb
)
{
int32_t
contLen
=
sizeof
(
S
DropStbInternalMsg
);
int32_t
contLen
=
sizeof
(
S
VDropStbReq
);
S
DropStbInternalMsg
*
pDrop
=
calloc
(
1
,
contLen
);
S
VDropStbReq
*
pDrop
=
calloc
(
1
,
contLen
);
if
(
pDrop
==
NULL
)
{
if
(
pDrop
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
...
@@ -402,7 +370,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
...
@@ -402,7 +370,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
if
(
pIter
==
NULL
)
break
;
if
(
pIter
==
NULL
)
break
;
if
(
pVgroup
->
dbUid
!=
pDb
->
uid
)
continue
;
if
(
pVgroup
->
dbUid
!=
pDb
->
uid
)
continue
;
S
DropStbInternalMsg
*
pMsg
=
mndBuildDropStbMsg
(
pMnode
,
pVgroup
,
pStb
);
S
VDropStbReq
*
pMsg
=
mndBuildDropStbMsg
(
pMnode
,
pVgroup
,
pStb
);
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
sdbRelease
(
pSdb
,
pVgroup
);
...
@@ -413,7 +381,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
...
@@ -413,7 +381,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
STransAction
action
=
{
0
};
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
action
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
action
.
pCont
=
pMsg
;
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
S
DropStbInternalMsg
);
action
.
contLen
=
sizeof
(
S
VDropStbReq
);
action
.
msgType
=
TDMT_VND_DROP_STB
;
action
.
msgType
=
TDMT_VND_DROP_STB
;
if
(
mndTransAppendUndoAction
(
pTrans
,
&
action
)
!=
0
)
{
if
(
mndTransAppendUndoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
free
(
pMsg
);
...
...
source/dnode/mnode/impl/src/mndTopic.c
浏览文件 @
8ecd7a56
...
@@ -33,10 +33,7 @@ static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic);
...
@@ -33,10 +33,7 @@ static int32_t mndTopicActionInsert(SSdb *pSdb, STopicObj *pTopic);
static
int32_t
mndTopicActionDelete
(
SSdb
*
pSdb
,
STopicObj
*
pTopic
);
static
int32_t
mndTopicActionDelete
(
SSdb
*
pSdb
,
STopicObj
*
pTopic
);
static
int32_t
mndTopicActionUpdate
(
SSdb
*
pSdb
,
STopicObj
*
pTopic
,
STopicObj
*
pNewTopic
);
static
int32_t
mndTopicActionUpdate
(
SSdb
*
pSdb
,
STopicObj
*
pTopic
,
STopicObj
*
pNewTopic
);
static
int32_t
mndProcessCreateTopicMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateTopicMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterTopicMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropTopicMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropTopicMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessCreateTopicInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessAlterTopicInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropTopicInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessDropTopicInRsp
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessTopicMetaMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndProcessTopicMetaMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mndGetTopicMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndGetTopicMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
...
@@ -53,19 +50,8 @@ int32_t mndInitTopic(SMnode *pMnode) {
...
@@ -53,19 +50,8 @@ int32_t mndInitTopic(SMnode *pMnode) {
.
deleteFp
=
(
SdbDeleteFp
)
mndTopicActionDelete
};
.
deleteFp
=
(
SdbDeleteFp
)
mndTopicActionDelete
};
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_TOPIC
,
mndProcessCreateTopicMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_TOPIC
,
mndProcessCreateTopicMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_ALTER_TOPIC
,
mndProcessAlterTopicMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DROP_TOPIC
,
mndProcessDropTopicMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DROP_TOPIC
,
mndProcessDropTopicMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_CREATE_TOPIC_RSP
,
mndProcessCreateTopicInRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_ALTER_TOPIC_RSP
,
mndProcessAlterTopicInRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_DROP_TOPIC_RSP
,
mndProcessDropTopicInRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_DROP_TOPIC_RSP
,
mndProcessDropTopicInRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_TABLE_META
,
mndProcessTopicMetaMsg
);
/*mndAddShowMetaHandle(pMnode, TSDB_MGMT_TOPIC, mndGetTopicMeta);*/
/*mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TOPIC, mndRetrieveTopic);*/
/*mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TOPIC, mndCancelGetNextTopic);*/
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_TOPIC
,
mndProcessCreateTopicMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_CREATE_TOPIC_RSP
,
mndProcessCreateTopicInRsp
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
}
...
@@ -145,24 +131,9 @@ static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pOldTopic, STopicObj
...
@@ -145,24 +131,9 @@ static int32_t mndTopicActionUpdate(SSdb *pSdb, STopicObj *pOldTopic, STopicObj
atomic_exchange_32
(
&
pOldTopic
->
version
,
pNewTopic
->
version
);
atomic_exchange_32
(
&
pOldTopic
->
version
,
pNewTopic
->
version
);
taosWLockLatch
(
&
pOldTopic
->
lock
);
taosWLockLatch
(
&
pOldTopic
->
lock
);
#if 0
pOldTopic->numOfColumns = pNewTopic->numOfColumns;
//TODO handle update
pOldTopic->numOfTags = pNewTopic->numOfTags;
int32_t totalCols = pNewTopic->numOfTags + pNewTopic->numOfColumns;
int32_t totalSize = totalCols * sizeof(SSchema);
if (pOldTopic->numOfTags + pOldTopic->numOfColumns < totalCols) {
void *pSchema = malloc(totalSize);
if (pSchema != NULL) {
free(pOldTopic->pSchema);
pOldTopic->pSchema = pSchema;
}
}
memcpy(pOldTopic->pSchema, pNewTopic->pSchema, totalSize);
#endif
taosWUnLockLatch
(
&
pOldTopic
->
lock
);
taosWUnLockLatch
(
&
pOldTopic
->
lock
);
return
0
;
return
0
;
}
}
...
@@ -191,45 +162,10 @@ static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) {
...
@@ -191,45 +162,10 @@ static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) {
return
mndAcquireDb
(
pMnode
,
db
);
return
mndAcquireDb
(
pMnode
,
db
);
}
}
static
SCreateTopicInternalMsg
*
mndBuildCreateTopicMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
STopicObj
*
pTopic
)
{
static
SDDropTopicMsg
*
mndBuildDropTopicMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
STopicObj
*
pTopic
)
{
int32_t
totalCols
=
0
;
int32_t
contLen
=
sizeof
(
SDDropTopicMsg
);
int32_t
contLen
=
sizeof
(
SCreateTopicInternalMsg
)
+
pTopic
->
execLen
+
pTopic
->
sqlLen
;
SCreateTopicInternalMsg
*
pCreate
=
calloc
(
1
,
contLen
);
if
(
pCreate
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pCreate
->
head
.
contLen
=
htonl
(
contLen
);
pCreate
->
head
.
vgId
=
htonl
(
pVgroup
->
vgId
);
memcpy
(
pCreate
->
name
,
pTopic
->
name
,
TSDB_TABLE_FNAME_LEN
);
pCreate
->
tuid
=
htobe64
(
pTopic
->
uid
);
pCreate
->
sverson
=
htonl
(
pTopic
->
version
);
pCreate
->
sql
=
malloc
(
pTopic
->
sqlLen
);
if
(
pCreate
->
sql
==
NULL
)
{
free
(
pCreate
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
memcpy
(
pCreate
->
sql
,
pTopic
->
sql
,
pTopic
->
sqlLen
);
pCreate
->
executor
=
malloc
(
pTopic
->
execLen
);
if
(
pCreate
->
executor
==
NULL
)
{
free
(
pCreate
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
memcpy
(
pCreate
->
executor
,
pTopic
->
executor
,
pTopic
->
execLen
);
return
pCreate
;
}
static
SDropTopicInternalMsg
*
mndBuildDropTopicMsg
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
STopicObj
*
pTopic
)
{
int32_t
contLen
=
sizeof
(
SDropTopicInternalMsg
);
SD
ropTopicInternal
Msg
*
pDrop
=
calloc
(
1
,
contLen
);
SD
DropTopic
Msg
*
pDrop
=
calloc
(
1
,
contLen
);
if
(
pDrop
==
NULL
)
{
if
(
pDrop
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
...
@@ -243,109 +179,12 @@ static SDropTopicInternalMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgro
...
@@ -243,109 +179,12 @@ static SDropTopicInternalMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgro
return
pDrop
;
return
pDrop
;
}
}
static
int32_t
mndCheckCreateTopicMsg
(
SC
reateTopicMsg
*
pCreate
)
{
static
int32_t
mndCheckCreateTopicMsg
(
SC
MCreateTopicReq
*
pCreate
)
{
// deserialize and other stuff
// deserialize and other stuff
return
0
;
return
0
;
}
}
static
int32_t
mndSetCreateTopicRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
STopicObj
*
pTopic
)
{
static
int32_t
mndCreateTopic
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCMCreateTopicReq
*
pCreate
,
SDbObj
*
pDb
)
{
SSdbRaw
*
pRedoRaw
=
mndTopicActionEncode
(
pTopic
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateTopicUndoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
STopicObj
*
pTopic
)
{
SSdbRaw
*
pUndoRaw
=
mndTopicActionEncode
(
pTopic
);
if
(
pUndoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateTopicCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
STopicObj
*
pTopic
)
{
SSdbRaw
*
pCommitRaw
=
mndTopicActionEncode
(
pTopic
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetCreateTopicRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
STopicObj
*
pTopic
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
pVgroup
->
dbUid
!=
pDb
->
uid
)
continue
;
SCreateTopicInternalMsg
*
pMsg
=
mndBuildCreateTopicMsg
(
pMnode
,
pVgroup
,
pTopic
);
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
htonl
(
pMsg
->
head
.
contLen
);
action
.
msgType
=
TDMT_VND_CREATE_TOPIC
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
return
-
1
;
}
sdbRelease
(
pSdb
,
pVgroup
);
}
return
0
;
}
static
int32_t
mndSetCreateTopicUndoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SDbObj
*
pDb
,
STopicObj
*
pTopic
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
pVgroup
->
dbUid
!=
pDb
->
uid
)
continue
;
SDropTopicInternalMsg
*
pMsg
=
mndBuildDropTopicMsg
(
pMnode
,
pVgroup
,
pTopic
);
if
(
pMsg
==
NULL
)
{
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
STransAction
action
=
{
0
};
action
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
action
.
pCont
=
pMsg
;
action
.
contLen
=
sizeof
(
SDropTopicInternalMsg
);
action
.
msgType
=
TDMT_VND_DROP_TOPIC
;
if
(
mndTransAppendUndoAction
(
pTrans
,
&
action
)
!=
0
)
{
free
(
pMsg
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
return
-
1
;
}
sdbRelease
(
pSdb
,
pVgroup
);
}
return
0
;
}
static
int32_t
mndCreateTopic
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
SCreateTopicMsg
*
pCreate
,
SDbObj
*
pDb
)
{
STopicObj
topicObj
=
{
0
};
STopicObj
topicObj
=
{
0
};
tstrncpy
(
topicObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
tstrncpy
(
topicObj
.
name
,
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
tstrncpy
(
topicObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
tstrncpy
(
topicObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
...
@@ -355,66 +194,17 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCreateTopicMsg *
...
@@ -355,66 +194,17 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCreateTopicMsg *
topicObj
.
dbUid
=
pDb
->
uid
;
topicObj
.
dbUid
=
pDb
->
uid
;
topicObj
.
version
=
1
;
topicObj
.
version
=
1
;
#if 0
SSdbRaw
*
pTopicRaw
=
mndTopicActionEncode
(
&
topicObj
);
int32_t totalCols = topicObj.numOfColumns + topicObj.numOfTags;
if
(
pTopicRaw
==
NULL
)
return
-
1
;
int32_t totalSize = totalCols * sizeof(SSchema);
if
(
sdbSetRawStatus
(
pTopicRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
topicObj.sql = malloc(totalSize);
return
sdbWrite
(
pMnode
->
pSdb
,
pTopicRaw
);
if (topicObj.sql == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
memcpy(topicObj.sql, pCreate->sql, totalSize);
#endif
int32_t
code
=
0
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to create topic:%s"
,
pTrans
->
id
,
pCreate
->
name
);
if
(
mndSetCreateTopicRedoLogs
(
pMnode
,
pTrans
,
pDb
,
&
topicObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_TOPIC_OVER
;
}
if
(
mndSetCreateTopicUndoLogs
(
pMnode
,
pTrans
,
pDb
,
&
topicObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set undo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_TOPIC_OVER
;
}
if
(
mndSetCreateTopicCommitLogs
(
pMnode
,
pTrans
,
pDb
,
&
topicObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_TOPIC_OVER
;
}
if
(
mndSetCreateTopicRedoActions
(
pMnode
,
pTrans
,
pDb
,
&
topicObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_TOPIC_OVER
;
}
if
(
mndSetCreateTopicUndoActions
(
pMnode
,
pTrans
,
pDb
,
&
topicObj
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
CREATE_TOPIC_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
code
=
0
;
CREATE_TOPIC_OVER:
mndTransDrop
(
pTrans
);
return
code
;
}
}
static
int32_t
mndProcessCreateTopicMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mndProcessCreateTopicMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SCreateTopicMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
char
*
msgStr
=
pMsg
->
rpcMsg
.
pCont
;
SCMCreateTopicReq
*
pCreate
;
tDeserializeSCMCreateTopicReq
(
msgStr
,
pCreate
);
mDebug
(
"topic:%s, start to create"
,
pCreate
->
name
);
mDebug
(
"topic:%s, start to create"
,
pCreate
->
name
);
...
@@ -436,15 +226,6 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) {
...
@@ -436,15 +226,6 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) {
}
}
}
}
// topic should have different name with stb
SStbObj
*
pStb
=
mndAcquireStb
(
pMnode
,
pCreate
->
name
);
if
(
pStb
!=
NULL
)
{
sdbRelease
(
pMnode
->
pSdb
,
pStb
);
terrno
=
TSDB_CODE_MND_NAME_CONFLICT_WITH_STB
;
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
SDbObj
*
pDb
=
mndAcquireDbByTopic
(
pMnode
,
pCreate
->
name
);
SDbObj
*
pDb
=
mndAcquireDbByTopic
(
pMnode
,
pCreate
->
name
);
if
(
pDb
==
NULL
)
{
if
(
pDb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
...
@@ -464,144 +245,7 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) {
...
@@ -464,144 +245,7 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
}
static
int32_t
mndCheckAlterTopicMsg
(
SAlterTopicMsg
*
pAlter
)
{
SSchema
*
pSchema
=
&
pAlter
->
schema
;
pSchema
->
colId
=
htonl
(
pSchema
->
colId
);
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
if
(
pSchema
->
type
<=
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
return
-
1
;
}
if
(
pSchema
->
colId
<
0
||
pSchema
->
colId
>=
(
TSDB_MAX_COLUMNS
+
TSDB_MAX_TAGS
))
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
return
-
1
;
}
if
(
pSchema
->
bytes
<=
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
return
-
1
;
}
if
(
pSchema
->
name
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
return
-
1
;
}
return
0
;
}
static
int32_t
mndUpdateTopic
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
STopicObj
*
pOldTopic
,
STopicObj
*
pNewTopic
)
{
return
0
;
}
static
int32_t
mndProcessAlterTopicMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SAlterTopicMsg
*
pAlter
=
pMsg
->
rpcMsg
.
pCont
;
mDebug
(
"topic:%s, start to alter"
,
pAlter
->
name
);
if
(
mndCheckAlterTopicMsg
(
pAlter
)
!=
0
)
{
mError
(
"topic:%s, failed to alter since %s"
,
pAlter
->
name
,
terrstr
());
return
-
1
;
}
STopicObj
*
pTopic
=
mndAcquireTopic
(
pMnode
,
pAlter
->
name
);
if
(
pTopic
==
NULL
)
{
terrno
=
TSDB_CODE_MND_TOPIC_NOT_EXIST
;
mError
(
"topic:%s, failed to alter since %s"
,
pAlter
->
name
,
terrstr
());
return
-
1
;
}
STopicObj
topicObj
=
{
0
};
memcpy
(
&
topicObj
,
pTopic
,
sizeof
(
STopicObj
));
int32_t
code
=
mndUpdateTopic
(
pMnode
,
pMsg
,
pTopic
,
&
topicObj
);
mndReleaseTopic
(
pMnode
,
pTopic
);
if
(
code
!=
0
)
{
mError
(
"topic:%s, failed to alter since %s"
,
pAlter
->
name
,
tstrerror
(
code
));
return
code
;
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
int32_t
mndProcessAlterTopicInRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndSetDropTopicRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STopicObj
*
pTopic
)
{
SSdbRaw
*
pRedoRaw
=
mndTopicActionEncode
(
pTopic
);
if
(
pRedoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_DROPPING
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropTopicUndoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STopicObj
*
pTopic
)
{
SSdbRaw
*
pUndoRaw
=
mndTopicActionEncode
(
pTopic
);
if
(
pUndoRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendUndolog
(
pTrans
,
pUndoRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropTopicCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STopicObj
*
pTopic
)
{
SSdbRaw
*
pCommitRaw
=
mndTopicActionEncode
(
pTopic
);
if
(
pCommitRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pCommitRaw
)
!=
0
)
return
-
1
;
if
(
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_DROPPED
)
!=
0
)
return
-
1
;
return
0
;
}
static
int32_t
mndSetDropTopicRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STopicObj
*
pTopic
)
{
return
0
;
}
static
int32_t
mndSetDropTopicUndoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STopicObj
*
pTopic
)
{
return
0
;
}
static
int32_t
mndDropTopic
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
STopicObj
*
pTopic
)
{
static
int32_t
mndDropTopic
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
,
STopicObj
*
pTopic
)
{
int32_t
code
=
-
1
;
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
mError
(
"topic:%s, failed to drop since %s"
,
pTopic
->
name
,
terrstr
());
return
-
1
;
}
mDebug
(
"trans:%d, used to drop topic:%s"
,
pTrans
->
id
,
pTopic
->
name
);
if
(
mndSetDropTopicRedoLogs
(
pMnode
,
pTrans
,
pTopic
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_TOPIC_OVER
;
}
if
(
mndSetDropTopicUndoLogs
(
pMnode
,
pTrans
,
pTopic
)
!=
0
)
{
mError
(
"trans:%d, failed to set undo log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_TOPIC_OVER
;
}
if
(
mndSetDropTopicCommitLogs
(
pMnode
,
pTrans
,
pTopic
)
!=
0
)
{
mError
(
"trans:%d, failed to set commit log since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_TOPIC_OVER
;
}
if
(
mndSetDropTopicRedoActions
(
pMnode
,
pTrans
,
pTopic
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_TOPIC_OVER
;
}
if
(
mndSetDropTopicUndoActions
(
pMnode
,
pTrans
,
pTopic
)
!=
0
)
{
mError
(
"trans:%d, failed to set redo actions since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_TOPIC_OVER
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
goto
DROP_TOPIC_OVER
;
}
code
=
0
;
DROP_TOPIC_OVER:
mndTransDrop
(
pTrans
);
return
0
;
return
0
;
}
}
...
@@ -705,11 +349,6 @@ static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg) {
...
@@ -705,11 +349,6 @@ static int32_t mndProcessTopicMetaMsg(SMnodeMsg *pMsg) {
return
0
;
return
0
;
}
}
static
int32_t
mndProcessCreateTopicInRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransProcessRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndGetNumOfTopics
(
SMnode
*
pMnode
,
char
*
dbName
,
int32_t
*
pNumOfTopics
)
{
static
int32_t
mndGetNumOfTopics
(
SMnode
*
pMnode
,
char
*
dbName
,
int32_t
*
pNumOfTopics
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
8ecd7a56
...
@@ -294,18 +294,18 @@ TRANS_DECODE_OVER:
...
@@ -294,18 +294,18 @@ TRANS_DECODE_OVER:
return
NULL
;
return
NULL
;
}
}
mTrace
(
"trans:%d, decode from raw:%p
"
,
pTrans
->
id
,
pRaw
);
mTrace
(
"trans:%d, decode from raw:%p
, data:%p"
,
pTrans
->
id
,
pRaw
,
pTrans
);
return
pRow
;
return
pRow
;
}
}
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
mTrace
(
"trans:%d, perform insert action
"
,
pTrans
->
id
);
mTrace
(
"trans:%d, perform insert action
, data:%p"
,
pTrans
->
id
,
pTrans
);
return
0
;
return
0
;
}
}
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
mTrace
(
"trans:%d, perform delete action
"
,
pTrans
->
id
);
mTrace
(
"trans:%d, perform delete action
, data:%p"
,
pTrans
->
id
,
pTrans
);
mndTransDropLogs
(
pTrans
->
redoLogs
);
mndTransDropLogs
(
pTrans
->
redoLogs
);
mndTransDropLogs
(
pTrans
->
undoLogs
);
mndTransDropLogs
(
pTrans
->
undoLogs
);
...
@@ -317,7 +317,7 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
...
@@ -317,7 +317,7 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
}
}
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pOldTrans
,
STrans
*
pNewTrans
)
{
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pOldTrans
,
STrans
*
pNewTrans
)
{
mTrace
(
"trans:%d, perform update action
"
,
pOldTrans
->
id
);
mTrace
(
"trans:%d, perform update action
, data:%p"
,
pOldTrans
->
id
,
pOldTrans
);
pOldTrans
->
stage
=
pNewTrans
->
stage
;
pOldTrans
->
stage
=
pNewTrans
->
stage
;
return
0
;
return
0
;
}
}
...
@@ -362,14 +362,14 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) {
...
@@ -362,14 +362,14 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) {
return
NULL
;
return
NULL
;
}
}
mDebug
(
"trans:%d, is created
"
,
pTrans
->
id
);
mDebug
(
"trans:%d, is created
, data:%p"
,
pTrans
->
id
,
pTrans
);
return
pTrans
;
return
pTrans
;
}
}
static
void
mndTransDropLogs
(
SArray
*
pArray
)
{
static
void
mndTransDropLogs
(
SArray
*
pArray
)
{
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGetP
(
pArray
,
i
);
SSdbRaw
*
pRaw
=
taosArrayGetP
(
pArray
,
i
);
tfree
(
pRaw
);
sdbFreeRaw
(
pRaw
);
}
}
taosArrayDestroy
(
pArray
);
taosArrayDestroy
(
pArray
);
...
@@ -391,7 +391,7 @@ void mndTransDrop(STrans *pTrans) {
...
@@ -391,7 +391,7 @@ void mndTransDrop(STrans *pTrans) {
mndTransDropActions
(
pTrans
->
redoActions
);
mndTransDropActions
(
pTrans
->
redoActions
);
mndTransDropActions
(
pTrans
->
undoActions
);
mndTransDropActions
(
pTrans
->
undoActions
);
//
mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans);
mDebug
(
"trans:%d, is dropped, data:%p"
,
pTrans
->
id
,
pTrans
);
tfree
(
pTrans
);
tfree
(
pTrans
);
}
}
...
@@ -442,7 +442,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
...
@@ -442,7 +442,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
}
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
m
Trace
(
"trans:%d, sync to other nodes"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, sync to other nodes"
,
pTrans
->
id
);
int32_t
code
=
mndSyncPropose
(
pMnode
,
pRaw
);
int32_t
code
=
mndSyncPropose
(
pMnode
,
pRaw
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
...
@@ -450,7 +450,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
...
@@ -450,7 +450,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
return
-
1
;
return
-
1
;
}
}
m
Trace
(
"trans:%d, sync finished"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, sync finished"
,
pTrans
->
id
);
code
=
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
code
=
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
8ecd7a56
...
@@ -86,7 +86,6 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
...
@@ -86,7 +86,6 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgid
->
dnodeId
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgid
->
dnodeId
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pVgid
->
role
)
}
}
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
...
@@ -121,7 +120,9 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
...
@@ -121,7 +120,9 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pVgid
->
dnodeId
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pVgid
->
dnodeId
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
(
int8_t
*
)
&
pVgid
->
role
)
if
(
pVgroup
->
replica
==
1
)
{
pVgid
->
role
=
TAOS_SYNC_STATE_LEADER
;
}
}
}
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
...
@@ -237,44 +238,95 @@ SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *p
...
@@ -237,44 +238,95 @@ SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *p
return
pDrop
;
return
pDrop
;
}
}
static
int32_t
mndGetAvailableDnode
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
static
SArray
*
mndBuildDnodesArray
(
SMnode
*
pMnode
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
allocedVnodes
=
0
;
int32_t
numOfDnodes
=
mndGetDnodeSize
(
pMnode
);
void
*
pIter
=
NULL
;
SArray
*
pArray
=
taosArrayInit
(
numOfDnodes
,
sizeof
(
SDnodeObj
));
if
(
pArray
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
while
(
allocedVnodes
<
pVgroup
->
replica
)
{
void
*
pIter
=
NULL
;
while
(
1
)
{
SDnodeObj
*
pDnode
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_DNODE
,
pIter
,
(
void
**
)
&
pDnode
);
pIter
=
sdbFetch
(
pSdb
,
SDB_DNODE
,
pIter
,
(
void
**
)
&
pDnode
);
if
(
pIter
==
NULL
)
break
;
if
(
pIter
==
NULL
)
break
;
// todo
int32_t
numOfVnodes
=
mndGetVnodesNum
(
pMnode
,
pDnode
->
id
);
if
(
mndIsDnodeInReadyStatus
(
pMnode
,
pDnode
))
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
allocedVnodes
];
bool
isMnode
=
mndIsMnode
(
pMnode
,
pDnode
->
id
);
pVgid
->
dnodeId
=
pDnode
->
id
;
if
(
isMnode
)
{
if
(
pVgroup
->
replica
==
1
)
{
pDnode
->
numOfVnodes
++
;
pVgid
->
role
=
TAOS_SYNC_STATE_LEADER
;
}
else
{
pVgid
->
role
=
TAOS_SYNC_STATE_FOLLOWER
;
}
}
allocedVnodes
++
;
bool
isReady
=
mndIsDnodeInReadyStatus
(
pMnode
,
pDnode
);
if
(
isReady
)
{
taosArrayPush
(
pArray
,
pDnode
);
}
}
mDebug
(
"dnode:%d, numOfVnodes:%d numOfSupportVnodes:%d isMnode:%d ready:%d"
,
pDnode
->
id
,
numOfVnodes
,
pDnode
->
numOfSupportVnodes
,
isMnode
,
isReady
);
sdbRelease
(
pSdb
,
pDnode
);
sdbRelease
(
pSdb
,
pDnode
);
}
}
if
(
allocedVnodes
!=
pVgroup
->
replica
)
{
return
pArray
;
}
static
int32_t
mndCompareDnodeVnodes
(
SDnodeObj
*
pDnode1
,
SDnodeObj
*
pDnode2
)
{
float
d1Score
=
(
float
)
pDnode1
->
numOfVnodes
/
pDnode1
->
numOfSupportVnodes
;
float
d2Score
=
(
float
)
pDnode2
->
numOfVnodes
/
pDnode2
->
numOfSupportVnodes
;
return
d1Score
>
d2Score
?
1
:
0
;
}
static
int32_t
mndGetAvailableDnode
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SArray
*
pArray
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
allocedVnodes
=
0
;
void
*
pIter
=
NULL
;
taosArraySort
(
pArray
,
(
__compar_fn_t
)
mndCompareDnodeVnodes
);
for
(
int32_t
v
=
0
;
v
<
pVgroup
->
replica
;
++
v
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
v
];
SDnodeObj
*
pDnode
=
taosArrayGet
(
pArray
,
v
);
if
(
pDnode
==
NULL
||
pDnode
->
numOfVnodes
>
pDnode
->
numOfSupportVnodes
)
{
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
return
-
1
;
return
-
1
;
}
}
pVgid
->
dnodeId
=
pDnode
->
id
;
if
(
pVgroup
->
replica
==
1
)
{
pVgid
->
role
=
TAOS_SYNC_STATE_LEADER
;
}
else
{
pVgid
->
role
=
TAOS_SYNC_STATE_FOLLOWER
;
}
mDebug
(
"db:%s, vgId:%d, vindex:%d dnodeId:%d is alloced"
,
pVgroup
->
dbName
,
pVgroup
->
vgId
,
v
,
pVgid
->
dnodeId
);
pDnode
->
numOfVnodes
++
;
}
return
0
;
return
0
;
}
}
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
)
{
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
)
{
SVgObj
*
pVgroups
=
calloc
(
pDb
->
cfg
.
numOfVgroups
,
sizeof
(
SVgObj
));
int32_t
code
=
-
1
;
SArray
*
pArray
=
NULL
;
SVgObj
*
pVgroups
=
NULL
;
pVgroups
=
calloc
(
pDb
->
cfg
.
numOfVgroups
,
sizeof
(
SVgObj
));
if
(
pVgroups
==
NULL
)
{
if
(
pVgroups
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
goto
ALLOC_VGROUP_OVER
;
}
pArray
=
mndBuildDnodesArray
(
pMnode
);
if
(
pArray
==
NULL
)
{
goto
ALLOC_VGROUP_OVER
;
}
}
mDebug
(
"db:%s, total %d dnodes used to create %d vgroups (%d vnodes)"
,
pDb
->
name
,
(
int32_t
)
taosArrayGetSize
(
pArray
),
pDb
->
cfg
.
numOfVgroups
,
pDb
->
cfg
.
numOfVgroups
*
pDb
->
cfg
.
replications
);
int32_t
allocedVgroups
=
0
;
int32_t
allocedVgroups
=
0
;
int32_t
maxVgId
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_VGROUP
);
int32_t
maxVgId
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_VGROUP
);
uint32_t
hashMin
=
0
;
uint32_t
hashMin
=
0
;
...
@@ -298,17 +350,23 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
...
@@ -298,17 +350,23 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
replica
=
pDb
->
cfg
.
replications
;
pVgroup
->
replica
=
pDb
->
cfg
.
replications
;
if
(
mndGetAvailableDnode
(
pMnode
,
pVgroup
)
!=
0
)
{
if
(
mndGetAvailableDnode
(
pMnode
,
pVgroup
,
pArray
)
!=
0
)
{
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
free
(
pVgroups
);
goto
ALLOC_VGROUP_OVER
;
return
-
1
;
}
}
allocedVgroups
++
;
allocedVgroups
++
;
}
}
*
ppVgroups
=
pVgroups
;
*
ppVgroups
=
pVgroups
;
return
0
;
code
=
0
;
mDebug
(
"db:%s, %d vgroups is alloced, replica:%d"
,
pDb
->
name
,
pDb
->
cfg
.
numOfVgroups
,
pDb
->
cfg
.
replications
);
ALLOC_VGROUP_OVER:
if
(
code
!=
0
)
free
(
pVgroups
);
taosArrayDestroy
(
pArray
);
return
code
;
}
}
SEpSet
mndGetVgroupEpset
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
SEpSet
mndGetVgroupEpset
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
...
@@ -348,6 +406,7 @@ static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) {
...
@@ -348,6 +406,7 @@ static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) {
}
}
static
int32_t
mndProcessSyncVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessSyncVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessCompactVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessCompactVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndGetVgroupMaxReplica
(
SMnode
*
pMnode
,
char
*
dbName
,
int8_t
*
pReplica
,
int32_t
*
pNumOfVgroups
)
{
static
int32_t
mndGetVgroupMaxReplica
(
SMnode
*
pMnode
,
char
*
dbName
,
int8_t
*
pReplica
,
int32_t
*
pNumOfVgroups
)
{
...
@@ -478,7 +537,7 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter) {
...
@@ -478,7 +537,7 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter) {
sdbCancelFetch
(
pSdb
,
pIter
);
sdbCancelFetch
(
pSdb
,
pIter
);
}
}
static
int32_t
mndGetVnodesNum
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
int32_t
mndGetVnodesNum
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfVnodes
=
0
;
int32_t
numOfVnodes
=
0
;
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
8ecd7a56
...
@@ -16,14 +16,16 @@
...
@@ -16,14 +16,16 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mndAcct.h"
#include "mndAcct.h"
#include "mndAuth.h"
#include "mndAuth.h"
#include "mndB
alanc
e.h"
#include "mndB
nod
e.h"
#include "mndCluster.h"
#include "mndCluster.h"
#include "mndDb.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndDnode.h"
#include "mndFunc.h"
#include "mndFunc.h"
#include "mndMnode.h"
#include "mndMnode.h"
#include "mndProfile.h"
#include "mndProfile.h"
#include "mndQnode.h"
#include "mndShow.h"
#include "mndShow.h"
#include "mndSnode.h"
#include "mndStb.h"
#include "mndStb.h"
#include "mndSync.h"
#include "mndSync.h"
#include "mndTelem.h"
#include "mndTelem.h"
...
@@ -146,15 +148,18 @@ static int32_t mndInitSteps(SMnode *pMnode) {
...
@@ -146,15 +148,18 @@ static int32_t mndInitSteps(SMnode *pMnode) {
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb"
,
mndInitSdb
,
mndCleanupSdb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb"
,
mndInitSdb
,
mndCleanupSdb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-trans"
,
mndInitTrans
,
mndCleanupTrans
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-trans"
,
mndInitTrans
,
mndCleanupTrans
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-cluster"
,
mndInitCluster
,
mndCleanupCluster
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-cluster"
,
mndInitCluster
,
mndCleanupCluster
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-dnode"
,
mndInitDnode
,
mndCleanupDnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-mnode"
,
mndInitMnode
,
mndCleanupMnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-mnode"
,
mndInitMnode
,
mndCleanupMnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-acct"
,
mndInitAcct
,
mndCleanupAcct
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitQnode
,
mndCleanupQnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-auth"
,
mndInitAuth
,
mndCleanupAuth
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitSnode
,
mndCleanupSnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitBnode
,
mndCleanupBnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-dnode"
,
mndInitDnode
,
mndCleanupDnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-user"
,
mndInitUser
,
mndCleanupUser
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-user"
,
mndInitUser
,
mndCleanupUser
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-db"
,
mndInitDb
,
mndCleanupDb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-auth"
,
mndInitAuth
,
mndCleanupAuth
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-acct"
,
mndInitAcct
,
mndCleanupAcct
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-topic"
,
mndInitTopic
,
mndCleanupTopic
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-vgroup"
,
mndInitVgroup
,
mndCleanupVgroup
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-vgroup"
,
mndInitVgroup
,
mndCleanupVgroup
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-stb"
,
mndInitStb
,
mndCleanupStb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-stb"
,
mndInitStb
,
mndCleanupStb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-
topic"
,
mndInitTopic
,
mndCleanupTopic
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-
db"
,
mndInitDb
,
mndCleanupDb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-func"
,
mndInitFunc
,
mndCleanupFunc
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-func"
,
mndInitFunc
,
mndCleanupFunc
)
!=
0
)
return
-
1
;
if
(
pMnode
->
clusterId
<=
0
)
{
if
(
pMnode
->
clusterId
<=
0
)
{
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb-deploy"
,
mndDeploySdb
,
NULL
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb-deploy"
,
mndDeploySdb
,
NULL
)
!=
0
)
return
-
1
;
...
@@ -162,7 +167,6 @@ static int32_t mndInitSteps(SMnode *pMnode) {
...
@@ -162,7 +167,6 @@ static int32_t mndInitSteps(SMnode *pMnode) {
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb-read"
,
mndReadSdb
,
NULL
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb-read"
,
mndReadSdb
,
NULL
)
!=
0
)
return
-
1
;
}
}
if
(
mndAllocStep
(
pMnode
,
"mnode-timer"
,
mndInitTimer
,
NULL
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-timer"
,
mndInitTimer
,
NULL
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-balance"
,
mndInitBalance
,
mndCleanupBalance
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-profile"
,
mndInitProfile
,
mndCleanupProfile
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-profile"
,
mndInitProfile
,
mndCleanupProfile
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-show"
,
mndInitShow
,
mndCleanupShow
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-show"
,
mndInitShow
,
mndCleanupShow
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-sync"
,
mndInitSync
,
mndCleanupSync
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-sync"
,
mndInitSync
,
mndCleanupSync
)
!=
0
)
return
-
1
;
...
...
source/dnode/mnode/sdb/inc/sdbInt.h
浏览文件 @
8ecd7a56
...
@@ -72,6 +72,7 @@ typedef struct SSdb {
...
@@ -72,6 +72,7 @@ typedef struct SSdb {
}
SSdb
;
}
SSdb
;
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
8ecd7a56
...
@@ -80,16 +80,12 @@ void sdbCleanup(SSdb *pSdb) {
...
@@ -80,16 +80,12 @@ void sdbCleanup(SSdb *pSdb) {
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
if
(
hash
==
NULL
)
continue
;
if
(
hash
==
NULL
)
continue
;
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
i
];
SSdbRow
**
ppRow
=
taosHashIterate
(
hash
,
NULL
);
SSdbRow
**
ppRow
=
taosHashIterate
(
hash
,
NULL
);
while
(
ppRow
!=
NULL
)
{
while
(
ppRow
!=
NULL
)
{
SSdbRow
*
pRow
=
*
ppRow
;
SSdbRow
*
pRow
=
*
ppRow
;
if
(
pRow
==
NULL
)
continue
;
if
(
pRow
==
NULL
)
continue
;
if
(
deleteFp
!=
NULL
)
{
sdbFreeRow
(
pSdb
,
pRow
);
(
*
deleteFp
)(
pSdb
,
pRow
->
pObj
);
}
sdbFreeRow
(
pRow
);
ppRow
=
taosHashIterate
(
hash
,
ppRow
);
ppRow
=
taosHashIterate
(
hash
,
ppRow
);
}
}
}
}
...
...
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
8ecd7a56
...
@@ -151,7 +151,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -151,7 +151,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
if
(
taosWriteFile
(
fd
,
pRaw
,
writeLen
)
!=
writeLen
)
{
if
(
taosWriteFile
(
fd
,
pRaw
,
writeLen
)
!=
writeLen
)
{
code
=
TAOS_SYSTEM_ERROR
(
terrno
);
code
=
TAOS_SYSTEM_ERROR
(
terrno
);
taosHashCancelIterate
(
hash
,
ppRow
);
taosHashCancelIterate
(
hash
,
ppRow
);
free
(
pRaw
);
sdbFreeRaw
(
pRaw
);
break
;
break
;
}
}
...
@@ -159,7 +159,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -159,7 +159,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
if
(
taosWriteFile
(
fd
,
&
cksum
,
sizeof
(
int32_t
))
!=
sizeof
(
int32_t
))
{
if
(
taosWriteFile
(
fd
,
&
cksum
,
sizeof
(
int32_t
))
!=
sizeof
(
int32_t
))
{
code
=
TAOS_SYSTEM_ERROR
(
terrno
);
code
=
TAOS_SYSTEM_ERROR
(
terrno
);
taosHashCancelIterate
(
hash
,
ppRow
);
taosHashCancelIterate
(
hash
,
ppRow
);
free
(
pRaw
);
sdbFreeRaw
(
pRaw
);
break
;
break
;
}
}
}
else
{
}
else
{
...
@@ -168,7 +168,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -168,7 +168,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
break
;
break
;
}
}
free
(
pRaw
);
sdbFreeRaw
(
pRaw
);
ppRow
=
taosHashIterate
(
hash
,
ppRow
);
ppRow
=
taosHashIterate
(
hash
,
ppRow
);
}
}
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
...
...
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
8ecd7a56
...
@@ -16,6 +16,57 @@
...
@@ -16,6 +16,57 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "sdbInt.h"
#include "sdbInt.h"
static
const
char
*
sdbTableName
(
ESdbType
type
)
{
switch
(
type
)
{
case
SDB_TRANS
:
return
"trans"
;
case
SDB_CLUSTER
:
return
"cluster"
;
case
SDB_MNODE
:
return
"mnode"
;
case
SDB_QNODE
:
return
"qnode"
;
case
SDB_SNODE
:
return
"snode"
;
case
SDB_BNODE
:
return
"bnode"
;
case
SDB_DNODE
:
return
"dnode"
;
case
SDB_USER
:
return
"user"
;
case
SDB_AUTH
:
return
"auth"
;
case
SDB_ACCT
:
return
"acct"
;
case
SDB_TOPIC
:
return
"topic"
;
case
SDB_VGROUP
:
return
"vgId"
;
case
SDB_STB
:
return
"stb"
;
case
SDB_DB
:
return
"db"
;
case
SDB_FUNC
:
return
"func"
;
default:
return
"undefine"
;
}
}
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
)
{
EKeyType
keyType
=
pSdb
->
keyTypes
[
pRow
->
type
];
if
(
keyType
==
SDB_KEY_BINARY
)
{
mTrace
(
"%s:%s, refCount:%d oper:%s"
,
sdbTableName
(
pRow
->
type
),
(
char
*
)
pRow
->
pObj
,
pRow
->
refCount
,
oper
);
}
else
if
(
keyType
==
SDB_KEY_INT32
)
{
mTrace
(
"%s:%d, refCount:%d oper:%s"
,
sdbTableName
(
pRow
->
type
),
*
(
int32_t
*
)
pRow
->
pObj
,
pRow
->
refCount
,
oper
);
}
else
if
(
keyType
==
SDB_KEY_INT64
)
{
mTrace
(
"%s:%"
PRId64
", refCount:%d oper:%s"
,
sdbTableName
(
pRow
->
type
),
*
(
int64_t
*
)
pRow
->
pObj
,
pRow
->
refCount
,
oper
);
}
else
{
}
}
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
if
(
type
>=
SDB_MAX
||
type
<=
SDB_START
)
{
if
(
type
>=
SDB_MAX
||
type
<=
SDB_START
)
{
terrno
=
TSDB_CODE_SDB_INVALID_TABLE_TYPE
;
terrno
=
TSDB_CODE_SDB_INVALID_TABLE_TYPE
;
...
@@ -55,17 +106,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -55,17 +106,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SSdbRow
*
pOldRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
SSdbRow
*
pOldRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
pOldRow
!=
NULL
)
{
if
(
pOldRow
!=
NULL
)
{
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
p
Sdb
,
p
Row
);
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
return
terrno
;
return
terrno
;
}
}
pRow
->
refCount
=
1
;
pRow
->
refCount
=
0
;
pRow
->
status
=
pRaw
->
status
;
pRow
->
status
=
pRaw
->
status
;
sdbPrintOper
(
pSdb
,
pRow
,
"insertRow"
);
if
(
taosHashPut
(
hash
,
pRow
->
pObj
,
keySize
,
&
pRow
,
sizeof
(
void
*
))
!=
0
)
{
if
(
taosHashPut
(
hash
,
pRow
->
pObj
,
keySize
,
&
pRow
,
sizeof
(
void
*
))
!=
0
)
{
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
p
Sdb
,
p
Row
);
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
return
terrno
;
return
terrno
;
}
}
...
@@ -83,7 +135,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -83,7 +135,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
taosWLockLatch
(
pLock
);
taosWLockLatch
(
pLock
);
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
p
Sdb
,
p
Row
);
terrno
=
code
;
terrno
=
code
;
return
terrno
;
return
terrno
;
}
}
...
@@ -113,7 +165,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -113,7 +165,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
code
=
(
*
updateFp
)(
pSdb
,
pOldRow
->
pObj
,
pNewRow
->
pObj
);
code
=
(
*
updateFp
)(
pSdb
,
pOldRow
->
pObj
,
pNewRow
->
pObj
);
}
}
sdbFreeRow
(
pNewRow
);
sdbFreeRow
(
p
Sdb
,
p
NewRow
);
return
code
;
return
code
;
}
}
...
@@ -123,14 +175,10 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -123,14 +175,10 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
taosWLockLatch
(
pLock
);
// remove attached object such as trans
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
pRow
->
type
];
if
(
deleteFp
!=
NULL
)
(
*
deleteFp
)(
pSdb
,
pRow
->
pObj
);
SSdbRow
**
ppOldRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
SSdbRow
**
ppOldRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
ppOldRow
==
NULL
||
*
ppOldRow
==
NULL
)
{
if
(
ppOldRow
==
NULL
||
*
ppOldRow
==
NULL
)
{
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
p
Sdb
,
p
Row
);
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
return
terrno
;
return
terrno
;
}
}
...
@@ -140,8 +188,8 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -140,8 +188,8 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
taosHashRemove
(
hash
,
pOldRow
->
pObj
,
keySize
);
taosHashRemove
(
hash
,
pOldRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
sdbRelease
(
pSdb
,
pOldRow
->
pObj
);
//
sdbRelease(pSdb, pOldRow->pObj);
sdbFreeRow
(
pRow
);
sdbFreeRow
(
p
Sdb
,
p
Row
);
return
code
;
return
code
;
}
}
...
@@ -206,6 +254,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) {
...
@@ -206,6 +254,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) {
case
SDB_STATUS_UPDATING
:
case
SDB_STATUS_UPDATING
:
atomic_add_fetch_32
(
&
pRow
->
refCount
,
1
);
atomic_add_fetch_32
(
&
pRow
->
refCount
,
1
);
pRet
=
pRow
->
pObj
;
pRet
=
pRow
->
pObj
;
sdbPrintOper
(
pSdb
,
pRow
,
"acquireRow"
);
break
;
break
;
case
SDB_STATUS_CREATING
:
case
SDB_STATUS_CREATING
:
terrno
=
TSDB_CODE_SDB_OBJ_CREATING
;
terrno
=
TSDB_CODE_SDB_OBJ_CREATING
;
...
@@ -232,13 +281,9 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
...
@@ -232,13 +281,9 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
taosRLockLatch
(
pLock
);
taosRLockLatch
(
pLock
);
int32_t
ref
=
atomic_sub_fetch_32
(
&
pRow
->
refCount
,
1
);
int32_t
ref
=
atomic_sub_fetch_32
(
&
pRow
->
refCount
,
1
);
sdbPrintOper
(
pSdb
,
pRow
,
"releaseRow"
);
if
(
ref
<=
0
&&
pRow
->
status
==
SDB_STATUS_DROPPED
)
{
if
(
ref
<=
0
&&
pRow
->
status
==
SDB_STATUS_DROPPED
)
{
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
pRow
->
type
];
sdbFreeRow
(
pSdb
,
pRow
);
if
(
deleteFp
!=
NULL
)
{
(
*
deleteFp
)(
pSdb
,
pRow
->
pObj
);
}
sdbFreeRow
(
pRow
);
}
}
taosRUnLockLatch
(
pLock
);
taosRUnLockLatch
(
pLock
);
...
@@ -255,9 +300,9 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
...
@@ -255,9 +300,9 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
if
(
pIter
!=
NULL
)
{
if
(
pIter
!=
NULL
)
{
SSdbRow
*
pLastRow
=
*
(
SSdbRow
**
)
pIter
;
SSdbRow
*
pLastRow
=
*
(
SSdbRow
**
)
pIter
;
int32_t
ref
=
atomic_
sub_fetch_32
(
&
pLastRow
->
refCount
,
1
);
int32_t
ref
=
atomic_
load_32
(
&
pLastRow
->
refCount
);
if
(
ref
<=
0
&&
pLastRow
->
status
==
SDB_STATUS_DROPPED
)
{
if
(
ref
<=
0
&&
pLastRow
->
status
==
SDB_STATUS_DROPPED
)
{
sdbFreeRow
(
pLastRow
);
sdbFreeRow
(
p
Sdb
,
p
LastRow
);
}
}
}
}
...
@@ -270,6 +315,7 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
...
@@ -270,6 +315,7 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
}
}
atomic_add_fetch_32
(
&
pRow
->
refCount
,
1
);
atomic_add_fetch_32
(
&
pRow
->
refCount
,
1
);
sdbPrintOper
(
pSdb
,
pRow
,
"fetchRow"
);
*
ppObj
=
pRow
->
pObj
;
*
ppObj
=
pRow
->
pObj
;
break
;
break
;
}
}
...
...
source/dnode/mnode/sdb/src/sdbRaw.c
浏览文件 @
8ecd7a56
...
@@ -27,12 +27,12 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
...
@@ -27,12 +27,12 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
pRaw
->
sver
=
sver
;
pRaw
->
sver
=
sver
;
pRaw
->
dataLen
=
dataLen
;
pRaw
->
dataLen
=
dataLen
;
//
mTrace("raw:%p, is created, len:%d", pRaw, dataLen);
mTrace
(
"raw:%p, is created, len:%d"
,
pRaw
,
dataLen
);
return
pRaw
;
return
pRaw
;
}
}
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
//
mTrace("raw:%p, is freed", pRaw);
mTrace
(
"raw:%p, is freed"
,
pRaw
);
free
(
pRaw
);
free
(
pRaw
);
}
}
...
...
source/dnode/mnode/sdb/src/sdbRow.c
浏览文件 @
8ecd7a56
...
@@ -35,4 +35,13 @@ void *sdbGetRowObj(SSdbRow *pRow) {
...
@@ -35,4 +35,13 @@ void *sdbGetRowObj(SSdbRow *pRow) {
return
pRow
->
pObj
;
return
pRow
->
pObj
;
}
}
void
sdbFreeRow
(
SSdbRow
*
pRow
)
{
tfree
(
pRow
);
}
void
sdbFreeRow
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
)
{
// remove attached object such as trans
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
pRow
->
type
];
if
(
deleteFp
!=
NULL
)
{
(
*
deleteFp
)(
pSdb
,
pRow
->
pObj
);
}
sdbPrintOper
(
pSdb
,
pRow
,
"freeRow"
);
tfree
(
pRow
);
}
source/dnode/qnode/src/qnode.c
浏览文件 @
8ecd7a56
...
@@ -24,12 +24,8 @@ void qndClose(SQnode *pQnode) { free(pQnode); }
...
@@ -24,12 +24,8 @@ void qndClose(SQnode *pQnode) { free(pQnode); }
int32_t
qndGetLoad
(
SQnode
*
pQnode
,
SQnodeLoad
*
pLoad
)
{
return
0
;
}
int32_t
qndGetLoad
(
SQnode
*
pQnode
,
SQnodeLoad
*
pLoad
)
{
return
0
;
}
int32_t
qndProcess
QueryReq
(
SQnode
*
pQnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int32_t
qndProcess
Msg
(
SQnode
*
pQnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
*
pRsp
=
NULL
;
*
pRsp
=
NULL
;
return
0
;
return
0
;
}
}
int32_t
qndProcessFetchReq
(
SQnode
*
pQnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
*
pRsp
=
NULL
;
return
0
;
}
source/dnode/snode/src/snode.c
浏览文件 @
8ecd7a56
...
@@ -24,7 +24,7 @@ void sndClose(SSnode *pSnode) { free(pSnode); }
...
@@ -24,7 +24,7 @@ void sndClose(SSnode *pSnode) { free(pSnode); }
int32_t
sndGetLoad
(
SSnode
*
pSnode
,
SSnodeLoad
*
pLoad
)
{
return
0
;
}
int32_t
sndGetLoad
(
SSnode
*
pSnode
,
SSnodeLoad
*
pLoad
)
{
return
0
;
}
int32_t
sndProcess
Write
Msg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int32_t
sndProcessMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
*
pRsp
=
NULL
;
*
pRsp
=
NULL
;
return
0
;
return
0
;
}
}
...
...
source/dnode/vnode/impl/src/vnodeInt.c
浏览文件 @
8ecd7a56
...
@@ -28,8 +28,3 @@ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -28,8 +28,3 @@ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
vInfo
(
"sync message is processed"
);
vInfo
(
"sync message is processed"
);
return
0
;
return
0
;
}
}
int
vnodeProcessConsumeReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
vInfo
(
"consume message is processed"
);
return
0
;
}
source/libs/catalog/inc/catalogInt.h
浏览文件 @
8ecd7a56
...
@@ -31,6 +31,11 @@ extern "C" {
...
@@ -31,6 +31,11 @@ extern "C" {
#define CTG_DEFAULT_INVALID_VERSION (-1)
#define CTG_DEFAULT_INVALID_VERSION (-1)
enum
{
CTG_READ
=
1
,
CTG_WRITE
,
};
typedef
struct
SVgroupListCache
{
typedef
struct
SVgroupListCache
{
int32_t
vgroupVersion
;
int32_t
vgroupVersion
;
SHashObj
*
cache
;
// key:vgId, value:SVgroupInfo
SHashObj
*
cache
;
// key:vgId, value:SVgroupInfo
...
@@ -41,6 +46,7 @@ typedef struct SDBVgroupCache {
...
@@ -41,6 +46,7 @@ typedef struct SDBVgroupCache {
}
SDBVgroupCache
;
}
SDBVgroupCache
;
typedef
struct
STableMetaCache
{
typedef
struct
STableMetaCache
{
SRWLatch
stableLock
;
SHashObj
*
cache
;
//key:fulltablename, value:STableMeta
SHashObj
*
cache
;
//key:fulltablename, value:STableMeta
SHashObj
*
stableCache
;
//key:suid, value:STableMeta*
SHashObj
*
stableCache
;
//key:suid, value:STableMeta*
}
STableMetaCache
;
}
STableMetaCache
;
...
@@ -71,6 +77,31 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t);
...
@@ -71,6 +77,31 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t);
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#define CTG_LOCK(type, _lock) do { \
if (CTG_READ == (type)) { \
if ((*(_lock)) < 0) assert(0); \
taosRLockLatch(_lock); \
ctgDebug("CTG RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} else { \
if ((*(_lock)) < 0) assert(0); \
taosWLockLatch(_lock); \
ctgDebug("CTG WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} \
} while (0)
#define CTG_UNLOCK(type, _lock) do { \
if (CTG_READ == (type)) { \
if ((*(_lock)) <= 0) assert(0); \
taosRUnLockLatch(_lock); \
ctgDebug("CTG RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} else { \
if ((*(_lock)) <= 0) assert(0); \
taosWUnLockLatch(_lock); \
ctgDebug("CTG WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} \
} while (0)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
8ecd7a56
...
@@ -37,6 +37,7 @@ typedef struct WriterCtx {
...
@@ -37,6 +37,7 @@ typedef struct WriterCtx {
struct
{
struct
{
int
fd
;
int
fd
;
bool
readOnly
;
bool
readOnly
;
char
buf
[
256
];
}
file
;
}
file
;
struct
{
struct
{
int32_t
capa
;
int32_t
capa
;
...
@@ -53,7 +54,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
...
@@ -53,7 +54,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
);
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
);
void
writerCtxDestroy
(
WriterCtx
*
w
);
void
writerCtxDestroy
(
WriterCtx
*
w
,
bool
remove
);
typedef
uint32_t
CheckSummer
;
typedef
uint32_t
CheckSummer
;
...
...
source/libs/index/inc/index_tfile.h
浏览文件 @
8ecd7a56
...
@@ -107,6 +107,7 @@ void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader*
...
@@ -107,6 +107,7 @@ void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader*
TFileReader
*
tfileGetReaderByCol
(
IndexTFile
*
tf
,
char
*
colName
);
TFileReader
*
tfileGetReaderByCol
(
IndexTFile
*
tf
,
char
*
colName
);
TFileReader
*
tfileReaderOpen
(
char
*
path
,
uint64_t
suid
,
int32_t
version
,
const
char
*
colName
);
TFileReader
*
tfileReaderCreate
(
WriterCtx
*
ctx
);
TFileReader
*
tfileReaderCreate
(
WriterCtx
*
ctx
);
void
tfileReaderDestroy
(
TFileReader
*
reader
);
void
tfileReaderDestroy
(
TFileReader
*
reader
);
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SArray
*
result
);
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SArray
*
result
);
...
@@ -114,10 +115,10 @@ void tfileReaderRef(TFileReader* reader);
...
@@ -114,10 +115,10 @@ void tfileReaderRef(TFileReader* reader);
void
tfileReaderUnRef
(
TFileReader
*
reader
);
void
tfileReaderUnRef
(
TFileReader
*
reader
);
TFileWriter
*
tfileWriterOpen
(
char
*
path
,
uint64_t
suid
,
int32_t
version
,
const
char
*
colName
,
uint8_t
type
);
TFileWriter
*
tfileWriterOpen
(
char
*
path
,
uint64_t
suid
,
int32_t
version
,
const
char
*
colName
,
uint8_t
type
);
void
tfileWriteClose
(
TFileWriter
*
tw
);
void
tfileWrite
r
Close
(
TFileWriter
*
tw
);
TFileWriter
*
tfileWriterCreate
(
WriterCtx
*
ctx
,
TFileHeader
*
header
);
TFileWriter
*
tfileWriterCreate
(
WriterCtx
*
ctx
,
TFileHeader
*
header
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
int
tfileWriterPut
(
TFileWriter
*
tw
,
void
*
data
);
int
tfileWriterPut
(
TFileWriter
*
tw
,
void
*
data
,
bool
order
);
int
tfileWriterFinish
(
TFileWriter
*
tw
);
int
tfileWriterFinish
(
TFileWriter
*
tw
);
//
//
...
...
source/libs/index/src/index.c
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/libs/index/src/index_cache.c
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/libs/index/src/index_fst_automation.c
浏览文件 @
8ecd7a56
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
StartWithStateValue
*
startWithStateValueCreate
(
StartWithStateKind
kind
,
ValueType
ty
,
void
*
val
)
{
StartWithStateValue
*
startWithStateValueCreate
(
StartWithStateKind
kind
,
ValueType
ty
,
void
*
val
)
{
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
if
(
nsv
==
NULL
)
{
return
NULL
;
}
if
(
nsv
==
NULL
)
{
return
NULL
;
}
nsv
->
kind
=
kind
;
nsv
->
kind
=
kind
;
nsv
->
type
=
ty
;
nsv
->
type
=
ty
;
...
@@ -35,7 +37,9 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueTyp
...
@@ -35,7 +37,9 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueTyp
}
}
void
startWithStateValueDestroy
(
void
*
val
)
{
void
startWithStateValueDestroy
(
void
*
val
)
{
StartWithStateValue
*
sv
=
(
StartWithStateValue
*
)
val
;
StartWithStateValue
*
sv
=
(
StartWithStateValue
*
)
val
;
if
(
sv
==
NULL
)
{
return
;
}
if
(
sv
==
NULL
)
{
return
;
}
if
(
sv
->
type
==
FST_INT
)
{
if
(
sv
->
type
==
FST_INT
)
{
//
//
...
@@ -48,7 +52,9 @@ void startWithStateValueDestroy(void* val) {
...
@@ -48,7 +52,9 @@ void startWithStateValueDestroy(void* val) {
}
}
StartWithStateValue
*
startWithStateValueDump
(
StartWithStateValue
*
sv
)
{
StartWithStateValue
*
startWithStateValueDump
(
StartWithStateValue
*
sv
)
{
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
if
(
nsv
==
NULL
)
{
return
NULL
;
}
if
(
nsv
==
NULL
)
{
return
NULL
;
}
nsv
->
kind
=
sv
->
kind
;
nsv
->
kind
=
sv
->
kind
;
nsv
->
type
=
sv
->
type
;
nsv
->
type
=
sv
->
type
;
...
@@ -65,24 +71,12 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) {
...
@@ -65,24 +71,12 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) {
}
}
// iterate fst
// iterate fst
static
void
*
alwaysMatchStart
(
AutomationCtx
*
ctx
)
{
static
void
*
alwaysMatchStart
(
AutomationCtx
*
ctx
)
{
return
NULL
;
}
return
NULL
;
static
bool
alwaysMatchIsMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
}
static
bool
alwaysMatchCanMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
bool
alwaysMatchIsMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
bool
alwaysMatchWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
return
true
;
static
void
*
alwaysMatchAccpet
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
}
static
void
*
alwaysMatchAccpetEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
static
bool
alwaysMatchCanMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
bool
alwaysMatchWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
alwaysMatchAccpet
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
static
void
*
alwaysMatchAccpetEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
// prefix query, impl later
// prefix query, impl later
static
void
*
prefixStart
(
AutomationCtx
*
ctx
)
{
static
void
*
prefixStart
(
AutomationCtx
*
ctx
)
{
...
@@ -97,17 +91,20 @@ static bool prefixCanMatch(AutomationCtx* ctx, void* sv) {
...
@@ -97,17 +91,20 @@ static bool prefixCanMatch(AutomationCtx* ctx, void* sv) {
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
return
ssv
->
val
>=
0
;
return
ssv
->
val
>=
0
;
}
}
static
bool
prefixWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
bool
prefixWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
return
true
;
}
static
void
*
prefixAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
static
void
*
prefixAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
state
;
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
state
;
if
(
ssv
==
NULL
||
ctx
==
NULL
)
{
return
NULL
;
}
if
(
ssv
==
NULL
||
ctx
==
NULL
)
{
return
NULL
;
}
char
*
data
=
ctx
->
data
;
char
*
data
=
ctx
->
data
;
if
(
ssv
->
kind
==
Done
)
{
return
startWithStateValueCreate
(
Done
,
FST_INT
,
&
ssv
->
val
);
}
if
(
ssv
->
kind
==
Done
)
{
return
startWithStateValueCreate
(
Done
,
FST_INT
,
&
ssv
->
val
);
}
if
((
strlen
(
data
)
>
ssv
->
val
)
&&
data
[
ssv
->
val
]
==
byte
)
{
if
((
strlen
(
data
)
>
ssv
->
val
)
&&
data
[
ssv
->
val
]
==
byte
)
{
int
val
=
ssv
->
val
+
1
;
int
val
=
ssv
->
val
+
1
;
StartWithStateValue
*
nsv
=
startWithStateValueCreate
(
Running
,
FST_INT
,
&
val
);
StartWithStateValue
*
nsv
=
startWithStateValueCreate
(
Running
,
FST_INT
,
&
val
);
if
(
prefixIsMatch
(
ctx
,
nsv
))
{
if
(
prefixIsMatch
(
ctx
,
nsv
))
{
nsv
->
kind
=
Done
;
nsv
->
kind
=
Done
;
...
@@ -118,35 +115,22 @@ static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) {
...
@@ -118,35 +115,22 @@ static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) {
}
}
return
NULL
;
return
NULL
;
}
}
static
void
*
prefixAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
void
*
prefixAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
return
NULL
;
}
// pattern query, impl later
// pattern query, impl later
static
void
*
patternStart
(
AutomationCtx
*
ctx
)
{
static
void
*
patternStart
(
AutomationCtx
*
ctx
)
{
return
NULL
;
}
return
NULL
;
static
bool
patternIsMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
return
true
;
}
}
static
bool
patternCanMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternIsMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
static
bool
patternWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
return
true
;
}
static
bool
patternCanMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
patternAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
static
void
*
patternAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
return
NULL
;
}
static
void
*
patternAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
void
*
patternAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
return
NULL
;
}
AutomationFunc
automFuncs
[]
=
{
AutomationFunc
automFuncs
[]
=
{
{
alwaysMatchStart
,
alwaysMatchIsMatch
,
alwaysMatchCanMatch
,
alwaysMatchWillAlwaysMatch
,
alwaysMatchAccpet
,
alwaysMatchAccpetEof
},
{
alwaysMatchStart
,
alwaysMatchIsMatch
,
alwaysMatchCanMatch
,
alwaysMatchWillAlwaysMatch
,
alwaysMatchAccpet
,
alwaysMatchAccpetEof
},
{
prefixStart
,
prefixIsMatch
,
prefixCanMatch
,
prefixWillAlwaysMatch
,
prefixAccept
,
prefixAcceptEof
},
{
prefixStart
,
prefixIsMatch
,
prefixCanMatch
,
prefixWillAlwaysMatch
,
prefixAccept
,
prefixAcceptEof
},
{
patternStart
,
patternIsMatch
,
patternCanMatch
,
patternWillAlwaysMatch
,
patternAccept
,
patternAcceptEof
}
{
patternStart
,
patternIsMatch
,
patternCanMatch
,
patternWillAlwaysMatch
,
patternAccept
,
patternAcceptEof
}
// add more search type
// add more search type
...
@@ -154,7 +138,9 @@ AutomationFunc automFuncs[] = {
...
@@ -154,7 +138,9 @@ AutomationFunc automFuncs[] = {
AutomationCtx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
)
{
AutomationCtx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
)
{
AutomationCtx
*
ctx
=
calloc
(
1
,
sizeof
(
AutomationCtx
));
AutomationCtx
*
ctx
=
calloc
(
1
,
sizeof
(
AutomationCtx
));
if
(
ctx
==
NULL
)
{
return
NULL
;
}
if
(
ctx
==
NULL
)
{
return
NULL
;
}
StartWithStateValue
*
sv
=
NULL
;
StartWithStateValue
*
sv
=
NULL
;
if
(
atype
==
AUTOMATION_ALWAYS
)
{
if
(
atype
==
AUTOMATION_ALWAYS
)
{
...
@@ -170,11 +156,14 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
...
@@ -170,11 +156,14 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
// add more search type
// add more search type
}
}
char
*
dst
=
NULL
;
if
(
data
!=
NULL
)
{
char
*
src
=
(
char
*
)
data
;
char
*
src
=
(
char
*
)
data
;
size_t
len
=
strlen
(
src
);
size_t
len
=
strlen
(
src
);
char
*
dst
=
(
char
*
)
malloc
(
len
*
sizeof
(
char
)
+
1
);
dst
=
(
char
*
)
malloc
(
len
*
sizeof
(
char
)
+
1
);
memcpy
(
dst
,
src
,
len
);
memcpy
(
dst
,
src
,
len
);
dst
[
len
]
=
0
;
dst
[
len
]
=
0
;
}
ctx
->
data
=
dst
;
ctx
->
data
=
dst
;
ctx
->
type
=
atype
;
ctx
->
type
=
atype
;
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
8ecd7a56
...
@@ -52,7 +52,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
...
@@ -52,7 +52,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
}
}
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
// tfFsync(ctx->
fd);
tfFsync
(
ctx
->
file
.
fd
);
// tfFlush(ctx->file.fd);
// tfFlush(ctx->file.fd);
}
else
{
}
else
{
// do nothing
// do nothing
...
@@ -73,6 +73,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
...
@@ -73,6 +73,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
}
else
{
}
else
{
ctx
->
file
.
fd
=
tfOpenReadWrite
(
path
);
ctx
->
file
.
fd
=
tfOpenReadWrite
(
path
);
}
}
memcpy
(
ctx
->
file
.
buf
,
path
,
strlen
(
path
));
if
(
ctx
->
file
.
fd
<
0
)
{
if
(
ctx
->
file
.
fd
<
0
)
{
indexError
(
"open file error %d"
,
errno
);
indexError
(
"open file error %d"
,
errno
);
goto
END
;
goto
END
;
...
@@ -95,11 +96,15 @@ END:
...
@@ -95,11 +96,15 @@ END:
free
(
ctx
);
free
(
ctx
);
return
NULL
;
return
NULL
;
}
}
void
writerCtxDestroy
(
WriterCtx
*
ctx
)
{
void
writerCtxDestroy
(
WriterCtx
*
ctx
,
bool
remove
)
{
if
(
ctx
->
type
==
TMemory
)
{
if
(
ctx
->
type
==
TMemory
)
{
free
(
ctx
->
mem
.
buf
);
free
(
ctx
->
mem
.
buf
);
}
else
{
}
else
{
tfClose
(
ctx
->
file
.
fd
);
tfClose
(
ctx
->
file
.
fd
);
if
(
remove
)
{
indexError
(
"rm file %s"
,
ctx
->
file
.
buf
);
unlink
(
ctx
->
file
.
buf
);
}
}
}
free
(
ctx
);
free
(
ctx
);
}
}
...
@@ -138,9 +143,7 @@ int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len)
...
@@ -138,9 +143,7 @@ int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len)
return
nRead
;
return
nRead
;
}
}
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
return
0
;
}
return
0
;
}
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
WriterCtx
*
ctx
=
write
->
wrt
;
WriterCtx
*
ctx
=
write
->
wrt
;
ctx
->
flush
(
ctx
);
ctx
->
flush
(
ctx
);
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/libs/index/test/fstTest.cc
浏览文件 @
8ecd7a56
...
@@ -12,9 +12,7 @@
...
@@ -12,9 +12,7 @@
#include "tskiplist.h"
#include "tskiplist.h"
#include "tutil.h"
#include "tutil.h"
void
*
callback
(
void
*
s
)
{
void
*
callback
(
void
*
s
)
{
return
s
;
}
return
s
;
}
static
std
::
string
fileName
=
"/tmp/tindex.tindex"
;
static
std
::
string
fileName
=
"/tmp/tindex.tindex"
;
class
FstWriter
{
class
FstWriter
{
...
@@ -34,7 +32,7 @@ class FstWriter {
...
@@ -34,7 +32,7 @@ class FstWriter {
fstBuilderFinish
(
_b
);
fstBuilderFinish
(
_b
);
fstBuilderDestroy
(
_b
);
fstBuilderDestroy
(
_b
);
writerCtxDestroy
(
_wc
);
writerCtxDestroy
(
_wc
,
false
);
}
}
private:
private:
...
@@ -102,7 +100,7 @@ class FstReadMemory {
...
@@ -102,7 +100,7 @@ class FstReadMemory {
fstCountingWriterDestroy
(
_w
);
fstCountingWriterDestroy
(
_w
);
fstDestroy
(
_fst
);
fstDestroy
(
_fst
);
fstSliceDestroy
(
&
_s
);
fstSliceDestroy
(
&
_s
);
writerCtxDestroy
(
_wc
);
writerCtxDestroy
(
_wc
,
false
);
}
}
private:
private:
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/libs/qworker/inc/qworkerInt.h
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/util/CMakeLists.txt
浏览文件 @
8ecd7a56
...
@@ -13,3 +13,5 @@ target_link_libraries(
...
@@ -13,3 +13,5 @@ target_link_libraries(
PUBLIC lz4_static
PUBLIC lz4_static
PUBLIC api
PUBLIC api
)
)
ADD_SUBDIRECTORY
(
test
)
source/util/src/terror.c
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/util/src/thash.c
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/util/test/CMakeLists.txt
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
source/util/test/hashTest.cpp
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
tests/script/general/db/basic1.sim
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
tests/script/general/table/basic1.sim
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
tests/script/sh/exec.sh
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
tests/script/tmp/dnodes.sim
浏览文件 @
8ecd7a56
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录