Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2f1bb281
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2f1bb281
编写于
11月 21, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add daemon
上级
7f1a4b9c
变更
22
展开全部
隐藏空白更改
内联
并排
Showing
22 changed file
with
792 addition
and
314 deletion
+792
-314
include/dnode/mgmt/dnode.h
include/dnode/mgmt/dnode.h
+46
-0
include/dnode/mnode/mnode.h
include/dnode/mnode/mnode.h
+117
-30
include/dnode/vnode/vnode.h
include/dnode/vnode/vnode.h
+5
-5
source/dnode/CMakeLists.txt
source/dnode/CMakeLists.txt
+1
-1
source/dnode/mgmt/CMakeLists.txt
source/dnode/mgmt/CMakeLists.txt
+2
-16
source/dnode/mgmt/daemon/CMakeLists.txt
source/dnode/mgmt/daemon/CMakeLists.txt
+8
-0
source/dnode/mgmt/daemon/src/daemon.c
source/dnode/mgmt/daemon/src/daemon.c
+14
-7
source/dnode/mgmt/impl/CMakeLists.txt
source/dnode/mgmt/impl/CMakeLists.txt
+16
-0
source/dnode/mgmt/impl/inc/dnodeDnode.h
source/dnode/mgmt/impl/inc/dnodeDnode.h
+3
-3
source/dnode/mgmt/impl/inc/dnodeInt.h
source/dnode/mgmt/impl/inc/dnodeInt.h
+97
-0
source/dnode/mgmt/impl/inc/dnodeMnode.h
source/dnode/mgmt/impl/inc/dnodeMnode.h
+0
-0
source/dnode/mgmt/impl/inc/dnodeTransport.h
source/dnode/mgmt/impl/inc/dnodeTransport.h
+2
-2
source/dnode/mgmt/impl/inc/dnodeVnodes.h
source/dnode/mgmt/impl/inc/dnodeVnodes.h
+0
-0
source/dnode/mgmt/impl/src/dnodeDnode.c
source/dnode/mgmt/impl/src/dnodeDnode.c
+139
-145
source/dnode/mgmt/impl/src/dnodeInt.c
source/dnode/mgmt/impl/src/dnodeInt.c
+260
-0
source/dnode/mgmt/impl/src/dnodeMnode.c
source/dnode/mgmt/impl/src/dnodeMnode.c
+19
-13
source/dnode/mgmt/impl/src/dnodeTransport.c
source/dnode/mgmt/impl/src/dnodeTransport.c
+6
-6
source/dnode/mgmt/impl/src/dnodeVnodes.c
source/dnode/mgmt/impl/src/dnodeVnodes.c
+1
-1
source/dnode/mnode/impl/inc/mnodeInt.h
source/dnode/mnode/impl/inc/mnodeInt.h
+11
-10
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+43
-73
source/dnode/mnode/impl/src/mnodeAuth.c
source/dnode/mnode/impl/src/mnodeAuth.c
+1
-1
source/dnode/mnode/impl/src/mnodeTelem.c
source/dnode/mnode/impl/src/mnodeTelem.c
+1
-1
未找到文件。
include/dnode/mgmt/dnode.h
0 → 100644
浏览文件 @
2f1bb281
/*
* 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_DNODE_H_
#define _TD_DNODE_H_
#ifdef __cplusplus
extern
"C"
{
#endif
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef
struct
SDnode
SDnode
;
/* ------------------------ SDnode ------------------------ */
/**
* @brief Initialize and start the dnode.
*
* @param cfgPath Config file path.
* @return SDnode* The dnode object.
*/
SDnode
*
dnodeInit
(
const
char
*
cfgPath
);
/**
* @brief Stop and cleanup dnode.
*
* @param pDnode The dnode object to close.
*/
void
dnodeCleanup
(
SDnode
*
pDnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_DNODE_H_*/
include/dnode/mnode/mnode.h
浏览文件 @
2f1bb281
...
...
@@ -20,17 +20,16 @@
extern
"C"
{
#endif
typedef
enum
{
MN_MSG_TYPE_WRITE
=
1
,
MN_MSG_TYPE_APPLY
,
MN_MSG_TYPE_SYNC
,
MN_MSG_TYPE_READ
}
EMnMsgType
;
/* ------------------------ TYPES EXPOSED ------------------------ */
typedef
struct
SDnode
SDnode
;
typedef
struct
SMnode
SMnode
;
typedef
struct
SMnodeMsg
SMnodeMsg
;
typedef
void
(
*
SendMsgToDnodeFp
)(
SDnode
*
pDnode
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToMnodeFp
)(
SDnode
*
pDnode
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendRedirectMsgFp
)(
SDnode
*
pDnode
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
typedef
int32_t
(
*
PutMsgToMnodeQFp
)(
SDnode
*
pDnode
,
SMnodeMsg
*
pMsg
);
typedef
struct
{
int8_t
replica
;
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
}
SMnodeCfg
;
typedef
struct
{
typedef
struct
SMnodeLoad
{
int64_t
numOfDnode
;
int64_t
numOfMnode
;
int64_t
numOfVgroup
;
...
...
@@ -43,38 +42,126 @@ typedef struct {
int64_t
compStorage
;
}
SMnodeLoad
;
typedef
struct
SMnode
SMnode
;
typedef
struct
SServer
SServer
;
typedef
void
(
*
SendMsgToDnodeFp
)(
SServer
*
pServer
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToMnodeFp
)(
SServer
*
pServer
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendRedirectMsgFp
)(
SServer
*
pServer
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
typedef
int32_t
(
*
PutMsgToMnodeQFp
)(
SServer
*
pServer
,
SMnodeMsg
*
pMsg
);
typedef
struct
{
int32_t
dnodeId
;
int64_t
clusterId
;
int8_t
replica
;
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
struct
SServer
*
pServer
;
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
SendRedirectMsgFp
sendRedirectMsgFp
;
}
SMnodePara
;
}
SMnodeOptions
;
/* ------------------------ SMnode ------------------------ */
/**
* @brief Open a mnode.
*
* @param path Path of the mnode
* @param pOptions Options of the mnode
* @return SMnode* The mnode object
*/
SMnode
*
mnodeOpen
(
const
char
*
path
,
const
SMnodeOptions
*
pOptions
);
/**
* @brief Close a mnode
*
* @param pMnode The mnode object to close
*/
void
mnodeClose
(
SMnode
*
pMnode
);
/**
* @brief Close a mnode
*
* @param pMnode The mnode object to close
* @param pOptions Options of the mnode
* @return int32_t 0 for success, -1 for failure
*/
int32_t
mnodeAlter
(
SMnode
*
pMnode
,
const
SMnodeOptions
*
pOptions
);
/**
* @brief Drop a mnode.
*
* @param path Path of the mnode.
*/
void
mnodeDestroy
(
const
char
*
path
);
/**
* @brief Get mnode statistics info
*
* @param pMnode The mnode object
* @param pLoad Statistics of the mnode.
* @return int32_t 0 for success, -1 for failure
*/
int32_t
mnodeGetLoad
(
SMnode
*
pMnode
,
SMnodeLoad
*
pLoad
);
SMnode
*
mnodeCreate
(
SMnodePara
para
);
void
mnodeCleanup
();
/**
* @brief Get user authentication info
*
* @param pMnode The mnode object
* @param user
* @param spi
* @param encrypt
* @param secret
* @param ckey
* @return int32_t 0 for success, -1 for failure
*/
int32_t
mnodeRetriveAuth
(
SMnode
*
pMnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
int32_t
mnodeDeploy
(
SMnodeCfg
*
pCfg
);
void
mnodeUnDeploy
();
int32_t
mnodeStart
(
SMnodeCfg
*
pCfg
);
int32_t
mnodeAlter
(
SMnodeCfg
*
pCfg
);
void
mnodeStop
();
/**
* @brief Initialize mnode msg
*
* @param pMnode The mnode object
* @param pMsg The request rpc msg
* @return int32_t The created mnode msg
*/
SMnodeMsg
*
mnodeInitMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pRpcMsg
);
int32_t
mnodeGetLoad
(
SMnodeLoad
*
pLoad
);
int32_t
mnodeRetriveAuth
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
/**
* @brief Cleanup mnode msg
*
* @param pMnode The mnode object
* @param pMsg The request msg
*/
void
mnodeCleanupMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
SMnodeMsg
*
mnodeInitMsg
(
SRpcMsg
*
pRpcMsg
);
void
mnodeCleanupMsg
(
SMnodeMsg
*
pMsg
);
void
mnodeProcessMsg
(
SMnodeMsg
*
pMsg
,
EMnMsgType
msgType
);
/**
* @brief Process the read request
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
*/
void
mnodeProcessReadMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
/**
* @brief Process the write request
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
*/
void
mnodeProcessWriteMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
/**
* @brief Process the sync request
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
*/
void
mnodeProcessSyncMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
/**
* @brief Process the apply request
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
*/
void
mnodeProcessApplyMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
include/dnode/vnode/vnode.h
浏览文件 @
2f1bb281
...
...
@@ -184,11 +184,11 @@ typedef struct {
SRpcMsg
rpcMsg
[];
}
SVnodeMsg
;
typedef
struct
S
Server
SServer
;
typedef
void
(
*
SendMsgToDnodeFp
)(
S
Server
*
pServer
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToMnodeFp
)(
S
Server
*
pServer
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendRedirectMsgFp
)(
S
Server
*
pServer
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
typedef
int32_t
(
*
PutMsgToVnodeQFp
)(
S
Server
*
pServer
,
int32_t
vgId
,
SVnodeMsg
*
pMsg
);
typedef
struct
S
Dnode
SDnode
;
typedef
void
(
*
SendMsgToDnodeFp
)(
S
Dnode
*
pDnode
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToMnodeFp
)(
S
Dnode
*
pDnode
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendRedirectMsgFp
)(
S
Dnode
*
pDnode
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
typedef
int32_t
(
*
PutMsgToVnodeQFp
)(
S
Dnode
*
pDnode
,
int32_t
vgId
,
SVnodeMsg
*
pMsg
);
typedef
struct
{
PutMsgToVnodeQFp
putMsgToApplyQueueFp
;
...
...
source/dnode/CMakeLists.txt
浏览文件 @
2f1bb281
add_subdirectory
(
mnode
)
add_subdirectory
(
vnode
)
add_subdirectory
(
qnode
)
add_subdirectory
(
mgmt
)
add_subdirectory
(
mgmt
)
\ No newline at end of file
source/dnode/mgmt/CMakeLists.txt
浏览文件 @
2f1bb281
aux_source_directory
(
src DNODE_SRC
)
add_executable
(
taosd
${
DNODE_SRC
}
)
target_link_libraries
(
taosd
PUBLIC cjson
PUBLIC mnode
PUBLIC vnode
PUBLIC wal
PUBLIC sync
PUBLIC taos
)
target_include_directories
(
taosd
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/dnode"
private
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
add_subdirectory
(
daemon
)
add_subdirectory
(
impl
)
\ No newline at end of file
source/dnode/mgmt/daemon/CMakeLists.txt
0 → 100644
浏览文件 @
2f1bb281
aux_source_directory
(
src DAEMON_SRC
)
add_executable
(
taosd
${
DAEMON_SRC
}
)
target_link_libraries
(
taosd
PUBLIC dnode
PUBLIC util
PUBLIC os
)
source/dnode/mgmt/
src/dnode
.c
→
source/dnode/mgmt/
daemon/src/daemon
.c
浏览文件 @
2f1bb281
...
...
@@ -14,10 +14,14 @@
*/
#define _DEFAULT_SOURCE
#include "dnodeInt.h"
#include "dnode.h"
#include "os.h"
#include "ulog.h"
static
bool
stop
=
false
;
static
void
sigintHandler
(
int32_t
signum
,
void
*
info
,
void
*
ctx
)
{
stop
=
true
;
}
static
void
setSignalHandler
()
{
taosSetSignal
(
SIGTERM
,
sigintHandler
);
taosSetSignal
(
SIGHUP
,
sigintHandler
);
...
...
@@ -27,20 +31,23 @@ static void setSignalHandler() {
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
setSignalHandler
()
;
const
char
*
path
=
"/etc/taos"
;
int32_t
code
=
dnodeInit
(
);
if
(
code
!=
0
)
{
dInfo
(
"Failed to start TDengine, please check the log at:
%s"
,
tsLogDir
);
SDnode
*
pDnode
=
dnodeInit
(
path
);
if
(
pDnode
==
NULL
)
{
uInfo
(
"Failed to start TDengine, please check the log at
%s"
,
tsLogDir
);
exit
(
EXIT_FAILURE
);
}
uInfo
(
"Started TDengine service successfully."
);
setSignalHandler
();
while
(
!
stop
)
{
taosMsleep
(
100
);
}
d
Info
(
"TDengine is shut down!"
);
dnodeCleanup
();
u
Info
(
"TDengine is shut down!"
);
dnodeCleanup
(
pDnode
);
return
0
;
}
source/dnode/mgmt/impl/CMakeLists.txt
0 → 100644
浏览文件 @
2f1bb281
aux_source_directory
(
src DNODE_SRC
)
add_library
(
dnode
${
DNODE_SRC
}
)
target_link_libraries
(
dnode
PUBLIC cjson
PUBLIC mnode
PUBLIC vnode
PUBLIC wal
PUBLIC sync
PUBLIC taos
)
target_include_directories
(
dnode
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/dnode/mgmt"
private
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
source/dnode/mgmt/inc/dnodeDnode.h
→
source/dnode/mgmt/i
mpl/i
nc/dnodeDnode.h
浏览文件 @
2f1bb281
...
...
@@ -21,8 +21,8 @@ extern "C" {
#endif
#include "dnodeInt.h"
int32_t
dnodeInitDnode
();
void
dnodeCleanupDnode
();
int32_t
dnodeInitDnode
(
SDnode
*
pDnode
);
void
dnodeCleanupDnode
(
SDnode
*
pDnode
);
void
dnodeProcessDnodeMsg
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
int32_t
dnodeGetDnodeId
();
...
...
@@ -30,7 +30,7 @@ int64_t dnodeGetClusterId();
void
dnodeGetDnodeEp
(
int32_t
dnodeId
,
char
*
epstr
,
char
*
fqdn
,
uint16_t
*
port
);
void
dnodeGetMnodeEpSetForPeer
(
SEpSet
*
epSet
);
void
dnodeGetMnodeEpSetForShell
(
SEpSet
*
epSet
);
void
dnodeSendRedirectMsg
(
S
Server
*
pServer
,
SRpcMsg
*
rpcMsg
,
bool
forShell
);
void
dnodeSendRedirectMsg
(
S
Dnode
*
pDnode
,
SRpcMsg
*
rpcMsg
,
bool
forShell
);
#ifdef __cplusplus
}
...
...
source/dnode/mgmt/inc/dnodeInt.h
→
source/dnode/mgmt/i
mpl/i
nc/dnodeInt.h
浏览文件 @
2f1bb281
...
...
@@ -22,33 +22,73 @@ extern "C" {
#include "os.h"
#include "taosmsg.h"
#include "tglobal.h"
#include "thash.h"
#include "tlog.h"
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
extern
int32_t
dDebugFlag
;
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("
DND
FATAL ", 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("
DND
ERROR ", 255, __VA_ARGS__); }}
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("
DND
WARN ", 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("
DND
", 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("
DND
", dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("
DND
", dDebugFlag, __VA_ARGS__); }}
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("
SRV
FATAL ", 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("
SRV
ERROR ", 255, __VA_ARGS__); }}
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("
SRV
WARN ", 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("
SRV
", 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("
SRV
", dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("
SRV
", dDebugFlag, __VA_ARGS__); }}
typedef
enum
{
DN_
RUN_STAT_INIT
,
DN_RUN_STAT_RUNNING
,
DN_RUN_STAT_STOPPED
}
EDn
Stat
;
typedef
enum
{
DN_
STAT_INIT
,
DN_STAT_RUNNING
,
DN_STAT_STOPPED
}
E
Stat
;
typedef
void
(
*
MsgFp
)(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
typedef
struct
SServer
{
}
SServer
;
typedef
struct
{
char
*
dnode
;
char
*
mnode
;
char
*
vnodes
;
}
SDnodeDir
;
int32_t
dnodeInit
();
void
dnodeCleanup
();
typedef
struct
{
int32_t
dnodeId
;
int64_t
clusterId
;
SDnodeEps
*
dnodeEps
;
SHashObj
*
dnodeHash
;
SEpSet
mnodeEpSetForShell
;
SEpSet
mnodeEpSetForPeer
;
char
*
file
;
uint32_t
rebootTime
;
int8_t
dropped
;
int8_t
threadStop
;
pthread_t
*
threadId
;
pthread_mutex_t
mutex
;
}
SDnodeDnode
;
EDnStat
dnodeGetRunStat
();
void
dnodeSetRunStat
(
EDnStat
stat
)
;
typedef
struct
{
}
SDnodeMnode
;
void
dnodeReportStartup
(
char
*
name
,
char
*
desc
);
void
dnodeReportStartupFinished
(
char
*
name
,
char
*
desc
);
void
dnodeGetStartup
(
SStartupMsg
*
);
typedef
struct
{
}
SDnodeVnodes
;
typedef
struct
{
void
*
peerRpc
;
void
*
shellRpc
;
void
*
clientRpc
;
}
SDnodeTrans
;
typedef
struct
SDnode
{
EStat
stat
;
SDnodeDir
dir
;
SDnodeDnode
dnode
;
SDnodeVnodes
vnodes
;
SDnodeMnode
mnode
;
SDnodeTrans
trans
;
SStartupMsg
startup
;
}
SDnode
;
EStat
dnodeGetStat
(
SDnode
*
pDnode
);
void
dnodeSetStat
(
SDnode
*
pDnode
,
EStat
stat
);
char
*
dnodeStatStr
(
EStat
stat
);
void
dnodeReportStartup
(
SDnode
*
pDnode
,
char
*
name
,
char
*
desc
);
void
dnodeGetStartup
(
SDnode
*
pDnode
,
SStartupMsg
*
pStartup
);
#ifdef __cplusplus
}
...
...
source/dnode/mgmt/inc/dnodeMnode.h
→
source/dnode/mgmt/i
mpl/i
nc/dnodeMnode.h
浏览文件 @
2f1bb281
文件已移动
source/dnode/mgmt/inc/dnodeTransport.h
→
source/dnode/mgmt/i
mpl/i
nc/dnodeTransport.h
浏览文件 @
2f1bb281
...
...
@@ -23,8 +23,8 @@ extern "C" {
int32_t
dnodeInitTrans
();
void
dnodeCleanupTrans
();
void
dnodeSendMsgToMnode
(
S
Server
*
pServer
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToDnode
(
S
Server
*
pServer
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToMnode
(
S
Dnode
*
pDnode
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToDnode
(
S
Dnode
*
pDnode
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
);
#ifdef __cplusplus
}
...
...
source/dnode/mgmt/inc/dnodeVnodes.h
→
source/dnode/mgmt/i
mpl/i
nc/dnodeVnodes.h
浏览文件 @
2f1bb281
文件已移动
source/dnode/mgmt/src/dnodeDnode.c
→
source/dnode/mgmt/
impl/
src/dnodeDnode.c
浏览文件 @
2f1bb281
此差异已折叠。
点击以展开。
source/dnode/mgmt/src/dnodeInt.c
→
source/dnode/mgmt/
impl/
src/dnodeInt.c
浏览文件 @
2f1bb281
...
...
@@ -25,48 +25,53 @@
#include "tstep.h"
#include "wal.h"
static
struct
{
SStartupMsg
startup
;
EDnStat
runStat
;
SSteps
*
steps
;
}
tsInt
;
EStat
dnodeGetStat
(
SDnode
*
pDnode
)
{
return
pDnode
->
stat
;
}
EDnStat
dnodeGetRunStat
()
{
return
tsInt
.
runStat
;
}
void
dnodeSetStat
(
SDnode
*
pDnode
,
EStat
stat
)
{
dDebug
(
"dnode stat set from %s to %s"
,
dnodeStatStr
(
pDnode
->
stat
),
dnodeStatStr
(
stat
));
pDnode
->
stat
=
stat
;
}
void
dnodeSetRunStat
(
EDnStat
stat
)
{
dDebug
(
"runstat set to %d"
,
stat
);
tsInt
.
runStat
=
stat
;
char
*
dnodeStatStr
(
EStat
stat
)
{
switch
(
stat
)
{
case
DN_STAT_INIT
:
return
"init"
;
case
DN_STAT_RUNNING
:
return
"running"
;
case
DN_STAT_STOPPED
:
return
"stopped"
;
default:
return
"unknown"
;
}
}
void
dnodeReportStartup
(
char
*
name
,
char
*
desc
)
{
SStartupMsg
*
pStartup
=
&
tsInt
.
startup
;
void
dnodeReportStartup
(
SDnode
*
pDnode
,
char
*
name
,
char
*
desc
)
{
SStartupMsg
*
pStartup
=
&
pDnode
->
startup
;
tstrncpy
(
pStartup
->
name
,
name
,
strlen
(
pStartup
->
name
));
tstrncpy
(
pStartup
->
desc
,
desc
,
strlen
(
pStartup
->
desc
));
pStartup
->
finished
=
0
;
}
void
dnodeReportStartupFinished
(
char
*
name
,
char
*
desc
)
{
SStartupMsg
*
pStartup
=
&
tsInt
.
startup
;
tstrncpy
(
pStartup
->
name
,
name
,
strlen
(
pStartup
->
name
));
tstrncpy
(
pStartup
->
desc
,
desc
,
strlen
(
pStartup
->
desc
));
pStartup
->
finished
=
1
;
void
dnodeGetStartup
(
SDnode
*
pDnode
,
SStartupMsg
*
pStartup
)
{
memcpy
(
pStartup
,
&
pDnode
->
startup
,
sizeof
(
SStartupMsg
);
pStartup
->
finished
=
(
dnodeGetStat
(
pDnode
)
==
DN_STAT_RUNNING
);
}
void
dnodeGetStartup
(
SStartupMsg
*
pStartup
)
{
memcpy
(
pStartup
,
&
tsInt
.
startup
,
sizeof
(
SStartupMsg
));
}
static
int32_t
dnodeCheckRunning
(
char
*
dir
)
{
char
filepath
[
256
]
=
{
0
};
snprintf
(
filepath
,
sizeof
(
filepath
),
"%s/.running"
,
dir
);
static
int32_t
dnodeCheckRunning
(
char
*
dataDir
)
{
char
filepath
[
PATH_MAX
]
=
{
0
};
snprintf
(
filepath
,
sizeof
(
filepath
),
"%s/.running"
,
dataDir
);
FileFd
fd
=
taosOpenFileCreateWriteTrunc
(
filepath
);
if
(
fd
<
0
)
{
dError
(
"failed to open lock file:%s since %s, quit"
,
filepath
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
int32_t
ret
=
taosLockFile
(
fd
);
if
(
ret
!=
0
)
{
dError
(
"failed to lock file:%s since %s, quit"
,
filepath
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
taosCloseFile
(
fd
);
return
-
1
;
}
...
...
@@ -74,35 +79,49 @@ static int32_t dnodeCheckRunning(char *dir) {
return
0
;
}
static
int32_t
dnodeInitDir
()
{
sprintf
(
tsMnodeDir
,
"%s/mnode"
,
tsDataDir
);
sprintf
(
tsVnodeDir
,
"%s/vnode"
,
tsDataDir
);
sprintf
(
tsDnodeDir
,
"%s/dnode"
,
tsDataDir
);
static
int32_t
dnodeInitDisk
(
SDnode
*
pDnode
,
char
*
dataDir
)
{
char
path
[
PATH_MAX
];
snprintf
(
path
,
PATH_MAX
,
"%s/mnode"
,
dataDir
);
pDnode
->
dir
.
mnode
=
strdup
(
path
);
sprintf
(
path
,
PATH_MAX
,
"%s/vnode"
,
dataDir
);
pDnode
->
dir
.
vnodes
=
strdup
(
path
);
sprintf
(
path
,
PATH_MAX
,
"%s/dnode"
,
dataDir
);
pDnode
->
dir
.
dnode
=
strdup
(
path
);
if
(
pDnode
->
dir
.
mnode
==
NULL
||
pDnode
->
dir
.
vnodes
==
NULL
||
pDnode
->
dir
.
dnode
==
NULL
)
{
dError
(
"failed to malloc dir object"
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
!
taosMkDir
(
tsDnodeDir
))
{
dError
(
"failed to create dir:%s since %s"
,
tsDnodeDir
,
strerror
(
errno
));
if
(
!
taosMkDir
(
pDnode
->
dir
.
dnode
))
{
dError
(
"failed to create dir:%s since %s"
,
pDnode
->
dir
.
dnode
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
!
taosMkDir
(
tsMnodeDir
))
{
dError
(
"failed to create dir:%s since %s"
,
tsMnodeDir
,
strerror
(
errno
));
if
(
!
taosMkDir
(
pDnode
->
dir
.
mnode
))
{
dError
(
"failed to create dir:%s since %s"
,
pDnode
->
dir
.
mnode
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
!
taosMkDir
(
tsVnodeDir
))
{
dError
(
"failed to create dir:%s since %s"
,
tsVnodeDir
,
strerror
(
errno
));
if
(
!
taosMkDir
(
pDnode
->
dir
.
vnodes
))
{
dError
(
"failed to create dir:%s since %s"
,
pDnode
->
dir
.
vnodes
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
dnodeCheckRunning
(
tsDnode
Dir
)
!=
0
)
{
if
(
dnodeCheckRunning
(
data
Dir
)
!=
0
)
{
return
-
1
;
}
return
0
;
}
static
int32_t
dnodeInitMain
()
{
tscEmbedded
=
1
;
static
int32_t
dnodeInitEnv
(
SDnode
*
pDnode
,
const
char
*
cfgPath
)
{
taosIgnSIGPIPE
();
taosBlockSIGPIPE
();
taosResolveCRC
();
...
...
@@ -118,7 +137,8 @@ static int32_t dnodeInitMain() {
char
temp
[
TSDB_FILENAME_LEN
];
sprintf
(
temp
,
"%s/taosdlog"
,
tsLogDir
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
<
0
)
{
printf
(
"failed to init log file
\n
"
);
dError
(
"failed to init log file
\n
"
);
return
-
1
;
}
if
(
!
taosReadGlobalCfg
())
{
...
...
@@ -127,55 +147,114 @@ static int32_t dnodeInitMain() {
return
-
1
;
}
dInfo
(
"start to initialize TDengine"
);
taosInitNotes
();
if
(
taosCheckGlobalCfg
()
!=
0
)
{
dError
(
"TDengine check global config failed"
);
return
-
1
;
}
dnodeInitDir
();
if
(
dnodeInitDisk
(
pDnode
,
tsDataDir
)
!=
0
)
{
dError
(
"TDengine failed to init directory"
);
return
-
1
;
}
return
0
;
}
static
void
dnodeCleanupMain
()
{
taos_cleanup
();
static
void
dnodeCleanupEnv
(
SDnode
*
pDnode
)
{
if
(
pDnode
->
dir
.
mnode
!=
NULL
)
{
tfree
(
pDnode
->
dir
.
mnode
);
}
if
(
pDnode
->
dir
.
vnodes
!=
NULL
)
{
tfree
(
pDnode
->
dir
.
vnodes
);
}
if
(
pDnode
->
dir
.
dnode
!=
NULL
)
{
tfree
(
pDnode
->
dir
.
dnode
);
}
taosCloseLog
();
taosStopCacheRefreshWorker
();
}
int32_t
dnodeInit
()
{
SSteps
*
steps
=
taosStepInit
(
10
,
dnodeReportStartup
);
if
(
steps
==
NULL
)
return
-
1
;
#if 1
dnodeSetRunStat
(
DN_RUN_STAT_RUNNING
);
#endif
taosStepAdd
(
steps
,
"dnode-main"
,
dnodeInitMain
,
dnodeCleanupMain
);
taosStepAdd
(
steps
,
"dnode-rpc"
,
rpcInit
,
rpcCleanup
);
taosStepAdd
(
steps
,
"dnode-tfs"
,
NULL
,
NULL
);
taosStepAdd
(
steps
,
"dnode-wal"
,
walInit
,
walCleanUp
);
//taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp);
taosStepAdd
(
steps
,
"dnode-dnode"
,
dnodeInitDnode
,
dnodeCleanupDnode
);
taosStepAdd
(
steps
,
"dnode-vnodes"
,
dnodeInitVnodes
,
dnodeCleanupVnodes
);
taosStepAdd
(
steps
,
"dnode-mnode"
,
dnodeInitMnode
,
dnodeCleanupMnode
);
taosStepAdd
(
steps
,
"dnode-trans"
,
dnodeInitTrans
,
dnodeCleanupTrans
);
tsInt
.
steps
=
steps
;
taosStepExec
(
tsInt
.
steps
);
dnodeSetRunStat
(
DN_RUN_STAT_RUNNING
);
dnodeReportStartupFinished
(
"TDengine"
,
"initialized successfully"
);
SDnode
*
dnodeInit
(
const
char
*
cfgPath
)
{
SDnode
*
pDnode
=
calloc
(
1
,
sizeof
(
pDnode
));
if
(
pDnode
==
NULL
)
{
dError
(
"failed to create dnode object"
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
dInfo
(
"start to initialize TDengine"
);
dnodeSetStat
(
pDnode
,
DN_STAT_INIT
);
if
(
dnodeInitEnv
(
pDnode
,
cfgPath
)
!=
0
)
{
dError
(
"failed to init env"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
if
(
rpcInit
()
!=
0
)
{
dError
(
"failed to init rpc env"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
if
(
walInit
()
!=
0
)
{
dError
(
"failed to init wal env"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
if
(
dnodeInitDnode
(
pDnode
)
!=
0
)
{
dError
(
"failed to init dnode"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
if
(
dnodeInitVnodes
(
pDnode
)
!=
0
)
{
dError
(
"failed to init vnodes"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
if
(
dnodeInitMnode
(
pDnode
)
!=
0
)
{
dError
(
"failed to init mnode"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
if
(
dnodeInitTrans
(
pDnode
)
!=
0
)
{
dError
(
"failed to init transport"
);
dnodeCleanup
(
pDnode
);
return
NULL
;
}
dnodeSetStat
(
pDnode
,
DN_STAT_RUNNING
);
dnodeReportStartup
(
pDnode
,
"TDengine"
,
"initialized successfully"
);
dInfo
(
"TDengine is initialized successfully"
);
return
0
;
}
void
dnodeCleanup
()
{
if
(
dnodeGetRunStat
()
!=
DN_RUN_STAT_STOPPED
)
{
dnodeSetRunStat
(
DN_RUN_STAT_STOPPED
);
taosStepCleanup
(
tsInt
.
steps
);
tsInt
.
steps
=
NULL
;
void
dnodeCleanup
(
SDnode
*
pDnode
)
{
if
(
dnodeGetStat
(
pDnode
)
==
DN_STAT_STOPPED
)
{
dError
(
"dnode is shutting down"
);
return
;
}
dInfo
(
"start to cleanup TDengine"
);
dnodeSetStat
(
pDnode
,
DN_STAT_STOPPED
);
dnodeCleanupTrans
(
pDnode
);
dnodeCleanupMnode
(
pDnode
);
dnodeCleanupVnodes
(
pDnode
);
dnodeCleanupDnode
(
pDnode
);
walCleanUp
();
rpcCleanup
();
dInfo
(
"TDengine is cleaned up successfully"
);
dnodeCleanupEnv
(
pDnode
);
free
(
pDnode
);
}
source/dnode/mgmt/src/dnodeMnode.c
→
source/dnode/mgmt/
impl/
src/dnodeMnode.c
浏览文件 @
2f1bb281
...
...
@@ -51,19 +51,24 @@ static void dnodeFreeMnodeApplyQueue();
static
int32_t
dnodeAllocMnodeSyncQueue
();
static
void
dnodeFreeMnodeSyncQueue
();
static
int32_t
dnodeAcquireMnode
()
{
static
SMnode
*
dnodeAcquireMnode
()
{
SMnode
*
pMnode
=
NULL
;
taosRLockLatch
(
&
tsMnode
.
latch
);
int32_t
code
=
tsMnode
.
deployed
?
0
:
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
;
if
(
code
==
0
)
{
if
(
tsMnode
.
deployed
)
{
atomic_add_fetch_32
(
&
tsMnode
.
refCount
,
1
);
pMnode
=
tsMnode
.
pMnode
;
}
taosRUnLockLatch
(
&
tsMnode
.
latch
);
return
c
ode
;
return
pMn
ode
;
}
static
void
dnodeReleaseMnode
()
{
atomic_sub_fetch_32
(
&
tsMnode
.
refCount
,
1
);
}
static
void
dnodeReleaseMnode
(
SMnode
*
pMnode
)
{
taosRLockLatch
(
&
tsMnode
.
latch
);
atomic_sub_fetch_32
(
&
tsMnode
.
refCount
,
1
);
taosRUnLockLatch
(
&
tsMnode
.
latch
);
}
static
int32_t
dnodeReadMnodeFile
()
{
int32_t
code
=
TSDB_CODE_DND_READ_MNODE_FILE_ERROR
;
...
...
@@ -503,12 +508,12 @@ static void dnodeCleanupMnodeSyncWorker() { tWorkerCleanup(&tsMnode.syncPool); }
static
int32_t
dnodeInitMnodeModule
()
{
taosInitRWLatch
(
&
tsMnode
.
latch
);
SMnode
Para
para
;
SMnode
Options
para
;
para
.
dnodeId
=
dnodeGetDnodeId
();
para
.
clusterId
=
dnodeGetClusterId
();
para
.
sendMsgToDnodeFp
=
dnodeSendMsgToDnode
;
para
.
sendMsgToMnodeFp
=
dnodeSendMsgToMnode
;
para
.
send
MsgToMnode
Fp
=
dnodeSendRedirectMsg
;
para
.
send
RedirectMsg
Fp
=
dnodeSendRedirectMsg
;
tsMnode
.
pMnode
=
mnodeCreate
(
para
);
if
(
tsMnode
.
pMnode
!=
NULL
)
{
...
...
@@ -517,7 +522,7 @@ static int32_t dnodeInitMnodeModule() {
return
0
;
}
static
void
dnodeCleanupMnodeModule
()
{
mnode
Cleanup
(
);
}
static
void
dnodeCleanupMnodeModule
()
{
mnode
Drop
(
NULL
);
}
static
bool
dnodeNeedDeployMnode
()
{
if
(
dnodeGetDnodeId
()
>
0
)
return
false
;
...
...
@@ -590,13 +595,14 @@ void dnodeCleanupMnode() {
}
int32_t
dnodeGetUserAuthFromMnode
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int32_t
c
ode
=
dnodeAcquireMnode
();
if
(
code
!=
0
)
{
SMnode
*
pMn
ode
=
dnodeAcquireMnode
();
if
(
pMnode
==
NULL
)
{
dTrace
(
"failed to get user auth since mnode not deployed"
);
return
code
;
terrno
=
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
;
return
-
1
;
}
code
=
mnodeRetriveAuth
(
user
,
spi
,
encrypt
,
secret
,
ckey
);
dnodeReleaseMnode
();
int32_t
code
=
mnodeRetriveAuth
(
pMnode
,
user
,
spi
,
encrypt
,
secret
,
ckey
);
dnodeReleaseMnode
(
pMnode
);
return
code
;
}
\ No newline at end of file
source/dnode/mgmt/src/dnodeTransport.c
→
source/dnode/mgmt/
impl/
src/dnodeTransport.c
浏览文件 @
2f1bb281
...
...
@@ -135,7 +135,7 @@ static void dnodeProcessPeerReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
return
;
}
if
(
dnodeGet
RunStat
()
!=
DN_RU
N_STAT_RUNNING
)
{
if
(
dnodeGet
Stat
()
!=
D
N_STAT_RUNNING
)
{
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
...
...
@@ -193,7 +193,7 @@ static void dnodeCleanupPeerServer() {
static
void
dnodeProcessPeerRsp
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
int32_t
msgType
=
pMsg
->
msgType
;
if
(
dnodeGet
RunStat
()
==
DN_RU
N_STAT_STOPPED
)
{
if
(
dnodeGet
Stat
()
==
D
N_STAT_STOPPED
)
{
if
(
pMsg
==
NULL
||
pMsg
->
pCont
==
NULL
)
return
;
dTrace
(
"RPC %p, peer rsp:%s is ignored since dnode is stopping"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
rpcFreeCont
(
pMsg
->
pCont
);
...
...
@@ -248,13 +248,13 @@ static void dnodeProcessShellReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
handle
};
int32_t
msgType
=
pMsg
->
msgType
;
if
(
dnodeGet
RunStat
()
==
DN_RU
N_STAT_STOPPED
)
{
if
(
dnodeGet
Stat
()
==
D
N_STAT_STOPPED
)
{
dError
(
"RPC %p, shell req:%s is ignored since dnode exiting"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
rspMsg
.
code
=
TSDB_CODE_DND_EXITING
;
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
return
;
}
else
if
(
dnodeGet
RunStat
()
!=
DN_RU
N_STAT_RUNNING
)
{
}
else
if
(
dnodeGet
Stat
()
!=
D
N_STAT_RUNNING
)
{
dError
(
"RPC %p, shell req:%s is ignored since dnode not running"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rpcSendResponse
(
&
rspMsg
);
...
...
@@ -382,13 +382,13 @@ void dnodeCleanupTrans() {
dnodeCleanupClient
();
}
void
dnodeSendMsgToDnode
(
S
Server
*
pServer
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
void
dnodeSendMsgToDnode
(
S
Dnode
*
pDnode
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
#if 0
rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL);
#endif
}
void
dnodeSendMsgToMnode
(
S
Server
*
pServer
,
SRpcMsg
*
rpcMsg
)
{
void
dnodeSendMsgToMnode
(
S
Dnode
*
pDnode
,
SRpcMsg
*
rpcMsg
)
{
SEpSet
epSet
=
{
0
};
dnodeGetMnodeEpSetForPeer
(
&
epSet
);
dnodeSendMsgToDnode
(
NULL
,
&
epSet
,
rpcMsg
);
...
...
source/dnode/mgmt/src/dnodeVnodes.c
→
source/dnode/mgmt/
impl/
src/dnodeVnodes.c
浏览文件 @
2f1bb281
...
...
@@ -815,7 +815,7 @@ void dnodeProcessVnodeFetchMsg(SRpcMsg *pMsg, SEpSet *pEpSet) {
}
}
static
int32_t
dnodePutMsgIntoVnodeApplyQueue
(
S
Server
*
pServer
,
int32_t
vgId
,
SVnodeMsg
*
pMsg
)
{
static
int32_t
dnodePutMsgIntoVnodeApplyQueue
(
S
Dnode
*
pDnode
,
int32_t
vgId
,
SVnodeMsg
*
pMsg
)
{
SVnodeObj
*
pVnode
=
dnodeAcquireVnode
(
vgId
);
if
(
pVnode
==
NULL
)
{
return
terrno
;
...
...
source/dnode/mnode/impl/inc/mnodeInt.h
浏览文件 @
2f1bb281
...
...
@@ -32,21 +32,22 @@ typedef struct SMnodeBak {
tmr_h
timer
;
SSteps
*
pInitSteps
;
SSteps
*
pStartSteps
;
SMnode
Para
para
;
SMnode
Options
para
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
}
SMnodeBak
;
typedef
struct
SMnode
{
int32_t
dnodeId
;
int64_t
clusterId
;
tmr_h
timer
;
SSteps
*
pInitSteps
;
S
Steps
*
pStartSteps
;
SMnodePara
para
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
]
;
int32_t
dnodeId
;
int64_t
clusterId
;
int8_t
replica
;
int8_t
selfIndex
;
S
Replica
replicas
[
TSDB_MAX_REPLICA
]
;
tmr_h
timer
;
SSteps
*
pInitSteps
;
SSteps
*
pStartSteps
;
struct
SSdb
*
pSdb
;
struct
SServer
*
pServer
;
struct
SDnode
*
pServer
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
2f1bb281
...
...
@@ -77,40 +77,20 @@ static void mnodeCleanupTimer() {
tmr_h
mnodeGetTimer
()
{
return
tsMint
.
timer
;
}
static
int32_t
mnodeSetPara
(
SMnode
*
pMnode
,
SMnodePara
para
)
{
pMnode
->
dnodeId
=
para
.
dnodeId
;
pMnode
->
clusterId
=
para
.
clusterId
;
pMnode
->
putMsgToApplyMsgFp
=
para
.
putMsgToApplyMsgFp
;
pMnode
->
sendMsgToDnodeFp
=
para
.
sendMsgToDnodeFp
;
pMnode
->
sendMsgToMnodeFp
=
para
.
sendMsgToMnodeFp
;
pMnode
->
sendRedirectMsgFp
=
para
.
sendRedirectMsgFp
;
if
(
pMnode
->
sendMsgToDnodeFp
==
NULL
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
if
(
pMnode
->
sendMsgToMnodeFp
==
NULL
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
if
(
pMnode
->
sendRedirectMsgFp
==
NULL
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
if
(
pMnode
->
putMsgToApplyMsgFp
==
NULL
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
if
(
pMnode
->
dnodeId
<
0
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
if
(
pMnode
->
clusterId
<
0
)
{
static
int32_t
mnodeSetOptions
(
SMnode
*
pMnode
,
const
SMnodeOptions
*
pOptions
)
{
pMnode
->
dnodeId
=
pOptions
->
dnodeId
;
pMnode
->
clusterId
=
pOptions
->
clusterId
;
pMnode
->
replica
=
pOptions
->
replica
;
pMnode
->
selfIndex
=
pOptions
->
selfIndex
;
memcpy
(
&
pMnode
->
replicas
,
pOptions
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
pMnode
->
pServer
=
pOptions
->
pServer
;
pMnode
->
putMsgToApplyMsgFp
=
pOptions
->
putMsgToApplyMsgFp
;
pMnode
->
sendMsgToDnodeFp
=
pOptions
->
sendMsgToDnodeFp
;
pMnode
->
sendMsgToMnodeFp
=
pOptions
->
sendMsgToMnodeFp
;
pMnode
->
sendRedirectMsgFp
=
pOptions
->
sendRedirectMsgFp
;
if
(
pMnode
->
sendMsgToDnodeFp
==
NULL
||
pMnode
->
sendMsgToMnodeFp
==
NULL
||
pMnode
->
sendRedirectMsgFp
==
NULL
||
pMnode
->
putMsgToApplyMsgFp
==
NULL
||
pMnode
->
dnodeId
<
0
||
pMnode
->
clusterId
<
0
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
...
...
@@ -156,12 +136,12 @@ static int32_t mnodeAllocStartSteps() {
return
0
;
}
SMnode
*
mnode
Create
(
SMnodePara
para
)
{
SMnode
*
mnode
Open
(
const
char
*
path
,
const
SMnodeOptions
*
pOptions
)
{
SMnode
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnode
));
if
(
mnodeSet
Para
(
pMnode
,
para
)
!=
0
)
{
if
(
mnodeSet
Options
(
pMnode
,
pOptions
)
!=
0
)
{
free
(
pMnode
);
mError
(
"failed to init mnode
para
since %s"
,
terrstr
());
mError
(
"failed to init mnode
options
since %s"
,
terrstr
());
return
NULL
;
}
...
...
@@ -175,35 +155,31 @@ SMnode *mnodeCreate(SMnodePara para) {
return
NULL
;
}
taosStepExec
(
tsMint
.
pInitSteps
);
return
NULL
;
}
void
mnodeCleanup
()
{
taosStepCleanup
(
tsMint
.
pInitSteps
);
}
taosStepExec
(
tsMint
.
pInitSteps
);
int32_t
mnodeDeploy
(
SMnodeCfg
*
pCfg
)
{
if
(
tsMint
.
para
.
dnodeId
<=
0
&&
tsMint
.
para
.
clusterId
<=
0
)
{
if
(
sdbDeploy
()
!=
0
)
{
mError
(
"failed to deploy sdb since %s"
,
terrstr
());
return
-
1
;
return
NULL
;
}
else
{
mInfo
(
"mnode is deployed"
);
}
}
mDebug
(
"mnode is deployed"
);
return
0
;
}
taosStepExec
(
tsMint
.
pStartSteps
);
void
mnodeUnDeploy
()
{
sdbUnDeploy
();
}
return
pMnode
;
}
int32_t
mnodeStart
(
SMnodeCfg
*
pCfg
)
{
return
taosStepExec
(
tsMint
.
pStartSteps
);
}
void
mnodeClose
(
SMnode
*
pMnode
)
{
free
(
pMnode
);
}
int32_t
mnodeAlter
(
SMnode
Cfg
*
pCfg
)
{
return
0
;
}
int32_t
mnodeAlter
(
SMnode
*
pMnode
,
const
SMnodeOptions
*
pOptions
)
{
return
0
;
}
void
mnode
Stop
()
{
taosStepCleanup
(
tsMint
.
pStartSteps
);
}
void
mnode
Destroy
(
const
char
*
path
)
{
sdbUnDeploy
(
);
}
int32_t
mnodeGetLoad
(
SMnodeLoad
*
pLoad
)
{
return
0
;
}
int32_t
mnodeGetLoad
(
SMnode
*
pMnode
,
SMnode
Load
*
pLoad
)
{
return
0
;
}
SMnodeMsg
*
mnodeInitMsg
(
SRpcMsg
*
pRpcMsg
)
{
SMnodeMsg
*
mnodeInitMsg
(
S
Mnode
*
pMnode
,
S
RpcMsg
*
pRpcMsg
)
{
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -211,7 +187,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
}
if
(
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
pMsg
->
conn
)
!=
0
)
{
mnodeCleanupMsg
(
pMsg
);
mnodeCleanupMsg
(
pM
node
,
pM
sg
);
mError
(
"can not get user from conn:%p"
,
pMsg
->
rpcMsg
.
handle
);
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
return
NULL
;
...
...
@@ -223,7 +199,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
return
pMsg
;
}
void
mnodeCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
void
mnodeCleanupMsg
(
SMnode
*
pMnode
,
SMnode
Msg
*
pMsg
)
{
if
(
pMsg
->
pUser
!=
NULL
)
{
sdbRelease
(
pMsg
->
pUser
);
}
...
...
@@ -232,6 +208,12 @@ void mnodeCleanupMsg(SMnodeMsg *pMsg) {
}
static
void
mnodeProcessRpcMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
!
mnodeIsMaster
())
{
mnodeSendRedirectMsg
(
NULL
,
&
pMsg
->
rpcMsg
,
true
);
mnodeCleanupMsg
(
NULL
,
pMsg
);
return
;
}
int32_t
msgType
=
pMsg
->
rpcMsg
.
msgType
;
MnodeRpcFp
fp
=
tsMint
.
msgFp
[
msgType
];
...
...
@@ -250,25 +232,13 @@ void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) {
}
}
void
mnodeProcessMsg
(
SMnodeMsg
*
pMsg
,
EMnMsgType
msgType
)
{
if
(
!
mnodeIsMaster
())
{
mnodeSendRedirectMsg
(
NULL
,
&
pMsg
->
rpcMsg
,
true
);
mnodeCleanupMsg
(
pMsg
);
return
;
}
void
mnodeProcessReadMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
switch
(
msgType
)
{
case
MN_MSG_TYPE_READ
:
case
MN_MSG_TYPE_WRITE
:
case
MN_MSG_TYPE_SYNC
:
mnodeProcessRpcMsg
(
pMsg
);
break
;
case
MN_MSG_TYPE_APPLY
:
break
;
default:
break
;
}
}
void
mnodeProcessWriteMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
void
mnodeProcessSyncMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
void
mnodeProcessApplyMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{}
#if 0
...
...
source/dnode/mnode/impl/src/mnodeAuth.c
浏览文件 @
2f1bb281
...
...
@@ -20,7 +20,7 @@
int32_t
mnodeInitAuth
()
{
return
0
;
}
void
mnodeCleanupAuth
()
{}
int32_t
mnodeRetriveAuth
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int32_t
mnodeRetriveAuth
(
SMnode
*
pMnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
if
(
strcmp
(
user
,
TSDB_NETTEST_USER
)
==
0
)
{
char
pass
[
32
]
=
{
0
};
taosEncryptPass
((
uint8_t
*
)
user
,
strlen
(
user
),
pass
);
...
...
source/dnode/mnode/impl/src/mnodeTelem.c
浏览文件 @
2f1bb281
...
...
@@ -174,7 +174,7 @@ static void mnodeAddVersionInfo(SBufferWriter* bw) {
static
void
mnodeAddRuntimeInfo
(
SBufferWriter
*
bw
)
{
SMnodeLoad
load
=
{
0
};
if
(
mnodeGetLoad
(
&
load
)
!=
0
)
{
if
(
mnodeGetLoad
(
NULL
,
&
load
)
!=
0
)
{
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录