Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9c29039a
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
9c29039a
编写于
9月 29, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-10430] add dnode cfg for dnode module
上级
7a78d722
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
223 addition
and
0 deletion
+223
-0
source/server/dnode/inc/dnodeCfg.h
source/server/dnode/inc/dnodeCfg.h
+45
-0
source/server/dnode/src/dnodeCfg.c
source/server/dnode/src/dnodeCfg.c
+178
-0
未找到文件。
source/server/dnode/inc/dnodeCfg.h
0 → 100644
浏览文件 @
9c29039a
/*
* 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_CFG_H_
#define _TD_DNODE_CFG_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#include "dnodeInt.h"
typedef
struct
DnCfg
{
Dnode
*
dnode
;
int32_t
dnodeId
;
int32_t
dropped
;
char
clusterId
[
TSDB_CLUSTER_ID_LEN
];
char
file
[
PATH_MAX
+
20
];
pthread_mutex_t
mutex
;
}
DnCfg
;
int32_t
dnodeInitCfg
(
Dnode
*
dnode
,
DnCfg
**
cfg
);
void
dnodeCleanupCfg
(
Dnode
*
dnode
,
DnCfg
**
cfg
);
void
dnodeUpdateCfg
(
DnCfg
*
cfg
,
SDnodeCfg
*
data
);
int32_t
dnodeGetDnodeId
(
DnCfg
*
cfg
);
void
dnodeGetClusterId
(
DnCfg
*
cfg
,
char
*
clusterId
);
void
dnodeGetCfg
(
DnCfg
*
cfg
,
int32_t
*
dnodeId
,
char
*
clusterId
);
void
dnodeSetDropped
(
DnCfg
*
cfg
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_DNODE_CFG_H_*/
source/server/dnode/src/dnodeCfg.c
0 → 100644
浏览文件 @
9c29039a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "cJSON.h"
#include "dnodeCfg.h"
static
int32_t
dnodeReadCfg
(
DnCfg
*
cfg
)
{
int32_t
len
=
0
;
int32_t
maxLen
=
200
;
char
*
content
=
calloc
(
1
,
maxLen
+
1
);
cJSON
*
root
=
NULL
;
FILE
*
fp
=
NULL
;
fp
=
fopen
(
cfg
->
file
,
"r"
);
if
(
!
fp
)
{
dDebug
(
"file %s not exist"
,
cfg
->
file
);
goto
PARSE_CFG_OVER
;
}
len
=
(
int32_t
)
fread
(
content
,
1
,
maxLen
,
fp
);
if
(
len
<=
0
)
{
dError
(
"failed to read %s since content is null"
,
cfg
->
file
);
goto
PARSE_CFG_OVER
;
}
content
[
len
]
=
0
;
root
=
cJSON_Parse
(
content
);
if
(
root
==
NULL
)
{
dError
(
"failed to read %s since invalid json format"
,
cfg
->
file
);
goto
PARSE_CFG_OVER
;
}
cJSON
*
dnodeId
=
cJSON_GetObjectItem
(
root
,
"dnodeId"
);
if
(
!
dnodeId
||
dnodeId
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since dnodeId not found"
,
cfg
->
file
);
goto
PARSE_CFG_OVER
;
}
cfg
->
dnodeId
=
(
int32_t
)
dnodeId
->
valueint
;
cJSON
*
dropped
=
cJSON_GetObjectItem
(
root
,
"dropped"
);
if
(
!
dropped
||
dropped
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since dropped not found"
,
cfg
->
file
);
goto
PARSE_CFG_OVER
;
}
cfg
->
dropped
=
(
int32_t
)
dropped
->
valueint
;
cJSON
*
clusterId
=
cJSON_GetObjectItem
(
root
,
"clusterId"
);
if
(
!
clusterId
||
clusterId
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s since clusterId not found"
,
cfg
->
file
);
goto
PARSE_CFG_OVER
;
}
tstrncpy
(
cfg
->
clusterId
,
clusterId
->
valuestring
,
TSDB_CLUSTER_ID_LEN
);
dInfo
(
"successed to read %s"
,
cfg
->
file
);
PARSE_CFG_OVER:
if
(
content
!=
NULL
)
free
(
content
);
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
terrno
=
0
;
return
0
;
}
static
int32_t
dnodeWriteCfg
(
DnCfg
*
cfg
)
{
FILE
*
fp
=
fopen
(
cfg
->
file
,
"w"
);
if
(
!
fp
)
{
dError
(
"failed to write %s since %s"
,
cfg
->
file
,
strerror
(
errno
));
return
-
1
;
}
int32_t
len
=
0
;
int32_t
maxLen
=
200
;
char
*
content
=
calloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
: %d,
\n
"
,
cfg
->
dnodeId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dropped
\"
: %d,
\n
"
,
cfg
->
dropped
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
clusterId
\"
:
\"
%s
\"\n
"
,
cfg
->
clusterId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
taosFsync
(
fileno
(
fp
));
fclose
(
fp
);
free
(
content
);
terrno
=
0
;
dInfo
(
"successed to write %s"
,
cfg
->
file
);
return
0
;
}
int32_t
dnodeInitCfg
(
Dnode
*
dnode
,
DnCfg
**
out
)
{
DnCfg
*
cfg
=
calloc
(
1
,
sizeof
(
DnCfg
));
if
(
cfg
==
NULL
)
return
-
1
;
cfg
->
dnode
=
dnode
;
cfg
->
dnodeId
=
0
;
cfg
->
dropped
=
0
;
cfg
->
clusterId
[
0
]
=
0
;
snprintf
(
cfg
->
file
,
sizeof
(
cfg
->
file
),
"%s/dnodeCfg.json"
,
tsDnodeDir
);
pthread_mutex_init
(
&
cfg
->
mutex
,
NULL
);
*
out
=
cfg
;
int32_t
ret
=
dnodeReadCfg
(
cfg
);
if
(
ret
==
0
)
{
dInfo
(
"dnode cfg is initialized"
);
}
if
(
cfg
->
dropped
)
{
dInfo
(
"dnode is dropped and start to exit"
);
return
-
1
;
}
return
ret
;
}
void
dnodeCleanupCfg
(
Dnode
*
dnode
,
DnCfg
**
out
)
{
DnCfg
*
cfg
=
*
out
;
*
out
=
NULL
;
pthread_mutex_destroy
(
&
cfg
->
mutex
);
free
(
cfg
);
}
void
dnodeUpdateCfg
(
DnCfg
*
cfg
,
SDnodeCfg
*
data
)
{
if
(
cfg
==
NULL
||
cfg
->
dnodeId
==
0
)
return
;
pthread_mutex_lock
(
&
cfg
->
mutex
);
cfg
->
dnodeId
=
data
->
dnodeId
;
tstrncpy
(
cfg
->
clusterId
,
data
->
clusterId
,
TSDB_CLUSTER_ID_LEN
);
dInfo
(
"dnodeId is set to %d, clusterId is set to %s"
,
cfg
->
dnodeId
,
cfg
->
clusterId
);
dnodeWriteCfg
(
cfg
);
pthread_mutex_unlock
(
&
cfg
->
mutex
);
}
void
dnodeSetDropped
(
DnCfg
*
cfg
)
{
pthread_mutex_lock
(
&
cfg
->
mutex
);
cfg
->
dropped
=
1
;
dnodeWriteCfg
(
cfg
);
pthread_mutex_unlock
(
&
cfg
->
mutex
);
}
int32_t
dnodeGetDnodeId
(
DnCfg
*
cfg
)
{
int32_t
dnodeId
=
0
;
pthread_mutex_lock
(
&
cfg
->
mutex
);
dnodeId
=
cfg
->
dnodeId
;
pthread_mutex_unlock
(
&
cfg
->
mutex
);
return
dnodeId
;
}
void
dnodeGetClusterId
(
DnCfg
*
cfg
,
char
*
clusterId
)
{
pthread_mutex_lock
(
&
cfg
->
mutex
);
tstrncpy
(
clusterId
,
cfg
->
clusterId
,
TSDB_CLUSTER_ID_LEN
);
pthread_mutex_unlock
(
&
cfg
->
mutex
);
}
void
dnodeGetCfg
(
DnCfg
*
cfg
,
int32_t
*
dnodeId
,
char
*
clusterId
)
{
pthread_mutex_lock
(
&
cfg
->
mutex
);
*
dnodeId
=
cfg
->
dnodeId
;
tstrncpy
(
clusterId
,
cfg
->
clusterId
,
TSDB_CLUSTER_ID_LEN
);
pthread_mutex_unlock
(
&
cfg
->
mutex
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录