Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2f1bb281
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看板
提交
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 @@
...
@@ -20,17 +20,16 @@
extern
"C"
{
extern
"C"
{
#endif
#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
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
{
typedef
struct
SMnodeLoad
{
int8_t
replica
;
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
}
SMnodeCfg
;
typedef
struct
{
int64_t
numOfDnode
;
int64_t
numOfDnode
;
int64_t
numOfMnode
;
int64_t
numOfMnode
;
int64_t
numOfVgroup
;
int64_t
numOfVgroup
;
...
@@ -43,38 +42,126 @@ typedef struct {
...
@@ -43,38 +42,126 @@ typedef struct {
int64_t
compStorage
;
int64_t
compStorage
;
}
SMnodeLoad
;
}
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
{
typedef
struct
{
int32_t
dnodeId
;
int32_t
dnodeId
;
int64_t
clusterId
;
int64_t
clusterId
;
int8_t
replica
;
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
struct
SServer
*
pServer
;
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
SendRedirectMsgFp
sendRedirectMsgFp
;
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
);
SMnode
*
mnodeCreate
(
SMnodePara
para
);
/**
void
mnodeCleanup
();
* @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
);
/**
* @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
();
* @brief Initialize mnode msg
int32_t
mnodeStart
(
SMnodeCfg
*
pCfg
);
*
int32_t
mnodeAlter
(
SMnodeCfg
*
pCfg
);
* @param pMnode The mnode object
void
mnodeStop
();
* @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
);
* @brief Process the read request
void
mnodeProcessMsg
(
SMnodeMsg
*
pMsg
,
EMnMsgType
msgType
);
*
* @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
#ifdef __cplusplus
}
}
...
...
include/dnode/vnode/vnode.h
浏览文件 @
2f1bb281
...
@@ -184,11 +184,11 @@ typedef struct {
...
@@ -184,11 +184,11 @@ typedef struct {
SRpcMsg
rpcMsg
[];
SRpcMsg
rpcMsg
[];
}
SVnodeMsg
;
}
SVnodeMsg
;
typedef
struct
S
Server
SServer
;
typedef
struct
S
Dnode
SDnode
;
typedef
void
(
*
SendMsgToDnodeFp
)(
S
Server
*
pServer
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToDnodeFp
)(
S
Dnode
*
pDnode
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToMnodeFp
)(
S
Server
*
pServer
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendMsgToMnodeFp
)(
S
Dnode
*
pDnode
,
struct
SRpcMsg
*
rpcMsg
);
typedef
void
(
*
SendRedirectMsgFp
)(
S
Server
*
pServer
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
typedef
void
(
*
SendRedirectMsgFp
)(
S
Dnode
*
pDnode
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
typedef
int32_t
(
*
PutMsgToVnodeQFp
)(
S
Server
*
pServer
,
int32_t
vgId
,
SVnodeMsg
*
pMsg
);
typedef
int32_t
(
*
PutMsgToVnodeQFp
)(
S
Dnode
*
pDnode
,
int32_t
vgId
,
SVnodeMsg
*
pMsg
);
typedef
struct
{
typedef
struct
{
PutMsgToVnodeQFp
putMsgToApplyQueueFp
;
PutMsgToVnodeQFp
putMsgToApplyQueueFp
;
...
...
source/dnode/CMakeLists.txt
浏览文件 @
2f1bb281
source/dnode/mgmt/CMakeLists.txt
浏览文件 @
2f1bb281
aux_source_directory
(
src DNODE_SRC
)
add_subdirectory
(
daemon
)
add_executable
(
taosd
${
DNODE_SRC
}
)
add_subdirectory
(
impl
)
target_link_libraries
(
\ No newline at end of file
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"
)
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 @@
...
@@ -14,10 +14,14 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "dnodeInt.h"
#include "dnode.h"
#include "os.h"
#include "ulog.h"
static
bool
stop
=
false
;
static
bool
stop
=
false
;
static
void
sigintHandler
(
int32_t
signum
,
void
*
info
,
void
*
ctx
)
{
stop
=
true
;
}
static
void
sigintHandler
(
int32_t
signum
,
void
*
info
,
void
*
ctx
)
{
stop
=
true
;
}
static
void
setSignalHandler
()
{
static
void
setSignalHandler
()
{
taosSetSignal
(
SIGTERM
,
sigintHandler
);
taosSetSignal
(
SIGTERM
,
sigintHandler
);
taosSetSignal
(
SIGHUP
,
sigintHandler
);
taosSetSignal
(
SIGHUP
,
sigintHandler
);
...
@@ -27,20 +31,23 @@ static void setSignalHandler() {
...
@@ -27,20 +31,23 @@ static void setSignalHandler() {
}
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
int
main
(
int
argc
,
char
const
*
argv
[])
{
setSignalHandler
()
;
const
char
*
path
=
"/etc/taos"
;
int32_t
code
=
dnodeInit
(
);
SDnode
*
pDnode
=
dnodeInit
(
path
);
if
(
code
!=
0
)
{
if
(
pDnode
==
NULL
)
{
dInfo
(
"Failed to start TDengine, please check the log at:
%s"
,
tsLogDir
);
uInfo
(
"Failed to start TDengine, please check the log at
%s"
,
tsLogDir
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
uInfo
(
"Started TDengine service successfully."
);
setSignalHandler
();
while
(
!
stop
)
{
while
(
!
stop
)
{
taosMsleep
(
100
);
taosMsleep
(
100
);
}
}
d
Info
(
"TDengine is shut down!"
);
u
Info
(
"TDengine is shut down!"
);
dnodeCleanup
();
dnodeCleanup
(
pDnode
);
return
0
;
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" {
...
@@ -21,8 +21,8 @@ extern "C" {
#endif
#endif
#include "dnodeInt.h"
#include "dnodeInt.h"
int32_t
dnodeInitDnode
();
int32_t
dnodeInitDnode
(
SDnode
*
pDnode
);
void
dnodeCleanupDnode
();
void
dnodeCleanupDnode
(
SDnode
*
pDnode
);
void
dnodeProcessDnodeMsg
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
void
dnodeProcessDnodeMsg
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
int32_t
dnodeGetDnodeId
();
int32_t
dnodeGetDnodeId
();
...
@@ -30,7 +30,7 @@ int64_t dnodeGetClusterId();
...
@@ -30,7 +30,7 @@ int64_t dnodeGetClusterId();
void
dnodeGetDnodeEp
(
int32_t
dnodeId
,
char
*
epstr
,
char
*
fqdn
,
uint16_t
*
port
);
void
dnodeGetDnodeEp
(
int32_t
dnodeId
,
char
*
epstr
,
char
*
fqdn
,
uint16_t
*
port
);
void
dnodeGetMnodeEpSetForPeer
(
SEpSet
*
epSet
);
void
dnodeGetMnodeEpSetForPeer
(
SEpSet
*
epSet
);
void
dnodeGetMnodeEpSetForShell
(
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
#ifdef __cplusplus
}
}
...
...
source/dnode/mgmt/inc/dnodeInt.h
→
source/dnode/mgmt/i
mpl/i
nc/dnodeInt.h
浏览文件 @
2f1bb281
...
@@ -22,33 +22,73 @@ extern "C" {
...
@@ -22,33 +22,73 @@ extern "C" {
#include "os.h"
#include "os.h"
#include "taosmsg.h"
#include "taosmsg.h"
#include "tglobal.h"
#include "tglobal.h"
#include "thash.h"
#include "tlog.h"
#include "tlog.h"
#include "trpc.h"
#include "trpc.h"
#include "tthread.h"
#include "ttime.h"
extern
int32_t
dDebugFlag
;
extern
int32_t
dDebugFlag
;
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("
DND
FATAL ", 255, __VA_ARGS__); }}
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("
SRV
FATAL ", 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("
DND
ERROR ", 255, __VA_ARGS__); }}
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("
SRV
ERROR ", 255, __VA_ARGS__); }}
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("
DND
WARN ", 255, __VA_ARGS__); }}
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("
SRV
WARN ", 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("
DND
", 255, __VA_ARGS__); }}
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("
SRV
", 255, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("
DND
", dDebugFlag, __VA_ARGS__); }}
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("
SRV
", dDebugFlag, __VA_ARGS__); }}
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("
DND
", 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
void
(
*
MsgFp
)(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
typedef
struct
SServer
{
typedef
struct
{
}
SServer
;
char
*
dnode
;
char
*
mnode
;
char
*
vnodes
;
}
SDnodeDir
;
int32_t
dnodeInit
();
typedef
struct
{
void
dnodeCleanup
();
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
();
typedef
struct
{
void
dnodeSetRunStat
(
EDnStat
stat
)
;
}
SDnodeMnode
;
void
dnodeReportStartup
(
char
*
name
,
char
*
desc
);
typedef
struct
{
void
dnodeReportStartupFinished
(
char
*
name
,
char
*
desc
);
}
SDnodeVnodes
;
void
dnodeGetStartup
(
SStartupMsg
*
);
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
#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" {
...
@@ -23,8 +23,8 @@ extern "C" {
int32_t
dnodeInitTrans
();
int32_t
dnodeInitTrans
();
void
dnodeCleanupTrans
();
void
dnodeCleanupTrans
();
void
dnodeSendMsgToMnode
(
S
Server
*
pServer
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToMnode
(
S
Dnode
*
pDnode
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToDnode
(
S
Server
*
pServer
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
);
void
dnodeSendMsgToDnode
(
S
Dnode
*
pDnode
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
);
#ifdef __cplusplus
#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
...
@@ -18,67 +18,49 @@
...
@@ -18,67 +18,49 @@
#include "dnodeTransport.h"
#include "dnodeTransport.h"
#include "dnodeVnodes.h"
#include "dnodeVnodes.h"
#include "cJSON.h"
#include "cJSON.h"
#include "thash.h"
#include "tthread.h"
#include "ttime.h"
static
struct
{
int32_t
dnodeId
;
int64_t
clusterId
;
SDnodeEps
*
dnodeEps
;
SHashObj
*
dnodeHash
;
SEpSet
mnodeEpSetForShell
;
SEpSet
mnodeEpSetForPeer
;
char
file
[
PATH_MAX
+
20
];
uint32_t
rebootTime
;
int8_t
dropped
;
int8_t
threadStop
;
pthread_t
*
threadId
;
pthread_mutex_t
mutex
;
}
tsDnode
=
{
0
};
int32_t
dnodeGetDnodeId
()
{
int32_t
dnodeGetDnodeId
()
{
int32_t
dnodeId
=
0
;
int32_t
dnodeId
=
0
;
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
dnodeId
=
tsDnode
.
dnodeId
;
dnodeId
=
pDnode
->
dnodeId
;
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
return
dnodeId
;
return
dnodeId
;
}
}
int64_t
dnodeGetClusterId
()
{
int64_t
dnodeGetClusterId
()
{
int64_t
clusterId
=
0
;
int64_t
clusterId
=
0
;
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
clusterId
=
tsDnode
.
clusterId
;
clusterId
=
pDnode
->
clusterId
;
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
return
clusterId
;
return
clusterId
;
}
}
void
dnodeGetDnodeEp
(
int32_t
dnodeId
,
char
*
ep
,
char
*
fqdn
,
uint16_t
*
port
)
{
void
dnodeGetDnodeEp
(
int32_t
dnodeId
,
char
*
ep
,
char
*
fqdn
,
uint16_t
*
port
)
{
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
SDnodeEp
*
pEp
=
taosHashGet
(
tsDnode
.
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
SDnodeEp
*
pEp
=
taosHashGet
(
pDnode
->
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
if
(
pEp
!=
NULL
)
{
if
(
pEp
!=
NULL
)
{
if
(
port
)
*
port
=
pEp
->
dnodePort
;
if
(
port
)
*
port
=
pEp
->
dnodePort
;
if
(
fqdn
)
tstrncpy
(
fqdn
,
pEp
->
dnodeFqdn
,
TSDB_FQDN_LEN
);
if
(
fqdn
)
tstrncpy
(
fqdn
,
pEp
->
dnodeFqdn
,
TSDB_FQDN_LEN
);
if
(
ep
)
snprintf
(
ep
,
TSDB_EP_LEN
,
"%s:%u"
,
pEp
->
dnodeFqdn
,
pEp
->
dnodePort
);
if
(
ep
)
snprintf
(
ep
,
TSDB_EP_LEN
,
"%s:%u"
,
pEp
->
dnodeFqdn
,
pEp
->
dnodePort
);
}
}
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
}
}
void
dnodeGetMnodeEpSetForPeer
(
SEpSet
*
pEpSet
)
{
void
dnodeGetMnodeEpSetForPeer
(
SEpSet
*
pEpSet
)
{
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
*
pEpSet
=
tsDnode
.
mnodeEpSetForPeer
;
*
pEpSet
=
pDnode
->
mnodeEpSetForPeer
;
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
}
}
void
dnodeGetMnodeEpSetForShell
(
SEpSet
*
pEpSet
)
{
void
dnodeGetMnodeEpSetForShell
(
SEpSet
*
pEpSet
)
{
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
*
pEpSet
=
tsDnode
.
mnodeEpSetForShell
;
*
pEpSet
=
pDnode
->
mnodeEpSetForShell
;
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
}
}
void
dnodeSendRedirectMsg
(
S
Server
*
pServer
,
SRpcMsg
*
pMsg
,
bool
forShell
)
{
void
dnodeSendRedirectMsg
(
S
Dnode
*
pDnode
,
SRpcMsg
*
pMsg
,
bool
forShell
)
{
int32_t
msgType
=
pMsg
->
msgType
;
int32_t
msgType
=
pMsg
->
msgType
;
SEpSet
epSet
=
{
0
};
SEpSet
epSet
=
{
0
};
...
@@ -106,7 +88,7 @@ void dnodeSendRedirectMsg(SServer *pServer, SRpcMsg *pMsg, bool forShell) {
...
@@ -106,7 +88,7 @@ void dnodeSendRedirectMsg(SServer *pServer, SRpcMsg *pMsg, bool forShell) {
rpcSendRedirectRsp
(
pMsg
->
handle
,
&
epSet
);
rpcSendRedirectRsp
(
pMsg
->
handle
,
&
epSet
);
}
}
static
void
dnodeUpdateMnodeEpSet
(
SEpSet
*
pEpSet
)
{
static
void
dnodeUpdateMnodeEpSet
(
S
DnodeDnode
*
pDnode
,
S
EpSet
*
pEpSet
)
{
if
(
pEpSet
==
NULL
||
pEpSet
->
numOfEps
<=
0
)
{
if
(
pEpSet
==
NULL
||
pEpSet
->
numOfEps
<=
0
)
{
dError
(
"mnode is changed, but content is invalid, discard it"
);
dError
(
"mnode is changed, but content is invalid, discard it"
);
return
;
return
;
...
@@ -114,22 +96,22 @@ static void dnodeUpdateMnodeEpSet(SEpSet *pEpSet) {
...
@@ -114,22 +96,22 @@ static void dnodeUpdateMnodeEpSet(SEpSet *pEpSet) {
dInfo
(
"mnode is changed, num:%d use:%d"
,
pEpSet
->
numOfEps
,
pEpSet
->
inUse
);
dInfo
(
"mnode is changed, num:%d use:%d"
,
pEpSet
->
numOfEps
,
pEpSet
->
inUse
);
}
}
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
tsDnode
.
mnodeEpSetForPeer
=
*
pEpSet
;
pDnode
->
mnodeEpSetForPeer
=
*
pEpSet
;
for
(
int32_t
i
=
0
;
i
<
pEpSet
->
numOfEps
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pEpSet
->
numOfEps
;
++
i
)
{
pEpSet
->
port
[
i
]
-=
TSDB_PORT_DNODEDNODE
;
pEpSet
->
port
[
i
]
-=
TSDB_PORT_DNODEDNODE
;
dInfo
(
"mnode index:%d %s:%u"
,
i
,
pEpSet
->
fqdn
[
i
],
pEpSet
->
port
[
i
]);
dInfo
(
"mnode index:%d %s:%u"
,
i
,
pEpSet
->
fqdn
[
i
],
pEpSet
->
port
[
i
]);
}
}
tsDnode
.
mnodeEpSetForShell
=
*
pEpSet
;
pDnode
->
mnodeEpSetForShell
=
*
pEpSet
;
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
}
}
static
void
dnodePrintDnodes
()
{
static
void
dnodePrintDnodes
()
{
dDebug
(
"print dnode endpoint list, num:%d"
,
tsDnode
.
dnodeEps
->
dnodeNum
);
dDebug
(
"print dnode endpoint list, num:%d"
,
pDnode
->
dnodeEps
->
dnodeNum
);
for
(
int32_t
i
=
0
;
i
<
tsDnode
.
dnodeEps
->
dnodeNum
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
pDnode
->
dnodeEps
->
dnodeNum
;
i
++
)
{
SDnodeEp
*
ep
=
&
tsDnode
.
dnodeEps
->
dnodeEps
[
i
];
SDnodeEp
*
ep
=
&
pDnode
->
dnodeEps
->
dnodeEps
[
i
];
dDebug
(
"dnode:%d, fqdn:%s port:%u isMnode:%d"
,
ep
->
dnodeId
,
ep
->
dnodeFqdn
,
ep
->
dnodePort
,
ep
->
isMnode
);
dDebug
(
"dnode:%d, fqdn:%s port:%u isMnode:%d"
,
ep
->
dnodeId
,
ep
->
dnodeFqdn
,
ep
->
dnodePort
,
ep
->
isMnode
);
}
}
}
}
...
@@ -138,36 +120,36 @@ static void dnodeResetDnodes(SDnodeEps *pEps) {
...
@@ -138,36 +120,36 @@ static void dnodeResetDnodes(SDnodeEps *pEps) {
assert
(
pEps
!=
NULL
);
assert
(
pEps
!=
NULL
);
int32_t
size
=
sizeof
(
SDnodeEps
)
+
pEps
->
dnodeNum
*
sizeof
(
SDnodeEp
);
int32_t
size
=
sizeof
(
SDnodeEps
)
+
pEps
->
dnodeNum
*
sizeof
(
SDnodeEp
);
if
(
pEps
->
dnodeNum
>
tsDnode
.
dnodeEps
->
dnodeNum
)
{
if
(
pEps
->
dnodeNum
>
pDnode
->
dnodeEps
->
dnodeNum
)
{
SDnodeEps
*
tmp
=
calloc
(
1
,
size
);
SDnodeEps
*
tmp
=
calloc
(
1
,
size
);
if
(
tmp
==
NULL
)
return
;
if
(
tmp
==
NULL
)
return
;
tfree
(
tsDnode
.
dnodeEps
);
tfree
(
pDnode
->
dnodeEps
);
tsDnode
.
dnodeEps
=
tmp
;
pDnode
->
dnodeEps
=
tmp
;
}
}
if
(
tsDnode
.
dnodeEps
!=
pEps
)
{
if
(
pDnode
->
dnodeEps
!=
pEps
)
{
memcpy
(
tsDnode
.
dnodeEps
,
pEps
,
size
);
memcpy
(
pDnode
->
dnodeEps
,
pEps
,
size
);
}
}
tsDnode
.
mnodeEpSetForPeer
.
inUse
=
0
;
pDnode
->
mnodeEpSetForPeer
.
inUse
=
0
;
tsDnode
.
mnodeEpSetForShell
.
inUse
=
0
;
pDnode
->
mnodeEpSetForShell
.
inUse
=
0
;
int32_t
mIndex
=
0
;
int32_t
mIndex
=
0
;
for
(
int32_t
i
=
0
;
i
<
tsDnode
.
dnodeEps
->
dnodeNum
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
pDnode
->
dnodeEps
->
dnodeNum
;
i
++
)
{
SDnodeEp
*
ep
=
&
tsDnode
.
dnodeEps
->
dnodeEps
[
i
];
SDnodeEp
*
ep
=
&
pDnode
->
dnodeEps
->
dnodeEps
[
i
];
if
(
!
ep
->
isMnode
)
continue
;
if
(
!
ep
->
isMnode
)
continue
;
if
(
mIndex
>=
TSDB_MAX_REPLICA
)
continue
;
if
(
mIndex
>=
TSDB_MAX_REPLICA
)
continue
;
strcpy
(
tsDnode
.
mnodeEpSetForShell
.
fqdn
[
mIndex
],
ep
->
dnodeFqdn
);
strcpy
(
pDnode
->
mnodeEpSetForShell
.
fqdn
[
mIndex
],
ep
->
dnodeFqdn
);
strcpy
(
tsDnode
.
mnodeEpSetForPeer
.
fqdn
[
mIndex
],
ep
->
dnodeFqdn
);
strcpy
(
pDnode
->
mnodeEpSetForPeer
.
fqdn
[
mIndex
],
ep
->
dnodeFqdn
);
tsDnode
.
mnodeEpSetForShell
.
port
[
mIndex
]
=
ep
->
dnodePort
;
pDnode
->
mnodeEpSetForShell
.
port
[
mIndex
]
=
ep
->
dnodePort
;
tsDnode
.
mnodeEpSetForShell
.
port
[
mIndex
]
=
ep
->
dnodePort
+
tsDnodeDnodePort
;
pDnode
->
mnodeEpSetForShell
.
port
[
mIndex
]
=
ep
->
dnodePort
+
tsDnodeDnodePort
;
mIndex
++
;
mIndex
++
;
}
}
for
(
int32_t
i
=
0
;
i
<
tsDnode
.
dnodeEps
->
dnodeNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pDnode
->
dnodeEps
->
dnodeNum
;
++
i
)
{
SDnodeEp
*
ep
=
&
tsDnode
.
dnodeEps
->
dnodeEps
[
i
];
SDnodeEp
*
ep
=
&
pDnode
->
dnodeEps
->
dnodeEps
[
i
];
taosHashPut
(
tsDnode
.
dnodeHash
,
&
ep
->
dnodeId
,
sizeof
(
int32_t
),
ep
,
sizeof
(
SDnodeEp
));
taosHashPut
(
pDnode
->
dnodeHash
,
&
ep
->
dnodeId
,
sizeof
(
int32_t
),
ep
,
sizeof
(
SDnodeEp
));
}
}
dnodePrintDnodes
();
dnodePrintDnodes
();
...
@@ -175,16 +157,16 @@ static void dnodeResetDnodes(SDnodeEps *pEps) {
...
@@ -175,16 +157,16 @@ static void dnodeResetDnodes(SDnodeEps *pEps) {
static
bool
dnodeIsEpChanged
(
int32_t
dnodeId
,
char
*
epStr
)
{
static
bool
dnodeIsEpChanged
(
int32_t
dnodeId
,
char
*
epStr
)
{
bool
changed
=
false
;
bool
changed
=
false
;
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
SDnodeEp
*
pEp
=
taosHashGet
(
tsDnode
.
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
SDnodeEp
*
pEp
=
taosHashGet
(
pDnode
->
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
if
(
pEp
!=
NULL
)
{
if
(
pEp
!=
NULL
)
{
char
epSaved
[
TSDB_EP_LEN
+
1
];
char
epSaved
[
TSDB_EP_LEN
+
1
];
snprintf
(
epSaved
,
TSDB_EP_LEN
,
"%s:%u"
,
pEp
->
dnodeFqdn
,
pEp
->
dnodePort
);
snprintf
(
epSaved
,
TSDB_EP_LEN
,
"%s:%u"
,
pEp
->
dnodeFqdn
,
pEp
->
dnodePort
);
changed
=
strcmp
(
epStr
,
epSaved
)
!=
0
;
changed
=
strcmp
(
epStr
,
epSaved
)
!=
0
;
}
}
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
return
changed
;
return
changed
;
}
}
...
@@ -195,101 +177,101 @@ static int32_t dnodeReadDnodes() {
...
@@ -195,101 +177,101 @@ static int32_t dnodeReadDnodes() {
cJSON
*
root
=
NULL
;
cJSON
*
root
=
NULL
;
FILE
*
fp
=
NULL
;
FILE
*
fp
=
NULL
;
fp
=
fopen
(
tsDnode
.
file
,
"r"
);
fp
=
fopen
(
pDnode
->
file
,
"r"
);
if
(
!
fp
)
{
if
(
!
fp
)
{
dDebug
(
"file %s not exist"
,
tsDnode
.
file
);
dDebug
(
"file %s not exist"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
len
=
(
int32_t
)
fread
(
content
,
1
,
maxLen
,
fp
);
len
=
(
int32_t
)
fread
(
content
,
1
,
maxLen
,
fp
);
if
(
len
<=
0
)
{
if
(
len
<=
0
)
{
dError
(
"failed to read %s since content is null"
,
tsDnode
.
file
);
dError
(
"failed to read %s since content is null"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
content
[
len
]
=
0
;
content
[
len
]
=
0
;
root
=
cJSON_Parse
(
content
);
root
=
cJSON_Parse
(
content
);
if
(
root
==
NULL
)
{
if
(
root
==
NULL
)
{
dError
(
"failed to read %s since invalid json format"
,
tsDnode
.
file
);
dError
(
"failed to read %s since invalid json format"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
cJSON
*
dnodeId
=
cJSON_GetObjectItem
(
root
,
"dnodeId"
);
cJSON
*
dnodeId
=
cJSON_GetObjectItem
(
root
,
"dnodeId"
);
if
(
!
dnodeId
||
dnodeId
->
type
!=
cJSON_String
)
{
if
(
!
dnodeId
||
dnodeId
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s since dnodeId not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s since dnodeId not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
tsDnode
.
dnodeId
=
atoi
(
dnodeId
->
valuestring
);
pDnode
->
dnodeId
=
atoi
(
dnodeId
->
valuestring
);
cJSON
*
clusterId
=
cJSON_GetObjectItem
(
root
,
"clusterId"
);
cJSON
*
clusterId
=
cJSON_GetObjectItem
(
root
,
"clusterId"
);
if
(
!
clusterId
||
clusterId
->
type
!=
cJSON_String
)
{
if
(
!
clusterId
||
clusterId
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s since clusterId not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s since clusterId not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
tsDnode
.
clusterId
=
atoll
(
clusterId
->
valuestring
);
pDnode
->
clusterId
=
atoll
(
clusterId
->
valuestring
);
cJSON
*
dropped
=
cJSON_GetObjectItem
(
root
,
"dropped"
);
cJSON
*
dropped
=
cJSON_GetObjectItem
(
root
,
"dropped"
);
if
(
!
dropped
||
dropped
->
type
!=
cJSON_String
)
{
if
(
!
dropped
||
dropped
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s since dropped not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s since dropped not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
tsDnode
.
dropped
=
atoi
(
dropped
->
valuestring
);
pDnode
->
dropped
=
atoi
(
dropped
->
valuestring
);
cJSON
*
dnodeInfos
=
cJSON_GetObjectItem
(
root
,
"dnodeInfos"
);
cJSON
*
dnodeInfos
=
cJSON_GetObjectItem
(
root
,
"dnodeInfos"
);
if
(
!
dnodeInfos
||
dnodeInfos
->
type
!=
cJSON_Array
)
{
if
(
!
dnodeInfos
||
dnodeInfos
->
type
!=
cJSON_Array
)
{
dError
(
"failed to read %s since dnodeInfos not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s since dnodeInfos not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
int32_t
dnodeInfosSize
=
cJSON_GetArraySize
(
dnodeInfos
);
int32_t
dnodeInfosSize
=
cJSON_GetArraySize
(
dnodeInfos
);
if
(
dnodeInfosSize
<=
0
)
{
if
(
dnodeInfosSize
<=
0
)
{
dError
(
"failed to read %s since dnodeInfos size:%d invalid"
,
tsDnode
.
file
,
dnodeInfosSize
);
dError
(
"failed to read %s since dnodeInfos size:%d invalid"
,
pDnode
->
file
,
dnodeInfosSize
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
tsDnode
.
dnodeEps
=
calloc
(
1
,
dnodeInfosSize
*
sizeof
(
SDnodeEp
)
+
sizeof
(
SDnodeEps
));
pDnode
->
dnodeEps
=
calloc
(
1
,
dnodeInfosSize
*
sizeof
(
SDnodeEp
)
+
sizeof
(
SDnodeEps
));
if
(
tsDnode
.
dnodeEps
==
NULL
)
{
if
(
pDnode
->
dnodeEps
==
NULL
)
{
dError
(
"failed to calloc dnodeEpList since %s"
,
strerror
(
errno
));
dError
(
"failed to calloc dnodeEpList since %s"
,
strerror
(
errno
));
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
tsDnode
.
dnodeEps
->
dnodeNum
=
dnodeInfosSize
;
pDnode
->
dnodeEps
->
dnodeNum
=
dnodeInfosSize
;
for
(
int32_t
i
=
0
;
i
<
dnodeInfosSize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
dnodeInfosSize
;
++
i
)
{
cJSON
*
dnodeInfo
=
cJSON_GetArrayItem
(
dnodeInfos
,
i
);
cJSON
*
dnodeInfo
=
cJSON_GetArrayItem
(
dnodeInfos
,
i
);
if
(
dnodeInfo
==
NULL
)
break
;
if
(
dnodeInfo
==
NULL
)
break
;
SDnodeEp
*
pEp
=
&
tsDnode
.
dnodeEps
->
dnodeEps
[
i
];
SDnodeEp
*
pEp
=
&
pDnode
->
dnodeEps
->
dnodeEps
[
i
];
cJSON
*
dnodeId
=
cJSON_GetObjectItem
(
dnodeInfo
,
"dnodeId"
);
cJSON
*
dnodeId
=
cJSON_GetObjectItem
(
dnodeInfo
,
"dnodeId"
);
if
(
!
dnodeId
||
dnodeId
->
type
!=
cJSON_String
)
{
if
(
!
dnodeId
||
dnodeId
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s, dnodeId not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s, dnodeId not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
pEp
->
dnodeId
=
atoi
(
dnodeId
->
valuestring
);
pEp
->
dnodeId
=
atoi
(
dnodeId
->
valuestring
);
cJSON
*
isMnode
=
cJSON_GetObjectItem
(
dnodeInfo
,
"isMnode"
);
cJSON
*
isMnode
=
cJSON_GetObjectItem
(
dnodeInfo
,
"isMnode"
);
if
(
!
isMnode
||
isMnode
->
type
!=
cJSON_String
)
{
if
(
!
isMnode
||
isMnode
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s, isMnode not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s, isMnode not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
pEp
->
isMnode
=
atoi
(
isMnode
->
valuestring
);
pEp
->
isMnode
=
atoi
(
isMnode
->
valuestring
);
cJSON
*
dnodeFqdn
=
cJSON_GetObjectItem
(
dnodeInfo
,
"dnodeFqdn"
);
cJSON
*
dnodeFqdn
=
cJSON_GetObjectItem
(
dnodeInfo
,
"dnodeFqdn"
);
if
(
!
dnodeFqdn
||
dnodeFqdn
->
type
!=
cJSON_String
||
dnodeFqdn
->
valuestring
==
NULL
)
{
if
(
!
dnodeFqdn
||
dnodeFqdn
->
type
!=
cJSON_String
||
dnodeFqdn
->
valuestring
==
NULL
)
{
dError
(
"failed to read %s, dnodeFqdn not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s, dnodeFqdn not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
tstrncpy
(
pEp
->
dnodeFqdn
,
dnodeFqdn
->
valuestring
,
TSDB_FQDN_LEN
);
tstrncpy
(
pEp
->
dnodeFqdn
,
dnodeFqdn
->
valuestring
,
TSDB_FQDN_LEN
);
cJSON
*
dnodePort
=
cJSON_GetObjectItem
(
dnodeInfo
,
"dnodePort"
);
cJSON
*
dnodePort
=
cJSON_GetObjectItem
(
dnodeInfo
,
"dnodePort"
);
if
(
!
dnodePort
||
dnodePort
->
type
!=
cJSON_String
)
{
if
(
!
dnodePort
||
dnodePort
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s, dnodePort not found"
,
tsDnode
.
file
);
dError
(
"failed to read %s, dnodePort not found"
,
pDnode
->
file
);
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
pEp
->
dnodePort
=
atoi
(
dnodePort
->
valuestring
);
pEp
->
dnodePort
=
atoi
(
dnodePort
->
valuestring
);
}
}
dInfo
(
"succcessed to read file %s"
,
tsDnode
.
file
);
dInfo
(
"succcessed to read file %s"
,
pDnode
->
file
);
dnodePrintDnodes
();
dnodePrintDnodes
();
PRASE_DNODE_OVER:
PRASE_DNODE_OVER:
...
@@ -297,28 +279,28 @@ PRASE_DNODE_OVER:
...
@@ -297,28 +279,28 @@ PRASE_DNODE_OVER:
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
if
(
dnodeIsEpChanged
(
tsDnode
.
dnodeId
,
tsLocalEp
))
{
if
(
dnodeIsEpChanged
(
pDnode
->
dnodeId
,
tsLocalEp
))
{
dError
(
"localEp %s different with %s and need reconfigured"
,
tsLocalEp
,
tsDnode
.
file
);
dError
(
"localEp %s different with %s and need reconfigured"
,
tsLocalEp
,
pDnode
->
file
);
return
-
1
;
return
-
1
;
}
}
if
(
tsDnode
.
dnodeEps
==
NULL
)
{
if
(
pDnode
->
dnodeEps
==
NULL
)
{
tsDnode
.
dnodeEps
=
calloc
(
1
,
sizeof
(
SDnodeEps
)
+
sizeof
(
SDnodeEp
));
pDnode
->
dnodeEps
=
calloc
(
1
,
sizeof
(
SDnodeEps
)
+
sizeof
(
SDnodeEp
));
tsDnode
.
dnodeEps
->
dnodeNum
=
1
;
pDnode
->
dnodeEps
->
dnodeNum
=
1
;
tsDnode
.
dnodeEps
->
dnodeEps
[
0
].
dnodePort
=
tsServerPort
;
pDnode
->
dnodeEps
->
dnodeEps
[
0
].
dnodePort
=
tsServerPort
;
tstrncpy
(
tsDnode
.
dnodeEps
->
dnodeEps
[
0
].
dnodeFqdn
,
tsLocalFqdn
,
TSDB_FQDN_LEN
);
tstrncpy
(
pDnode
->
dnodeEps
->
dnodeEps
[
0
].
dnodeFqdn
,
tsLocalFqdn
,
TSDB_FQDN_LEN
);
}
}
dnodeResetDnodes
(
tsDnode
.
dnodeEps
);
dnodeResetDnodes
(
pDnode
->
dnodeEps
);
terrno
=
0
;
terrno
=
0
;
return
0
;
return
0
;
}
}
static
int32_t
dnodeWriteDnodes
()
{
static
int32_t
dnodeWriteDnodes
()
{
FILE
*
fp
=
fopen
(
tsDnode
.
file
,
"w"
);
FILE
*
fp
=
fopen
(
pDnode
->
file
,
"w"
);
if
(
!
fp
)
{
if
(
!
fp
)
{
dError
(
"failed to write %s since %s"
,
tsDnode
.
file
,
strerror
(
errno
));
dError
(
"failed to write %s since %s"
,
pDnode
->
file
,
strerror
(
errno
));
return
-
1
;
return
-
1
;
}
}
...
@@ -327,17 +309,17 @@ static int32_t dnodeWriteDnodes() {
...
@@ -327,17 +309,17 @@ static int32_t dnodeWriteDnodes() {
char
*
content
=
calloc
(
1
,
maxLen
+
1
);
char
*
content
=
calloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
:
\"
%d
\"
,
\n
"
,
tsDnode
.
dnodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
:
\"
%d
\"
,
\n
"
,
pDnode
->
dnodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
clusterId
\"
:
\"
%"
PRId64
"
\"
,
\n
"
,
tsDnode
.
clusterId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
clusterId
\"
:
\"
%"
PRId64
"
\"
,
\n
"
,
pDnode
->
clusterId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dropped
\"
:
\"
%d
\"
,
\n
"
,
tsDnode
.
dropped
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dropped
\"
:
\"
%d
\"
,
\n
"
,
pDnode
->
dropped
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeInfos
\"
: [{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeInfos
\"
: [{
\n
"
);
for
(
int32_t
i
=
0
;
i
<
tsDnode
.
dnodeEps
->
dnodeNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pDnode
->
dnodeEps
->
dnodeNum
;
++
i
)
{
SDnodeEp
*
ep
=
&
tsDnode
.
dnodeEps
->
dnodeEps
[
i
];
SDnodeEp
*
ep
=
&
pDnode
->
dnodeEps
->
dnodeEps
[
i
];
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
:
\"
%d
\"
,
\n
"
,
ep
->
dnodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
:
\"
%d
\"
,
\n
"
,
ep
->
dnodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
isMnode
\"
:
\"
%d
\"
,
\n
"
,
ep
->
isMnode
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
isMnode
\"
:
\"
%d
\"
,
\n
"
,
ep
->
isMnode
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeFqdn
\"
:
\"
%s
\"
,
\n
"
,
ep
->
dnodeFqdn
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeFqdn
\"
:
\"
%s
\"
,
\n
"
,
ep
->
dnodeFqdn
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodePort
\"
:
\"
%u
\"\n
"
,
ep
->
dnodePort
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodePort
\"
:
\"
%u
\"\n
"
,
ep
->
dnodePort
);
if
(
i
<
tsDnode
.
dnodeEps
->
dnodeNum
-
1
)
{
if
(
i
<
pDnode
->
dnodeEps
->
dnodeNum
-
1
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" },{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" },{
\n
"
);
}
else
{
}
else
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" }]
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" }]
\n
"
);
...
@@ -351,7 +333,7 @@ static int32_t dnodeWriteDnodes() {
...
@@ -351,7 +333,7 @@ static int32_t dnodeWriteDnodes() {
free
(
content
);
free
(
content
);
terrno
=
0
;
terrno
=
0
;
dInfo
(
"successed to write %s"
,
tsDnode
.
file
);
dInfo
(
"successed to write %s"
,
pDnode
->
file
);
return
0
;
return
0
;
}
}
...
@@ -367,7 +349,7 @@ static void dnodeSendStatusMsg() {
...
@@ -367,7 +349,7 @@ static void dnodeSendStatusMsg() {
pStatus
->
sversion
=
htonl
(
tsVersion
);
pStatus
->
sversion
=
htonl
(
tsVersion
);
pStatus
->
dnodeId
=
htonl
(
dnodeGetDnodeId
());
pStatus
->
dnodeId
=
htonl
(
dnodeGetDnodeId
());
pStatus
->
clusterId
=
htobe64
(
dnodeGetClusterId
());
pStatus
->
clusterId
=
htobe64
(
dnodeGetClusterId
());
pStatus
->
rebootTime
=
htonl
(
tsDnode
.
rebootTime
);
pStatus
->
rebootTime
=
htonl
(
pDnode
->
rebootTime
);
pStatus
->
numOfCores
=
htonl
(
tsNumOfCores
);
pStatus
->
numOfCores
=
htonl
(
tsNumOfCores
);
tstrncpy
(
pStatus
->
dnodeEp
,
tsLocalEp
,
TSDB_EP_LEN
);
tstrncpy
(
pStatus
->
dnodeEp
,
tsLocalEp
,
TSDB_EP_LEN
);
...
@@ -387,37 +369,37 @@ static void dnodeSendStatusMsg() {
...
@@ -387,37 +369,37 @@ static void dnodeSendStatusMsg() {
}
}
static
void
dnodeUpdateCfg
(
SDnodeCfg
*
pCfg
)
{
static
void
dnodeUpdateCfg
(
SDnodeCfg
*
pCfg
)
{
if
(
tsDnode
.
dnodeId
==
0
)
return
;
if
(
pDnode
->
dnodeId
==
0
)
return
;
if
(
tsDnode
.
dropped
)
return
;
if
(
pDnode
->
dropped
)
return
;
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
tsDnode
.
dnodeId
=
pCfg
->
dnodeId
;
pDnode
->
dnodeId
=
pCfg
->
dnodeId
;
tsDnode
.
clusterId
=
pCfg
->
clusterId
;
pDnode
->
clusterId
=
pCfg
->
clusterId
;
tsDnode
.
dropped
=
pCfg
->
dropped
;
pDnode
->
dropped
=
pCfg
->
dropped
;
dInfo
(
"dnodeId is set to %d, clusterId is set to %"
PRId64
,
pCfg
->
dnodeId
,
pCfg
->
clusterId
);
dInfo
(
"dnodeId is set to %d, clusterId is set to %"
PRId64
,
pCfg
->
dnodeId
,
pCfg
->
clusterId
);
dnodeWriteDnodes
();
dnodeWriteDnodes
();
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
}
}
static
void
dnodeUpdateDnodeEps
(
SDnodeEps
*
pEps
)
{
static
void
dnodeUpdateDnodeEps
(
SDnodeEps
*
pEps
)
{
if
(
pEps
==
NULL
||
pEps
->
dnodeNum
<=
0
)
return
;
if
(
pEps
==
NULL
||
pEps
->
dnodeNum
<=
0
)
return
;
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
if
(
pEps
->
dnodeNum
!=
tsDnode
.
dnodeEps
->
dnodeNum
)
{
if
(
pEps
->
dnodeNum
!=
pDnode
->
dnodeEps
->
dnodeNum
)
{
dnodeResetDnodes
(
pEps
);
dnodeResetDnodes
(
pEps
);
dnodeWriteDnodes
();
dnodeWriteDnodes
();
}
else
{
}
else
{
int32_t
size
=
pEps
->
dnodeNum
*
sizeof
(
SDnodeEp
)
+
sizeof
(
SDnodeEps
);
int32_t
size
=
pEps
->
dnodeNum
*
sizeof
(
SDnodeEp
)
+
sizeof
(
SDnodeEps
);
if
(
memcmp
(
tsDnode
.
dnodeEps
,
pEps
,
size
)
!=
0
)
{
if
(
memcmp
(
pDnode
->
dnodeEps
,
pEps
,
size
)
!=
0
)
{
dnodeResetDnodes
(
pEps
);
dnodeResetDnodes
(
pEps
);
dnodeWriteDnodes
();
dnodeWriteDnodes
();
}
}
}
}
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
}
}
static
void
dnodeProcessStatusRsp
(
SRpcMsg
*
pMsg
)
{
static
void
dnodeProcessStatusRsp
(
SRpcMsg
*
pMsg
)
{
...
@@ -455,7 +437,7 @@ static void dnodeProcessStartupReq(SRpcMsg *pMsg) {
...
@@ -455,7 +437,7 @@ static void dnodeProcessStartupReq(SRpcMsg *pMsg) {
dInfo
(
"startup msg is received, cont:%s"
,
(
char
*
)
pMsg
->
pCont
);
dInfo
(
"startup msg is received, cont:%s"
,
(
char
*
)
pMsg
->
pCont
);
SStartupMsg
*
pStartup
=
rpcMallocCont
(
sizeof
(
SStartupMsg
));
SStartupMsg
*
pStartup
=
rpcMallocCont
(
sizeof
(
SStartupMsg
));
dnodeGetStartup
(
pStartup
);
dnodeGetStartup
(
NULL
,
pStartup
);
dInfo
(
"startup msg is sent, step:%s desc:%s finished:%d"
,
pStartup
->
name
,
pStartup
->
desc
,
pStartup
->
finished
);
dInfo
(
"startup msg is sent, step:%s desc:%s finished:%d"
,
pStartup
->
name
,
pStartup
->
desc
,
pStartup
->
finished
);
...
@@ -467,8 +449,8 @@ static void dnodeProcessStartupReq(SRpcMsg *pMsg) {
...
@@ -467,8 +449,8 @@ static void dnodeProcessStartupReq(SRpcMsg *pMsg) {
static
void
*
dnodeThreadRoutine
(
void
*
param
)
{
static
void
*
dnodeThreadRoutine
(
void
*
param
)
{
int32_t
ms
=
tsStatusInterval
*
1000
;
int32_t
ms
=
tsStatusInterval
*
1000
;
while
(
!
tsDnode
.
threadStop
)
{
while
(
!
pDnode
->
threadStop
)
{
if
(
dnodeGet
RunStat
()
!=
DN_RU
N_STAT_RUNNING
)
{
if
(
dnodeGet
Stat
()
!=
D
N_STAT_RUNNING
)
{
continue
;
continue
;
}
else
{
}
else
{
dnodeSendStatusMsg
();
dnodeSendStatusMsg
();
...
@@ -477,31 +459,41 @@ static void *dnodeThreadRoutine(void *param) {
...
@@ -477,31 +459,41 @@ static void *dnodeThreadRoutine(void *param) {
}
}
}
}
int32_t
dnodeInitDnode
()
{
int32_t
dnodeInitDnode
(
SDnode
*
pServer
)
{
tsDnode
.
dnodeId
=
0
;
SDnodeDnode
*
pDnode
=
&
pServer
->
dnode
;
tsDnode
.
clusterId
=
0
;
tsDnode
.
dnodeEps
=
NULL
;
char
path
[
PATH_MAX
];
snprintf
(
tsDnode
.
file
,
sizeof
(
tsDnode
.
file
),
"%s/dnode.json"
,
tsDnodeDir
);
snprintf
(
path
,
PATH_MAX
,
"%s/dnode.json"
,
pServer
->
dir
.
dnode
);
tsDnode
.
rebootTime
=
taosGetTimestampSec
();
pDnode
->
file
=
strdup
(
path
);
tsDnode
.
dropped
=
0
;
if
(
pDnode
->
file
==
NULL
)
{
pthread_mutex_init
(
&
tsDnode
.
mutex
,
NULL
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
tsDnode
.
threadStop
=
false
;
return
-
1
;
}
tsDnode
.
dnodeHash
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_ENTRY_LOCK
);
if
(
tsDnode
.
dnodeHash
==
NULL
)
{
pDnode
->
dnodeId
=
0
;
pDnode
->
clusterId
=
0
;
pDnode
->
dnodeEps
=
NULL
;
pDnode
->
rebootTime
=
taosGetTimestampSec
();
pDnode
->
dropped
=
0
;
pthread_mutex_init
(
&
pDnode
->
mutex
,
NULL
);
pDnode
->
threadStop
=
false
;
pDnode
->
dnodeHash
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_ENTRY_LOCK
);
if
(
pDnode
->
dnodeHash
==
NULL
)
{
dError
(
"failed to init dnode hash"
);
dError
(
"failed to init dnode hash"
);
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
}
}
tsDnode
.
threadId
=
taosCreateThread
(
dnodeThreadRoutine
,
NULL
);
pDnode
->
threadId
=
taosCreateThread
(
dnodeThreadRoutine
,
NULL
);
if
(
tsDnode
.
threadId
==
NULL
)
{
if
(
pDnode
->
threadId
==
NULL
)
{
dError
(
"failed to init dnode thread"
);
dError
(
"failed to init dnode thread"
);
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
}
}
int32_t
code
=
dnodeReadDnodes
();
int32_t
code
=
dnodeReadDnodes
();
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
dError
(
"failed to read file:%s since %s"
,
tsDnode
.
file
,
tstrerror
(
code
));
dError
(
"failed to read file:%s since %s"
,
pDnode
->
file
,
tstrerror
(
code
));
return
code
;
return
code
;
}
}
...
@@ -509,36 +501,38 @@ int32_t dnodeInitDnode() {
...
@@ -509,36 +501,38 @@ int32_t dnodeInitDnode() {
return
0
;
return
0
;
}
}
void
dnodeCleanupDnode
()
{
void
dnodeCleanupDnode
(
SDnode
*
pServer
)
{
if
(
tsDnode
.
threadId
!=
NULL
)
{
SDnodeDnode
*
pDnode
=
&
pServer
->
dnode
;
tsDnode
.
threadStop
=
true
;
taosDestoryThread
(
tsDnode
.
threadId
);
if
(
pDnode
->
threadId
!=
NULL
)
{
tsDnode
.
threadId
=
NULL
;
pDnode
->
threadStop
=
true
;
taosDestoryThread
(
pDnode
->
threadId
);
pDnode
->
threadId
=
NULL
;
}
}
pthread_mutex_lock
(
&
tsDnode
.
mutex
);
pthread_mutex_lock
(
&
pDnode
->
mutex
);
if
(
tsDnode
.
dnodeEps
!=
NULL
)
{
if
(
pDnode
->
dnodeEps
!=
NULL
)
{
free
(
tsDnode
.
dnodeEps
);
free
(
pDnode
->
dnodeEps
);
tsDnode
.
dnodeEps
=
NULL
;
pDnode
->
dnodeEps
=
NULL
;
}
}
if
(
tsDnode
.
dnodeHash
)
{
if
(
pDnode
->
dnodeHash
)
{
taosHashCleanup
(
tsDnode
.
dnodeHash
);
taosHashCleanup
(
pDnode
->
dnodeHash
);
tsDnode
.
dnodeHash
=
NULL
;
pDnode
->
dnodeHash
=
NULL
;
}
}
pthread_mutex_unlock
(
&
tsDnode
.
mutex
);
pthread_mutex_unlock
(
&
pDnode
->
mutex
);
pthread_mutex_destroy
(
&
tsDnode
.
mutex
);
pthread_mutex_destroy
(
&
pDnode
->
mutex
);
dInfo
(
"dnode-dnode is cleaned up"
);
dInfo
(
"dnode-dnode is cleaned up"
);
}
}
void
dnodeProcessDnodeMsg
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
void
dnodeProcessDnodeMsg
(
S
Dnode
*
pDnode
,
S
RpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
int32_t
msgType
=
pMsg
->
msgType
;
int32_t
msgType
=
pMsg
->
msgType
;
if
(
msgType
==
TSDB_MSG_TYPE_STATUS_RSP
&&
pEpSet
)
{
if
(
msgType
==
TSDB_MSG_TYPE_STATUS_RSP
&&
pEpSet
)
{
dnodeUpdateMnodeEpSet
(
pEpSet
);
dnodeUpdateMnodeEpSet
(
&
pDnode
->
dnode
,
pEpSet
);
}
}
switch
(
msgType
)
{
switch
(
msgType
)
{
...
...
source/dnode/mgmt/src/dnodeInt.c
→
source/dnode/mgmt/
impl/
src/dnodeInt.c
浏览文件 @
2f1bb281
...
@@ -25,48 +25,53 @@
...
@@ -25,48 +25,53 @@
#include "tstep.h"
#include "tstep.h"
#include "wal.h"
#include "wal.h"
static
struct
{
EStat
dnodeGetStat
(
SDnode
*
pDnode
)
{
return
pDnode
->
stat
;
}
SStartupMsg
startup
;
EDnStat
runStat
;
SSteps
*
steps
;
}
tsInt
;
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
)
{
char
*
dnodeStatStr
(
EStat
stat
)
{
dDebug
(
"runstat set to %d"
,
stat
);
switch
(
stat
)
{
tsInt
.
runStat
=
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
)
{
void
dnodeReportStartup
(
SDnode
*
pDnode
,
char
*
name
,
char
*
desc
)
{
SStartupMsg
*
pStartup
=
&
tsInt
.
startup
;
SStartupMsg
*
pStartup
=
&
pDnode
->
startup
;
tstrncpy
(
pStartup
->
name
,
name
,
strlen
(
pStartup
->
name
));
tstrncpy
(
pStartup
->
name
,
name
,
strlen
(
pStartup
->
name
));
tstrncpy
(
pStartup
->
desc
,
desc
,
strlen
(
pStartup
->
desc
));
tstrncpy
(
pStartup
->
desc
,
desc
,
strlen
(
pStartup
->
desc
));
pStartup
->
finished
=
0
;
pStartup
->
finished
=
0
;
}
}
void
dnodeReportStartupFinished
(
char
*
name
,
char
*
desc
)
{
void
dnodeGetStartup
(
SDnode
*
pDnode
,
SStartupMsg
*
pStartup
)
{
SStartupMsg
*
pStartup
=
&
tsInt
.
startup
;
memcpy
(
pStartup
,
&
pDnode
->
startup
,
sizeof
(
SStartupMsg
);
tstrncpy
(
pStartup
->
name
,
name
,
strlen
(
pStartup
->
name
));
pStartup
->
finished
=
(
dnodeGetStat
(
pDnode
)
==
DN_STAT_RUNNING
);
tstrncpy
(
pStartup
->
desc
,
desc
,
strlen
(
pStartup
->
desc
));
pStartup
->
finished
=
1
;
}
}
void
dnodeGetStartup
(
SStartupMsg
*
pStartup
)
{
memcpy
(
pStartup
,
&
tsInt
.
startup
,
sizeof
(
SStartupMsg
));
}
static
int32_t
dnodeCheckRunning
(
char
*
dataDir
)
{
char
filepath
[
PATH_MAX
]
=
{
0
};
static
int32_t
dnodeCheckRunning
(
char
*
dir
)
{
snprintf
(
filepath
,
sizeof
(
filepath
),
"%s/.running"
,
dataDir
);
char
filepath
[
256
]
=
{
0
};
snprintf
(
filepath
,
sizeof
(
filepath
),
"%s/.running"
,
dir
);
FileFd
fd
=
taosOpenFileCreateWriteTrunc
(
filepath
);
FileFd
fd
=
taosOpenFileCreateWriteTrunc
(
filepath
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
dError
(
"failed to open lock file:%s since %s, quit"
,
filepath
,
strerror
(
errno
));
dError
(
"failed to open lock file:%s since %s, quit"
,
filepath
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
int32_t
ret
=
taosLockFile
(
fd
);
int32_t
ret
=
taosLockFile
(
fd
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
dError
(
"failed to lock file:%s since %s, quit"
,
filepath
,
strerror
(
errno
));
dError
(
"failed to lock file:%s since %s, quit"
,
filepath
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
taosCloseFile
(
fd
);
taosCloseFile
(
fd
);
return
-
1
;
return
-
1
;
}
}
...
@@ -74,35 +79,49 @@ static int32_t dnodeCheckRunning(char *dir) {
...
@@ -74,35 +79,49 @@ static int32_t dnodeCheckRunning(char *dir) {
return
0
;
return
0
;
}
}
static
int32_t
dnodeInitDir
()
{
static
int32_t
dnodeInitDisk
(
SDnode
*
pDnode
,
char
*
dataDir
)
{
sprintf
(
tsMnodeDir
,
"%s/mnode"
,
tsDataDir
);
char
path
[
PATH_MAX
];
sprintf
(
tsVnodeDir
,
"%s/vnode"
,
tsDataDir
);
snprintf
(
path
,
PATH_MAX
,
"%s/mnode"
,
dataDir
);
sprintf
(
tsDnodeDir
,
"%s/dnode"
,
tsDataDir
);
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
))
{
if
(
!
taosMkDir
(
pDnode
->
dir
.
dnode
))
{
dError
(
"failed to create dir:%s since %s"
,
tsDnodeDir
,
strerror
(
errno
));
dError
(
"failed to create dir:%s since %s"
,
pDnode
->
dir
.
dnode
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
if
(
!
taosMkDir
(
tsMnodeDir
))
{
if
(
!
taosMkDir
(
pDnode
->
dir
.
mnode
))
{
dError
(
"failed to create dir:%s since %s"
,
tsMnodeDir
,
strerror
(
errno
));
dError
(
"failed to create dir:%s since %s"
,
pDnode
->
dir
.
mnode
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
if
(
!
taosMkDir
(
tsVnodeDir
))
{
if
(
!
taosMkDir
(
pDnode
->
dir
.
vnodes
))
{
dError
(
"failed to create dir:%s since %s"
,
tsVnodeDir
,
strerror
(
errno
));
dError
(
"failed to create dir:%s since %s"
,
pDnode
->
dir
.
vnodes
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
return
-
1
;
}
}
if
(
dnodeCheckRunning
(
tsDnode
Dir
)
!=
0
)
{
if
(
dnodeCheckRunning
(
data
Dir
)
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static
int32_t
dnodeInitMain
()
{
static
int32_t
dnodeInitEnv
(
SDnode
*
pDnode
,
const
char
*
cfgPath
)
{
tscEmbedded
=
1
;
taosIgnSIGPIPE
();
taosIgnSIGPIPE
();
taosBlockSIGPIPE
();
taosBlockSIGPIPE
();
taosResolveCRC
();
taosResolveCRC
();
...
@@ -118,7 +137,8 @@ static int32_t dnodeInitMain() {
...
@@ -118,7 +137,8 @@ static int32_t dnodeInitMain() {
char
temp
[
TSDB_FILENAME_LEN
];
char
temp
[
TSDB_FILENAME_LEN
];
sprintf
(
temp
,
"%s/taosdlog"
,
tsLogDir
);
sprintf
(
temp
,
"%s/taosdlog"
,
tsLogDir
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
<
0
)
{
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
<
0
)
{
printf
(
"failed to init log file
\n
"
);
dError
(
"failed to init log file
\n
"
);
return
-
1
;
}
}
if
(
!
taosReadGlobalCfg
())
{
if
(
!
taosReadGlobalCfg
())
{
...
@@ -127,55 +147,114 @@ static int32_t dnodeInitMain() {
...
@@ -127,55 +147,114 @@ static int32_t dnodeInitMain() {
return
-
1
;
return
-
1
;
}
}
dInfo
(
"start to initialize TDengine"
);
taosInitNotes
();
taosInitNotes
();
if
(
taosCheckGlobalCfg
()
!=
0
)
{
if
(
taosCheckGlobalCfg
()
!=
0
)
{
dError
(
"TDengine check global config failed"
);
return
-
1
;
return
-
1
;
}
}
dnodeInitDir
();
if
(
dnodeInitDisk
(
pDnode
,
tsDataDir
)
!=
0
)
{
dError
(
"TDengine failed to init directory"
);
return
-
1
;
}
return
0
;
return
0
;
}
}
static
void
dnodeCleanupMain
()
{
static
void
dnodeCleanupEnv
(
SDnode
*
pDnode
)
{
taos_cleanup
();
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
();
taosCloseLog
();
taosStopCacheRefreshWorker
();
taosStopCacheRefreshWorker
();
}
}
int32_t
dnodeInit
()
{
SDnode
*
dnodeInit
(
const
char
*
cfgPath
)
{
SSteps
*
steps
=
taosStepInit
(
10
,
dnodeReportStartup
);
SDnode
*
pDnode
=
calloc
(
1
,
sizeof
(
pDnode
));
if
(
steps
==
NULL
)
return
-
1
;
if
(
pDnode
==
NULL
)
{
#if 1
dError
(
"failed to create dnode object"
);
dnodeSetRunStat
(
DN_RUN_STAT_RUNNING
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
#endif
return
NULL
;
taosStepAdd
(
steps
,
"dnode-main"
,
dnodeInitMain
,
dnodeCleanupMain
);
}
taosStepAdd
(
steps
,
"dnode-rpc"
,
rpcInit
,
rpcCleanup
);
taosStepAdd
(
steps
,
"dnode-tfs"
,
NULL
,
NULL
);
dInfo
(
"start to initialize TDengine"
);
taosStepAdd
(
steps
,
"dnode-wal"
,
walInit
,
walCleanUp
);
dnodeSetStat
(
pDnode
,
DN_STAT_INIT
);
//taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp);
taosStepAdd
(
steps
,
"dnode-dnode"
,
dnodeInitDnode
,
dnodeCleanupDnode
);
if
(
dnodeInitEnv
(
pDnode
,
cfgPath
)
!=
0
)
{
taosStepAdd
(
steps
,
"dnode-vnodes"
,
dnodeInitVnodes
,
dnodeCleanupVnodes
);
dError
(
"failed to init env"
);
taosStepAdd
(
steps
,
"dnode-mnode"
,
dnodeInitMnode
,
dnodeCleanupMnode
);
dnodeCleanup
(
pDnode
);
taosStepAdd
(
steps
,
"dnode-trans"
,
dnodeInitTrans
,
dnodeCleanupTrans
);
return
NULL
;
}
tsInt
.
steps
=
steps
;
taosStepExec
(
tsInt
.
steps
);
if
(
rpcInit
()
!=
0
)
{
dError
(
"failed to init rpc env"
);
dnodeSetRunStat
(
DN_RUN_STAT_RUNNING
);
dnodeCleanup
(
pDnode
);
dnodeReportStartupFinished
(
"TDengine"
,
"initialized successfully"
);
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"
);
dInfo
(
"TDengine is initialized successfully"
);
return
0
;
return
0
;
}
}
void
dnodeCleanup
()
{
void
dnodeCleanup
(
SDnode
*
pDnode
)
{
if
(
dnodeGetRunStat
()
!=
DN_RUN_STAT_STOPPED
)
{
if
(
dnodeGetStat
(
pDnode
)
==
DN_STAT_STOPPED
)
{
dnodeSetRunStat
(
DN_RUN_STAT_STOPPED
);
dError
(
"dnode is shutting down"
);
taosStepCleanup
(
tsInt
.
steps
);
return
;
tsInt
.
steps
=
NULL
;
}
}
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();
...
@@ -51,19 +51,24 @@ static void dnodeFreeMnodeApplyQueue();
static
int32_t
dnodeAllocMnodeSyncQueue
();
static
int32_t
dnodeAllocMnodeSyncQueue
();
static
void
dnodeFreeMnodeSyncQueue
();
static
void
dnodeFreeMnodeSyncQueue
();
static
int32_t
dnodeAcquireMnode
()
{
static
SMnode
*
dnodeAcquireMnode
()
{
SMnode
*
pMnode
=
NULL
;
taosRLockLatch
(
&
tsMnode
.
latch
);
taosRLockLatch
(
&
tsMnode
.
latch
);
int32_t
code
=
tsMnode
.
deployed
?
0
:
TSDB_CODE_DND_MNODE_NOT_DEPLOYED
;
if
(
tsMnode
.
deployed
)
{
if
(
code
==
0
)
{
atomic_add_fetch_32
(
&
tsMnode
.
refCount
,
1
);
atomic_add_fetch_32
(
&
tsMnode
.
refCount
,
1
);
pMnode
=
tsMnode
.
pMnode
;
}
}
taosRUnLockLatch
(
&
tsMnode
.
latch
);
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
()
{
static
int32_t
dnodeReadMnodeFile
()
{
int32_t
code
=
TSDB_CODE_DND_READ_MNODE_FILE_ERROR
;
int32_t
code
=
TSDB_CODE_DND_READ_MNODE_FILE_ERROR
;
...
@@ -503,12 +508,12 @@ static void dnodeCleanupMnodeSyncWorker() { tWorkerCleanup(&tsMnode.syncPool); }
...
@@ -503,12 +508,12 @@ static void dnodeCleanupMnodeSyncWorker() { tWorkerCleanup(&tsMnode.syncPool); }
static
int32_t
dnodeInitMnodeModule
()
{
static
int32_t
dnodeInitMnodeModule
()
{
taosInitRWLatch
(
&
tsMnode
.
latch
);
taosInitRWLatch
(
&
tsMnode
.
latch
);
SMnode
Para
para
;
SMnode
Options
para
;
para
.
dnodeId
=
dnodeGetDnodeId
();
para
.
dnodeId
=
dnodeGetDnodeId
();
para
.
clusterId
=
dnodeGetClusterId
();
para
.
clusterId
=
dnodeGetClusterId
();
para
.
sendMsgToDnodeFp
=
dnodeSendMsgToDnode
;
para
.
sendMsgToDnodeFp
=
dnodeSendMsgToDnode
;
para
.
sendMsgToMnodeFp
=
dnodeSendMsgToMnode
;
para
.
sendMsgToMnodeFp
=
dnodeSendMsgToMnode
;
para
.
send
MsgToMnode
Fp
=
dnodeSendRedirectMsg
;
para
.
send
RedirectMsg
Fp
=
dnodeSendRedirectMsg
;
tsMnode
.
pMnode
=
mnodeCreate
(
para
);
tsMnode
.
pMnode
=
mnodeCreate
(
para
);
if
(
tsMnode
.
pMnode
!=
NULL
)
{
if
(
tsMnode
.
pMnode
!=
NULL
)
{
...
@@ -517,7 +522,7 @@ static int32_t dnodeInitMnodeModule() {
...
@@ -517,7 +522,7 @@ static int32_t dnodeInitMnodeModule() {
return
0
;
return
0
;
}
}
static
void
dnodeCleanupMnodeModule
()
{
mnode
Cleanup
(
);
}
static
void
dnodeCleanupMnodeModule
()
{
mnode
Drop
(
NULL
);
}
static
bool
dnodeNeedDeployMnode
()
{
static
bool
dnodeNeedDeployMnode
()
{
if
(
dnodeGetDnodeId
()
>
0
)
return
false
;
if
(
dnodeGetDnodeId
()
>
0
)
return
false
;
...
@@ -590,13 +595,14 @@ void dnodeCleanupMnode() {
...
@@ -590,13 +595,14 @@ void dnodeCleanupMnode() {
}
}
int32_t
dnodeGetUserAuthFromMnode
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int32_t
dnodeGetUserAuthFromMnode
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int32_t
c
ode
=
dnodeAcquireMnode
();
SMnode
*
pMn
ode
=
dnodeAcquireMnode
();
if
(
code
!=
0
)
{
if
(
pMnode
==
NULL
)
{
dTrace
(
"failed to get user auth since mnode not deployed"
);
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
);
int32_t
code
=
mnodeRetriveAuth
(
pMnode
,
user
,
spi
,
encrypt
,
secret
,
ckey
);
dnodeReleaseMnode
();
dnodeReleaseMnode
(
pMnode
);
return
code
;
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) {
...
@@ -135,7 +135,7 @@ static void dnodeProcessPeerReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
return
;
return
;
}
}
if
(
dnodeGet
RunStat
()
!=
DN_RU
N_STAT_RUNNING
)
{
if
(
dnodeGet
Stat
()
!=
D
N_STAT_RUNNING
)
{
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rpcSendResponse
(
&
rspMsg
);
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
...
@@ -193,7 +193,7 @@ static void dnodeCleanupPeerServer() {
...
@@ -193,7 +193,7 @@ static void dnodeCleanupPeerServer() {
static
void
dnodeProcessPeerRsp
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
static
void
dnodeProcessPeerRsp
(
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
int32_t
msgType
=
pMsg
->
msgType
;
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
;
if
(
pMsg
==
NULL
||
pMsg
->
pCont
==
NULL
)
return
;
dTrace
(
"RPC %p, peer rsp:%s is ignored since dnode is stopping"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
dTrace
(
"RPC %p, peer rsp:%s is ignored since dnode is stopping"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
...
@@ -248,13 +248,13 @@ static void dnodeProcessShellReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
...
@@ -248,13 +248,13 @@ static void dnodeProcessShellReq(SRpcMsg *pMsg, SEpSet *pEpSet) {
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
handle
};
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
handle
};
int32_t
msgType
=
pMsg
->
msgType
;
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
]);
dError
(
"RPC %p, shell req:%s is ignored since dnode exiting"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
rspMsg
.
code
=
TSDB_CODE_DND_EXITING
;
rspMsg
.
code
=
TSDB_CODE_DND_EXITING
;
rpcSendResponse
(
&
rspMsg
);
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
return
;
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
]);
dError
(
"RPC %p, shell req:%s is ignored since dnode not running"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rpcSendResponse
(
&
rspMsg
);
rpcSendResponse
(
&
rspMsg
);
...
@@ -382,13 +382,13 @@ void dnodeCleanupTrans() {
...
@@ -382,13 +382,13 @@ void dnodeCleanupTrans() {
dnodeCleanupClient
();
dnodeCleanupClient
();
}
}
void
dnodeSendMsgToDnode
(
S
Server
*
pServer
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
void
dnodeSendMsgToDnode
(
S
Dnode
*
pDnode
,
SEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
#if 0
#if 0
rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL);
rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL);
#endif
#endif
}
}
void
dnodeSendMsgToMnode
(
S
Server
*
pServer
,
SRpcMsg
*
rpcMsg
)
{
void
dnodeSendMsgToMnode
(
S
Dnode
*
pDnode
,
SRpcMsg
*
rpcMsg
)
{
SEpSet
epSet
=
{
0
};
SEpSet
epSet
=
{
0
};
dnodeGetMnodeEpSetForPeer
(
&
epSet
);
dnodeGetMnodeEpSetForPeer
(
&
epSet
);
dnodeSendMsgToDnode
(
NULL
,
&
epSet
,
rpcMsg
);
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) {
...
@@ -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
);
SVnodeObj
*
pVnode
=
dnodeAcquireVnode
(
vgId
);
if
(
pVnode
==
NULL
)
{
if
(
pVnode
==
NULL
)
{
return
terrno
;
return
terrno
;
...
...
source/dnode/mnode/impl/inc/mnodeInt.h
浏览文件 @
2f1bb281
...
@@ -32,21 +32,22 @@ typedef struct SMnodeBak {
...
@@ -32,21 +32,22 @@ typedef struct SMnodeBak {
tmr_h
timer
;
tmr_h
timer
;
SSteps
*
pInitSteps
;
SSteps
*
pInitSteps
;
SSteps
*
pStartSteps
;
SSteps
*
pStartSteps
;
SMnode
Para
para
;
SMnode
Options
para
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
}
SMnodeBak
;
}
SMnodeBak
;
typedef
struct
SMnode
{
typedef
struct
SMnode
{
int32_t
dnodeId
;
int32_t
dnodeId
;
int64_t
clusterId
;
int64_t
clusterId
;
int8_t
replica
;
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
tmr_h
timer
;
tmr_h
timer
;
SSteps
*
pInitSteps
;
SSteps
*
pInitSteps
;
SSteps
*
pStartSteps
;
SSteps
*
pStartSteps
;
SMnodePara
para
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
struct
SSdb
*
pSdb
;
struct
SSdb
*
pSdb
;
struct
SServer
*
pServer
;
struct
SDnode
*
pServer
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
2f1bb281
...
@@ -77,40 +77,20 @@ static void mnodeCleanupTimer() {
...
@@ -77,40 +77,20 @@ static void mnodeCleanupTimer() {
tmr_h
mnodeGetTimer
()
{
return
tsMint
.
timer
;
}
tmr_h
mnodeGetTimer
()
{
return
tsMint
.
timer
;
}
static
int32_t
mnodeSetPara
(
SMnode
*
pMnode
,
SMnodePara
para
)
{
static
int32_t
mnodeSetOptions
(
SMnode
*
pMnode
,
const
SMnodeOptions
*
pOptions
)
{
pMnode
->
dnodeId
=
para
.
dnodeId
;
pMnode
->
dnodeId
=
pOptions
->
dnodeId
;
pMnode
->
clusterId
=
para
.
clusterId
;
pMnode
->
clusterId
=
pOptions
->
clusterId
;
pMnode
->
putMsgToApplyMsgFp
=
para
.
putMsgToApplyMsgFp
;
pMnode
->
replica
=
pOptions
->
replica
;
pMnode
->
sendMsgToDnodeFp
=
para
.
sendMsgToDnodeFp
;
pMnode
->
selfIndex
=
pOptions
->
selfIndex
;
pMnode
->
sendMsgToMnodeFp
=
para
.
sendMsgToMnodeFp
;
memcpy
(
&
pMnode
->
replicas
,
pOptions
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
pMnode
->
sendRedirectMsgFp
=
para
.
sendRedirectMsgFp
;
pMnode
->
pServer
=
pOptions
->
pServer
;
pMnode
->
putMsgToApplyMsgFp
=
pOptions
->
putMsgToApplyMsgFp
;
if
(
pMnode
->
sendMsgToDnodeFp
==
NULL
)
{
pMnode
->
sendMsgToDnodeFp
=
pOptions
->
sendMsgToDnodeFp
;
terrno
=
TSDB_CODE_MND_APP_ERROR
;
pMnode
->
sendMsgToMnodeFp
=
pOptions
->
sendMsgToMnodeFp
;
return
-
1
;
pMnode
->
sendRedirectMsgFp
=
pOptions
->
sendRedirectMsgFp
;
}
if
(
pMnode
->
sendMsgToDnodeFp
==
NULL
||
pMnode
->
sendMsgToMnodeFp
==
NULL
||
pMnode
->
sendRedirectMsgFp
==
NULL
||
if
(
pMnode
->
sendMsgToMnodeFp
==
NULL
)
{
pMnode
->
putMsgToApplyMsgFp
==
NULL
||
pMnode
->
dnodeId
<
0
||
pMnode
->
clusterId
<
0
)
{
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
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
return
-
1
;
}
}
...
@@ -156,12 +136,12 @@ static int32_t mnodeAllocStartSteps() {
...
@@ -156,12 +136,12 @@ static int32_t mnodeAllocStartSteps() {
return
0
;
return
0
;
}
}
SMnode
*
mnode
Create
(
SMnodePara
para
)
{
SMnode
*
mnode
Open
(
const
char
*
path
,
const
SMnodeOptions
*
pOptions
)
{
SMnode
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnode
));
SMnode
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnode
));
if
(
mnodeSet
Para
(
pMnode
,
para
)
!=
0
)
{
if
(
mnodeSet
Options
(
pMnode
,
pOptions
)
!=
0
)
{
free
(
pMnode
);
free
(
pMnode
);
mError
(
"failed to init mnode
para
since %s"
,
terrstr
());
mError
(
"failed to init mnode
options
since %s"
,
terrstr
());
return
NULL
;
return
NULL
;
}
}
...
@@ -176,34 +156,30 @@ SMnode *mnodeCreate(SMnodePara para) {
...
@@ -176,34 +156,30 @@ SMnode *mnodeCreate(SMnodePara para) {
}
}
taosStepExec
(
tsMint
.
pInitSteps
);
taosStepExec
(
tsMint
.
pInitSteps
);
return
NULL
;
}
void
mnodeCleanup
()
{
taosStepCleanup
(
tsMint
.
pInitSteps
);
}
int32_t
mnodeDeploy
(
SMnodeCfg
*
pCfg
)
{
if
(
tsMint
.
para
.
dnodeId
<=
0
&&
tsMint
.
para
.
clusterId
<=
0
)
{
if
(
tsMint
.
para
.
dnodeId
<=
0
&&
tsMint
.
para
.
clusterId
<=
0
)
{
if
(
sdbDeploy
()
!=
0
)
{
if
(
sdbDeploy
()
!=
0
)
{
mError
(
"failed to deploy sdb since %s"
,
terrstr
());
mError
(
"failed to deploy sdb since %s"
,
terrstr
());
return
-
1
;
return
NULL
;
}
else
{
mInfo
(
"mnode is deployed"
);
}
}
}
}
mDebug
(
"mnode is deployed"
);
taosStepExec
(
tsMint
.
pStartSteps
);
return
0
;
}
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
));
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -211,7 +187,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
...
@@ -211,7 +187,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
}
}
if
(
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
pMsg
->
conn
)
!=
0
)
{
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
);
mError
(
"can not get user from conn:%p"
,
pMsg
->
rpcMsg
.
handle
);
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
return
NULL
;
return
NULL
;
...
@@ -223,7 +199,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
...
@@ -223,7 +199,7 @@ SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
return
pMsg
;
return
pMsg
;
}
}
void
mnodeCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
void
mnodeCleanupMsg
(
SMnode
*
pMnode
,
SMnode
Msg
*
pMsg
)
{
if
(
pMsg
->
pUser
!=
NULL
)
{
if
(
pMsg
->
pUser
!=
NULL
)
{
sdbRelease
(
pMsg
->
pUser
);
sdbRelease
(
pMsg
->
pUser
);
}
}
...
@@ -232,6 +208,12 @@ void mnodeCleanupMsg(SMnodeMsg *pMsg) {
...
@@ -232,6 +208,12 @@ void mnodeCleanupMsg(SMnodeMsg *pMsg) {
}
}
static
void
mnodeProcessRpcMsg
(
SMnodeMsg
*
pMsg
)
{
static
void
mnodeProcessRpcMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
!
mnodeIsMaster
())
{
mnodeSendRedirectMsg
(
NULL
,
&
pMsg
->
rpcMsg
,
true
);
mnodeCleanupMsg
(
NULL
,
pMsg
);
return
;
}
int32_t
msgType
=
pMsg
->
rpcMsg
.
msgType
;
int32_t
msgType
=
pMsg
->
rpcMsg
.
msgType
;
MnodeRpcFp
fp
=
tsMint
.
msgFp
[
msgType
];
MnodeRpcFp
fp
=
tsMint
.
msgFp
[
msgType
];
...
@@ -250,25 +232,13 @@ void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) {
...
@@ -250,25 +232,13 @@ void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) {
}
}
}
}
void
mnodeProcessMsg
(
SMnodeMsg
*
pMsg
,
EMnMsgType
msgType
)
{
void
mnodeProcessReadMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
if
(
!
mnodeIsMaster
())
{
mnodeSendRedirectMsg
(
NULL
,
&
pMsg
->
rpcMsg
,
true
);
mnodeCleanupMsg
(
pMsg
);
return
;
}
switch
(
msgType
)
{
void
mnodeProcessWriteMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
case
MN_MSG_TYPE_READ
:
case
MN_MSG_TYPE_WRITE
:
void
mnodeProcessSyncMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
case
MN_MSG_TYPE_SYNC
:
mnodeProcessRpcMsg
(
pMsg
);
void
mnodeProcessApplyMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{}
break
;
case
MN_MSG_TYPE_APPLY
:
break
;
default:
break
;
}
}
#if 0
#if 0
...
...
source/dnode/mnode/impl/src/mnodeAuth.c
浏览文件 @
2f1bb281
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
int32_t
mnodeInitAuth
()
{
return
0
;
}
int32_t
mnodeInitAuth
()
{
return
0
;
}
void
mnodeCleanupAuth
()
{}
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
)
{
if
(
strcmp
(
user
,
TSDB_NETTEST_USER
)
==
0
)
{
char
pass
[
32
]
=
{
0
};
char
pass
[
32
]
=
{
0
};
taosEncryptPass
((
uint8_t
*
)
user
,
strlen
(
user
),
pass
);
taosEncryptPass
((
uint8_t
*
)
user
,
strlen
(
user
),
pass
);
...
...
source/dnode/mnode/impl/src/mnodeTelem.c
浏览文件 @
2f1bb281
...
@@ -174,7 +174,7 @@ static void mnodeAddVersionInfo(SBufferWriter* bw) {
...
@@ -174,7 +174,7 @@ static void mnodeAddVersionInfo(SBufferWriter* bw) {
static
void
mnodeAddRuntimeInfo
(
SBufferWriter
*
bw
)
{
static
void
mnodeAddRuntimeInfo
(
SBufferWriter
*
bw
)
{
SMnodeLoad
load
=
{
0
};
SMnodeLoad
load
=
{
0
};
if
(
mnodeGetLoad
(
&
load
)
!=
0
)
{
if
(
mnodeGetLoad
(
NULL
,
&
load
)
!=
0
)
{
return
;
return
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录