Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7607a978
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看板
提交
7607a978
编写于
1月 06, 2023
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: handle error while write json file
上级
675f0057
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
45 addition
and
46 deletion
+45
-46
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
+6
-5
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
+6
-5
source/dnode/mgmt/node_util/src/dmEps.c
source/dnode/mgmt/node_util/src/dmEps.c
+3
-2
source/dnode/mgmt/node_util/src/dmFile.c
source/dnode/mgmt/node_util/src/dmFile.c
+30
-34
未找到文件。
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
浏览文件 @
7607a978
...
...
@@ -166,22 +166,22 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
snprintf
(
file
,
sizeof
(
file
),
"%s%smnode.json.bak"
,
path
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%smnode.json"
,
path
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
goto
_OVER
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
mmEncodeOption
(
pJson
,
pOption
)
!=
0
)
goto
_OVER
;
buffer
=
tjsonToString
(
pJson
);
if
(
buffer
==
NULL
)
goto
_OVER
;
terrno
=
0
;
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
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
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
code
=
0
;
...
...
@@ -193,6 +193,7 @@ _OVER:
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
if
(
terrno
==
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to write mnode file:%s since %s, deloyed:%d"
,
realfile
,
terrstr
(),
pOption
->
deploy
);
}
return
code
;
...
...
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
浏览文件 @
7607a978
...
...
@@ -176,9 +176,6 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
snprintf
(
file
,
sizeof
(
file
),
"%s%svnodes.json.bak"
,
pMgmt
->
path
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%svnodes.json"
,
pMgmt
->
path
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
goto
_OVER
;
int32_t
numOfVnodes
=
0
;
ppVnodes
=
vmGetVnodeListFromHash
(
pMgmt
,
&
numOfVnodes
);
if
(
ppVnodes
==
NULL
)
goto
_OVER
;
...
...
@@ -187,15 +184,18 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
vmEncodeVnodeList
(
pJson
,
ppVnodes
,
numOfVnodes
)
!=
0
)
goto
_OVER
;
buffer
=
tjsonToString
(
pJson
);
if
(
buffer
==
NULL
)
goto
_OVER
;
terrno
=
0
;
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
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
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
code
=
0
;
...
...
@@ -216,6 +216,7 @@ _OVER:
}
if
(
code
!=
0
)
{
if
(
terrno
==
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to write vnodes file:%s since %s, vnodes:%d"
,
realfile
,
terrstr
(),
numOfVnodes
);
}
return
code
;
...
...
source/dnode/mgmt/node_util/src/dmEps.c
浏览文件 @
7607a978
...
...
@@ -225,15 +225,15 @@ int32_t dmWriteEps(SDnodeData *pData) {
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
dmEncodeEps
(
pJson
,
pData
)
!=
0
)
goto
_OVER
;
buffer
=
tjsonToString
(
pJson
);
if
(
buffer
==
NULL
)
goto
_OVER
;
terrno
=
0
;
int32_t
len
=
strlen
(
buffer
);
if
(
taosWriteFile
(
pFile
,
buffer
,
len
)
<=
0
)
goto
_OVER
;
if
(
taosFsyncFile
(
pFile
)
<
0
)
goto
_OVER
;
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
code
=
0
;
...
...
@@ -246,6 +246,7 @@ _OVER:
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
if
(
terrno
==
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dInfo
(
"succeed to write dnode file:%s since %s, dnodeVer:%"
PRId64
,
realfile
,
terrstr
(),
pData
->
dnodeVer
);
}
return
code
;
...
...
source/dnode/mgmt/node_util/src/dmFile.c
浏览文件 @
7607a978
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "dmUtil.h"
#include "tjson.h"
#define MAXLEN 1024
...
...
@@ -63,56 +64,51 @@ _OVER:
return
code
;
}
static
int32_t
dmEncodeFile
(
SJson
*
pJson
,
bool
deployed
)
{
if
(
tjsonAddDoubleToObject
(
pJson
,
"deployed"
,
deployed
)
<
0
)
return
-
1
;
return
0
;
}
int32_t
dmWriteFile
(
const
char
*
path
,
const
char
*
name
,
bool
deployed
)
{
int32_t
code
=
-
1
;
int32_t
len
=
0
;
char
content
[
MAXLEN
+
1
]
=
{
0
};
char
*
buffer
=
NULL
;
SJson
*
pJson
=
NULL
;
TdFilePtr
pFile
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
TdFilePtr
pFile
=
NULL
;
snprintf
(
file
,
sizeof
(
file
),
"%s%s%s.json"
,
path
,
TD_DIRSEP
,
name
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%s%s.json"
,
path
,
TD_DIRSEP
,
name
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to write %s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
deployed
\"
: %d
\n
"
,
deployed
);
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"}
\n
"
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
dmEncodeFile
(
pJson
,
deployed
)
!=
0
)
goto
_OVER
;
buffer
=
tjsonToString
(
pJson
);
if
(
buffer
==
NULL
)
goto
_OVER
;
terrno
=
0
;
if
(
taosWriteFile
(
pFile
,
content
,
len
)
!=
len
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to write file:%s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
goto
_OVER
;
if
(
taosFsyncFile
(
pFile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to fsync file:%s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
int32_t
len
=
strlen
(
buffer
);
if
(
taosWriteFile
(
pFile
,
buffer
,
len
)
<=
0
)
goto
_OVER
;
if
(
taosFsyncFile
(
pFile
)
<
0
)
goto
_OVER
;
taosCloseFile
(
&
pFile
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to rename %s since %s"
,
file
,
terrstr
());
return
-
1
;
}
dInfo
(
"succeed to write %s, deployed:%d"
,
realfile
,
deployed
);
code
=
0
;
dInfo
(
"succeed to write file:%s, deloyed:%d"
,
realfile
,
deployed
);
_OVER:
if
(
p
File
!=
NULL
)
{
taosCloseFile
(
&
pFile
);
}
if
(
p
Json
!=
NULL
)
tjsonDelete
(
pJson
);
if
(
buffer
!=
NULL
)
taosMemoryFree
(
buffer
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
if
(
terrno
==
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to write file:%s since %s, deloyed:%d"
,
realfile
,
terrstr
(),
deployed
);
}
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录