Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
2136789e
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2136789e
编写于
8月 08, 2020
作者:
H
Hui Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-662]
上级
0ba581ec
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
322 addition
and
0 deletion
+322
-0
src/dnode/inc/dnodeCheck.h
src/dnode/inc/dnodeCheck.h
+31
-0
src/dnode/src/dnodeCheck.c
src/dnode/src/dnodeCheck.c
+275
-0
src/dnode/src/dnodeMain.c
src/dnode/src/dnodeMain.c
+3
-0
src/inc/taosdef.h
src/inc/taosdef.h
+13
-0
未找到文件。
src/dnode/inc/dnodeCheck.h
0 → 100644
浏览文件 @
2136789e
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_DNODE_CHECK_H
#define TDENGINE_DNODE_CHECK_H
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
dnodeInitCheck
();
void
dnodeStartCheck
();
void
dnodeCleanupCheck
();
#ifdef __cplusplus
}
#endif
#endif
src/dnode/src/dnodeCheck.c
0 → 100644
浏览文件 @
2136789e
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <sys/statfs.h>
#include <sys/vfs.h>
#include <sys/sysinfo.h>
#include <errno.h>
#include "os.h"
#include "taosdef.h"
#include "tglobal.h"
#include "mnode.h"
#include "dnodeInt.h"
#include "dnodeCheck.h"
typedef
struct
{
bool
enable
;
char
*
name
;
int32_t
(
*
initFp
)();
int32_t
(
*
startFp
)();
void
(
*
cleanUpFp
)();
void
(
*
stopFp
)();
}
SCheckItem
;
static
SCheckItem
tsCheckItem
[
TSDB_CHECK_ITEM_MAX
]
=
{{
0
}};
int64_t
tsMinFreeMemSizeForStart
=
0
;
static
int
bindTcpPort
(
int
port
)
{
int
serverSocket
;
struct
sockaddr_in
server_addr
;
if
((
serverSocket
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
))
<
0
)
{
dError
(
"socket() fail: %s"
,
strerror
(
errno
));
return
-
1
;
}
bzero
(
&
server_addr
,
sizeof
(
server_addr
));
server_addr
.
sin_family
=
AF_INET
;
server_addr
.
sin_port
=
htons
(
port
);
server_addr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
if
(
bind
(
serverSocket
,
(
struct
sockaddr
*
)
&
server_addr
,
sizeof
(
server_addr
))
<
0
)
{
dError
(
"port:%d tcp bind() fail: %s"
,
port
,
strerror
(
errno
));
close
(
serverSocket
);
return
-
1
;
}
if
(
listen
(
serverSocket
,
5
)
<
0
)
{
dError
(
"port:%d listen() fail: %s"
,
port
,
strerror
(
errno
));
close
(
serverSocket
);
return
-
1
;
}
close
(
serverSocket
);
return
0
;
}
static
int
bindUdpPort
(
int
port
)
{
int
serverSocket
;
struct
sockaddr_in
server_addr
;
if
((
serverSocket
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
))
<
0
)
{
dError
(
"socket() fail: %s"
,
strerror
(
errno
));
return
-
1
;
}
bzero
(
&
server_addr
,
sizeof
(
server_addr
));
server_addr
.
sin_family
=
AF_INET
;
server_addr
.
sin_port
=
htons
(
port
);
server_addr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
if
(
bind
(
serverSocket
,
(
struct
sockaddr
*
)
&
server_addr
,
sizeof
(
server_addr
))
<
0
)
{
dError
(
"port:%d udp bind() fail: %s"
,
port
,
strerror
(
errno
));
close
(
serverSocket
);
return
-
1
;
}
close
(
serverSocket
);
return
0
;
}
static
int
dnodeCheckNetwork
()
{
int
ret
;
int
startPort
=
tsServerPort
;
for
(
int
port
=
startPort
;
port
<
startPort
+
12
;
port
++
)
{
ret
=
bindTcpPort
(
port
);
if
(
0
!=
ret
)
{
return
-
1
;
}
ret
=
bindUdpPort
(
port
);
if
(
0
!=
ret
)
{
return
-
1
;
}
}
return
0
;
}
static
int
dnodeCheckMem
()
{
float
memoryUsedMB
;
float
memoryAvailMB
;
if
(
true
!=
taosGetSysMemory
(
&
memoryUsedMB
))
{
dError
(
"failed to get system mem infomation, errno:%u, reason:%s"
,
errno
,
strerror
(
errno
));
return
-
1
;
}
memoryAvailMB
=
(
float
)
tsTotalMemoryMB
-
memoryUsedMB
;
if
(
memoryAvailMB
<
tsMinFreeMemSizeForStart
)
{
dError
(
"free mem %f too little, quit"
,
memoryAvailMB
);
return
-
1
;
}
return
0
;
}
static
int
dnodeCheckCpu
()
{
// TODO:
return
0
;
}
static
int
dnodeCheckDisk
()
{
if
(
tsAvailDataDirGB
<
tsMinimalDataDirGB
)
{
dError
(
"free disk size: %f GB, too little, quit"
,
tsAvailDataDirGB
);
return
-
1
;
}
if
(
tsAvailLogDirGB
<
tsMinimalLogDirGB
)
{
dError
(
"free disk size: %f GB, too little, quit"
,
tsAvailLogDirGB
);
return
-
1
;
}
if
(
tsAvailTmpDirectorySpace
<
tsReservedTmpDirectorySpace
)
{
dError
(
"free disk size: %f GB, too little, quit"
,
tsAvailTmpDirectorySpace
);
return
-
1
;
}
return
0
;
}
static
int
dnodeCheckOs
()
{
// TODO:
return
0
;
}
static
int
dnodeCheckAccess
()
{
// TODO:
return
0
;
}
static
int
dnodeCheckVersion
()
{
// TODO:
return
0
;
}
static
int
dnodeCheckDatafile
()
{
// TODO:
return
0
;
}
static
void
dnodeAllocCheckItem
()
{
tsCheckItem
[
TSDB_CHECK_ITEM_NETWORK
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_NETWORK
].
name
=
"network"
;
tsCheckItem
[
TSDB_CHECK_ITEM_NETWORK
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_NETWORK
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_NETWORK
].
startFp
=
dnodeCheckNetwork
;
tsCheckItem
[
TSDB_CHECK_ITEM_NETWORK
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_MEM
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_MEM
].
name
=
"mem"
;
tsCheckItem
[
TSDB_CHECK_ITEM_MEM
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_MEM
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_MEM
].
startFp
=
dnodeCheckMem
;
tsCheckItem
[
TSDB_CHECK_ITEM_MEM
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_CPU
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_CPU
].
name
=
"cpu"
;
tsCheckItem
[
TSDB_CHECK_ITEM_CPU
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_CPU
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_CPU
].
startFp
=
dnodeCheckCpu
;
tsCheckItem
[
TSDB_CHECK_ITEM_CPU
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_DISK
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_DISK
].
name
=
"disk"
;
tsCheckItem
[
TSDB_CHECK_ITEM_DISK
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_DISK
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_DISK
].
startFp
=
dnodeCheckDisk
;
tsCheckItem
[
TSDB_CHECK_ITEM_DISK
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_OS
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_OS
].
name
=
"os"
;
tsCheckItem
[
TSDB_CHECK_ITEM_OS
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_OS
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_OS
].
startFp
=
dnodeCheckOs
;
tsCheckItem
[
TSDB_CHECK_ITEM_OS
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_ACCESS
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_ACCESS
].
name
=
"access"
;
tsCheckItem
[
TSDB_CHECK_ITEM_ACCESS
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_ACCESS
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_ACCESS
].
startFp
=
dnodeCheckAccess
;
tsCheckItem
[
TSDB_CHECK_ITEM_ACCESS
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_VERSION
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_VERSION
].
name
=
"version"
;
tsCheckItem
[
TSDB_CHECK_ITEM_VERSION
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_VERSION
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_VERSION
].
startFp
=
dnodeCheckVersion
;
tsCheckItem
[
TSDB_CHECK_ITEM_VERSION
].
stopFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_DATAFILE
].
enable
=
true
;
tsCheckItem
[
TSDB_CHECK_ITEM_DATAFILE
].
name
=
"datafile"
;
tsCheckItem
[
TSDB_CHECK_ITEM_DATAFILE
].
initFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_DATAFILE
].
cleanUpFp
=
NULL
;
tsCheckItem
[
TSDB_CHECK_ITEM_DATAFILE
].
startFp
=
dnodeCheckDatafile
;
tsCheckItem
[
TSDB_CHECK_ITEM_DATAFILE
].
stopFp
=
NULL
;
}
void
dnodeCleanupCheck
()
{
for
(
ECheckItemType
index
=
0
;
index
<
TSDB_CHECK_ITEM_MAX
;
++
index
)
{
if
(
tsCheckItem
[
index
].
enable
&&
tsCheckItem
[
index
].
stopFp
)
{
(
*
tsCheckItem
[
index
].
stopFp
)();
}
if
(
tsCheckItem
[
index
].
cleanUpFp
)
{
(
*
tsCheckItem
[
index
].
cleanUpFp
)();
}
}
}
int32_t
dnodeInitCheck
()
{
dnodeAllocCheckItem
();
for
(
ECheckItemType
index
=
0
;
index
<
TSDB_CHECK_ITEM_MAX
;
++
index
)
{
if
(
tsCheckItem
[
index
].
initFp
)
{
if
((
*
tsCheckItem
[
index
].
initFp
)()
!=
0
)
{
dError
(
"failed to init check item:%s"
,
tsCheckItem
[
index
].
name
);
return
-
1
;
}
}
}
return
0
;
}
void
dnodeStartCheck
()
{
for
(
ECheckItemType
index
=
0
;
index
<
TSDB_CHECK_ITEM_MAX
;
++
index
)
{
if
(
tsCheckItem
[
index
].
enable
&&
tsCheckItem
[
index
].
startFp
)
{
if
((
*
tsCheckItem
[
index
].
startFp
)()
!=
0
)
{
dError
(
"failed to check item:%s"
,
tsCheckItem
[
index
].
name
);
exit
(
-
1
);
}
}
}
}
src/dnode/src/dnodeMain.c
浏览文件 @
2136789e
...
...
@@ -24,6 +24,7 @@
#include "dnodeMgmt.h"
#include "dnodePeer.h"
#include "dnodeModule.h"
#include "dnodeCheck.h"
#include "dnodeVRead.h"
#include "dnodeVWrite.h"
#include "dnodeMRead.h"
...
...
@@ -61,6 +62,7 @@ static const SDnodeComponent tsDnodeComponents[] = {
{
"mgmt-tmr"
,
dnodeInitMgmtTimer
,
dnodeCleanupMgmtTimer
},
{
"shell"
,
dnodeInitShell
,
dnodeCleanupShell
},
{
"telemetry"
,
dnodeInitTelemetry
,
dnodeCleanupTelemetry
},
{
"check"
,
dnodeInitCheck
,
dnodeCleanupCheck
},
};
static
int
dnodeCreateDir
(
const
char
*
dir
)
{
...
...
@@ -123,6 +125,7 @@ int32_t dnodeInitSystem() {
return
-
1
;
}
dnodeStartCheck
();
dnodeStartModules
();
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_RUNING
);
...
...
src/inc/taosdef.h
浏览文件 @
2136789e
...
...
@@ -416,6 +416,19 @@ typedef enum {
TSDB_MOD_MAX
}
EModuleType
;
typedef
enum
{
TSDB_CHECK_ITEM_NETWORK
,
TSDB_CHECK_ITEM_MEM
,
TSDB_CHECK_ITEM_CPU
,
TSDB_CHECK_ITEM_DISK
,
TSDB_CHECK_ITEM_OS
,
TSDB_CHECK_ITEM_ACCESS
,
TSDB_CHECK_ITEM_VERSION
,
TSDB_CHECK_ITEM_DATAFILE
,
TSDB_CHECK_ITEM_MAX
}
ECheckItemType
;
#ifdef __cplusplus
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录