Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e194d87e
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看板
未验证
提交
e194d87e
编写于
1月 10, 2023
作者:
S
Shengliang Guan
提交者:
GitHub
1月 10, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19456 from taosdata/fix/TD-21646
enh: read mnode file
上级
6a6d53b8
012dbf31
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
65 addition
and
85 deletion
+65
-85
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
+65
-85
未找到文件。
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
浏览文件 @
e194d87e
...
...
@@ -17,117 +17,97 @@
#include "mmInt.h"
#include "tjson.h"
int32_t
mmReadFile
(
const
char
*
path
,
SMnodeOpt
*
pOption
)
{
int32_t
code
=
TSDB_CODE_INVALID_JSON_FORMAT
;
int32_t
len
=
0
;
int32_t
maxLen
=
4096
;
char
*
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
cJSON
*
root
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
TdFilePtr
pFile
=
NULL
;
static
int32_t
mmDecodeOption
(
SJson
*
pJson
,
SMnodeOpt
*
pOption
)
{
int32_t
code
=
0
;
snprintf
(
file
,
sizeof
(
file
),
"%s%smnode.json"
,
path
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
code
=
0
;
goto
_OVER
;
}
tjsonGetInt32ValueFromDouble
(
pJson
,
"deployed"
,
pOption
->
deploy
,
code
);
if
(
code
<
0
)
return
-
1
;
tjsonGetInt32ValueFromDouble
(
pJson
,
"selfIndex"
,
pOption
->
selfIndex
,
code
);
if
(
code
<
0
)
return
0
;
len
=
(
int32_t
)
taosReadFile
(
pFile
,
content
,
maxLen
);
if
(
len
<=
0
)
{
dError
(
"failed to read %s since content is null"
,
file
);
goto
_OVER
;
}
SJson
*
replicas
=
tjsonGetObjectItem
(
pJson
,
"replicas"
);
if
(
replicas
==
NULL
)
return
0
;
pOption
->
numOfReplicas
=
tjsonGetArraySize
(
replicas
);
content
[
len
]
=
0
;
root
=
cJSON_Parse
(
content
);
if
(
root
==
NULL
)
{
dError
(
"failed to read %s since invalid json format"
,
file
);
goto
_OVER
;
for
(
int32_t
i
=
0
;
i
<
pOption
->
numOfReplicas
;
++
i
)
{
SJson
*
replica
=
tjsonGetArrayItem
(
replicas
,
i
);
if
(
replica
==
NULL
)
return
-
1
;
SReplica
*
pReplica
=
pOption
->
replicas
+
i
;
tjsonGetInt32ValueFromDouble
(
replica
,
"id"
,
pReplica
->
id
,
code
);
if
(
code
<
0
)
return
-
1
;
code
=
tjsonGetStringValue
(
replica
,
"fqdn"
,
pReplica
->
fqdn
);
if
(
code
<
0
)
return
-
1
;
tjsonGetUInt16ValueFromDouble
(
replica
,
"port"
,
pReplica
->
port
,
code
);
if
(
code
<
0
)
return
-
1
;
}
cJSON
*
deployed
=
cJSON_GetObjectItem
(
root
,
"deployed"
);
if
(
!
deployed
||
deployed
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since deployed not found"
,
file
);
goto
_OVER
;
return
0
;
}
int32_t
mmReadFile
(
const
char
*
path
,
SMnodeOpt
*
pOption
)
{
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
NULL
;
char
*
pData
=
NULL
;
SJson
*
pJson
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%smnode.json"
,
path
,
TD_DIRSEP
);
if
(
taosStatFile
(
file
,
NULL
,
NULL
)
<
0
)
{
dInfo
(
"mnode file:%s not exist"
,
file
);
return
0
;
}
pOption
->
deploy
=
deployed
->
valueint
;
cJSON
*
selfIndex
=
cJSON_GetObjectItem
(
root
,
"selfIndex"
);
if
(
selfIndex
)
{
if
(
selfIndex
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since selfIndex not found"
,
file
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to open mnode file:%s since %s"
,
file
,
terrstr
()
);
goto
_OVER
;
}
pOption
->
selfIndex
=
selfIndex
->
valueint
;
}
cJSON
*
replicas
=
cJSON_GetObjectItem
(
root
,
"replicas"
)
;
if
(
replicas
)
{
if
(
replicas
->
type
!=
cJSON_Array
)
{
dError
(
"failed to read %s since replicas not found"
,
file
);
int64_t
size
=
0
;
if
(
taosFStatFile
(
pFile
,
&
size
,
NULL
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to fstat mnode file:%s since %s"
,
file
,
terrstr
()
);
goto
_OVER
;
}
int32_t
numOfReplicas
=
cJSON_GetArraySize
(
replicas
);
if
(
numOfReplicas
<=
0
)
{
dError
(
"failed to read %s since numOfReplicas:%d invalid"
,
file
,
numOfReplicas
)
;
pData
=
taosMemoryMalloc
(
size
+
1
);
if
(
pData
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_OVER
;
}
pOption
->
numOfReplicas
=
numOfReplicas
;
for
(
int32_t
i
=
0
;
i
<
numOfReplicas
;
++
i
)
{
SReplica
*
pReplica
=
pOption
->
replicas
+
i
;
cJSON
*
replica
=
cJSON_GetArrayItem
(
replicas
,
i
);
if
(
replica
==
NULL
)
break
;
cJSON
*
id
=
cJSON_GetObjectItem
(
replica
,
"id"
);
if
(
id
)
{
if
(
id
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since id not found"
,
file
);
if
(
taosReadFile
(
pFile
,
pData
,
size
)
!=
size
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to read mnode file:%s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
if
(
pReplica
)
{
pReplica
->
id
=
id
->
valueint
;
}
}
cJSON
*
fqdn
=
cJSON_GetObjectItem
(
replica
,
"fqdn"
);
if
(
fqdn
)
{
if
(
fqdn
->
type
!=
cJSON_String
||
fqdn
->
valuestring
==
NULL
)
{
dError
(
"failed to read %s since fqdn not found"
,
file
);
pData
[
size
]
=
'\0'
;
pJson
=
tjsonParse
(
pData
);
if
(
pJson
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_JSON_FORMAT
;
goto
_OVER
;
}
if
(
pReplica
)
{
tstrncpy
(
pReplica
->
fqdn
,
fqdn
->
valuestring
,
TSDB_FQDN_LEN
);
}
}
cJSON
*
port
=
cJSON_GetObjectItem
(
replica
,
"port"
);
if
(
port
)
{
if
(
port
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since port not found"
,
file
);
if
(
mmDecodeOption
(
pJson
,
pOption
)
<
0
)
{
terrno
=
TSDB_CODE_INVALID_JSON_FORMAT
;
goto
_OVER
;
}
if
(
pReplica
)
{
pReplica
->
port
=
(
uint16_t
)
port
->
valueint
;
}
}
}
}
code
=
0
;
dInfo
(
"succceed to read mnode file %s"
,
file
);
_OVER:
if
(
content
!=
NULL
)
taosMemoryFree
(
content
);
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
pData
!=
NULL
)
taosMemoryFree
(
pData
);
if
(
pJson
!=
NULL
)
cJSON_Delete
(
pJson
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
==
0
)
{
dDebug
(
"succcessed to read file %s, deployed:%d"
,
file
,
pOption
->
deploy
);
}
terrno
=
code
;
if
(
code
!=
0
)
{
dError
(
"failed to read mnode file:%s since %s"
,
file
,
terrstr
());
}
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录