Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8ecd7a56
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
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
...
@@ -20,24 +20,28 @@
...
@@ -20,24 +20,28 @@
SCatalogMgmt
ctgMgmt
=
{
0
};
SCatalogMgmt
ctgMgmt
=
{
0
};
int32_t
ctgGetDBVgroupFromCache
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
dbInfo
,
int32_t
*
exist
)
{
int32_t
ctgGetDBVgroupFromCache
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
*
dbInfo
,
bool
*
inCache
)
{
if
(
NULL
==
pCatalog
->
dbCache
.
cache
)
{
if
(
NULL
==
pCatalog
->
dbCache
.
cache
)
{
*
exist
=
0
;
*
inCache
=
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SDBVgroupInfo
*
info
=
taosHash
Get
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
SDBVgroupInfo
*
info
=
taosHash
Acquire
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
if
(
NULL
==
info
)
{
if
(
NULL
==
info
)
{
*
exist
=
0
;
*
inCache
=
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
dbInfo
)
{
CTG_LOCK
(
CTG_READ
,
&
info
->
lock
);
*
dbInfo
=
*
info
;
if
(
NULL
==
info
->
vgInfo
)
{
CTG_UNLOCK
(
CTG_READ
,
&
info
->
lock
);
*
inCache
=
false
;
return
TSDB_CODE_SUCCESS
;
}
}
*
exist
=
1
;
*
dbInfo
=
info
;
*
inCache
=
true
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -80,46 +84,51 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN
...
@@ -80,46 +84,51 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN
char
tbFullName
[
TSDB_TABLE_FNAME_LEN
];
char
tbFullName
[
TSDB_TABLE_FNAME_LEN
];
tNameExtractFullName
(
pTableName
,
tbFullName
);
tNameExtractFullName
(
pTableName
,
tbFullName
);
STableMeta
*
tbMeta
=
taosHashGet
(
pCatalog
->
tableCache
.
cache
,
tbFullName
,
strlen
(
tbFullName
))
;
*
pTableMeta
=
NULL
;
if
(
NULL
==
tbMeta
)
{
size_t
sz
=
0
;
STableMeta
*
tbMeta
=
taosHashGetCloneExt
(
pCatalog
->
tableCache
.
cache
,
tbFullName
,
strlen
(
tbFullName
),
NULL
,
(
void
**
)
pTableMeta
,
&
sz
);
if
(
NULL
==
*
pTableMeta
)
{
*
exist
=
0
;
*
exist
=
0
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
tbMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
*
exist
=
1
;
if
(
tbMeta
->
tableType
!=
TSDB_CHILD_TABLE
)
{
return
TSDB_CODE_SUCCESS
;
}
CTG_LOCK
(
CTG_READ
,
&
pCatalog
->
tableCache
.
stableLock
);
STableMeta
**
stbMeta
=
taosHashGet
(
pCatalog
->
tableCache
.
stableCache
,
&
tbMeta
->
suid
,
sizeof
(
tbMeta
->
suid
));
STableMeta
**
stbMeta
=
taosHashGet
(
pCatalog
->
tableCache
.
stableCache
,
&
tbMeta
->
suid
,
sizeof
(
tbMeta
->
suid
));
if
(
NULL
==
stbMeta
||
NULL
==
*
stbMeta
)
{
if
(
NULL
==
stbMeta
||
NULL
==
*
stbMeta
)
{
CTG_UNLOCK
(
CTG_READ
,
&
pCatalog
->
tableCache
.
stableLock
);
qError
(
"no stable:%"
PRIx64
" meta in cache"
,
tbMeta
->
suid
);
tfree
(
*
pTableMeta
);
*
exist
=
0
;
*
exist
=
0
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
((
*
stbMeta
)
->
suid
!=
tbMeta
->
suid
)
{
if
((
*
stbMeta
)
->
suid
!=
tbMeta
->
suid
)
{
CTG_UNLOCK
(
CTG_READ
,
&
pCatalog
->
tableCache
.
stableLock
);
tfree
(
*
pTableMeta
);
ctgError
(
"stable cache error, expected suid:%"
PRId64
",actual suid:%"
PRId64
,
tbMeta
->
suid
,
(
*
stbMeta
)
->
suid
);
ctgError
(
"stable cache error, expected suid:%"
PRId64
",actual suid:%"
PRId64
,
tbMeta
->
suid
,
(
*
stbMeta
)
->
suid
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
int32_t
metaSize
=
sizeof
(
STableMeta
)
+
((
*
stbMeta
)
->
tableInfo
.
numOfTags
+
(
*
stbMeta
)
->
tableInfo
.
numOfColumns
)
*
sizeof
(
SSchema
);
int32_t
metaSize
=
sizeof
(
STableMeta
)
+
((
*
stbMeta
)
->
tableInfo
.
numOfTags
+
(
*
stbMeta
)
->
tableInfo
.
numOfColumns
)
*
sizeof
(
SSchema
);
*
pTableMeta
=
calloc
(
1
,
metaSize
);
*
pTableMeta
=
realloc
(
*
pTableMeta
,
metaSize
);
if
(
NULL
==
*
pTableMeta
)
{
if
(
NULL
==
*
pTableMeta
)
{
CTG_UNLOCK
(
CTG_READ
,
&
pCatalog
->
tableCache
.
stableLock
);
ctgError
(
"calloc size[%d] failed"
,
metaSize
);
ctgError
(
"calloc size[%d] failed"
,
metaSize
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
memcpy
(
*
pTableMeta
,
tbMeta
,
sizeof
(
SCTableMeta
));
memcpy
(
&
(
*
pTableMeta
)
->
sversion
,
&
(
*
stbMeta
)
->
sversion
,
metaSize
-
sizeof
(
SCTableMeta
));
memcpy
(
&
(
*
pTableMeta
)
->
sversion
,
&
(
*
stbMeta
)
->
sversion
,
metaSize
-
sizeof
(
SCTableMeta
));
}
else
{
int32_t
metaSize
=
sizeof
(
STableMeta
)
+
(
tbMeta
->
tableInfo
.
numOfTags
+
tbMeta
->
tableInfo
.
numOfColumns
)
*
sizeof
(
SSchema
);
*
pTableMeta
=
calloc
(
1
,
metaSize
);
if
(
NULL
==
*
pTableMeta
)
{
ctgError
(
"calloc size[%d] failed"
,
metaSize
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
memcpy
(
*
pTableMeta
,
tbMeta
,
metaSize
);
}
*
exist
=
1
;
CTG_UNLOCK
(
CTG_READ
,
&
pCatalog
->
tableCache
.
stableLock
)
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -223,9 +232,11 @@ int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) {
...
@@ -223,9 +232,11 @@ int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) {
int32_t
ctgGetVgInfoFromDB
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
SDBVgroupInfo
*
dbInfo
,
SArray
**
vgroupList
)
{
int32_t
ctgGetVgInfoFromDB
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
SDBVgroupInfo
*
dbInfo
,
SArray
**
vgroupList
)
{
SHashObj
*
vgroupHash
=
NULL
;
SHashObj
*
vgroupHash
=
NULL
;
SVgroupInfo
*
vgInfo
=
NULL
;
SVgroupInfo
*
vgInfo
=
NULL
;
SArray
*
vgList
=
NULL
;
int32_t
code
=
0
;
*
vgroup
List
=
taosArrayInit
(
taosHashGetSize
(
dbInfo
->
vgInfo
),
sizeof
(
SVgroupInfo
));
vg
List
=
taosArrayInit
(
taosHashGetSize
(
dbInfo
->
vgInfo
),
sizeof
(
SVgroupInfo
));
if
(
NULL
==
*
vgroup
List
)
{
if
(
NULL
==
vg
List
)
{
ctgError
(
"taosArrayInit failed"
);
ctgError
(
"taosArrayInit failed"
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
...
@@ -234,19 +245,34 @@ int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *
...
@@ -234,19 +245,34 @@ int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *
while
(
pIter
)
{
while
(
pIter
)
{
vgInfo
=
pIter
;
vgInfo
=
pIter
;
if
(
NULL
==
taosArrayPush
(
*
vgroup
List
,
vgInfo
))
{
if
(
NULL
==
taosArrayPush
(
vg
List
,
vgInfo
))
{
ctgError
(
"taosArrayPush failed"
);
ctgError
(
"taosArrayPush failed"
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
pIter
=
taosHashIterate
(
dbInfo
->
vgInfo
,
pIter
);
pIter
=
taosHashIterate
(
dbInfo
->
vgInfo
,
pIter
);
vgInfo
=
NULL
;
vgInfo
=
NULL
;
}
}
*
vgroupList
=
vgList
;
vgList
=
NULL
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
_return:
if
(
vgList
)
{
taosArrayDestroy
(
vgList
);
}
CTG_RET
(
code
);
}
}
int32_t
ctgGetVgInfoFromHashValue
(
SDBVgroupInfo
*
dbInfo
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
int32_t
ctgGetVgInfoFromHashValue
(
SDBVgroupInfo
*
dbInfo
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
int32_t
code
=
0
;
CTG_LOCK
(
CTG_READ
,
&
dbInfo
->
lock
);
int32_t
vgNum
=
taosHashGetSize
(
dbInfo
->
vgInfo
);
int32_t
vgNum
=
taosHashGetSize
(
dbInfo
->
vgInfo
);
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
pTableName
,
db
);
tNameGetFullDbName
(
pTableName
,
db
);
...
@@ -259,7 +285,7 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName
...
@@ -259,7 +285,7 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName
tableNameHashFp
fp
=
NULL
;
tableNameHashFp
fp
=
NULL
;
SVgroupInfo
*
vgInfo
=
NULL
;
SVgroupInfo
*
vgInfo
=
NULL
;
CTG_ERR_RET
(
ctgGetHashFunction
(
dbInfo
->
hashMethod
,
&
fp
));
CTG_ERR_
J
RET
(
ctgGetHashFunction
(
dbInfo
->
hashMethod
,
&
fp
));
char
tbFullName
[
TSDB_TABLE_FNAME_LEN
];
char
tbFullName
[
TSDB_TABLE_FNAME_LEN
];
tNameExtractFullName
(
pTableName
,
tbFullName
);
tNameExtractFullName
(
pTableName
,
tbFullName
);
...
@@ -279,12 +305,16 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName
...
@@ -279,12 +305,16 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName
if
(
NULL
==
vgInfo
)
{
if
(
NULL
==
vgInfo
)
{
ctgError
(
"no hash range found for hashvalue[%u]"
,
hashValue
);
ctgError
(
"no hash range found for hashvalue[%u]"
,
hashValue
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
*
pVgroup
=
*
vgInfo
;
*
pVgroup
=
*
vgInfo
;
return
TSDB_CODE_SUCCESS
;
_return:
CTG_UNLOCK
(
CTG_READ
,
&
dbInfo
->
lock
);
CTG_RET
(
TSDB_CODE_SUCCESS
);
}
}
int32_t
ctgGetTableMetaImpl
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
bool
forceUpdate
,
STableMeta
**
pTableMeta
)
{
int32_t
ctgGetTableMetaImpl
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
bool
forceUpdate
,
STableMeta
**
pTableMeta
)
{
...
@@ -316,21 +346,23 @@ int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
...
@@ -316,21 +346,23 @@ int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
int32_t
ctgUpdateTableMetaCache
(
struct
SCatalog
*
pCatalog
,
STableMetaOutput
*
output
)
{
int32_t
ctgUpdateTableMetaCache
(
struct
SCatalog
*
pCatalog
,
STableMetaOutput
*
output
)
{
int32_t
code
=
0
;
if
(
output
->
metaNum
!=
1
&&
output
->
metaNum
!=
2
)
{
if
(
output
->
metaNum
!=
1
&&
output
->
metaNum
!=
2
)
{
ctgError
(
"invalid table meta number[%d] got from meta rsp"
,
output
->
metaNum
);
ctgError
(
"invalid table meta number[%d] got from meta rsp"
,
output
->
metaNum
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
if
(
NULL
==
output
->
tbMeta
)
{
if
(
NULL
==
output
->
tbMeta
)
{
ctgError
(
"no valid table meta got from meta rsp"
);
ctgError
(
"no valid table meta got from meta rsp"
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
pCatalog
->
tableCache
.
cache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
pCatalog
->
tableCache
.
cache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
ctgError
(
"init hash[%d] for tablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
ctgError
(
"init hash[%d] for tablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
}
}
...
@@ -338,50 +370,59 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out
...
@@ -338,50 +370,59 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out
pCatalog
->
tableCache
.
stableCache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
true
,
HASH_ENTRY_LOCK
);
pCatalog
->
tableCache
.
stableCache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
pCatalog
->
tableCache
.
stableCache
)
{
if
(
NULL
==
pCatalog
->
tableCache
.
stableCache
)
{
ctgError
(
"init hash[%d] for stablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
ctgError
(
"init hash[%d] for stablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
}
}
if
(
output
->
metaNum
==
2
)
{
if
(
output
->
metaNum
==
2
)
{
if
(
taosHashPut
(
pCatalog
->
tableCache
.
cache
,
output
->
ctbFname
,
strlen
(
output
->
ctbFname
),
&
output
->
ctbMeta
,
sizeof
(
output
->
ctbMeta
))
!=
0
)
{
if
(
taosHashPut
(
pCatalog
->
tableCache
.
cache
,
output
->
ctbFname
,
strlen
(
output
->
ctbFname
),
&
output
->
ctbMeta
,
sizeof
(
output
->
ctbMeta
))
!=
0
)
{
ctgError
(
"push ctable[%s] to table cache failed"
,
output
->
ctbFname
);
ctgError
(
"push ctable[%s] to table cache failed"
,
output
->
ctbFname
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
if
(
TSDB_SUPER_TABLE
!=
output
->
tbMeta
->
tableType
)
{
if
(
TSDB_SUPER_TABLE
!=
output
->
tbMeta
->
tableType
)
{
ctgError
(
"table type[%d] error, expected:%d"
,
output
->
tbMeta
->
tableType
,
TSDB_SUPER_TABLE
);
ctgError
(
"table type[%d] error, expected:%d"
,
output
->
tbMeta
->
tableType
,
TSDB_SUPER_TABLE
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_
J
RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
}
}
int32_t
tbSize
=
sizeof
(
*
output
->
tbMeta
)
+
sizeof
(
SSchema
)
*
(
output
->
tbMeta
->
tableInfo
.
numOfColumns
+
output
->
tbMeta
->
tableInfo
.
numOfTags
);
int32_t
tbSize
=
sizeof
(
*
output
->
tbMeta
)
+
sizeof
(
SSchema
)
*
(
output
->
tbMeta
->
tableInfo
.
numOfColumns
+
output
->
tbMeta
->
tableInfo
.
numOfTags
);
if
(
TSDB_SUPER_TABLE
==
output
->
tbMeta
->
tableType
)
{
CTG_LOCK
(
CTG_WRITE
,
&
pCatalog
->
tableCache
.
stableLock
);
if
(
taosHashPut
(
pCatalog
->
tableCache
.
cache
,
output
->
tbFname
,
strlen
(
output
->
tbFname
),
output
->
tbMeta
,
tbSize
)
!=
0
)
{
if
(
taosHashPut
(
pCatalog
->
tableCache
.
cache
,
output
->
tbFname
,
strlen
(
output
->
tbFname
),
output
->
tbMeta
,
tbSize
)
!=
0
)
{
CTG_UNLOCK
(
CTG_WRITE
,
&
pCatalog
->
tableCache
.
stableLock
);
ctgError
(
"push table[%s] to table cache failed"
,
output
->
tbFname
);
ctgError
(
"push table[%s] to table cache failed"
,
output
->
tbFname
);
CTG_ERR_
RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_J
RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
if
(
TSDB_SUPER_TABLE
==
output
->
tbMeta
->
tableType
)
{
STableMeta
*
tbMeta
=
taosHashGet
(
pCatalog
->
tableCache
.
cache
,
output
->
tbFname
,
strlen
(
output
->
tbFname
));
if
(
taosHashPut
(
pCatalog
->
tableCache
.
stableCache
,
&
output
->
tbMeta
->
suid
,
sizeof
(
output
->
tbMeta
->
suid
),
&
output
->
tbMeta
,
POINTER_BYTES
)
!=
0
)
{
if
(
taosHashPut
(
pCatalog
->
tableCache
.
stableCache
,
&
output
->
tbMeta
->
suid
,
sizeof
(
output
->
tbMeta
->
suid
),
&
tbMeta
,
POINTER_BYTES
)
!=
0
)
{
CTG_UNLOCK
(
CTG_WRITE
,
&
pCatalog
->
tableCache
.
stableLock
);
ctgError
(
"push suid[%"
PRIu64
"] to stable cache failed"
,
output
->
tbMeta
->
suid
);
ctgError
(
"push suid[%"
PRIu64
"] to stable cache failed"
,
output
->
tbMeta
->
suid
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
CTG_UNLOCK
(
CTG_WRITE
,
&
pCatalog
->
tableCache
.
stableLock
);
}
else
{
if
(
taosHashPut
(
pCatalog
->
tableCache
.
cache
,
output
->
tbFname
,
strlen
(
output
->
tbFname
),
output
->
tbMeta
,
tbSize
)
!=
0
)
{
ctgError
(
"push table[%s] to table cache failed"
,
output
->
tbFname
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
}
}
return
TSDB_CODE_SUCCESS
;
_return:
}
tfree
(
output
->
tbMeta
);
int32_t
ctgGetDBVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
dbName
,
int32_t
forceUpdate
,
SDBVgroupInfo
*
dbInfo
)
{
CTG_RET
(
code
);
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
)
{
}
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
int32_t
exist
=
0
;
int32_t
ctgGetDBVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
dbName
,
int32_t
forceUpdate
,
SDBVgroupInfo
**
dbInfo
)
{
bool
inCache
=
false
;
if
(
0
==
forceUpdate
)
{
if
(
0
==
forceUpdate
)
{
CTG_ERR_RET
(
ctgGetDBVgroupFromCache
(
pCatalog
,
dbName
,
dbInfo
,
&
exist
));
CTG_ERR_RET
(
ctgGetDBVgroupFromCache
(
pCatalog
,
dbName
,
dbInfo
,
&
inCache
));
if
(
exist
)
{
if
(
inCache
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
}
}
...
@@ -397,9 +438,7 @@ int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgm
...
@@ -397,9 +438,7 @@ int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgm
CTG_ERR_RET
(
catalogUpdateDBVgroup
(
pCatalog
,
dbName
,
&
DbOut
.
dbVgroup
));
CTG_ERR_RET
(
catalogUpdateDBVgroup
(
pCatalog
,
dbName
,
&
DbOut
.
dbVgroup
));
if
(
dbInfo
)
{
CTG_ERR_RET
(
ctgGetDBVgroupFromCache
(
pCatalog
,
dbName
,
dbInfo
,
&
inCache
));
*
dbInfo
=
DbOut
.
dbVgroup
;
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -479,17 +518,68 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
...
@@ -479,17 +518,68 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SDBVgroupInfo
*
dbInfo
=
taosHash
Get
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
SDBVgroupInfo
*
dbInfo
=
taosHash
Acquire
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
if
(
NULL
==
dbInfo
)
{
if
(
NULL
==
dbInfo
)
{
*
version
=
CTG_DEFAULT_INVALID_VERSION
;
*
version
=
CTG_DEFAULT_INVALID_VERSION
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
*
version
=
dbInfo
->
vgVersion
;
*
version
=
dbInfo
->
vgVersion
;
taosHashRelease
(
pCatalog
->
dbCache
.
cache
,
dbInfo
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
catalogGetDBVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
dbName
,
int32_t
forceUpdate
,
SArray
**
vgroupList
)
{
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
vgroupList
)
{
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
SDBVgroupInfo
*
db
=
NULL
;
int32_t
code
=
0
;
SVgroupInfo
*
vgInfo
=
NULL
;
SArray
*
vgList
=
NULL
;
CTG_ERR_JRET
(
ctgGetDBVgroup
(
pCatalog
,
pRpc
,
pMgmtEps
,
dbName
,
forceUpdate
,
&
db
));
vgList
=
taosArrayInit
(
taosHashGetSize
(
db
->
vgInfo
),
sizeof
(
SVgroupInfo
));
if
(
NULL
==
vgList
)
{
ctgError
(
"taosArrayInit failed"
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
void
*
pIter
=
taosHashIterate
(
db
->
vgInfo
,
NULL
);
while
(
pIter
)
{
vgInfo
=
pIter
;
if
(
NULL
==
taosArrayPush
(
vgList
,
vgInfo
))
{
ctgError
(
"taosArrayPush failed"
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
pIter
=
taosHashIterate
(
db
->
vgInfo
,
pIter
);
vgInfo
=
NULL
;
}
*
vgroupList
=
vgList
;
vgList
=
NULL
;
_return:
if
(
db
)
{
CTG_UNLOCK
(
CTG_READ
,
&
db
->
lock
);
taosHashRelease
(
pCatalog
->
dbCache
.
cache
,
db
);
}
if
(
vgList
)
{
taosArrayDestroy
(
vgList
);
vgList
=
NULL
;
}
CTG_RET
(
code
);
}
int32_t
catalogUpdateDBVgroup
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
dbInfo
)
{
int32_t
catalogUpdateDBVgroup
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
dbInfo
)
{
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
dbInfo
)
{
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
dbInfo
)
{
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
);
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
);
...
@@ -497,13 +587,17 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB
...
@@ -497,13 +587,17 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB
if
(
dbInfo
->
vgVersion
<
0
)
{
if
(
dbInfo
->
vgVersion
<
0
)
{
if
(
pCatalog
->
dbCache
.
cache
)
{
if
(
pCatalog
->
dbCache
.
cache
)
{
SDBVgroupInfo
*
oldInfo
=
taosHashGet
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
SDBVgroupInfo
*
oldInfo
=
taosHashAcquire
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
if
(
oldInfo
&&
oldInfo
->
vgInfo
)
{
if
(
oldInfo
)
{
CTG_LOCK
(
CTG_WRITE
,
&
oldInfo
->
lock
);
if
(
oldInfo
->
vgInfo
)
{
taosHashCleanup
(
oldInfo
->
vgInfo
);
taosHashCleanup
(
oldInfo
->
vgInfo
);
oldInfo
->
vgInfo
=
NULL
;
oldInfo
->
vgInfo
=
NULL
;
}
}
CTG_UNLOCK
(
CTG_WRITE
,
&
oldInfo
->
lock
);
taosHashRemove
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
taosHashRelease
(
pCatalog
->
dbCache
.
cache
,
oldInfo
);
}
}
}
ctgWarn
(
"remove db [%s] from cache"
,
dbName
);
ctgWarn
(
"remove db [%s] from cache"
,
dbName
);
...
@@ -517,11 +611,17 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB
...
@@ -517,11 +611,17 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
}
else
{
}
else
{
SDBVgroupInfo
*
oldInfo
=
taosHashGet
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
SDBVgroupInfo
*
oldInfo
=
taosHashAcquire
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
if
(
oldInfo
&&
oldInfo
->
vgInfo
)
{
if
(
oldInfo
)
{
CTG_LOCK
(
CTG_WRITE
,
&
oldInfo
->
lock
);
if
(
oldInfo
->
vgInfo
)
{
taosHashCleanup
(
oldInfo
->
vgInfo
);
taosHashCleanup
(
oldInfo
->
vgInfo
);
oldInfo
->
vgInfo
=
NULL
;
oldInfo
->
vgInfo
=
NULL
;
}
}
CTG_UNLOCK
(
CTG_WRITE
,
&
oldInfo
->
lock
);
taosHashRelease
(
pCatalog
->
dbCache
.
cache
,
oldInfo
);
}
}
}
if
(
taosHashPut
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
),
dbInfo
,
sizeof
(
*
dbInfo
))
!=
0
)
{
if
(
taosHashPut
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
),
dbInfo
,
sizeof
(
*
dbInfo
))
!=
0
)
{
...
@@ -573,7 +673,10 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
...
@@ -573,7 +673,10 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
STableMeta
*
tbMeta
=
NULL
;
STableMeta
*
tbMeta
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
SVgroupInfo
vgroupInfo
=
{
0
};
SVgroupInfo
vgroupInfo
=
{
0
};
SDBVgroupInfo
dbVgroup
=
{
0
};
SDBVgroupInfo
*
dbVgroup
=
NULL
;
SArray
*
vgList
=
NULL
;
*
pVgroupList
=
NULL
;
CTG_ERR_JRET
(
catalogGetTableMeta
(
pCatalog
,
pRpc
,
pMgmtEps
,
pTableName
,
&
tbMeta
));
CTG_ERR_JRET
(
catalogGetTableMeta
(
pCatalog
,
pRpc
,
pMgmtEps
,
pTableName
,
&
tbMeta
));
...
@@ -582,38 +685,48 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
...
@@ -582,38 +685,48 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
CTG_ERR_JRET
(
ctgGetDBVgroup
(
pCatalog
,
pRpc
,
pMgmtEps
,
db
,
false
,
&
dbVgroup
));
CTG_ERR_JRET
(
ctgGetDBVgroup
(
pCatalog
,
pRpc
,
pMgmtEps
,
db
,
false
,
&
dbVgroup
));
if
(
tbMeta
->
tableType
==
TSDB_SUPER_TABLE
)
{
if
(
tbMeta
->
tableType
==
TSDB_SUPER_TABLE
)
{
CTG_ERR_JRET
(
ctgGetVgInfoFromDB
(
pCatalog
,
pRpc
,
pMgmtEps
,
&
dbVgroup
,
pVgroupList
));
CTG_ERR_JRET
(
ctgGetVgInfoFromDB
(
pCatalog
,
pRpc
,
pMgmtEps
,
dbVgroup
,
pVgroupList
));
}
else
{
}
else
{
int32_t
vgId
=
tbMeta
->
vgId
;
int32_t
vgId
=
tbMeta
->
vgId
;
if
(
NULL
==
taosHashGetClone
(
dbVgroup
.
vgInfo
,
&
vgId
,
sizeof
(
vgId
),
&
vgroupInfo
))
{
if
(
NULL
==
taosHashGetClone
(
dbVgroup
->
vgInfo
,
&
vgId
,
sizeof
(
vgId
),
&
vgroupInfo
))
{
ctgError
(
"vgId[%d] not found in vgroup list"
,
vgId
);
ctgError
(
"vgId[%d] not found in vgroup list"
,
vgId
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
*
pVgroup
List
=
taosArrayInit
(
1
,
sizeof
(
SVgroupInfo
));
vg
List
=
taosArrayInit
(
1
,
sizeof
(
SVgroupInfo
));
if
(
NULL
==
*
pVgroup
List
)
{
if
(
NULL
==
vg
List
)
{
ctgError
(
"taosArrayInit failed"
);
ctgError
(
"taosArrayInit failed"
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_MEM_ERROR
);
}
}
if
(
NULL
==
taosArrayPush
(
*
pVgroup
List
,
&
vgroupInfo
))
{
if
(
NULL
==
taosArrayPush
(
vg
List
,
&
vgroupInfo
))
{
ctgError
(
"push vgroupInfo to array failed"
);
ctgError
(
"push vgroupInfo to array failed"
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
CTG_ERR_JRET
(
TSDB_CODE_CTG_INTERNAL_ERROR
);
}
}
}
tfree
(
tbMeta
);
*
pVgroupList
=
vgList
;
return
TSDB_CODE_SUCCESS
;
vgList
=
NULL
;
}
_return:
_return:
tfree
(
tbMeta
);
tfree
(
tbMeta
);
taosArrayDestroy
(
*
pVgroupList
);
if
(
dbVgroup
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbVgroup
->
lock
);
taosHashRelease
(
pCatalog
->
dbCache
.
cache
,
dbVgroup
);
}
if
(
vgList
)
{
taosArrayDestroy
(
vgList
);
vgList
=
NULL
;
}
CTG_RET
(
code
);
CTG_RET
(
code
);
}
}
int32_t
catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pTransporter
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
int32_t
catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pTransporter
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
SVgroupInfo
*
pVgroup
)
{
SDBVgroupInfo
dbInfo
=
{
0
}
;
SDBVgroupInfo
*
dbInfo
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
...
@@ -621,12 +734,14 @@ int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter,
...
@@ -621,12 +734,14 @@ int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter,
CTG_ERR_RET
(
ctgGetDBVgroup
(
pCatalog
,
pTransporter
,
pMgmtEps
,
db
,
false
,
&
dbInfo
));
CTG_ERR_RET
(
ctgGetDBVgroup
(
pCatalog
,
pTransporter
,
pMgmtEps
,
db
,
false
,
&
dbInfo
));
if
(
dbInfo
.
vgVersion
<
0
||
NULL
==
dbInfo
.
vgInfo
)
{
CTG_ERR_JRET
(
ctgGetVgInfoFromHashValue
(
dbInfo
,
pTableName
,
pVgroup
));
ctgError
(
"db[%s] vgroup cache invalid, vgroup version:%d, vgInfo:%p"
,
db
,
dbInfo
.
vgVersion
,
dbInfo
.
vgInfo
);
CTG_ERR_RET
(
TSDB_CODE_TSC_DB_NOT_SELECTED
);
}
CTG_ERR_RET
(
ctgGetVgInfoFromHashValue
(
&
dbInfo
,
pTableName
,
pVgroup
));
_return:
if
(
dbInfo
)
{
CTG_UNLOCK
(
CTG_READ
,
&
dbInfo
->
lock
);
taosHashRelease
(
pCatalog
->
dbCache
.
cache
,
dbInfo
);
}
CTG_RET
(
code
);
CTG_RET
(
code
);
}
}
...
...
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
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
#endif
#endif
#define INDEX_NUM_OF_THREADS 4
#define INDEX_NUM_OF_THREADS 4
#define INDEX_QUEUE_SIZE
4
#define INDEX_QUEUE_SIZE
200
void
*
indexQhandle
=
NULL
;
void
*
indexQhandle
=
NULL
;
...
@@ -52,18 +52,17 @@ typedef struct SIdxColInfo {
...
@@ -52,18 +52,17 @@ typedef struct SIdxColInfo {
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
// static void indexInit();
// static void indexInit();
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
void
indexInterResultsDestroy
(
SArray
*
results
);
static
void
indexInterResultsDestroy
(
SArray
*
results
);
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
finalResult
);
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
finalResult
);
static
int
indexGenTFile
(
SIndex
*
index
,
IndexCache
*
cache
,
SArray
*
batch
);
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
// pthread_once(&isInit, indexInit);
// pthread_once(&isInit, indexInit);
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
if
(
sIdx
==
NULL
)
{
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
return
-
1
;
}
#ifdef USE_LUCENE
#ifdef USE_LUCENE
index_t
*
index
=
index_open
(
path
);
index_t
*
index
=
index_open
(
path
);
...
@@ -99,9 +98,7 @@ void indexClose(SIndex* sIdx) {
...
@@ -99,9 +98,7 @@ void indexClose(SIndex* sIdx) {
void
*
iter
=
taosHashIterate
(
sIdx
->
colObj
,
NULL
);
void
*
iter
=
taosHashIterate
(
sIdx
->
colObj
,
NULL
);
while
(
iter
)
{
while
(
iter
)
{
IndexCache
**
pCache
=
iter
;
IndexCache
**
pCache
=
iter
;
if
(
*
pCache
)
{
if
(
*
pCache
)
{
indexCacheUnRef
(
*
pCache
);
}
indexCacheUnRef
(
*
pCache
);
}
iter
=
taosHashIterate
(
sIdx
->
colObj
,
iter
);
iter
=
taosHashIterate
(
sIdx
->
colObj
,
iter
);
}
}
taosHashCleanup
(
sIdx
->
colObj
);
taosHashCleanup
(
sIdx
->
colObj
);
...
@@ -147,9 +144,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
...
@@ -147,9 +144,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
IndexCache
**
cache
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
IndexCache
**
cache
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
assert
(
*
cache
!=
NULL
);
assert
(
*
cache
!=
NULL
);
int
ret
=
indexCachePut
(
*
cache
,
p
,
uid
);
int
ret
=
indexCachePut
(
*
cache
,
p
,
uid
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
return
ret
;
}
return
ret
;
}
}
}
#endif
#endif
...
@@ -179,9 +174,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result
...
@@ -179,9 +174,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result
int
tsz
=
0
;
int
tsz
=
0
;
index_multi_search
(
index
->
index
,
(
const
char
**
)
fields
,
(
const
char
**
)
keys
,
types
,
nQuery
,
opera
,
&
tResult
,
&
tsz
);
index_multi_search
(
index
->
index
,
(
const
char
**
)
fields
,
(
const
char
**
)
keys
,
types
,
nQuery
,
opera
,
&
tResult
,
&
tsz
);
for
(
int
i
=
0
;
i
<
tsz
;
i
++
)
{
for
(
int
i
=
0
;
i
<
tsz
;
i
++
)
{
taosArrayPush
(
result
,
&
tResult
[
i
]);
}
taosArrayPush
(
result
,
&
tResult
[
i
]);
}
for
(
int
i
=
0
;
i
<
nQuery
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nQuery
;
i
++
)
{
free
(
fields
[
i
]);
free
(
fields
[
i
]);
...
@@ -238,9 +231,7 @@ void indexOptsDestroy(SIndexOpts* opts) {
...
@@ -238,9 +231,7 @@ void indexOptsDestroy(SIndexOpts* opts) {
*/
*/
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
opera
)
{
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
opera
)
{
SIndexMultiTermQuery
*
p
=
(
SIndexMultiTermQuery
*
)
malloc
(
sizeof
(
SIndexMultiTermQuery
));
SIndexMultiTermQuery
*
p
=
(
SIndexMultiTermQuery
*
)
malloc
(
sizeof
(
SIndexMultiTermQuery
));
if
(
p
==
NULL
)
{
if
(
p
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
p
->
opera
=
opera
;
p
->
opera
=
opera
;
p
->
query
=
taosArrayInit
(
4
,
sizeof
(
SIndexTermQuery
));
p
->
query
=
taosArrayInit
(
4
,
sizeof
(
SIndexTermQuery
));
return
p
;
return
p
;
...
@@ -262,9 +253,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde
...
@@ -262,9 +253,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EInde
SIndexTerm
*
indexTermCreate
(
int64_t
suid
,
SIndexOperOnColumn
oper
,
uint8_t
colType
,
const
char
*
colName
,
SIndexTerm
*
indexTermCreate
(
int64_t
suid
,
SIndexOperOnColumn
oper
,
uint8_t
colType
,
const
char
*
colName
,
int32_t
nColName
,
const
char
*
colVal
,
int32_t
nColVal
)
{
int32_t
nColName
,
const
char
*
colVal
,
int32_t
nColVal
)
{
SIndexTerm
*
t
=
(
SIndexTerm
*
)
calloc
(
1
,
(
sizeof
(
SIndexTerm
)));
SIndexTerm
*
t
=
(
SIndexTerm
*
)
calloc
(
1
,
(
sizeof
(
SIndexTerm
)));
if
(
t
==
NULL
)
{
if
(
t
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
t
->
suid
=
suid
;
t
->
suid
=
suid
;
t
->
operType
=
oper
;
t
->
operType
=
oper
;
...
@@ -317,7 +306,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
...
@@ -317,7 +306,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
// TODO: iterator mem and tidex
// TODO: iterator mem and tidex
STermValueType
s
;
STermValueType
s
=
kTypeValue
;
if
(
0
==
indexCacheSearch
(
cache
,
query
,
*
result
,
&
s
))
{
if
(
0
==
indexCacheSearch
(
cache
,
query
,
*
result
,
&
s
))
{
if
(
s
==
kTypeDeletion
)
{
if
(
s
==
kTypeDeletion
)
{
indexInfo
(
"col: %s already drop by other opera"
,
term
->
colName
);
indexInfo
(
"col: %s already drop by other opera"
,
term
->
colName
);
...
@@ -336,9 +325,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
...
@@ -336,9 +325,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
return
0
;
return
0
;
}
}
static
void
indexInterResultsDestroy
(
SArray
*
results
)
{
static
void
indexInterResultsDestroy
(
SArray
*
results
)
{
if
(
results
==
NULL
)
{
if
(
results
==
NULL
)
{
return
;
}
return
;
}
size_t
sz
=
taosArrayGetSize
(
results
);
size_t
sz
=
taosArrayGetSize
(
results
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
...
@@ -368,23 +355,43 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType
...
@@ -368,23 +355,43 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType
return
0
;
return
0
;
}
}
int
indexFlushCacheTFile
(
SIndex
*
sIdx
,
void
*
cache
)
{
static
void
indexMergeSameKey
(
SArray
*
result
,
TFileValue
*
tv
)
{
if
(
sIdx
==
NULL
)
{
int32_t
sz
=
result
?
taosArrayGetSize
(
result
)
:
0
;
return
-
1
;
if
(
sz
>
0
)
{
// TODO(yihao): remove duplicate tableid
TFileValue
*
lv
=
taosArrayGetP
(
result
,
sz
-
1
);
if
(
strcmp
(
lv
->
colVal
,
tv
->
colVal
)
==
0
)
{
taosArrayAddAll
(
lv
->
tableId
,
tv
->
tableId
);
tfileValueDestroy
(
tv
);
}
else
{
taosArrayPush
(
result
,
&
tv
);
}
}
else
{
taosArrayPush
(
result
,
&
tv
);
}
}
}
static
void
indexDestroyTempResult
(
SArray
*
result
)
{
int32_t
sz
=
result
?
taosArrayGetSize
(
result
)
:
0
;
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
TFileValue
*
tv
=
taosArrayGetP
(
result
,
i
);
tfileValueDestroy
(
tv
);
}
taosArrayDestroy
(
result
);
}
int
indexFlushCacheTFile
(
SIndex
*
sIdx
,
void
*
cache
)
{
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
IndexCache
*
pCache
=
(
IndexCache
*
)
cache
;
IndexCache
*
pCache
=
(
IndexCache
*
)
cache
;
TFileReader
*
pReader
=
tfileGetReaderByCol
(
sIdx
->
tindex
,
pCache
->
colName
);
TFileReader
*
pReader
=
tfileGetReaderByCol
(
sIdx
->
tindex
,
pCache
->
colName
);
// handle flush
// handle flush
Iterate
*
cacheIter
=
indexCacheIteratorCreate
(
pCache
);
Iterate
*
cacheIter
=
indexCacheIteratorCreate
(
pCache
);
Iterate
*
tfileIter
=
tfileIteratorCreate
(
pReader
);
Iterate
*
tfileIter
=
tfileIteratorCreate
(
pReader
);
SArray
*
result
=
taosArrayInit
(
1024
,
sizeof
(
void
*
));
SArray
*
result
=
taosArrayInit
(
1024
,
sizeof
(
void
*
));
bool
cn
=
cacheIter
->
next
(
cacheIter
)
;
bool
cn
=
cacheIter
?
cacheIter
->
next
(
cacheIter
)
:
false
;
bool
tn
=
tfileIter
->
next
(
tfileIter
)
;
bool
tn
=
tfileIter
?
tfileIter
->
next
(
tfileIter
)
:
false
;
while
(
cn
==
true
&&
tn
==
true
)
{
while
(
cn
==
true
&&
tn
==
true
)
{
IterateValue
*
cv
=
cacheIter
->
getValue
(
cacheIter
);
IterateValue
*
cv
=
cacheIter
->
getValue
(
cacheIter
);
IterateValue
*
tv
=
tfileIter
->
getValue
(
tfileIter
);
IterateValue
*
tv
=
tfileIter
->
getValue
(
tfileIter
);
...
@@ -395,7 +402,7 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -395,7 +402,7 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
tv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
tv
->
val
);
taosArrayPush
(
result
,
&
tfv
);
indexMergeSameKey
(
result
,
tfv
);
cn
=
cacheIter
->
next
(
cacheIter
);
cn
=
cacheIter
->
next
(
cacheIter
);
tn
=
tfileIter
->
next
(
tfileIter
);
tn
=
tfileIter
->
next
(
tfileIter
);
...
@@ -403,13 +410,15 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -403,13 +410,15 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
}
else
if
(
comp
<
0
)
{
}
else
if
(
comp
<
0
)
{
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayPush
(
result
,
&
tfv
);
indexMergeSameKey
(
result
,
tfv
);
// copy to final Result;
// copy to final Result;
cn
=
cacheIter
->
next
(
cacheIter
);
cn
=
cacheIter
->
next
(
cacheIter
);
}
else
{
}
else
{
TFileValue
*
tfv
=
tfileValueCreate
(
tv
->
colVal
);
TFileValue
*
tfv
=
tfileValueCreate
(
tv
->
colVal
);
taosArrayPush
(
result
,
&
tfv
);
taosArrayAddAll
(
tfv
->
tableId
,
tv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
tv
->
val
);
indexMergeSameKey
(
result
,
tfv
);
// copy to final result
// copy to final result
tn
=
tfileIter
->
next
(
tfileIter
);
tn
=
tfileIter
->
next
(
tfileIter
);
}
}
...
@@ -418,33 +427,24 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -418,33 +427,24 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
IterateValue
*
cv
=
cacheIter
->
getValue
(
cacheIter
);
IterateValue
*
cv
=
cacheIter
->
getValue
(
cacheIter
);
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayPush
(
result
,
&
tfv
);
indexMergeSameKey
(
result
,
tfv
);
cn
=
cacheIter
->
next
(
cacheIter
);
cn
=
cacheIter
->
next
(
cacheIter
);
}
}
while
(
tn
==
true
)
{
while
(
tn
==
true
)
{
IterateValue
*
tv
=
tfileIter
->
getValue
(
tfileIter
);
IterateValue
*
tv
=
tfileIter
->
getValue
(
tfileIter
);
TFileValue
*
tfv
=
tfileValueCreate
(
tv
->
colVal
);
TFileValue
*
tfv
=
tfileValueCreate
(
tv
->
colVal
);
if
(
tv
->
val
==
NULL
)
{
// HO
printf
(
"NO...."
);
}
taosArrayAddAll
(
tfv
->
tableId
,
tv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
tv
->
val
);
taosArrayPush
(
result
,
&
tfv
);
indexMergeSameKey
(
result
,
tfv
);
tn
=
tfileIter
->
next
(
tfileIter
);
tn
=
tfileIter
->
next
(
tfileIter
);
}
}
int
ret
=
indexGenTFile
(
sIdx
,
pCache
,
result
);
int32_t
version
=
CACHE_VERSION
(
pCache
);
indexDestroyTempResult
(
result
);
uint8_t
colType
=
pCache
->
type
;
TFileWriter
*
tw
=
tfileWriterOpen
(
sIdx
->
path
,
sIdx
->
suid
,
version
,
pCache
->
colName
,
colType
);
if
(
tw
==
NULL
)
{
indexError
(
"faile to open file to write"
);
}
else
{
int
ret
=
tfileWriterPut
(
tw
,
result
);
if
(
ret
!=
0
)
{
indexError
(
"faile to write into tindex "
);
}
}
// not free later, just put int table cache
indexCacheDestroyImm
(
pCache
);
indexCacheDestroyImm
(
pCache
);
tfileWriteClose
(
tw
);
indexCacheIteratorDestroy
(
cacheIter
);
indexCacheIteratorDestroy
(
cacheIter
);
tfileIteratorDestroy
(
tfileIter
);
tfileIteratorDestroy
(
tfileIter
);
...
@@ -455,9 +455,45 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -455,9 +455,45 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
void
iterateValueDestroy
(
IterateValue
*
value
,
bool
destroy
)
{
void
iterateValueDestroy
(
IterateValue
*
value
,
bool
destroy
)
{
if
(
destroy
)
{
if
(
destroy
)
{
taosArrayDestroy
(
value
->
val
);
taosArrayDestroy
(
value
->
val
);
value
->
val
=
NULL
;
}
else
{
}
else
{
taosArrayClear
(
value
->
val
);
if
(
value
->
val
!=
NULL
)
{
taosArrayClear
(
value
->
val
);
}
}
}
free
(
value
->
colVal
);
//
free(value->colVal);
value
->
colVal
=
NULL
;
value
->
colVal
=
NULL
;
}
}
static
int
indexGenTFile
(
SIndex
*
sIdx
,
IndexCache
*
cache
,
SArray
*
batch
)
{
int32_t
version
=
CACHE_VERSION
(
cache
);
uint8_t
colType
=
cache
->
type
;
TFileWriter
*
tw
=
tfileWriterOpen
(
sIdx
->
path
,
sIdx
->
suid
,
version
,
cache
->
colName
,
colType
);
if
(
tw
==
NULL
)
{
indexError
(
"failed to open file to write"
);
return
-
1
;
}
int
ret
=
tfileWriterPut
(
tw
,
batch
,
true
);
if
(
ret
!=
0
)
{
indexError
(
"failed to write into tindex "
);
goto
END
;
}
tfileWriterClose
(
tw
);
TFileReader
*
reader
=
tfileReaderOpen
(
sIdx
->
path
,
sIdx
->
suid
,
version
,
cache
->
colName
);
char
buf
[
128
]
=
{
0
};
TFileHeader
*
header
=
&
reader
->
header
;
TFileCacheKey
key
=
{.
suid
=
header
->
suid
,
.
colName
=
header
->
colName
,
.
nColName
=
strlen
(
header
->
colName
),
.
colType
=
header
->
colType
};
pthread_mutex_lock
(
&
sIdx
->
mtx
);
IndexTFile
*
ifile
=
(
IndexTFile
*
)
sIdx
->
tindex
;
tfileCachePut
(
ifile
->
cache
,
&
key
,
reader
);
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
return
ret
;
END:
tfileWriterClose
(
tw
);
}
source/libs/index/src/index_cache.c
浏览文件 @
8ecd7a56
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MEM_TERM_LIMIT
10000
00
#define MEM_TERM_LIMIT
2
00
// ref index_cache.h:22
// ref index_cache.h:22
//#define CACHE_KEY_LEN(p) \
//#define CACHE_KEY_LEN(p) \
// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) +
// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) +
...
@@ -66,6 +66,7 @@ void indexCacheDebug(IndexCache* cache) {
...
@@ -66,6 +66,7 @@ void indexCacheDebug(IndexCache* cache) {
indexMemRef
(
tbl
);
indexMemRef
(
tbl
);
pthread_mutex_unlock
(
&
cache
->
mtx
);
pthread_mutex_unlock
(
&
cache
->
mtx
);
{
SSkipList
*
slt
=
tbl
->
mem
;
SSkipList
*
slt
=
tbl
->
mem
;
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
while
(
tSkipListIterNext
(
iter
))
{
while
(
tSkipListIterNext
(
iter
))
{
...
@@ -79,32 +80,56 @@ void indexCacheDebug(IndexCache* cache) {
...
@@ -79,32 +80,56 @@ void indexCacheDebug(IndexCache* cache) {
tSkipListDestroyIter
(
iter
);
tSkipListDestroyIter
(
iter
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
}
}
void
indexCacheDestroySkiplist
(
SSkipList
*
slt
)
{
{
pthread_mutex_lock
(
&
cache
->
mtx
);
tbl
=
cache
->
imm
;
indexMemRef
(
tbl
);
pthread_mutex_unlock
(
&
cache
->
mtx
);
if
(
tbl
!=
NULL
)
{
SSkipList
*
slt
=
tbl
->
mem
;
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
while
(
tSkipListIterNext
(
iter
))
{
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
ct
!=
NULL
)
{
if
(
ct
!=
NULL
)
{
// TODO, add more debug info
indexInfo
(
"{colVal: %s, version: %d}
\t
"
,
ct
->
colVal
,
ct
->
version
);
}
}
}
tSkipListDestroyIter
(
iter
);
}
indexMemUnRef
(
tbl
);
}
}
void
indexCacheDestroySkiplist
(
SSkipList
*
slt
)
{
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
slt
);
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
ct
!=
NULL
)
{}
}
}
tSkipListDestroyIter
(
iter
);
tSkipListDestroyIter
(
iter
);
tSkipListDestroy
(
slt
);
tSkipListDestroy
(
slt
);
}
}
void
indexCacheDestroyImm
(
IndexCache
*
cache
)
{
void
indexCacheDestroyImm
(
IndexCache
*
cache
)
{
if
(
cache
==
NULL
)
{
return
;
}
MemTable
*
tbl
=
NULL
;
MemTable
*
tbl
=
NULL
;
pthread_mutex_lock
(
&
cache
->
mtx
);
pthread_mutex_lock
(
&
cache
->
mtx
);
tbl
=
cache
->
imm
;
tbl
=
cache
->
imm
;
cache
->
imm
=
NULL
;
// or throw int bg thread
cache
->
imm
=
NULL
;
// or throw int bg thread
pthread_mutex_unlock
(
&
cache
->
mtx
);
pthread_mutex_unlock
(
&
cache
->
mtx
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
}
}
void
indexCacheDestroy
(
void
*
cache
)
{
void
indexCacheDestroy
(
void
*
cache
)
{
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
if
(
pCache
==
NULL
)
{
if
(
pCache
==
NULL
)
{
return
;
}
return
;
}
indexMemUnRef
(
pCache
->
mem
);
indexMemUnRef
(
pCache
->
mem
);
indexMemUnRef
(
pCache
->
imm
);
indexMemUnRef
(
pCache
->
imm
);
free
(
pCache
->
colName
);
free
(
pCache
->
colName
);
...
@@ -114,9 +139,11 @@ void indexCacheDestroy(void* cache) {
...
@@ -114,9 +139,11 @@ void indexCacheDestroy(void* cache) {
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
)
{
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
)
{
Iterate
*
iiter
=
calloc
(
1
,
sizeof
(
Iterate
));
Iterate
*
iiter
=
calloc
(
1
,
sizeof
(
Iterate
));
if
(
iiter
==
NULL
)
{
if
(
iiter
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
pthread_mutex_lock
(
&
cache
->
mtx
);
indexMemRef
(
cache
->
imm
);
MemTable
*
tbl
=
cache
->
imm
;
MemTable
*
tbl
=
cache
->
imm
;
iiter
->
val
.
val
=
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
iiter
->
val
.
val
=
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
...
@@ -124,12 +151,12 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
...
@@ -124,12 +151,12 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
iiter
->
next
=
indexCacheIteratorNext
;
iiter
->
next
=
indexCacheIteratorNext
;
iiter
->
getValue
=
indexCacheIteratorGetValue
;
iiter
->
getValue
=
indexCacheIteratorGetValue
;
pthread_mutex_unlock
(
&
cache
->
mtx
);
return
iiter
;
return
iiter
;
}
}
void
indexCacheIteratorDestroy
(
Iterate
*
iter
)
{
void
indexCacheIteratorDestroy
(
Iterate
*
iter
)
{
if
(
iter
==
NULL
)
{
if
(
iter
==
NULL
)
{
return
;
}
return
;
}
tSkipListDestroyIter
(
iter
->
iter
);
tSkipListDestroyIter
(
iter
->
iter
);
iterateValueDestroy
(
&
iter
->
val
,
true
);
iterateValueDestroy
(
&
iter
->
val
,
true
);
free
(
iter
);
free
(
iter
);
...
@@ -155,6 +182,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
...
@@ -155,6 +182,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
taosMsleep
(
50
);
taosMsleep
(
50
);
pthread_mutex_lock
(
&
cache
->
mtx
);
pthread_mutex_lock
(
&
cache
->
mtx
);
}
else
{
}
else
{
indexCacheRef
(
cache
);
cache
->
imm
=
cache
->
mem
;
cache
->
imm
=
cache
->
mem
;
cache
->
mem
=
indexInternalCacheCreate
(
cache
->
type
);
cache
->
mem
=
indexInternalCacheCreate
(
cache
->
type
);
cache
->
nTerm
=
1
;
cache
->
nTerm
=
1
;
...
@@ -166,17 +194,13 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
...
@@ -166,17 +194,13 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
}
}
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
if
(
cache
==
NULL
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
indexCacheRef
(
pCache
);
indexCacheRef
(
pCache
);
// encode data
// encode data
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
if
(
cache
==
NULL
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
return
-
1
;
}
// set up key
// set up key
ct
->
colType
=
term
->
colType
;
ct
->
colType
=
term
->
colType
;
ct
->
colVal
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
term
->
nColVal
+
1
));
ct
->
colVal
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
term
->
nColVal
+
1
));
...
@@ -205,32 +229,11 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u
...
@@ -205,32 +229,11 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
return
0
;
return
0
;
}
}
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SArray
*
result
,
STermValueType
*
s
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
MemTable
*
mem
=
NULL
,
*
imm
=
NULL
;
pthread_mutex_lock
(
&
pCache
->
mtx
);
mem
=
pCache
->
mem
;
imm
=
pCache
->
imm
;
indexMemRef
(
mem
);
indexMemRef
(
imm
);
pthread_mutex_unlock
(
&
pCache
->
mtx
);
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
if
(
ct
==
NULL
)
{
return
-
1
;
}
ct
->
colVal
=
calloc
(
1
,
sizeof
(
char
)
*
(
term
->
nColVal
+
1
));
memcpy
(
ct
->
colVal
,
term
->
colVal
,
term
->
nColVal
);
ct
->
version
=
atomic_load_32
(
&
pCache
->
version
);
static
int
indexQueryMem
(
MemTable
*
mem
,
CacheTerm
*
ct
,
EIndexQueryType
qtype
,
SArray
*
result
,
STermValueType
*
s
)
{
if
(
mem
==
NULL
)
{
return
0
;
}
char
*
key
=
getIndexKey
(
ct
);
char
*
key
=
getIndexKey
(
ct
);
// TODO handle multi situation later, and refactor
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
...
@@ -251,51 +254,56 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
...
@@ -251,51 +254,56 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
}
}
}
}
tSkipListDestroyIter
(
iter
);
tSkipListDestroyIter
(
iter
);
cacheTermDestroy
(
ct
);
return
0
;
// int32_t keyLen = CACHE_KEY_LEN(term);
}
// char* buf = calloc(1, keyLen);
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SArray
*
result
,
STermValueType
*
s
)
{
if
(
qtype
==
QUERY_TERM
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
//
IndexCache
*
pCache
=
cache
;
}
else
if
(
qtype
==
QUERY_PREFIX
)
{
//
MemTable
*
mem
=
NULL
,
*
imm
=
NULL
;
}
else
if
(
qtype
==
QUERY_SUFFIX
)
{
pthread_mutex_lock
(
&
pCache
->
mtx
);
//
mem
=
pCache
->
mem
;
}
else
if
(
qtype
==
QUERY_REGEX
)
{
imm
=
pCache
->
imm
;
//
indexMemRef
(
mem
);
indexMemRef
(
imm
);
pthread_mutex_unlock
(
&
pCache
->
mtx
);
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
CacheTerm
ct
=
{.
colVal
=
term
->
colVal
,
.
version
=
atomic_load_32
(
&
pCache
->
version
)};
indexCacheDebug
(
pCache
);
int
ret
=
indexQueryMem
(
mem
,
&
ct
,
qtype
,
result
,
s
);
if
(
ret
==
0
&&
*
s
!=
kTypeDeletion
)
{
// continue search in imm
ret
=
indexQueryMem
(
imm
,
&
ct
,
qtype
,
result
,
s
);
}
}
// cacheTermDestroy(ct);
indexMemUnRef
(
mem
);
indexMemUnRef
(
mem
);
indexMemUnRef
(
imm
);
indexMemUnRef
(
imm
);
return
0
;
return
ret
;
}
}
void
indexCacheRef
(
IndexCache
*
cache
)
{
void
indexCacheRef
(
IndexCache
*
cache
)
{
if
(
cache
==
NULL
)
{
if
(
cache
==
NULL
)
{
return
;
}
return
;
}
int
ref
=
T_REF_INC
(
cache
);
int
ref
=
T_REF_INC
(
cache
);
UNUSED
(
ref
);
UNUSED
(
ref
);
}
}
void
indexCacheUnRef
(
IndexCache
*
cache
)
{
void
indexCacheUnRef
(
IndexCache
*
cache
)
{
if
(
cache
==
NULL
)
{
if
(
cache
==
NULL
)
{
return
;
}
return
;
}
int
ref
=
T_REF_DEC
(
cache
);
int
ref
=
T_REF_DEC
(
cache
);
if
(
ref
==
0
)
{
if
(
ref
==
0
)
{
indexCacheDestroy
(
cache
);
}
indexCacheDestroy
(
cache
);
}
}
}
void
indexMemRef
(
MemTable
*
tbl
)
{
void
indexMemRef
(
MemTable
*
tbl
)
{
if
(
tbl
==
NULL
)
{
if
(
tbl
==
NULL
)
{
return
;
}
return
;
}
int
ref
=
T_REF_INC
(
tbl
);
int
ref
=
T_REF_INC
(
tbl
);
UNUSED
(
ref
);
UNUSED
(
ref
);
}
}
void
indexMemUnRef
(
MemTable
*
tbl
)
{
void
indexMemUnRef
(
MemTable
*
tbl
)
{
if
(
tbl
==
NULL
)
{
if
(
tbl
==
NULL
)
{
return
;
}
return
;
}
int
ref
=
T_REF_DEC
(
tbl
);
int
ref
=
T_REF_DEC
(
tbl
);
if
(
ref
==
0
)
{
if
(
ref
==
0
)
{
SSkipList
*
slt
=
tbl
->
mem
;
SSkipList
*
slt
=
tbl
->
mem
;
...
@@ -305,9 +313,7 @@ void indexMemUnRef(MemTable* tbl) {
...
@@ -305,9 +313,7 @@ void indexMemUnRef(MemTable* tbl) {
}
}
static
void
cacheTermDestroy
(
CacheTerm
*
ct
)
{
static
void
cacheTermDestroy
(
CacheTerm
*
ct
)
{
if
(
ct
==
NULL
)
{
if
(
ct
==
NULL
)
{
return
;
}
return
;
}
free
(
ct
->
colVal
);
free
(
ct
->
colVal
);
free
(
ct
);
free
(
ct
);
}
}
...
@@ -322,9 +328,7 @@ static int32_t compareKey(const void* l, const void* r) {
...
@@ -322,9 +328,7 @@ static int32_t compareKey(const void* l, const void* r) {
// compare colVal
// compare colVal
int32_t
cmp
=
strcmp
(
lt
->
colVal
,
rt
->
colVal
);
int32_t
cmp
=
strcmp
(
lt
->
colVal
,
rt
->
colVal
);
if
(
cmp
==
0
)
{
if
(
cmp
==
0
)
{
return
rt
->
version
-
lt
->
version
;
}
return
rt
->
version
-
lt
->
version
;
}
return
cmp
;
return
cmp
;
}
}
...
@@ -344,9 +348,7 @@ static void doMergeWork(SSchedMsg* msg) {
...
@@ -344,9 +348,7 @@ static void doMergeWork(SSchedMsg* msg) {
}
}
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
)
{
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
)
{
SSkipListIterator
*
iter
=
itera
->
iter
;
SSkipListIterator
*
iter
=
itera
->
iter
;
if
(
iter
==
NULL
)
{
if
(
iter
==
NULL
)
{
return
false
;
}
return
false
;
}
IterateValue
*
iv
=
&
itera
->
val
;
IterateValue
*
iv
=
&
itera
->
val
;
iterateValueDestroy
(
iv
,
false
);
iterateValueDestroy
(
iv
,
false
);
...
@@ -356,7 +358,8 @@ static bool indexCacheIteratorNext(Iterate* itera) {
...
@@ -356,7 +358,8 @@ static bool indexCacheIteratorNext(Iterate* itera) {
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
iv
->
type
=
ct
->
operaType
;
iv
->
type
=
ct
->
operaType
;
iv
->
colVal
=
ct
->
colVal
;
iv
->
colVal
=
calloc
(
1
,
strlen
(
ct
->
colVal
)
+
1
);
memcpy
(
iv
->
colVal
,
ct
->
colVal
,
strlen
(
ct
->
colVal
));
taosArrayPush
(
iv
->
val
,
&
ct
->
uid
);
taosArrayPush
(
iv
->
val
,
&
ct
->
uid
);
}
}
...
...
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
...
@@ -32,6 +32,7 @@ typedef struct TFileFstIter {
...
@@ -32,6 +32,7 @@ typedef struct TFileFstIter {
#define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t))
#define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t))
static
int
tfileUidCompare
(
const
void
*
a
,
const
void
*
b
);
static
int
tfileStrCompare
(
const
void
*
a
,
const
void
*
b
);
static
int
tfileStrCompare
(
const
void
*
a
,
const
void
*
b
);
static
int
tfileValueCompare
(
const
void
*
a
,
const
void
*
b
,
const
void
*
param
);
static
int
tfileValueCompare
(
const
void
*
a
,
const
void
*
b
,
const
void
*
param
);
static
void
tfileSerialTableIdsToBuf
(
char
*
buf
,
SArray
*
tableIds
);
static
void
tfileSerialTableIdsToBuf
(
char
*
buf
,
SArray
*
tableIds
);
...
@@ -52,11 +53,16 @@ static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId,
...
@@ -52,11 +53,16 @@ static int tfileParseFileName(const char* filename, uint64_t* suid, int* colId,
static
void
tfileGenFileName
(
char
*
filename
,
uint64_t
suid
,
int
colId
,
int
version
);
static
void
tfileGenFileName
(
char
*
filename
,
uint64_t
suid
,
int
colId
,
int
version
);
static
void
tfileSerialCacheKey
(
TFileCacheKey
*
key
,
char
*
buf
);
static
void
tfileSerialCacheKey
(
TFileCacheKey
*
key
,
char
*
buf
);
static
TFileReader
*
tfileReaderCreateImpl
(
WriterCtx
*
ctx
)
{
TFileReader
*
reader
=
tfileReaderCreate
(
ctx
);
tfileReaderRef
(
reader
);
// tfileSerialCacheKey(&key, buf);
return
reader
;
}
TFileCache
*
tfileCacheCreate
(
const
char
*
path
)
{
TFileCache
*
tfileCacheCreate
(
const
char
*
path
)
{
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
if
(
tcache
==
NULL
)
{
if
(
tcache
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
tcache
->
tableCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
tcache
->
tableCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
tcache
->
capacity
=
64
;
tcache
->
capacity
=
64
;
...
@@ -75,22 +81,19 @@ TFileCache* tfileCacheCreate(const char* path) {
...
@@ -75,22 +81,19 @@ TFileCache* tfileCacheCreate(const char* path) {
continue
;
continue
;
}
}
WriterCtx
*
wc
=
writerCtxCreate
(
TFile
,
file
,
true
,
1024
*
64
);
WriterCtx
*
wc
=
writerCtxCreate
(
TFile
,
file
,
true
,
1024
*
1024
*
64
);
if
(
wc
==
NULL
)
{
if
(
wc
==
NULL
)
{
indexError
(
"failed to open index:%s"
,
file
);
indexError
(
"failed to open index:%s"
,
file
);
goto
End
;
goto
End
;
}
}
TFileReader
*
reader
=
tfileReaderCreate
(
wc
);
char
buf
[
128
]
=
{
0
};
tfileReaderRef
(
reader
);
TFileReader
*
reader
=
tfileReaderCreateImpl
(
wc
);
// loader fst and validate it
TFileHeader
*
header
=
&
reader
->
header
;
TFileHeader
*
header
=
&
reader
->
header
;
TFileCacheKey
key
=
{.
suid
=
header
->
suid
,
TFileCacheKey
key
=
{.
suid
=
header
->
suid
,
.
colName
=
header
->
colName
,
.
colName
=
header
->
colName
,
.
nColName
=
strlen
(
header
->
colName
),
.
nColName
=
strlen
(
header
->
colName
),
.
colType
=
header
->
colType
};
.
colType
=
header
->
colType
};
char
buf
[
128
]
=
{
0
};
tfileSerialCacheKey
(
&
key
,
buf
);
tfileSerialCacheKey
(
&
key
,
buf
);
taosHashPut
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
),
&
reader
,
sizeof
(
void
*
));
taosHashPut
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
),
&
reader
,
sizeof
(
void
*
));
}
}
...
@@ -102,9 +105,7 @@ End:
...
@@ -102,9 +105,7 @@ End:
return
NULL
;
return
NULL
;
}
}
void
tfileCacheDestroy
(
TFileCache
*
tcache
)
{
void
tfileCacheDestroy
(
TFileCache
*
tcache
)
{
if
(
tcache
==
NULL
)
{
if
(
tcache
==
NULL
)
{
return
;
}
return
;
}
// free table cache
// free table cache
TFileReader
**
reader
=
taosHashIterate
(
tcache
->
tableCache
,
NULL
);
TFileReader
**
reader
=
taosHashIterate
(
tcache
->
tableCache
,
NULL
);
...
@@ -125,9 +126,7 @@ TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key) {
...
@@ -125,9 +126,7 @@ TFileReader* tfileCacheGet(TFileCache* tcache, TFileCacheKey* key) {
tfileSerialCacheKey
(
key
,
buf
);
tfileSerialCacheKey
(
key
,
buf
);
TFileReader
**
reader
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
TFileReader
**
reader
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
if
(
reader
==
NULL
)
{
if
(
reader
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
tfileReaderRef
(
*
reader
);
tfileReaderRef
(
*
reader
);
return
*
reader
;
return
*
reader
;
...
@@ -137,7 +136,7 @@ void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader)
...
@@ -137,7 +136,7 @@ void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader)
tfileSerialCacheKey
(
key
,
buf
);
tfileSerialCacheKey
(
key
,
buf
);
// remove last version index reader
// remove last version index reader
TFileReader
**
p
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
TFileReader
**
p
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
if
(
*
p
!=
NULL
)
{
if
(
p
!=
NULL
)
{
TFileReader
*
oldReader
=
*
p
;
TFileReader
*
oldReader
=
*
p
;
taosHashRemove
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
taosHashRemove
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
tfileReaderUnRef
(
oldReader
);
tfileReaderUnRef
(
oldReader
);
...
@@ -149,9 +148,7 @@ void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader)
...
@@ -149,9 +148,7 @@ void tfileCachePut(TFileCache* tcache, TFileCacheKey* key, TFileReader* reader)
}
}
TFileReader
*
tfileReaderCreate
(
WriterCtx
*
ctx
)
{
TFileReader
*
tfileReaderCreate
(
WriterCtx
*
ctx
)
{
TFileReader
*
reader
=
calloc
(
1
,
sizeof
(
TFileReader
));
TFileReader
*
reader
=
calloc
(
1
,
sizeof
(
TFileReader
));
if
(
reader
==
NULL
)
{
if
(
reader
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
// T_REF_INC(reader);
// T_REF_INC(reader);
reader
->
ctx
=
ctx
;
reader
->
ctx
=
ctx
;
...
@@ -172,12 +169,10 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) {
...
@@ -172,12 +169,10 @@ TFileReader* tfileReaderCreate(WriterCtx* ctx) {
return
reader
;
return
reader
;
}
}
void
tfileReaderDestroy
(
TFileReader
*
reader
)
{
void
tfileReaderDestroy
(
TFileReader
*
reader
)
{
if
(
reader
==
NULL
)
{
if
(
reader
==
NULL
)
{
return
;
}
return
;
}
// T_REF_INC(reader);
// T_REF_INC(reader);
fstDestroy
(
reader
->
fst
);
fstDestroy
(
reader
->
fst
);
writerCtxDestroy
(
reader
->
ctx
);
writerCtxDestroy
(
reader
->
ctx
,
true
);
free
(
reader
);
free
(
reader
);
}
}
...
@@ -216,7 +211,8 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c
...
@@ -216,7 +211,8 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c
char
fullname
[
256
]
=
{
0
};
char
fullname
[
256
]
=
{
0
};
snprintf
(
fullname
,
sizeof
(
fullname
),
"%s/%s"
,
path
,
filename
);
snprintf
(
fullname
,
sizeof
(
fullname
),
"%s/%s"
,
path
,
filename
);
WriterCtx
*
wcx
=
writerCtxCreate
(
TFile
,
fullname
,
true
,
1024
*
1024
);
WriterCtx
*
wcx
=
writerCtxCreate
(
TFile
,
fullname
,
false
,
1024
*
1024
*
64
);
if
(
wcx
==
NULL
)
{
return
NULL
;
}
TFileHeader
tfh
=
{
0
};
TFileHeader
tfh
=
{
0
};
tfh
.
suid
=
suid
;
tfh
.
suid
=
suid
;
...
@@ -226,6 +222,21 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c
...
@@ -226,6 +222,21 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const c
return
tfileWriterCreate
(
wcx
,
&
tfh
);
return
tfileWriterCreate
(
wcx
,
&
tfh
);
}
}
TFileReader
*
tfileReaderOpen
(
char
*
path
,
uint64_t
suid
,
int32_t
version
,
const
char
*
colName
)
{
char
filename
[
128
]
=
{
0
};
int32_t
coldId
=
1
;
tfileGenFileName
(
filename
,
suid
,
coldId
,
version
);
char
fullname
[
256
]
=
{
0
};
snprintf
(
fullname
,
sizeof
(
fullname
),
"%s/%s"
,
path
,
filename
);
WriterCtx
*
wc
=
writerCtxCreate
(
TFile
,
fullname
,
true
,
1024
*
1024
*
1024
);
if
(
wc
==
NULL
)
{
return
NULL
;
}
TFileReader
*
reader
=
tfileReaderCreateImpl
(
wc
);
return
reader
;
// tfileSerialCacheKey(&key, buf);
}
TFileWriter
*
tfileWriterCreate
(
WriterCtx
*
ctx
,
TFileHeader
*
header
)
{
TFileWriter
*
tfileWriterCreate
(
WriterCtx
*
ctx
,
TFileHeader
*
header
)
{
// char pathBuf[128] = {0};
// char pathBuf[128] = {0};
// sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version);
// sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version);
...
@@ -249,10 +260,10 @@ TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) {
...
@@ -249,10 +260,10 @@ TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) {
return
tw
;
return
tw
;
}
}
int
tfileWriterPut
(
TFileWriter
*
tw
,
void
*
data
)
{
int
tfileWriterPut
(
TFileWriter
*
tw
,
void
*
data
,
bool
order
)
{
// sort by coltype and write to tindex
// sort by coltype and write to tindex
if
(
order
==
false
)
{
__compar_fn_t
fn
;
__compar_fn_t
fn
;
int8_t
colType
=
tw
->
header
.
colType
;
int8_t
colType
=
tw
->
header
.
colType
;
if
(
colType
==
TSDB_DATA_TYPE_BINARY
||
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
colType
==
TSDB_DATA_TYPE_BINARY
||
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
fn
=
tfileStrCompare
;
fn
=
tfileStrCompare
;
...
@@ -260,17 +271,18 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
...
@@ -260,17 +271,18 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
fn
=
getComparFunc
(
colType
,
0
);
fn
=
getComparFunc
(
colType
,
0
);
}
}
taosArraySortPWithExt
((
SArray
*
)(
data
),
tfileValueCompare
,
&
fn
);
taosArraySortPWithExt
((
SArray
*
)(
data
),
tfileValueCompare
,
&
fn
);
}
int32_t
bufLimit
=
4096
,
offset
=
0
;
int32_t
bufLimit
=
64
*
4096
,
offset
=
0
;
char
*
buf
=
calloc
(
1
,
sizeof
(
char
)
*
bufLimit
);
//
char* buf = calloc(1, sizeof(char) * bufLimit);
char
*
p
=
buf
;
//
char* p = buf;
int32_t
sz
=
taosArrayGetSize
((
SArray
*
)
data
);
int32_t
sz
=
taosArrayGetSize
((
SArray
*
)
data
);
int32_t
fstOffset
=
tw
->
offset
;
int32_t
fstOffset
=
tw
->
offset
;
// ugly code, refactor later
// ugly code, refactor later
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
TFileValue
*
v
=
taosArrayGetP
((
SArray
*
)
data
,
i
);
TFileValue
*
v
=
taosArrayGetP
((
SArray
*
)
data
,
i
);
// taosArrayRemoveDuplicate(v->tablId, tfileUidCompare, NULL);
int32_t
tbsz
=
taosArrayGetSize
(
v
->
tableId
);
int32_t
tbsz
=
taosArrayGetSize
(
v
->
tableId
);
fstOffset
+=
TF_TABLE_TATOAL_SIZE
(
tbsz
);
fstOffset
+=
TF_TABLE_TATOAL_SIZE
(
tbsz
);
}
}
...
@@ -282,30 +294,39 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
...
@@ -282,30 +294,39 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
int32_t
tbsz
=
taosArrayGetSize
(
v
->
tableId
);
int32_t
tbsz
=
taosArrayGetSize
(
v
->
tableId
);
// check buf has enough space or not
// check buf has enough space or not
int32_t
ttsz
=
TF_TABLE_TATOAL_SIZE
(
tbsz
);
int32_t
ttsz
=
TF_TABLE_TATOAL_SIZE
(
tbsz
);
if
(
offset
+
ttsz
>
bufLimit
)
{
// batch write
tw
->
ctx
->
write
(
tw
->
ctx
,
buf
,
offset
);
offset
=
0
;
memset
(
buf
,
0
,
bufLimit
);
p
=
buf
;
}
// if (offset + ttsz >= bufLimit) {
// // batch write
// indexInfo("offset: %d, ttsz: %d", offset, ttsz);
// // std::cout << "offset: " << offset << std::endl;
// // std::cout << "ttsz:" << ttsz < < < std::endl;
// tw->ctx->write(tw->ctx, buf, offset);
// offset = 0;
// memset(buf, 0, bufLimit);
// p = buf;
//}
// if (ttsz >= bufLimit) {
//}
char
*
buf
=
calloc
(
1
,
ttsz
*
sizeof
(
char
));
char
*
p
=
buf
;
tfileSerialTableIdsToBuf
(
p
,
v
->
tableId
);
tfileSerialTableIdsToBuf
(
p
,
v
->
tableId
);
offset
+=
ttsz
;
tw
->
ctx
->
write
(
tw
->
ctx
,
buf
,
ttsz
);
p
=
buf
+
offset
;
// offset += ttsz;
// p = buf + offset;
// set up value offset
// set up value offset
v
->
offset
=
tw
->
offset
;
v
->
offset
=
tw
->
offset
;
tw
->
offset
+=
ttsz
;
tw
->
offset
+=
ttsz
;
free
(
buf
);
}
}
if
(
offset
!=
0
)
{
//
if (offset != 0) {
// write reversed data in buf to tindex
// write reversed data in buf to tindex
tw
->
ctx
->
write
(
tw
->
ctx
,
buf
,
offset
);
//
tw->ctx->write(tw->ctx, buf, offset);
}
//
}
tfree
(
buf
);
//
tfree(buf);
tw
->
fb
=
fstBuilderCreate
(
tw
->
ctx
,
0
);
tw
->
fb
=
fstBuilderCreate
(
tw
->
ctx
,
0
);
if
(
tw
->
fb
==
NULL
)
{
if
(
tw
->
fb
==
NULL
)
{
tfileWriter
Destroy
(
tw
);
tfileWriter
Close
(
tw
);
return
-
1
;
return
-
1
;
}
}
// write fst
// write fst
...
@@ -321,27 +342,20 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
...
@@ -321,27 +342,20 @@ int tfileWriterPut(TFileWriter* tw, void* data) {
tw
->
fb
=
NULL
;
tw
->
fb
=
NULL
;
return
0
;
return
0
;
}
}
void
tfileWriteClose
(
TFileWriter
*
tw
)
{
void
tfileWriterClose
(
TFileWriter
*
tw
)
{
if
(
tw
==
NULL
)
{
if
(
tw
==
NULL
)
{
return
;
}
return
;
writerCtxDestroy
(
tw
->
ctx
,
false
);
}
writerCtxDestroy
(
tw
->
ctx
);
free
(
tw
);
free
(
tw
);
}
}
void
tfileWriterDestroy
(
TFileWriter
*
tw
)
{
void
tfileWriterDestroy
(
TFileWriter
*
tw
)
{
if
(
tw
==
NULL
)
{
if
(
tw
==
NULL
)
{
return
;
}
return
;
writerCtxDestroy
(
tw
->
ctx
,
false
);
}
writerCtxDestroy
(
tw
->
ctx
);
free
(
tw
);
free
(
tw
);
}
}
IndexTFile
*
indexTFileCreate
(
const
char
*
path
)
{
IndexTFile
*
indexTFileCreate
(
const
char
*
path
)
{
IndexTFile
*
tfile
=
calloc
(
1
,
sizeof
(
IndexTFile
));
IndexTFile
*
tfile
=
calloc
(
1
,
sizeof
(
IndexTFile
));
if
(
tfile
==
NULL
)
{
if
(
tfile
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
tfile
->
cache
=
tfileCacheCreate
(
path
);
tfile
->
cache
=
tfileCacheCreate
(
path
);
return
tfile
;
return
tfile
;
...
@@ -350,18 +364,14 @@ void IndexTFileDestroy(IndexTFile* tfile) { free(tfile); }
...
@@ -350,18 +364,14 @@ void IndexTFileDestroy(IndexTFile* tfile) { free(tfile); }
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
int
ret
=
-
1
;
int
ret
=
-
1
;
if
(
tfile
==
NULL
)
{
if
(
tfile
==
NULL
)
{
return
ret
;
}
return
ret
;
}
IndexTFile
*
pTfile
=
(
IndexTFile
*
)
tfile
;
IndexTFile
*
pTfile
=
(
IndexTFile
*
)
tfile
;
SIndexTerm
*
term
=
query
->
term
;
SIndexTerm
*
term
=
query
->
term
;
TFileCacheKey
key
=
{
TFileCacheKey
key
=
{
.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
TFileReader
*
reader
=
tfileCacheGet
(
pTfile
->
cache
,
&
key
);
TFileReader
*
reader
=
tfileCacheGet
(
pTfile
->
cache
,
&
key
);
if
(
reader
==
NULL
)
{
if
(
reader
==
NULL
)
{
return
0
;
}
return
0
;
}
return
tfileReaderSearch
(
reader
,
query
,
result
);
return
tfileReaderSearch
(
reader
,
query
,
result
);
}
}
...
@@ -381,9 +391,7 @@ static bool tfileIteratorNext(Iterate* iiter) {
...
@@ -381,9 +391,7 @@ static bool tfileIteratorNext(Iterate* iiter) {
TFileFstIter
*
tIter
=
iiter
->
iter
;
TFileFstIter
*
tIter
=
iiter
->
iter
;
StreamWithStateResult
*
rt
=
streamWithStateNextWith
(
tIter
->
st
,
NULL
);
StreamWithStateResult
*
rt
=
streamWithStateNextWith
(
tIter
->
st
,
NULL
);
if
(
rt
==
NULL
)
{
if
(
rt
==
NULL
)
{
return
false
;
}
return
false
;
}
int32_t
sz
=
0
;
int32_t
sz
=
0
;
char
*
ch
=
(
char
*
)
fstSliceData
(
&
rt
->
data
,
&
sz
);
char
*
ch
=
(
char
*
)
fstSliceData
(
&
rt
->
data
,
&
sz
);
...
@@ -391,12 +399,9 @@ static bool tfileIteratorNext(Iterate* iiter) {
...
@@ -391,12 +399,9 @@ static bool tfileIteratorNext(Iterate* iiter) {
memcpy
(
colVal
,
ch
,
sz
);
memcpy
(
colVal
,
ch
,
sz
);
offset
=
(
uint64_t
)(
rt
->
out
.
out
);
offset
=
(
uint64_t
)(
rt
->
out
.
out
);
swsResultDestroy
(
rt
);
swsResultDestroy
(
rt
);
// set up iterate value
// set up iterate value
if
(
tfileReaderLoadTableIds
(
tIter
->
rdr
,
offset
,
iv
->
val
)
!=
0
)
{
if
(
tfileReaderLoadTableIds
(
tIter
->
rdr
,
offset
,
iv
->
val
)
!=
0
)
{
return
false
;
}
return
false
;
}
iv
->
colVal
=
colVal
;
iv
->
colVal
=
colVal
;
...
@@ -407,9 +412,8 @@ static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; }
...
@@ -407,9 +412,8 @@ static IterateValue* tifileIterateGetValue(Iterate* iter) { return &iter->val; }
static
TFileFstIter
*
tfileFstIteratorCreate
(
TFileReader
*
reader
)
{
static
TFileFstIter
*
tfileFstIteratorCreate
(
TFileReader
*
reader
)
{
TFileFstIter
*
tIter
=
calloc
(
1
,
sizeof
(
Iterate
));
TFileFstIter
*
tIter
=
calloc
(
1
,
sizeof
(
Iterate
));
if
(
tIter
==
NULL
)
{
if
(
tIter
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
tIter
->
ctx
=
automCtxCreate
(
NULL
,
AUTOMATION_ALWAYS
);
tIter
->
ctx
=
automCtxCreate
(
NULL
,
AUTOMATION_ALWAYS
);
tIter
->
fb
=
fstSearch
(
reader
->
fst
,
tIter
->
ctx
);
tIter
->
fb
=
fstSearch
(
reader
->
fst
,
tIter
->
ctx
);
tIter
->
st
=
streamBuilderIntoStream
(
tIter
->
fb
);
tIter
->
st
=
streamBuilderIntoStream
(
tIter
->
fb
);
...
@@ -418,21 +422,22 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) {
...
@@ -418,21 +422,22 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) {
}
}
Iterate
*
tfileIteratorCreate
(
TFileReader
*
reader
)
{
Iterate
*
tfileIteratorCreate
(
TFileReader
*
reader
)
{
Iterate
*
iter
=
calloc
(
1
,
sizeof
(
Iterate
));
if
(
reader
==
NULL
)
{
return
NULL
;
}
Iterate
*
iter
=
calloc
(
1
,
sizeof
(
Iterate
));
iter
->
iter
=
tfileFstIteratorCreate
(
reader
);
iter
->
iter
=
tfileFstIteratorCreate
(
reader
);
if
(
iter
->
iter
==
NULL
)
{
if
(
iter
->
iter
==
NULL
)
{
free
(
iter
);
return
NULL
;
return
NULL
;
}
}
iter
->
next
=
tfileIteratorNext
;
iter
->
next
=
tfileIteratorNext
;
iter
->
getValue
=
tifileIterateGetValue
;
iter
->
getValue
=
tifileIterateGetValue
;
iter
->
val
.
val
=
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
return
iter
;
return
iter
;
}
}
void
tfileIteratorDestroy
(
Iterate
*
iter
)
{
void
tfileIteratorDestroy
(
Iterate
*
iter
)
{
if
(
iter
==
NULL
)
{
if
(
iter
==
NULL
)
{
return
;
}
return
;
}
IterateValue
*
iv
=
&
iter
->
val
;
IterateValue
*
iv
=
&
iter
->
val
;
iterateValueDestroy
(
iv
,
true
);
iterateValueDestroy
(
iv
,
true
);
...
@@ -445,18 +450,19 @@ void tfileIteratorDestroy(Iterate* iter) {
...
@@ -445,18 +450,19 @@ void tfileIteratorDestroy(Iterate* iter) {
}
}
TFileReader
*
tfileGetReaderByCol
(
IndexTFile
*
tf
,
char
*
colName
)
{
TFileReader
*
tfileGetReaderByCol
(
IndexTFile
*
tf
,
char
*
colName
)
{
if
(
tf
==
NULL
)
{
if
(
tf
==
NULL
)
{
return
NULL
;
}
return
NULL
;
}
TFileCacheKey
key
=
{.
suid
=
0
,
.
colType
=
TSDB_DATA_TYPE_BINARY
,
.
colName
=
colName
,
.
nColName
=
strlen
(
colName
)};
TFileCacheKey
key
=
{.
suid
=
0
,
.
colType
=
TSDB_DATA_TYPE_BINARY
,
.
colName
=
colName
,
.
nColName
=
strlen
(
colName
)};
return
tfileCacheGet
(
tf
->
cache
,
&
key
);
return
tfileCacheGet
(
tf
->
cache
,
&
key
);
}
}
static
int
tfileUidCompare
(
const
void
*
a
,
const
void
*
b
)
{
uint64_t
l
=
*
(
uint64_t
*
)
a
;
uint64_t
r
=
*
(
uint64_t
*
)
b
;
return
l
-
r
;
}
static
int
tfileStrCompare
(
const
void
*
a
,
const
void
*
b
)
{
static
int
tfileStrCompare
(
const
void
*
a
,
const
void
*
b
)
{
int
ret
=
strcmp
((
char
*
)
a
,
(
char
*
)
b
);
int
ret
=
strcmp
((
char
*
)
a
,
(
char
*
)
b
);
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
return
ret
;
}
return
ret
;
}
return
ret
<
0
?
-
1
:
1
;
return
ret
<
0
?
-
1
:
1
;
}
}
...
@@ -471,17 +477,13 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) {
...
@@ -471,17 +477,13 @@ static int tfileValueCompare(const void* a, const void* b, const void* param) {
TFileValue
*
tfileValueCreate
(
char
*
val
)
{
TFileValue
*
tfileValueCreate
(
char
*
val
)
{
TFileValue
*
tf
=
calloc
(
1
,
sizeof
(
TFileValue
));
TFileValue
*
tf
=
calloc
(
1
,
sizeof
(
TFileValue
));
if
(
tf
==
NULL
)
{
if
(
tf
==
NULL
)
{
return
NULL
;
}
return
NULL
;
tf
->
colVal
=
val
;
}
tf
->
tableId
=
taosArrayInit
(
32
,
sizeof
(
uint64_t
));
tf
->
tableId
=
taosArrayInit
(
32
,
sizeof
(
uint64_t
));
return
tf
;
return
tf
;
}
}
int
tfileValuePush
(
TFileValue
*
tf
,
uint64_t
val
)
{
int
tfileValuePush
(
TFileValue
*
tf
,
uint64_t
val
)
{
if
(
tf
==
NULL
)
{
if
(
tf
==
NULL
)
{
return
-
1
;
}
return
-
1
;
}
taosArrayPush
(
tf
->
tableId
,
&
val
);
taosArrayPush
(
tf
->
tableId
,
&
val
);
return
0
;
return
0
;
}
}
...
@@ -501,9 +503,7 @@ static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) {
...
@@ -501,9 +503,7 @@ static void tfileSerialTableIdsToBuf(char* buf, SArray* ids) {
static
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
)
{
static
int
tfileWriteFstOffset
(
TFileWriter
*
tw
,
int32_t
offset
)
{
int32_t
fstOffset
=
offset
+
sizeof
(
tw
->
header
.
fstOffset
);
int32_t
fstOffset
=
offset
+
sizeof
(
tw
->
header
.
fstOffset
);
tw
->
header
.
fstOffset
=
fstOffset
;
tw
->
header
.
fstOffset
=
fstOffset
;
if
(
sizeof
(
fstOffset
)
!=
tw
->
ctx
->
write
(
tw
->
ctx
,
(
char
*
)
&
fstOffset
,
sizeof
(
fstOffset
)))
{
if
(
sizeof
(
fstOffset
)
!=
tw
->
ctx
->
write
(
tw
->
ctx
,
(
char
*
)
&
fstOffset
,
sizeof
(
fstOffset
)))
{
return
-
1
;
}
return
-
1
;
}
tw
->
offset
+=
sizeof
(
fstOffset
);
tw
->
offset
+=
sizeof
(
fstOffset
);
return
0
;
return
0
;
}
}
...
@@ -514,9 +514,7 @@ static int tfileWriteHeader(TFileWriter* writer) {
...
@@ -514,9 +514,7 @@ static int tfileWriteHeader(TFileWriter* writer) {
memcpy
(
buf
,
(
char
*
)
header
,
sizeof
(
buf
));
memcpy
(
buf
,
(
char
*
)
header
,
sizeof
(
buf
));
int
nwrite
=
writer
->
ctx
->
write
(
writer
->
ctx
,
buf
,
sizeof
(
buf
));
int
nwrite
=
writer
->
ctx
->
write
(
writer
->
ctx
,
buf
,
sizeof
(
buf
));
if
(
sizeof
(
buf
)
!=
nwrite
)
{
if
(
sizeof
(
buf
)
!=
nwrite
)
{
return
-
1
;
}
return
-
1
;
}
writer
->
offset
=
nwrite
;
writer
->
offset
=
nwrite
;
return
0
;
return
0
;
}
}
...
@@ -547,12 +545,10 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
...
@@ -547,12 +545,10 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
}
}
static
int
tfileReaderLoadFst
(
TFileReader
*
reader
)
{
static
int
tfileReaderLoadFst
(
TFileReader
*
reader
)
{
// current load fst into memory, refactor it later
// current load fst into memory, refactor it later
static
int
FST_MAX_SIZE
=
16
*
1024
;
static
int
FST_MAX_SIZE
=
64
*
1024
;
char
*
buf
=
calloc
(
1
,
sizeof
(
char
)
*
FST_MAX_SIZE
);
char
*
buf
=
calloc
(
1
,
sizeof
(
char
)
*
FST_MAX_SIZE
);
if
(
buf
==
NULL
)
{
if
(
buf
==
NULL
)
{
return
-
1
;
}
return
-
1
;
}
WriterCtx
*
ctx
=
reader
->
ctx
;
WriterCtx
*
ctx
=
reader
->
ctx
;
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
buf
,
FST_MAX_SIZE
,
reader
->
header
.
fstOffset
);
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
buf
,
FST_MAX_SIZE
,
reader
->
header
.
fstOffset
);
...
@@ -575,36 +571,33 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
...
@@ -575,36 +571,33 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
int32_t
total
=
sizeof
(
uint64_t
)
*
nid
;
int32_t
total
=
sizeof
(
uint64_t
)
*
nid
;
char
*
buf
=
calloc
(
1
,
total
);
char
*
buf
=
calloc
(
1
,
total
);
if
(
buf
==
NULL
)
{
if
(
buf
==
NULL
)
{
return
-
1
;
}
return
-
1
;
}
nread
=
ctx
->
read
(
ctx
,
buf
,
total
);
nread
=
ctx
->
read
(
ctx
,
buf
,
total
);
assert
(
total
==
nread
);
assert
(
total
==
nread
);
for
(
int32_t
i
=
0
;
i
<
nid
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
nid
;
i
++
)
{
taosArrayPush
(
result
,
(
uint64_t
*
)
buf
+
i
);
}
taosArrayPush
(
result
,
(
uint64_t
*
)
buf
+
i
);
}
free
(
buf
);
free
(
buf
);
return
0
;
return
0
;
}
}
void
tfileReaderRef
(
TFileReader
*
reader
)
{
void
tfileReaderRef
(
TFileReader
*
reader
)
{
if
(
reader
==
NULL
)
{
return
;
}
int
ref
=
T_REF_INC
(
reader
);
int
ref
=
T_REF_INC
(
reader
);
UNUSED
(
ref
);
UNUSED
(
ref
);
}
}
void
tfileReaderUnRef
(
TFileReader
*
reader
)
{
void
tfileReaderUnRef
(
TFileReader
*
reader
)
{
if
(
reader
==
NULL
)
{
return
;
}
int
ref
=
T_REF_DEC
(
reader
);
int
ref
=
T_REF_DEC
(
reader
);
if
(
ref
==
0
)
{
if
(
ref
==
0
)
{
// do nothing
tfileReaderDestroy
(
reader
);
tfileReaderDestroy
(
reader
);
}
}
}
}
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
DIR
*
dir
=
opendir
(
path
);
DIR
*
dir
=
opendir
(
path
);
if
(
NULL
==
dir
)
{
if
(
NULL
==
dir
)
{
return
-
1
;
}
return
-
1
;
}
struct
dirent
*
entry
;
struct
dirent
*
entry
;
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
...
@@ -632,9 +625,7 @@ static int tfileCompare(const void* a, const void* b) {
...
@@ -632,9 +625,7 @@ static int tfileCompare(const void* a, const void* b) {
size_t
bLen
=
strlen
(
bName
);
size_t
bLen
=
strlen
(
bName
);
int
ret
=
strncmp
(
aName
,
bName
,
aLen
>
bLen
?
aLen
:
bLen
);
int
ret
=
strncmp
(
aName
,
bName
,
aLen
>
bLen
?
aLen
:
bLen
);
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
return
ret
;
}
return
ret
;
}
return
ret
<
0
?
-
1
:
1
;
return
ret
<
0
?
-
1
:
1
;
}
}
// tfile name suid-colId-version.tindex
// tfile name suid-colId-version.tindex
...
...
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
...
@@ -57,7 +57,7 @@ class FstWriter {
...
@@ -57,7 +57,7 @@ class FstWriter {
fstBuilderFinish
(
_b
);
fstBuilderFinish
(
_b
);
fstBuilderDestroy
(
_b
);
fstBuilderDestroy
(
_b
);
writerCtxDestroy
(
_wc
);
writerCtxDestroy
(
_wc
,
false
);
}
}
private:
private:
...
@@ -76,9 +76,7 @@ class FstReadMemory {
...
@@ -76,9 +76,7 @@ class FstReadMemory {
bool
init
()
{
bool
init
()
{
char
*
buf
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
_size
);
char
*
buf
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
_size
);
int
nRead
=
fstCountingWriterRead
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
int
nRead
=
fstCountingWriterRead
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
if
(
nRead
<=
0
)
{
if
(
nRead
<=
0
)
{
return
false
;
}
return
false
;
}
_size
=
nRead
;
_size
=
nRead
;
_s
=
fstSliceCreate
((
uint8_t
*
)
buf
,
_size
);
_s
=
fstSliceCreate
((
uint8_t
*
)
buf
,
_size
);
_fst
=
fstCreate
(
&
_s
);
_fst
=
fstCreate
(
&
_s
);
...
@@ -104,9 +102,7 @@ class FstReadMemory {
...
@@ -104,9 +102,7 @@ class FstReadMemory {
StreamWithState
*
st
=
streamBuilderIntoStream
(
sb
);
StreamWithState
*
st
=
streamBuilderIntoStream
(
sb
);
StreamWithStateResult
*
rt
=
NULL
;
StreamWithStateResult
*
rt
=
NULL
;
while
((
rt
=
streamWithStateNextWith
(
st
,
NULL
))
!=
NULL
)
{
while
((
rt
=
streamWithStateNextWith
(
st
,
NULL
))
!=
NULL
)
{
result
.
push_back
((
uint64_t
)(
rt
->
out
.
out
));
}
result
.
push_back
((
uint64_t
)(
rt
->
out
.
out
));
}
return
true
;
return
true
;
}
}
bool
SearchWithTimeCostUs
(
AutomationCtx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
bool
SearchWithTimeCostUs
(
AutomationCtx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
...
@@ -120,7 +116,7 @@ class FstReadMemory {
...
@@ -120,7 +116,7 @@ class FstReadMemory {
fstCountingWriterDestroy
(
_w
);
fstCountingWriterDestroy
(
_w
);
fstDestroy
(
_fst
);
fstDestroy
(
_fst
);
fstSliceDestroy
(
&
_s
);
fstSliceDestroy
(
&
_s
);
writerCtxDestroy
(
_wc
);
writerCtxDestroy
(
_wc
,
true
);
}
}
private:
private:
...
@@ -182,9 +178,7 @@ void checkFstPerf() {
...
@@ -182,9 +178,7 @@ void checkFstPerf() {
delete
fw
;
delete
fw
;
FstReadMemory
*
m
=
new
FstReadMemory
(
1024
*
64
);
FstReadMemory
*
m
=
new
FstReadMemory
(
1024
*
64
);
if
(
m
->
init
())
{
if
(
m
->
init
())
{
printf
(
"success to init fst read"
);
}
printf
(
"success to init fst read"
);
}
Performance_fstReadRecords
(
m
);
Performance_fstReadRecords
(
m
);
delete
m
;
delete
m
;
}
}
...
@@ -346,10 +340,8 @@ class TFileObj {
...
@@ -346,10 +340,8 @@ class TFileObj {
tfileReaderDestroy
(
reader_
);
tfileReaderDestroy
(
reader_
);
reader_
=
NULL
;
reader_
=
NULL
;
}
}
if
(
writer_
==
NULL
)
{
if
(
writer_
==
NULL
)
{
InitWriter
();
}
InitWriter
();
return
tfileWriterPut
(
writer_
,
tv
,
false
);
}
return
tfileWriterPut
(
writer_
,
tv
);
}
}
bool
InitWriter
()
{
bool
InitWriter
()
{
TFileHeader
header
;
TFileHeader
header
;
...
@@ -388,12 +380,8 @@ class TFileObj {
...
@@ -388,12 +380,8 @@ class TFileObj {
return
tfileReaderSearch
(
reader_
,
query
,
result
);
return
tfileReaderSearch
(
reader_
,
query
,
result
);
}
}
~
TFileObj
()
{
~
TFileObj
()
{
if
(
writer_
)
{
if
(
writer_
)
{
tfileWriterDestroy
(
writer_
);
}
tfileWriterDestroy
(
writer_
);
if
(
reader_
)
{
tfileReaderDestroy
(
reader_
);
}
}
if
(
reader_
)
{
tfileReaderDestroy
(
reader_
);
}
}
}
private:
private:
...
@@ -439,7 +427,7 @@ static TFileValue* genTFileValue(const char* val) {
...
@@ -439,7 +427,7 @@ static TFileValue* genTFileValue(const char* val) {
memcpy
(
tv
->
colVal
,
val
,
vlen
);
memcpy
(
tv
->
colVal
,
val
,
vlen
);
tv
->
tableId
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
tv
->
tableId
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
for
(
size_t
i
=
0
;
i
<
1
0
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
20
0
;
i
++
)
{
uint64_t
v
=
i
;
uint64_t
v
=
i
;
taosArrayPush
(
tv
->
tableId
,
&
v
);
taosArrayPush
(
tv
->
tableId
,
&
v
);
}
}
...
@@ -452,22 +440,17 @@ static void destroyTFileValue(void* val) {
...
@@ -452,22 +440,17 @@ static void destroyTFileValue(void* val) {
free
(
tv
);
free
(
tv
);
}
}
TEST_F
(
IndexTFileEnv
,
test_tfile_write
)
{
TEST_F
(
IndexTFileEnv
,
test_tfile_write
)
{
TFileValue
*
v1
=
genTFileValue
(
"c"
);
TFileValue
*
v1
=
genTFileValue
(
"ab"
);
TFileValue
*
v2
=
genTFileValue
(
"ab"
);
TFileValue
*
v3
=
genTFileValue
(
"b"
);
TFileValue
*
v4
=
genTFileValue
(
"d"
);
SArray
*
data
=
(
SArray
*
)
taosArrayInit
(
4
,
sizeof
(
void
*
));
SArray
*
data
=
(
SArray
*
)
taosArrayInit
(
4
,
sizeof
(
void
*
));
taosArrayPush
(
data
,
&
v1
);
taosArrayPush
(
data
,
&
v1
);
taosArrayPush
(
data
,
&
v2
);
//
taosArrayPush(data, &v2);
taosArrayPush
(
data
,
&
v3
);
//
taosArrayPush(data, &v3);
taosArrayPush
(
data
,
&
v4
);
//
taosArrayPush(data, &v4);
fObj
->
Put
(
data
);
fObj
->
Put
(
data
);
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
data
);
i
++
)
{
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
data
);
i
++
)
{
destroyTFileValue
(
taosArrayGetP
(
data
,
i
));
}
destroyTFileValue
(
taosArrayGetP
(
data
,
i
));
}
taosArrayDestroy
(
data
);
taosArrayDestroy
(
data
);
std
::
string
colName
(
"voltage"
);
std
::
string
colName
(
"voltage"
);
...
@@ -478,7 +461,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) {
...
@@ -478,7 +461,7 @@ TEST_F(IndexTFileEnv, test_tfile_write) {
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
fObj
->
Get
(
&
query
,
result
);
fObj
->
Get
(
&
query
,
result
);
assert
(
taosArrayGetSize
(
result
)
==
1
0
);
assert
(
taosArrayGetSize
(
result
)
==
20
0
);
indexTermDestroy
(
term
);
indexTermDestroy
(
term
);
// tfileWriterDestroy(twrite);
// tfileWriterDestroy(twrite);
...
@@ -569,7 +552,8 @@ TEST_F(IndexCacheEnv, cache_test) {
...
@@ -569,7 +552,8 @@ TEST_F(IndexCacheEnv, cache_test) {
colVal
.
c_str
(),
colVal
.
size
());
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
coj
->
Debug
();
std
::
cout
<<
"--------first----------"
<<
std
::
endl
;
{
{
std
::
string
colVal
(
"v3"
);
std
::
string
colVal
(
"v3"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
...
@@ -582,6 +566,8 @@ TEST_F(IndexCacheEnv, cache_test) {
...
@@ -582,6 +566,8 @@ TEST_F(IndexCacheEnv, cache_test) {
colVal
.
c_str
(),
colVal
.
size
());
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
othColId
,
version
++
,
suid
++
);
coj
->
Put
(
term
,
othColId
,
version
++
,
suid
++
);
}
}
coj
->
Debug
();
std
::
cout
<<
"--------second----------"
<<
std
::
endl
;
{
{
std
::
string
colVal
(
"v4"
);
std
::
string
colVal
(
"v4"
);
for
(
size_t
i
=
0
;
i
<
10
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
10
;
i
++
)
{
...
@@ -602,7 +588,7 @@ TEST_F(IndexCacheEnv, cache_test) {
...
@@ -602,7 +588,7 @@ TEST_F(IndexCacheEnv, cache_test) {
STermValueType
valType
;
STermValueType
valType
;
coj
->
Get
(
&
query
,
colId
,
10000
,
ret
,
&
valType
);
coj
->
Get
(
&
query
,
colId
,
10000
,
ret
,
&
valType
);
//
std::cout << "size : " << taosArrayGetSize(ret) << std::endl;
std
::
cout
<<
"size : "
<<
taosArrayGetSize
(
ret
)
<<
std
::
endl
;
assert
(
taosArrayGetSize
(
ret
)
==
4
);
assert
(
taosArrayGetSize
(
ret
)
==
4
);
}
}
{
{
...
@@ -635,6 +621,20 @@ class IndexObj {
...
@@ -635,6 +621,20 @@ class IndexObj {
}
}
return
ret
;
return
ret
;
}
}
int
WriteMillonData
(
const
std
::
string
&
colName
,
const
std
::
string
&
colVal
=
"Hello world"
,
size_t
numOfTable
=
100
*
10000
)
{
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SIndexMultiTerm
*
terms
=
indexMultiTermCreate
();
indexMultiTermAdd
(
terms
,
term
);
for
(
size_t
i
=
0
;
i
<
numOfTable
;
i
++
)
{
int
ret
=
Put
(
terms
,
i
);
assert
(
ret
==
0
);
}
indexMultiTermDestroy
(
terms
);
return
numOfTable
;
}
int
Put
(
SIndexMultiTerm
*
fvs
,
uint64_t
uid
)
{
int
Put
(
SIndexMultiTerm
*
fvs
,
uint64_t
uid
)
{
numOfWrite
+=
taosArrayGetSize
(
fvs
);
numOfWrite
+=
taosArrayGetSize
(
fvs
);
return
indexPut
(
idx
,
fvs
,
uid
);
return
indexPut
(
idx
,
fvs
,
uid
);
...
@@ -645,14 +645,25 @@ class IndexObj {
...
@@ -645,14 +645,25 @@ class IndexObj {
return
indexSearch
(
idx
,
multiQ
,
result
);
return
indexSearch
(
idx
,
multiQ
,
result
);
}
}
int
SearchOne
(
const
std
::
string
&
colName
,
const
std
::
string
&
colVal
)
{
SIndexMultiTermQuery
*
mq
=
indexMultiTermQueryCreate
(
MUST
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
indexMultiTermQueryAdd
(
mq
,
term
,
QUERY_TERM
);
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
if
(
Search
(
mq
,
result
)
==
0
)
{
std
::
cout
<<
"search one successfully"
<<
std
::
endl
;
}
return
taosArrayGetSize
(
result
);
// assert(taosArrayGetSize(result) == targetSize);
}
void
Debug
()
{
void
Debug
()
{
std
::
cout
<<
"numOfWrite:"
<<
numOfWrite
<<
std
::
endl
;
std
::
cout
<<
"numOfWrite:"
<<
numOfWrite
<<
std
::
endl
;
std
::
cout
<<
"numOfRead:"
<<
numOfRead
<<
std
::
endl
;
std
::
cout
<<
"numOfRead:"
<<
numOfRead
<<
std
::
endl
;
}
}
~
IndexObj
()
{
~
IndexObj
()
{
indexClose
(
idx
);
indexCleanUp
();
indexCleanUp
();
indexClose
(
idx
);
}
}
private:
private:
...
@@ -665,12 +676,13 @@ class IndexObj {
...
@@ -665,12 +676,13 @@ class IndexObj {
class
IndexEnv2
:
public
::
testing
::
Test
{
class
IndexEnv2
:
public
::
testing
::
Test
{
protected:
protected:
virtual
void
SetUp
()
{
virtual
void
SetUp
()
{
tfInit
();
index
=
new
IndexObj
();
index
=
new
IndexObj
();
//
//
}
}
virtual
void
TearDown
()
{
virtual
void
TearDown
()
{
// r
delete
index
;
delete
index
;
tfCleanup
();
}
}
IndexObj
*
index
;
IndexObj
*
index
;
};
};
...
@@ -681,9 +693,9 @@ TEST_F(IndexEnv2, testIndexOpen) {
...
@@ -681,9 +693,9 @@ TEST_F(IndexEnv2, testIndexOpen) {
exit
(
1
);
exit
(
1
);
}
}
int
targetSize
=
1
00
;
int
targetSize
=
2
00
;
{
{
std
::
string
colName
(
"tag1"
),
colVal
(
"Hello
world
"
);
std
::
string
colName
(
"tag1"
),
colVal
(
"Hello"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
colVal
.
c_str
(),
colVal
.
size
());
...
@@ -697,8 +709,8 @@ TEST_F(IndexEnv2, testIndexOpen) {
...
@@ -697,8 +709,8 @@ TEST_F(IndexEnv2, testIndexOpen) {
indexMultiTermDestroy
(
terms
);
indexMultiTermDestroy
(
terms
);
}
}
{
{
size_t
size
=
1
00
;
size_t
size
=
2
00
;
std
::
string
colName
(
"tag1"
),
colVal
(
"hello
world
"
);
std
::
string
colName
(
"tag1"
),
colVal
(
"hello"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
colVal
.
c_str
(),
colVal
.
size
());
...
@@ -713,7 +725,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
...
@@ -713,7 +725,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
}
}
{
{
std
::
string
colName
(
"tag1"
),
colVal
(
"Hello
world
"
);
std
::
string
colName
(
"tag1"
),
colVal
(
"Hello"
);
SIndexMultiTermQuery
*
mq
=
indexMultiTermQueryCreate
(
MUST
);
SIndexMultiTermQuery
*
mq
=
indexMultiTermQueryCreate
(
MUST
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
...
@@ -722,27 +734,39 @@ TEST_F(IndexEnv2, testIndexOpen) {
...
@@ -722,27 +734,39 @@ TEST_F(IndexEnv2, testIndexOpen) {
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
index
->
Search
(
mq
,
result
);
index
->
Search
(
mq
,
result
);
assert
(
taosArrayGetSize
(
result
)
==
targetSize
);
std
::
cout
<<
"target size: "
<<
taosArrayGetSize
(
result
)
<<
std
::
endl
;
// assert(taosArrayGetSize(result) == targetSize);
}
}
}
}
TEST_F
(
IndexEnv2
,
testIndex_CachePut
)
{
TEST_F
(
IndexEnv2
,
testIndex_TrigeFlush
)
{
std
::
string
path
=
"/tmp"
;
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
int
numOfTable
=
100
*
10000
;
index
->
WriteMillonData
(
"tag1"
,
"Hello world"
,
numOfTable
);
int
target
=
index
->
SearchOne
(
"tag1"
,
"Hello world"
);
assert
(
numOfTable
==
target
);
}
}
TEST_F
(
IndexEnv2
,
testIndex_serarch_cache_and_tfile
)
{
TEST_F
(
IndexEnv2
,
testIndexr_TFilePut
)
{
std
::
string
path
=
"/tmp"
;
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
}
}
TEST_F
(
IndexEnv2
,
testIndex_
CacheSearch
)
{
TEST_F
(
IndexEnv2
,
testIndex_
multi_thread_write
)
{
std
::
string
path
=
"/tmp"
;
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
}
}
TEST_F
(
IndexEnv2
,
testIndex_
TFileSearch
)
{
TEST_F
(
IndexEnv2
,
testIndex_
multi_thread_read
)
{
std
::
string
path
=
"/tmp"
;
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
}
TEST_F
(
IndexEnv2
,
testIndex_restart
)
{
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
TEST_F
(
IndexEnv2
,
testIndex_performance
)
{
std
::
string
path
=
"/tmp"
;
if
(
index
->
Init
(
path
)
!=
0
)
{}
}
}
TEST_F
(
IndexEnv2
,
testIndexMultiTag
)
{}
source/libs/qworker/inc/qworkerInt.h
浏览文件 @
8ecd7a56
...
@@ -106,11 +106,11 @@ typedef struct SQWorkerMgmt {
...
@@ -106,11 +106,11 @@ typedef struct SQWorkerMgmt {
if (QW_READ == (type)) { \
if (QW_READ == (type)) { \
if ((*(_lock)) < 0) assert(0); \
if ((*(_lock)) < 0) assert(0); \
taosRLockLatch(_lock); \
taosRLockLatch(_lock); \
qDebug("RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("
QW
RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} else { \
} else { \
if ((*(_lock)) < 0) assert(0); \
if ((*(_lock)) < 0) assert(0); \
taosWLockLatch(_lock); \
taosWLockLatch(_lock); \
qDebug("WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("
QW
WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} \
} \
} while (0)
} while (0)
...
@@ -118,11 +118,11 @@ typedef struct SQWorkerMgmt {
...
@@ -118,11 +118,11 @@ typedef struct SQWorkerMgmt {
if (QW_READ == (type)) { \
if (QW_READ == (type)) { \
if ((*(_lock)) <= 0) assert(0); \
if ((*(_lock)) <= 0) assert(0); \
taosRUnLockLatch(_lock); \
taosRUnLockLatch(_lock); \
qDebug("RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("
QW
RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} else { \
} else { \
if ((*(_lock)) <= 0) assert(0); \
if ((*(_lock)) <= 0) assert(0); \
taosWUnLockLatch(_lock); \
taosWUnLockLatch(_lock); \
qDebug("WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("
QW
WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
} \
} \
} while (0)
} while (0)
...
...
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
...
@@ -182,10 +182,15 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_CFG, "Invalid dnode cfg")
...
@@ -182,10 +182,15 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_CFG, "Invalid dnode cfg")
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DNODE_EP
,
"Invalid dnode end point"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DNODE_EP
,
"Invalid dnode end point"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DNODE_ID
,
"Invalid dnode id"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DNODE_ID
,
"Invalid dnode id"
)
// mnode-
m
node
// mnode-node
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MNODE_ALREADY_EXIST
,
"Mnode already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MNODE_ALREADY_EXIST
,
"Mnode already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MNODE_NOT_EXIST
,
"Mnode not there"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_MNODE_NOT_EXIST
,
"Mnode not there"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOO_MANY_MNODES
,
"Too many mnodes"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_QNODE_ALREADY_EXIST
,
"Qnode already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_QNODE_NOT_EXIST
,
"Qnode not there"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_SNODE_ALREADY_EXIST
,
"Snode already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_SNODE_NOT_EXIST
,
"Snode not there"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_BNODE_ALREADY_EXIST
,
"Bnode already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_BNODE_NOT_EXIST
,
"Bnode not there"
)
// mnode-acct
// mnode-acct
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_ACCT_ALREADY_EXIST
,
"Account already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_ACCT_ALREADY_EXIST
,
"Account already exists"
)
...
...
source/util/src/thash.c
浏览文件 @
8ecd7a56
...
@@ -362,7 +362,7 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo
...
@@ -362,7 +362,7 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo
return
data
;
return
data
;
}
}
void
*
taosHashGetClone
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
d
)
{
void
*
taosHashGetClone
Impl
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
d
,
bool
acquire
)
{
if
(
taosHashTableEmpty
(
pHashObj
)
||
keyLen
==
0
||
key
==
NULL
)
{
if
(
taosHashTableEmpty
(
pHashObj
)
||
keyLen
==
0
||
key
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -404,6 +404,10 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
...
@@ -404,6 +404,10 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
memcpy
(
d
,
GET_HASH_NODE_DATA
(
pNode
),
pNode
->
dataLen
);
memcpy
(
d
,
GET_HASH_NODE_DATA
(
pNode
),
pNode
->
dataLen
);
}
}
if
(
acquire
)
{
pNode
->
count
++
;
}
data
=
GET_HASH_NODE_DATA
(
pNode
);
data
=
GET_HASH_NODE_DATA
(
pNode
);
}
}
...
@@ -415,6 +419,15 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
...
@@ -415,6 +419,15 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
return
data
;
return
data
;
}
}
void
*
taosHashGetClone
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
d
)
{
return
taosHashGetCloneImpl
(
pHashObj
,
key
,
keyLen
,
d
,
false
);
}
void
*
taosHashAcquire
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
)
{
return
taosHashGetCloneImpl
(
pHashObj
,
key
,
keyLen
,
NULL
,
true
);
}
int32_t
taosHashRemove
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
/*, void *data, size_t dsize*/
)
{
int32_t
taosHashRemove
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
/*, void *data, size_t dsize*/
)
{
if
(
pHashObj
==
NULL
||
taosHashTableEmpty
(
pHashObj
))
{
if
(
pHashObj
==
NULL
||
taosHashTableEmpty
(
pHashObj
))
{
return
-
1
;
return
-
1
;
...
@@ -919,3 +932,9 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) {
...
@@ -919,3 +932,9 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) {
__rd_unlock
(
&
pHashObj
->
lock
,
pHashObj
->
type
);
__rd_unlock
(
&
pHashObj
->
lock
,
pHashObj
->
type
);
}
}
void
taosHashRelease
(
SHashObj
*
pHashObj
,
void
*
p
)
{
taosHashCancelIterate
(
pHashObj
,
p
);
}
source/util/test/CMakeLists.txt
浏览文件 @
8ecd7a56
...
@@ -13,17 +13,22 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
...
@@ -13,17 +13,22 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
LIST
(
REMOVE_ITEM SOURCE_LIST
${
CMAKE_CURRENT_SOURCE_DIR
}
/trefTest.c
)
LIST
(
REMOVE_ITEM SOURCE_LIST
${
CMAKE_CURRENT_SOURCE_DIR
}
/trefTest.c
)
ADD_EXECUTABLE
(
utilTest
${
SOURCE_LIST
}
)
ADD_EXECUTABLE
(
utilTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
utilTest tutil common os gtest pthread gcov
)
TARGET_LINK_LIBRARIES
(
utilTest util common os gtest pthread gcov
)
LIST
(
REMOVE_ITEM SOURCE_LIST
${
CMAKE_CURRENT_SOURCE_DIR
}
/cacheTest.cpp
)
LIST
(
APPEND SOURCE_LIST
${
CMAKE_CURRENT_SOURCE_DIR
}
/hashTest.cpp
)
ADD_EXECUTABLE
(
hashTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
hashTest util common os gtest pthread gcov
)
LIST
(
APPEND BIN_SRC
${
CMAKE_CURRENT_SOURCE_DIR
}
/trefTest.c
)
LIST
(
APPEND BIN_SRC
${
CMAKE_CURRENT_SOURCE_DIR
}
/trefTest.c
)
ADD_EXECUTABLE
(
trefTest
${
BIN_SRC
}
)
ADD_EXECUTABLE
(
trefTest
${
BIN_SRC
}
)
TARGET_LINK_LIBRARIES
(
trefTest common
t
util
)
TARGET_LINK_LIBRARIES
(
trefTest common util
)
ENDIF
()
ENDIF
()
#IF (TD_LINUX)
#IF (TD_LINUX)
# ADD_EXECUTABLE(trefTest ./trefTest.c)
# ADD_EXECUTABLE(trefTest ./trefTest.c)
# TARGET_LINK_LIBRARIES(trefTest
t
util common)
# TARGET_LINK_LIBRARIES(trefTest util common)
#ENDIF ()
#ENDIF ()
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/util/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/util/inc
)
...
...
source/util/test/hashTest.cpp
浏览文件 @
8ecd7a56
...
@@ -4,10 +4,15 @@
...
@@ -4,10 +4,15 @@
#include <taosdef.h>
#include <taosdef.h>
#include <iostream>
#include <iostream>
#include "hash.h"
#include "
t
hash.h"
#include "taos.h"
#include "taos.h"
namespace
{
namespace
{
typedef
struct
TESTSTRUCT
{
char
*
p
;
}
TESTSTRUCT
;
// the simple test code for basic operations
// the simple test code for basic operations
void
simpleTest
()
{
void
simpleTest
()
{
SHashObj
*
hashTable
=
(
SHashObj
*
)
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_ENTRY_LOCK
);
SHashObj
*
hashTable
=
(
SHashObj
*
)
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_ENTRY_LOCK
);
...
@@ -141,6 +146,52 @@ void invalidOperationTest() {
...
@@ -141,6 +146,52 @@ void invalidOperationTest() {
}
}
void
acquireRleaseTest
()
{
SHashObj
*
hashTable
=
(
SHashObj
*
)
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_ENTRY_LOCK
);
ASSERT_EQ
(
taosHashGetSize
(
hashTable
),
0
);
int32_t
key
=
2
;
int32_t
code
=
0
;
int32_t
num
=
0
;
TESTSTRUCT
data
=
{
0
};
char
*
str1
=
"abcdefg"
;
char
*
str2
=
"aaaaaaa"
;
char
*
str3
=
"123456789"
;
data
.
p
=
(
char
*
)
malloc
(
10
);
strcpy
(
data
.
p
,
str1
);
code
=
taosHashPut
(
hashTable
,
&
key
,
sizeof
(
key
),
&
data
,
sizeof
(
data
));
ASSERT_EQ
(
code
,
0
);
TESTSTRUCT
*
pdata
=
(
TESTSTRUCT
*
)
taosHashAcquire
(
hashTable
,
&
key
,
sizeof
(
key
));
ASSERT_TRUE
(
pdata
!=
nullptr
);
ASSERT_TRUE
(
strcmp
(
pdata
->
p
,
str1
)
==
0
);
code
=
taosHashRemove
(
hashTable
,
&
key
,
sizeof
(
key
));
ASSERT_EQ
(
code
,
0
);
ASSERT_TRUE
(
strcmp
(
pdata
->
p
,
str1
)
==
0
);
num
=
taosHashGetSize
(
hashTable
);
ASSERT_EQ
(
num
,
1
);
strcpy
(
pdata
->
p
,
str3
);
data
.
p
=
(
char
*
)
malloc
(
10
);
strcpy
(
data
.
p
,
str2
);
code
=
taosHashPut
(
hashTable
,
&
key
,
sizeof
(
key
),
&
data
,
sizeof
(
data
));
ASSERT_EQ
(
code
,
0
);
num
=
taosHashGetSize
(
hashTable
);
ASSERT_EQ
(
num
,
2
);
printf
(
"%s,expect:%s"
,
pdata
->
p
,
str3
);
ASSERT_TRUE
(
strcmp
(
pdata
->
p
,
str3
)
==
0
);
taosHashRelease
(
hashTable
,
pdata
);
num
=
taosHashGetSize
(
hashTable
);
ASSERT_EQ
(
num
,
1
);
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
...
@@ -153,4 +204,5 @@ TEST(testCase, hashTest) {
...
@@ -153,4 +204,5 @@ TEST(testCase, hashTest) {
stringKeyTest
();
stringKeyTest
();
noLockPerformanceTest
();
noLockPerformanceTest
();
multithreadsTest
();
multithreadsTest
();
acquireRleaseTest
();
}
}
tests/script/general/db/basic1.sim
浏览文件 @
8ecd7a56
...
@@ -59,9 +59,29 @@ if $data03 != 0 then
...
@@ -59,9 +59,29 @@ if $data03 != 0 then
endi
endi
print =============== show vgroups
print =============== show vgroups
sql show databases
if $rows != 1 then
return -1
endi
sql_error use d1
sql use d4
sql use d4
sql show vgroups
if $rows == 0 then
if $rows != 2 then
return -1
endi
print =============== show dnodes
sql show dnodes
if $data00 != 1 then
return -1
endi
if $data02 != 2 then
return -1
return -1
endi
endi
...
...
tests/script/general/table/basic1.sim
浏览文件 @
8ecd7a56
...
@@ -23,7 +23,7 @@ endi
...
@@ -23,7 +23,7 @@ endi
print $data00 $data01 $data02
print $data00 $data01 $data02
sql create table st2 (ts timestamp, i float) tags (j
big
int)
sql create table st2 (ts timestamp, i float) tags (j int)
sql show stables
sql show stables
if $rows != 2 then
if $rows != 2 then
return -1
return -1
...
@@ -39,15 +39,14 @@ if $rows != 1 then
...
@@ -39,15 +39,14 @@ if $rows != 1 then
return -1
return -1
endi
endi
print -->
print $data00 $data01 $data02
print $data00 $data01 $data02
print $data10 $data11 $data12
print $data10 $data11 $data12
return
print =============== create child table
print =============== create child table
sql create table c1 using st tags(1)
sql create table c1 using st tags(1)
sql create table c2 using st tags(2)
sql create table c2 using st tags(2)
return
sql show tables
sql show tables
if $rows != 2 then
if $rows != 2 then
return -1
return -1
...
...
tests/script/sh/exec.sh
浏览文件 @
8ecd7a56
...
@@ -17,7 +17,7 @@ OS_TYPE=`$UNAME_BIN`
...
@@ -17,7 +17,7 @@ OS_TYPE=`$UNAME_BIN`
NODE_NAME
=
NODE_NAME
=
EXEC_OPTON
=
EXEC_OPTON
=
CLEAR_OPTION
=
"false"
CLEAR_OPTION
=
"false"
while
getopts
"n:s:u:x:c
t
"
arg
while
getopts
"n:s:u:x:c
v
"
arg
do
do
case
$arg
in
case
$arg
in
n
)
n
)
...
@@ -29,7 +29,7 @@ do
...
@@ -29,7 +29,7 @@ do
c
)
c
)
CLEAR_OPTION
=
"clear"
CLEAR_OPTION
=
"clear"
;;
;;
t
)
v
)
SHELL_OPTION
=
"true"
SHELL_OPTION
=
"true"
;;
;;
u
)
u
)
...
...
tests/script/tmp/dnodes.sim
浏览文件 @
8ecd7a56
...
@@ -2,20 +2,19 @@ system sh/stop_dnodes.sh
...
@@ -2,20 +2,19 @@ system sh/stop_dnodes.sh
############## config parameter #####################
############## config parameter #####################
$node1 = 192.168.
101.174
$node1 = 192.168.
0.201
$node2 = 192.168.0.202
$node2 = 192.168.0.202
$node
2
= 192.168.0.203
$node
3
= 192.168.0.203
$node
3
= 192.168.0.204
$node
4
= 192.168.0.204
$first = 1
$num = 5
$self = $node1
$self = $node1
$num = 25
############### deploy firstEp #####################
############### deploy firstEp #####################
$firstEp = $node1 . :7100
$firstEp = $node1 . :7100
$firstPort = 7100
$firstPort = 7100
if $
first ==
1 then
if $
self == $node
1 then
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c firstEp -v $firstEp
system sh/cfg.sh -n dnode1 -c firstEp -v $firstEp
system sh/cfg.sh -n dnode1 -c secondEp -v $firstEp
system sh/cfg.sh -n dnode1 -c secondEp -v $firstEp
...
@@ -28,7 +27,7 @@ if $first == 1 then
...
@@ -28,7 +27,7 @@ if $first == 1 then
$i = 0
$i = 0
while $i < $num
while $i < $num
$port = $i * 100
$port = $i * 100
$port = $port + 8
0
00
$port = $port + 8
1
00
$i = $i + 1
$i = $i + 1
sql create dnode $node1 port $port
sql create dnode $node1 port $port
endw
endw
...
@@ -36,7 +35,7 @@ if $first == 1 then
...
@@ -36,7 +35,7 @@ if $first == 1 then
$i = 0
$i = 0
while $i < $num
while $i < $num
$port = $i * 100
$port = $i * 100
$port = $port + 8
0
00
$port = $port + 8
1
00
$i = $i + 1
$i = $i + 1
sql create dnode $node2 port $port
sql create dnode $node2 port $port
endw
endw
...
@@ -44,7 +43,7 @@ if $first == 1 then
...
@@ -44,7 +43,7 @@ if $first == 1 then
$i = 0
$i = 0
while $i < $num
while $i < $num
$port = $i * 100
$port = $i * 100
$port = $port + 8
0
00
$port = $port + 8
1
00
$i = $i + 1
$i = $i + 1
sql create dnode $node3 port $port
sql create dnode $node3 port $port
endw
endw
...
@@ -52,7 +51,7 @@ if $first == 1 then
...
@@ -52,7 +51,7 @@ if $first == 1 then
$i = 0
$i = 0
while $i < $num
while $i < $num
$port = $i * 100
$port = $i * 100
$port = $port + 8
0
00
$port = $port + 8
1
00
$i = $i + 1
$i = $i + 1
sql create dnode $node4 port $port
sql create dnode $node4 port $port
endw
endw
...
@@ -64,7 +63,7 @@ $i = 0
...
@@ -64,7 +63,7 @@ $i = 0
while $i < $num
while $i < $num
$index = $i + 80
$index = $i + 80
$port = $i * 100
$port = $i * 100
$port = $port + 8
0
00
$port = $port + 8
1
00
$dnodename = dnode . $index
$dnodename = dnode . $index
$i = $i + 1
$i = $i + 1
...
@@ -74,5 +73,5 @@ while $i < $num
...
@@ -74,5 +73,5 @@ while $i < $num
system sh/cfg.sh -n $dnodename -c fqdn -v $self
system sh/cfg.sh -n $dnodename -c fqdn -v $self
system sh/cfg.sh -n $dnodename -c serverPort -v $port
system sh/cfg.sh -n $dnodename -c serverPort -v $port
#
system sh/exec.sh -n $dnodename -s start
system sh/exec.sh -n $dnodename -s start
endw
endw
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录