Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Rattenking
TDengine
提交
90e23fb8
T
TDengine
项目概览
Rattenking
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
90e23fb8
编写于
7月 26, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-998]
上级
eb169e32
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
295 addition
and
11 deletion
+295
-11
src/inc/taosdef.h
src/inc/taosdef.h
+1
-0
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-0
src/mnode/inc/mnodeCluster.h
src/mnode/inc/mnodeCluster.h
+38
-0
src/mnode/inc/mnodeDef.h
src/mnode/inc/mnodeDef.h
+8
-0
src/mnode/inc/mnodeSdb.h
src/mnode/inc/mnodeSdb.h
+10
-9
src/mnode/src/mnodeAcct.c
src/mnode/src/mnodeAcct.c
+2
-2
src/mnode/src/mnodeCluster.c
src/mnode/src/mnodeCluster.c
+229
-0
src/mnode/src/mnodeMain.c
src/mnode/src/mnodeMain.c
+2
-0
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+2
-0
src/mnode/src/mnodeShow.c
src/mnode/src/mnodeShow.c
+2
-0
未找到文件。
src/inc/taosdef.h
浏览文件 @
90e23fb8
...
...
@@ -377,6 +377,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_ORDER_ASC 1
#define TSDB_ORDER_DESC 2
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE 10
...
...
src/inc/taosmsg.h
浏览文件 @
90e23fb8
...
...
@@ -139,6 +139,7 @@ enum _mgmt_table {
TSDB_MGMT_TABLE_GRANTS
,
TSDB_MGMT_TABLE_VNODES
,
TSDB_MGMT_TABLE_STREAMTABLES
,
TSDB_MGMT_TABLE_CLUSTER
,
TSDB_MGMT_TABLE_MAX
,
};
...
...
src/mnode/inc/mnodeCluster.h
0 → 100644
浏览文件 @
90e23fb8
/*
* 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 TDENGINE_MNODE_CLUSTER_H
#define TDENGINE_MNODE_CLUSTER_H
#ifdef __cplusplus
extern
"C"
{
#endif
struct
SClusterObj
;
int32_t
mnodeInitCluster
();
void
mnodeCleanupCluster
();
int32_t
mnodeGetClusterId
();
void
mnodeUpdateClusterId
();
void
*
mnodeGetCluster
(
int32_t
clusterId
);
void
*
mnodeGetNextCluster
(
void
*
pIter
,
struct
SClusterObj
**
pCluster
);
void
mnodeIncClusterRef
(
struct
SClusterObj
*
pCluster
);
void
mnodeDecClusterRef
(
struct
SClusterObj
*
pCluster
);
#ifdef __cplusplus
}
#endif
#endif
src/mnode/inc/mnodeDef.h
浏览文件 @
90e23fb8
...
...
@@ -36,6 +36,14 @@ struct define notes:
3. The fields behind the updataEnd field can be changed;
*/
typedef
struct
SClusterObj
{
int32_t
clusterId
;
int64_t
createdTime
;
int8_t
reserved
[
36
];
int8_t
updateEnd
[
4
];
int32_t
refCount
;
}
SClusterObj
;
typedef
struct
SDnodeObj
{
int32_t
dnodeId
;
int32_t
openVnodes
;
...
...
src/mnode/inc/mnodeSdb.h
浏览文件 @
90e23fb8
...
...
@@ -23,15 +23,16 @@ extern "C" {
struct
SMnodeMsg
;
typedef
enum
{
SDB_TABLE_DNODE
=
0
,
SDB_TABLE_MNODE
=
1
,
SDB_TABLE_ACCOUNT
=
2
,
SDB_TABLE_USER
=
3
,
SDB_TABLE_DB
=
4
,
SDB_TABLE_VGROUP
=
5
,
SDB_TABLE_STABLE
=
6
,
SDB_TABLE_CTABLE
=
7
,
SDB_TABLE_MAX
=
8
SDB_TABLE_CLUSTER
=
0
,
SDB_TABLE_DNODE
=
1
,
SDB_TABLE_MNODE
=
2
,
SDB_TABLE_ACCOUNT
=
3
,
SDB_TABLE_USER
=
4
,
SDB_TABLE_DB
=
5
,
SDB_TABLE_VGROUP
=
6
,
SDB_TABLE_STABLE
=
7
,
SDB_TABLE_CTABLE
=
8
,
SDB_TABLE_MAX
=
9
}
ESdbTable
;
typedef
enum
{
...
...
src/mnode/src/mnodeAcct.c
浏览文件 @
90e23fb8
...
...
@@ -64,7 +64,7 @@ static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeAc
tion
ActionEncode
(
SSdbOper
*
pOper
)
{
static
int32_t
mnodeAc
ct
ActionEncode
(
SSdbOper
*
pOper
)
{
SAcctObj
*
pAcct
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pAcct
,
tsAcctUpdateSize
);
pOper
->
rowSize
=
tsAcctUpdateSize
;
...
...
@@ -109,7 +109,7 @@ int32_t mnodeInitAccts() {
.
insertFp
=
mnodeAcctActionInsert
,
.
deleteFp
=
mnodeAcctActionDelete
,
.
updateFp
=
mnodeAcctActionUpdate
,
.
encodeFp
=
mnodeAc
tion
ActionEncode
,
.
encodeFp
=
mnodeAc
ct
ActionEncode
,
.
decodeFp
=
mnodeAcctActionDecode
,
.
destroyFp
=
mnodeAcctActionDestroy
,
.
restoredFp
=
mnodeAcctActionRestored
...
...
src/mnode/src/mnodeCluster.c
0 → 100644
浏览文件 @
90e23fb8
/*
* 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 "os.h"
#include "taoserror.h"
#include "ttime.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeCluster.h"
#include "mnodeSdb.h"
#include "mnodeShow.h"
#include "tglobal.h"
static
void
*
tsClusterSdb
=
NULL
;
static
int32_t
tsClusterUpdateSize
;
static
int32_t
tsClusterId
;
static
int32_t
mnodeCreateCluster
();
static
int32_t
mnodeGetClusterMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveClusters
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeClusterActionDestroy
(
SSdbOper
*
pOper
)
{
tfree
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeClusterActionInsert
(
SSdbOper
*
pOper
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeClusterActionDelete
(
SSdbOper
*
pOper
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeClusterActionUpdate
(
SSdbOper
*
pOper
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeClusterActionEncode
(
SSdbOper
*
pOper
)
{
SClusterObj
*
pCluster
=
pOper
->
pObj
;
memcpy
(
pOper
->
rowData
,
pCluster
,
tsClusterUpdateSize
);
pOper
->
rowSize
=
tsClusterUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeClusterActionDecode
(
SSdbOper
*
pOper
)
{
SClusterObj
*
pCluster
=
(
SClusterObj
*
)
calloc
(
1
,
sizeof
(
SClusterObj
));
if
(
pCluster
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pCluster
,
pOper
->
rowData
,
tsClusterUpdateSize
);
pOper
->
pObj
=
pCluster
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeClusterActionRestored
()
{
int32_t
numOfRows
=
sdbGetNumOfRows
(
tsClusterSdb
);
if
(
numOfRows
<=
0
&&
dnodeIsFirstDeploy
())
{
mInfo
(
"dnode first deploy, create cluster"
);
int32_t
code
=
mnodeCreateCluster
();
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"failed to create cluster, reason:%s"
,
tstrerror
(
code
));
return
code
;
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
mnodeInitCluster
()
{
SClusterObj
tObj
;
tsClusterUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableDesc
=
{
.
tableId
=
SDB_TABLE_CLUSTER
,
.
tableName
=
"cluster"
,
.
hashSessions
=
TSDB_DEFAULT_CLUSTER_HASH_SIZE
,
.
maxRowSize
=
tsClusterUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_INT
,
.
insertFp
=
mnodeClusterActionInsert
,
.
deleteFp
=
mnodeClusterActionDelete
,
.
updateFp
=
mnodeClusterActionUpdate
,
.
encodeFp
=
mnodeClusterActionEncode
,
.
decodeFp
=
mnodeClusterActionDecode
,
.
destroyFp
=
mnodeClusterActionDestroy
,
.
restoredFp
=
mnodeClusterActionRestored
};
tsClusterSdb
=
sdbOpenTable
(
&
tableDesc
);
if
(
tsClusterSdb
==
NULL
)
{
mError
(
"table:%s, failed to create hash"
,
tableDesc
.
tableName
);
return
-
1
;
}
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_CLUSTER
,
mnodeGetClusterMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_CLUSTER
,
mnodeRetrieveClusters
);
mDebug
(
"table:%s, hash is created"
,
tableDesc
.
tableName
);
return
TSDB_CODE_SUCCESS
;
}
void
mnodeCleanupCluster
()
{
sdbCloseTable
(
tsClusterSdb
);
tsClusterSdb
=
NULL
;
}
void
*
mnodeGetCluster
(
int32_t
clusterId
)
{
return
sdbGetRow
(
tsClusterSdb
,
&
clusterId
);
}
void
*
mnodeGetNextCluster
(
void
*
pIter
,
SClusterObj
**
pCluster
)
{
return
sdbFetchRow
(
tsClusterSdb
,
pIter
,
(
void
**
)
pCluster
);
}
void
mnodeIncClusterRef
(
SClusterObj
*
pCluster
)
{
sdbIncRef
(
tsClusterSdb
,
pCluster
);
}
void
mnodeDecClusterRef
(
SClusterObj
*
pCluster
)
{
sdbDecRef
(
tsClusterSdb
,
pCluster
);
}
static
int32_t
mnodeCreateCluster
()
{
int32_t
numOfClusters
=
sdbGetNumOfRows
(
tsClusterSdb
);
if
(
numOfClusters
!=
0
)
return
TSDB_CODE_SUCCESS
;
SClusterObj
*
pCluster
=
malloc
(
sizeof
(
SClusterObj
));
memset
(
pCluster
,
0
,
sizeof
(
SClusterObj
));
pCluster
->
createdTime
=
taosGetTimestampMs
();
pCluster
->
clusterId
=
(
pCluster
->
createdTime
>>
32
)
&
(
pCluster
->
createdTime
)
&
(
*
(
int32_t
*
)
tsFirst
);
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsClusterSdb
,
.
pObj
=
pCluster
,
};
return
sdbInsertRow
(
&
oper
);
}
int32_t
mnodeGetClusterId
()
{
return
tsClusterId
;
}
void
mnodeUpdateClusterId
()
{
SClusterObj
*
pCluster
=
NULL
;
mnodeGetNextCluster
(
NULL
,
&
pCluster
);
if
(
pCluster
!=
NULL
)
{
tsClusterId
=
pCluster
->
clusterId
;
mnodeDecClusterRef
(
pCluster
);
mInfo
(
"cluster id is %d"
,
tsClusterId
);
}
else
{
//assert(false);
}
}
static
int32_t
mnodeGetClusterMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"clusterId"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
tableId
,
"show cluster"
);
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
=
1
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
return
0
;
}
static
int32_t
mnodeRetrieveClusters
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
char
*
pWrite
;
SClusterObj
*
pCluster
=
NULL
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
mnodeGetNextCluster
(
pShow
->
pIter
,
&
pCluster
);
if
(
pCluster
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pCluster
->
clusterId
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pCluster
->
createdTime
;
cols
++
;
mnodeDecClusterRef
(
pCluster
);
numOfRows
++
;
}
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
src/mnode/src/mnodeMain.c
浏览文件 @
90e23fb8
...
...
@@ -32,6 +32,7 @@
#include "mnodeVgroup.h"
#include "mnodeUser.h"
#include "mnodeTable.h"
#include "mnodeCluster.h"
#include "mnodeShow.h"
#include "mnodeProfile.h"
...
...
@@ -46,6 +47,7 @@ static bool tsMgmtIsRunning = false;
static
const
SMnodeComponent
tsMnodeComponents
[]
=
{
{
"profile"
,
mnodeInitProfile
,
mnodeCleanupProfile
},
{
"cluster"
,
mnodeInitCluster
,
mnodeCleanupCluster
},
{
"accts"
,
mnodeInitAccts
,
mnodeCleanupAccts
},
{
"users"
,
mnodeInitUsers
,
mnodeCleanupUsers
},
{
"dnodes"
,
mnodeInitDnodes
,
mnodeCleanupDnodes
},
...
...
src/mnode/src/mnodeSdb.c
浏览文件 @
90e23fb8
...
...
@@ -29,6 +29,7 @@
#include "mnodeInt.h"
#include "mnodeMnode.h"
#include "mnodeDnode.h"
#include "mnodeCluster.h"
#include "mnodeSdb.h"
#define SDB_TABLE_LEN 12
...
...
@@ -214,6 +215,7 @@ void sdbUpdateMnodeRoles() {
}
}
mnodeUpdateClusterId
();
mnodeUpdateMnodeEpSet
();
}
...
...
src/mnode/src/mnodeShow.c
浏览文件 @
90e23fb8
...
...
@@ -103,6 +103,8 @@ static char *mnodeGetShowType(int32_t showType) {
case
TSDB_MGMT_TABLE_SCORES
:
return
"show scores"
;
case
TSDB_MGMT_TABLE_GRANTS
:
return
"show grants"
;
case
TSDB_MGMT_TABLE_VNODES
:
return
"show vnodes"
;
case
TSDB_MGMT_TABLE_CLUSTER
:
return
"show clusters"
;
case
TSDB_MGMT_TABLE_STREAMTABLES
:
return
"show streamtables"
;
default:
return
"undefined"
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录