Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ba7f9f1d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ba7f9f1d
编写于
1月 11, 2023
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: refact dmEps.c
上级
9a95c3d7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
99 deletion
+67
-99
source/dnode/mgmt/node_util/src/dmEps.c
source/dnode/mgmt/node_util/src/dmEps.c
+67
-99
未找到文件。
source/dnode/mgmt/node_util/src/dmEps.c
浏览文件 @
ba7f9f1d
...
...
@@ -41,14 +41,49 @@ static void dmGetDnodeEp(SDnodeData *pData, int32_t dnodeId, char *pEp, char *pF
taosThreadRwlockUnlock
(
&
pData
->
lock
);
}
static
int32_t
dmDecodeEps
(
SJson
*
pJson
,
SDnodeData
*
pData
)
{
int32_t
code
=
0
;
tjsonGetInt32ValueFromDouble
(
pJson
,
"dnodeId"
,
pData
->
dnodeId
,
code
);
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"dnodeVer"
,
pData
->
dnodeVer
,
code
);
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"clusterId"
,
pData
->
clusterId
,
code
);
if
(
code
<
0
)
return
-
1
;
tjsonGetInt32ValueFromDouble
(
pJson
,
"dropped"
,
pData
->
dropped
,
code
);
if
(
code
<
0
)
return
-
1
;
SJson
*
dnodes
=
tjsonGetObjectItem
(
pJson
,
"dnodes"
);
if
(
dnodes
==
NULL
)
return
0
;
int32_t
numOfDnodes
=
tjsonGetArraySize
(
dnodes
);
for
(
int32_t
i
=
0
;
i
<
numOfDnodes
;
++
i
)
{
SJson
*
dnode
=
tjsonGetArrayItem
(
dnodes
,
i
);
if
(
dnode
==
NULL
)
return
-
1
;
SDnodeEp
dnodeEp
=
{
0
};
tjsonGetInt32ValueFromDouble
(
dnode
,
"id"
,
dnodeEp
.
id
,
code
);
if
(
code
<
0
)
return
-
1
;
code
=
tjsonGetStringValue
(
dnode
,
"fqdn"
,
dnodeEp
.
ep
.
fqdn
);
if
(
code
<
0
)
return
-
1
;
tjsonGetUInt16ValueFromDouble
(
dnode
,
"port"
,
dnodeEp
.
ep
.
port
,
code
);
if
(
code
<
0
)
return
-
1
;
tjsonGetInt8ValueFromDouble
(
dnode
,
"isMnode"
,
dnodeEp
.
isMnode
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
taosArrayPush
(
pData
->
dnodeEps
,
&
dnodeEp
)
==
NULL
)
return
-
1
;
}
return
0
;
}
int32_t
dmReadEps
(
SDnodeData
*
pData
)
{
int32_t
code
=
TSDB_CODE_INVALID_JSON_FORMAT
;
int32_t
len
=
0
;
int32_t
maxLen
=
256
*
1024
;
char
*
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
cJSON
*
root
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
int32_t
code
=
-
1
;
TdFilePtr
pFile
=
NULL
;
char
*
content
=
NULL
;
SJson
*
pJson
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%sdnode%sdnode.json"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
pData
->
dnodeEps
=
taosArrayInit
(
1
,
sizeof
(
SDnodeEp
));
if
(
pData
->
dnodeEps
==
NULL
)
{
...
...
@@ -56,129 +91,62 @@ int32_t dmReadEps(SDnodeData *pData) {
goto
_OVER
;
}
snprintf
(
file
,
sizeof
(
file
),
"%s%sdnode%sdnode.json"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
if
(
taosStatFile
(
file
,
NULL
,
NULL
)
<
0
)
{
dInfo
(
"dnode file:%s not exist"
,
file
);
code
=
0
;
goto
_OVER
;
}
len
=
(
int32_t
)
taosReadFile
(
pFile
,
content
,
maxLen
);
if
(
len
<=
0
)
{
dError
(
"failed to read %s since content is null"
,
file
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to open dnode file:%s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
content
[
len
]
=
0
;
root
=
cJSON_Parse
(
content
);
if
(
root
==
NULL
)
{
dError
(
"failed to
read %s since invalid json format"
,
file
);
int64_t
size
=
0
;
if
(
taosFStatFile
(
pFile
,
&
size
,
NULL
)
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to
fstat dnode file:%s since %s"
,
file
,
terrstr
()
);
goto
_OVER
;
}
c
JSON
*
dnodeId
=
cJSON_GetObjectItem
(
root
,
"dnodeId"
);
if
(
!
dnodeId
||
dnodeId
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since dnodeId not found"
,
file
)
;
c
ontent
=
taosMemoryMalloc
(
size
+
1
);
if
(
content
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_OVER
;
}
pData
->
dnodeId
=
dnodeId
->
valueint
;
cJSON
*
dnodeVer
=
cJSON_GetObjectItem
(
root
,
"dnodeVer"
);
if
(
!
dnodeVer
||
dnodeVer
->
type
!=
cJSON_String
)
{
dError
(
"failed to read
%s since dnodeVer not found"
,
file
);
if
(
taosReadFile
(
pFile
,
content
,
size
)
!=
size
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to read
dnode file:%s since %s"
,
file
,
terrstr
()
);
goto
_OVER
;
}
pData
->
dnodeVer
=
atoll
(
dnodeVer
->
valuestring
);
cJSON
*
clusterId
=
cJSON_GetObjectItem
(
root
,
"clusterId"
);
if
(
!
clusterId
||
clusterId
->
type
!=
cJSON_String
)
{
dError
(
"failed to read %s since clusterId not found"
,
file
);
goto
_OVER
;
}
pData
->
clusterId
=
atoll
(
clusterId
->
valuestring
);
content
[
size
]
=
'\0'
;
cJSON
*
dropped
=
cJSON_GetObjectItem
(
root
,
"dropped"
);
if
(
!
dropped
||
dropped
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since dropped not found"
,
file
)
;
pJson
=
tjsonParse
(
content
);
if
(
pJson
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_JSON_FORMAT
;
goto
_OVER
;
}
pData
->
dropped
=
dropped
->
valueint
;
cJSON
*
dnodes
=
cJSON_GetObjectItem
(
root
,
"dnodes"
);
if
(
!
dnodes
||
dnodes
->
type
!=
cJSON_Array
)
{
dError
(
"failed to read %s since dnodes not found"
,
file
);
if
(
dmDecodeEps
(
pJson
,
pData
)
<
0
)
{
terrno
=
TSDB_CODE_INVALID_JSON_FORMAT
;
goto
_OVER
;
}
int32_t
numOfDnodes
=
cJSON_GetArraySize
(
dnodes
);
if
(
numOfDnodes
<=
0
)
{
dError
(
"failed to read %s since numOfDnodes:%d invalid"
,
file
,
numOfDnodes
);
goto
_OVER
;
}
for
(
int32_t
i
=
0
;
i
<
numOfDnodes
;
++
i
)
{
cJSON
*
node
=
cJSON_GetArrayItem
(
dnodes
,
i
);
if
(
node
==
NULL
)
break
;
SDnodeEp
dnodeEp
=
{
0
};
cJSON
*
did
=
cJSON_GetObjectItem
(
node
,
"id"
);
if
(
!
did
||
did
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since dnodeId not found"
,
file
);
goto
_OVER
;
}
dnodeEp
.
id
=
did
->
valueint
;
cJSON
*
dnodeFqdn
=
cJSON_GetObjectItem
(
node
,
"fqdn"
);
if
(
!
dnodeFqdn
||
dnodeFqdn
->
type
!=
cJSON_String
||
dnodeFqdn
->
valuestring
==
NULL
)
{
dError
(
"failed to read %s since dnodeFqdn not found"
,
file
);
goto
_OVER
;
}
tstrncpy
(
dnodeEp
.
ep
.
fqdn
,
dnodeFqdn
->
valuestring
,
TSDB_FQDN_LEN
);
cJSON
*
dnodePort
=
cJSON_GetObjectItem
(
node
,
"port"
);
if
(
!
dnodePort
||
dnodePort
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since dnodePort not found"
,
file
);
goto
_OVER
;
}
dnodeEp
.
ep
.
port
=
dnodePort
->
valueint
;
cJSON
*
isMnode
=
cJSON_GetObjectItem
(
node
,
"isMnode"
);
if
(
!
isMnode
||
isMnode
->
type
!=
cJSON_Number
)
{
dError
(
"failed to read %s since isMnode not found"
,
file
);
goto
_OVER
;
}
dnodeEp
.
isMnode
=
isMnode
->
valueint
;
taosArrayPush
(
pData
->
dnodeEps
,
&
dnodeEp
);
}
code
=
0
;
d
Debug
(
"succcessed to read
file %s"
,
file
);
d
Info
(
"succceed to read mnode
file %s"
,
file
);
_OVER:
if
(
content
!=
NULL
)
taosMemoryFree
(
content
);
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
pJson
!=
NULL
)
cJSON_Delete
(
pJson
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
taosArrayGetSize
(
pData
->
dnodeEps
)
==
0
)
{
SDnodeEp
dnodeEp
=
{
0
};
dnodeEp
.
isMnode
=
1
;
taosGetFqdnPortFromEp
(
tsFirst
,
&
dnodeEp
.
ep
);
taosArrayPush
(
pData
->
dnodeEps
,
&
dnodeEp
);
}
dDebug
(
"reset dnode list on startup"
);
dmResetEps
(
pData
,
pData
->
dnodeEps
);
if
(
dmIsEpChanged
(
pData
,
pData
->
dnodeId
,
tsLocalEp
))
{
dError
(
"localEp %s different with %s and need reconfigured"
,
tsLocalEp
,
file
);
return
-
1
;
if
(
code
!=
0
)
{
dError
(
"failed to read dnode file:%s since %s"
,
file
,
terrstr
());
}
terrno
=
code
;
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录