Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
675f0057
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
675f0057
编写于
1月 06, 2023
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: handle error while write dmEps.json
上级
3c619925
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
47 addition
and
55 deletion
+47
-55
source/dnode/mgmt/node_util/src/dmEps.c
source/dnode/mgmt/node_util/src/dmEps.c
+47
-55
未找到文件。
source/dnode/mgmt/node_util/src/dmEps.c
浏览文件 @
675f0057
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "dmUtil.h"
#include "dmUtil.h"
#include "tjson.h"
#include "tmisce.h"
#include "tmisce.h"
static
void
dmPrintEps
(
SDnodeData
*
pData
);
static
void
dmPrintEps
(
SDnodeData
*
pData
);
...
@@ -181,81 +182,72 @@ _OVER:
...
@@ -181,81 +182,72 @@ _OVER:
return
code
;
return
code
;
}
}
static
int32_t
dmEncodeEps
(
SJson
*
pJson
,
SDnodeData
*
pData
)
{
if
(
tjsonAddDoubleToObject
(
pJson
,
"dnodeId"
,
pData
->
dnodeId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"dnodeVer"
,
pData
->
dnodeVer
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"clusterId"
,
pData
->
clusterId
)
<
0
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
pJson
,
"dropped"
,
pData
->
dropped
)
<
0
)
return
-
1
;
SJson
*
dnodes
=
tjsonCreateArray
();
if
(
dnodes
==
NULL
)
return
-
1
;
if
(
tjsonAddItemToObject
(
pJson
,
"dnodes"
,
dnodes
)
<
0
)
return
-
1
;
int32_t
numOfEps
=
(
int32_t
)
taosArrayGetSize
(
pData
->
dnodeEps
);
for
(
int32_t
i
=
0
;
i
<
numOfEps
;
++
i
)
{
SDnodeEp
*
pDnodeEp
=
taosArrayGet
(
pData
->
dnodeEps
,
i
);
SJson
*
dnode
=
tjsonCreateObject
();
if
(
dnode
==
NULL
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
dnode
,
"id"
,
pDnodeEp
->
id
)
<
0
)
return
-
1
;
if
(
tjsonAddStringToObject
(
dnode
,
"fqdn"
,
pDnodeEp
->
ep
.
fqdn
)
<
0
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
dnode
,
"port"
,
pDnodeEp
->
ep
.
port
)
<
0
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
dnode
,
"isMnode"
,
pDnodeEp
->
isMnode
)
<
0
)
return
-
1
;
if
(
tjsonAddItemToArray
(
dnodes
,
dnode
)
<
0
)
return
-
1
;
}
return
0
;
}
int32_t
dmWriteEps
(
SDnodeData
*
pData
)
{
int32_t
dmWriteEps
(
SDnodeData
*
pData
)
{
int32_t
code
=
-
1
;
int32_t
code
=
-
1
;
char
*
content
=
NULL
;
char
*
buffer
=
NULL
;
SJson
*
pJson
=
NULL
;
TdFilePtr
pFile
=
NULL
;
TdFilePtr
pFile
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%sdnode%sdnode.json.bak"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
snprintf
(
file
,
sizeof
(
file
),
"%s%sdnode%sdnode.json.bak"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%sdnode%sdnode.json"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%sdnode%sdnode.json"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
goto
_OVER
;
dError
(
"failed to open %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
int32_t
len
=
0
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
maxLen
=
256
*
1024
;
pJson
=
tjsonCreateObject
();
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
dmEncodeEps
(
pJson
,
pData
)
!=
0
)
goto
_OVER
;
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
buffer
=
tjsonToString
(
pJson
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
: %d,
\n
"
,
pData
->
dnodeId
);
if
(
buffer
==
NULL
)
goto
_OVER
;
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeVer
\"
:
\"
%"
PRId64
"
\"
,
\n
"
,
pData
->
dnodeVer
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
clusterId
\"
:
\"
%"
PRId64
"
\"
,
\n
"
,
pData
->
clusterId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dropped
\"
: %d,
\n
"
,
pData
->
dropped
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodes
\"
: [{
\n
"
);
int32_t
numOfEps
=
(
int32_t
)
taosArrayGetSize
(
pData
->
dnodeEps
);
for
(
int32_t
i
=
0
;
i
<
numOfEps
;
++
i
)
{
SDnodeEp
*
pDnodeEp
=
taosArrayGet
(
pData
->
dnodeEps
,
i
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
id
\"
: %d,
\n
"
,
pDnodeEp
->
id
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
fqdn
\"
:
\"
%s
\"
,
\n
"
,
pDnodeEp
->
ep
.
fqdn
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
port
\"
: %u,
\n
"
,
pDnodeEp
->
ep
.
port
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
isMnode
\"
: %d
\n
"
,
pDnodeEp
->
isMnode
);
if
(
i
<
numOfEps
-
1
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" },{
\n
"
);
}
else
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" }]
\n
"
);
}
}
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
if
(
taosWriteFile
(
pFile
,
content
,
len
)
!=
len
)
{
dError
(
"failed to write %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
if
(
taosFsyncFile
(
pFile
)
<
0
)
{
dError
(
"failed to fsync %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
int32_t
len
=
strlen
(
buffer
);
if
(
taosWriteFile
(
pFile
,
buffer
,
len
)
<=
0
)
goto
_OVER
;
if
(
taosFsyncFile
(
pFile
)
<
0
)
goto
_OVER
;
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
taosMemoryFreeClear
(
content
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
{
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to rename %s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
code
=
0
;
code
=
0
;
pData
->
updateTime
=
taosGetTimestampMs
();
pData
->
updateTime
=
taosGetTimestampMs
();
dInfo
(
"succeed to write %s, dnodeVer:%"
PRId64
,
realfile
,
pData
->
dnodeVer
);
dInfo
(
"succeed to write
dnode file:
%s, dnodeVer:%"
PRId64
,
realfile
,
pData
->
dnodeVer
);
_OVER:
_OVER:
if
(
content
!=
NULL
)
taosMemoryFreeClear
(
content
);
if
(
pJson
!=
NULL
)
tjsonDelete
(
pJson
);
if
(
buffer
!=
NULL
)
taosMemoryFree
(
buffer
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
d
Error
(
"failed to write file %s since %s"
,
realfile
,
terrstr
()
);
d
Info
(
"succeed to write dnode file:%s since %s, dnodeVer:%"
PRId64
,
realfile
,
terrstr
(),
pData
->
dnodeVer
);
}
}
return
code
;
return
code
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录