Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
10e7d88e
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
10e7d88e
编写于
1月 06, 2023
作者:
S
Shengliang Guan
提交者:
GitHub
1月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19418 from taosdata/fix/TD-21789
fix: handle error while write vnodes.json
上级
9bcc8648
ef6c273c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
212 addition
and
212 deletion
+212
-212
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
+57
-42
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
+53
-56
source/dnode/mgmt/node_util/src/dmEps.c
source/dnode/mgmt/node_util/src/dmEps.c
+50
-57
source/dnode/mgmt/node_util/src/dmFile.c
source/dnode/mgmt/node_util/src/dmFile.c
+30
-34
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+15
-9
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+7
-14
未找到文件。
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
浏览文件 @
10e7d88e
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "mmInt.h"
#include "tjson.h"
int32_t
mmReadFile
(
const
char
*
path
,
SMnodeOpt
*
pOption
)
{
int32_t
code
=
TSDB_CODE_INVALID_JSON_FORMAT
;
...
...
@@ -130,56 +131,70 @@ _OVER:
return
code
;
}
int32_t
mmWriteFile
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
)
{
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%smnode.json.bak"
,
path
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%smnode.json"
,
path
,
TD_DIRSEP
);
TdFilePtr
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
());
return
-
1
;
}
int32_t
len
=
0
;
int32_t
maxLen
=
4096
;
char
*
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
static
int32_t
mmEncodeOption
(
SJson
*
pJson
,
const
SMnodeOpt
*
pOption
)
{
if
(
pOption
->
deploy
&&
pOption
->
numOfReplicas
>
0
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
selfIndex
\"
: %d,
\n
"
,
pOption
->
selfIndex
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
replicas
\"
: [{
\n
"
);
if
(
tjsonAddDoubleToObject
(
pJson
,
"selfIndex"
,
pOption
->
selfIndex
)
<
0
)
return
-
1
;
SJson
*
replicas
=
tjsonCreateArray
();
if
(
replicas
==
NULL
)
return
-
1
;
if
(
tjsonAddItemToObject
(
pJson
,
"replicas"
,
replicas
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pOption
->
numOfReplicas
;
++
i
)
{
SJson
*
replica
=
tjsonCreateObject
();
if
(
replica
==
NULL
)
return
-
1
;
const
SReplica
*
pReplica
=
pOption
->
replicas
+
i
;
if
(
pReplica
!=
NULL
&&
pReplica
->
id
>
0
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
id
\"
: %d,
\n
"
,
pReplica
->
id
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
fqdn
\"
:
\"
%s
\"
,
\n
"
,
pReplica
->
fqdn
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
port
\"
: %u
\n
"
,
pReplica
->
port
);
}
if
(
i
<
pOption
->
numOfReplicas
-
1
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" },{
\n
"
);
}
else
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" }],
\n
"
);
}
if
(
tjsonAddDoubleToObject
(
replica
,
"id"
,
pReplica
->
id
)
<
0
)
return
-
1
;
if
(
tjsonAddStringToObject
(
replica
,
"fqdn"
,
pReplica
->
fqdn
)
<
0
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
replica
,
"port"
,
pReplica
->
port
)
<
0
)
return
-
1
;
if
(
tjsonAddItemToArray
(
replicas
,
replica
)
<
0
)
return
-
1
;
}
}
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
deployed
\"
: %d
\n
"
,
pOption
->
deploy
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
taosWriteFile
(
pFile
,
content
,
len
);
taosFsyncFile
(
pFile
);
if
(
tjsonAddDoubleToObject
(
pJson
,
"deployed"
,
pOption
->
deploy
)
<
0
)
return
-
1
;
return
0
;
}
int32_t
mmWriteFile
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
)
{
int32_t
code
=
-
1
;
char
*
buffer
=
NULL
;
SJson
*
pJson
=
NULL
;
TdFilePtr
pFile
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%smnode.json.bak"
,
path
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%smnode.json"
,
path
,
TD_DIRSEP
);
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
);
taosMemoryFree
(
content
)
;
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
;
}
code
=
0
;
dInfo
(
"succeed to write mnode file:%s, deloyed:%d"
,
realfile
,
pOption
->
deploy
);
dDebug
(
"succeed to write %s, deployed:%d"
,
realfile
,
pOption
->
deploy
);
return
0
;
_OVER:
if
(
pJson
!=
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 mnode file:%s since %s, deloyed:%d"
,
realfile
,
terrstr
(),
pOption
->
deploy
);
}
return
code
;
}
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
浏览文件 @
10e7d88e
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "vmInt.h"
#include "tjson.h"
#define MAX_CONTENT_LEN 2 * 1024 * 1024
...
...
@@ -144,65 +145,66 @@ _OVER:
return
code
;
}
int32_t
vmWriteVnodeListToFile
(
SVnodeMgmt
*
pMgmt
)
{
int32_t
code
=
0
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%svnodes.json.bak"
,
pMgmt
->
path
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
file
),
"%s%svnodes.json"
,
pMgmt
->
path
,
TD_DIRSEP
);
TdFilePtr
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
());
return
-
1
;
}
int32_t
numOfVnodes
=
0
;
SVnodeObj
**
ppVnodes
=
vmGetVnodeListFromHash
(
pMgmt
,
&
numOfVnodes
);
if
(
ppVnodes
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
-
1
;
dError
(
"failed to write %s while get vnodelist"
,
file
);
goto
_OVER
;
}
int32_t
len
=
0
;
int32_t
maxLen
=
MAX_CONTENT_LEN
;
char
*
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
if
(
content
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
-
1
;
dError
(
"failed to write %s while malloc content"
,
file
);
goto
_OVER
;
}
static
int32_t
vmEncodeVnodeList
(
SJson
*
pJson
,
SVnodeObj
**
ppVnodes
,
int32_t
numOfVnodes
)
{
SJson
*
vnodes
=
tjsonCreateArray
();
if
(
vnodes
==
NULL
)
return
-
1
;
if
(
tjsonAddItemToObject
(
pJson
,
"vnodes"
,
vnodes
)
<
0
)
return
-
1
;
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
vnodes
\"
: [
\n
"
);
for
(
int32_t
i
=
0
;
i
<
numOfVnodes
;
++
i
)
{
SVnodeObj
*
pVnode
=
ppVnodes
[
i
];
if
(
pVnode
==
NULL
)
continue
;
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" {
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
vgId
\"
: %d,
\n
"
,
pVnode
->
vgId
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dropped
\"
: %d,
\n
"
,
pVnode
->
dropped
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
vgVersion
\"
: %d
\n
"
,
pVnode
->
vgVersion
);
if
(
i
<
numOfVnodes
-
1
)
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" },
\n
"
);
}
else
{
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" }
\n
"
);
}
SJson
*
vnode
=
tjsonCreateObject
();
if
(
vnode
==
NULL
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
vnode
,
"vgId"
,
pVnode
->
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
vnode
,
"dropped"
,
pVnode
->
dropped
)
<
0
)
return
-
1
;
if
(
tjsonAddDoubleToObject
(
vnode
,
"vgVersion"
,
pVnode
->
vgVersion
)
<
0
)
return
-
1
;
if
(
tjsonAddItemToArray
(
vnodes
,
vnode
)
<
0
)
return
-
1
;
}
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
" ]
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
return
0
;
}
int32_t
vmWriteVnodeListToFile
(
SVnodeMgmt
*
pMgmt
)
{
int32_t
code
=
-
1
;
char
*
buffer
=
NULL
;
SJson
*
pJson
=
NULL
;
TdFilePtr
pFile
=
NULL
;
SVnodeObj
**
ppVnodes
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%svnodes.json.bak"
,
pMgmt
->
path
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%svnodes.json"
,
pMgmt
->
path
,
TD_DIRSEP
);
int32_t
numOfVnodes
=
0
;
ppVnodes
=
vmGetVnodeListFromHash
(
pMgmt
,
&
numOfVnodes
);
if
(
ppVnodes
==
NULL
)
goto
_OVER
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
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
;
_OVER:
taosWriteFile
(
pFile
,
content
,
len
);
taosFsyncFile
(
pFile
);
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
);
taosMemoryFree
(
content
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
code
=
0
;
dInfo
(
"succeed to write vnodes file:%s, vnodes:%d"
,
realfile
,
numOfVnodes
);
_OVER:
if
(
pJson
!=
NULL
)
tjsonDelete
(
pJson
);
if
(
buffer
!=
NULL
)
taosMemoryFree
(
buffer
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
ppVnodes
!=
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
numOfVnodes
;
++
i
)
{
SVnodeObj
*
pVnode
=
ppVnodes
[
i
];
...
...
@@ -213,14 +215,9 @@ _OVER:
taosMemoryFree
(
ppVnodes
);
}
if
(
code
!=
0
)
return
-
1
;
dInfo
(
"succeed to write %s, numOfVnodes:%d"
,
realfile
,
numOfVnodes
);
code
=
taosRenameFile
(
file
,
realfile
);
if
(
code
!=
0
)
{
dError
(
"failed to rename %s to %s"
,
file
,
realfile
);
if
(
terrno
==
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to write vnodes file:%s since %s, vnodes:%d"
,
realfile
,
terrstr
(),
numOfVnodes
);
}
return
code
;
}
\ No newline at end of file
source/dnode/mgmt/node_util/src/dmEps.c
浏览文件 @
10e7d88e
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "dmUtil.h"
#include "tjson.h"
#include "tmisce.h"
static
void
dmPrintEps
(
SDnodeData
*
pData
);
...
...
@@ -181,81 +182,73 @@ _OVER:
return
code
;
}
int32_t
dmWriteEps
(
SDnodeData
*
pData
)
{
int32_t
code
=
-
1
;
char
*
content
=
NULL
;
TdFilePtr
pFile
=
NULL
;
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
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
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
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
dError
(
"failed to open %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
int32_t
len
=
0
;
int32_t
maxLen
=
256
*
1024
;
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
: %d,
\n
"
,
pData
->
dnodeId
);
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
"
);
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
);
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
"
);
}
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
;
}
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
;
}
return
0
;
}
if
(
taosFsyncFile
(
pFile
)
<
0
)
{
dError
(
"failed to fsync %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
int32_t
dmWriteEps
(
SDnodeData
*
pData
)
{
int32_t
code
=
-
1
;
char
*
buffer
=
NULL
;
SJson
*
pJson
=
NULL
;
TdFilePtr
pFile
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
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
);
taosCloseFile
(
&
pFile
);
taosMemoryFreeClear
(
content
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
dmEncodeEps
(
pJson
,
pData
)
!=
0
)
goto
_OVER
;
buffer
=
tjsonToString
(
pJson
);
if
(
buffer
==
NULL
)
goto
_OVER
;
terrno
=
0
;
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to rename %s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
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
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
code
=
0
;
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:
if
(
content
!=
NULL
)
taosMemoryFreeClear
(
content
);
if
(
pJson
!=
NULL
)
tjsonDelete
(
pJson
);
if
(
buffer
!=
NULL
)
taosMemoryFree
(
buffer
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
dError
(
"failed to write file %s since %s"
,
realfile
,
terrstr
());
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
浏览文件 @
10e7d88e
...
...
@@ -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
;
}
...
...
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
10e7d88e
...
...
@@ -636,15 +636,20 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
}
int32_t
sdbStopWrite
(
SSdb
*
pSdb
,
SSdbIter
*
pIter
,
bool
isApply
,
int64_t
index
,
int64_t
term
,
int64_t
config
)
{
int32_t
code
=
0
;
int32_t
code
=
-
1
;
if
(
!
isApply
)
{
mInfo
(
"sdbiter:%p, not apply to sdb"
,
pIter
);
sdbCloseIter
(
pIter
);
return
0
;
code
=
0
;
goto
_OVER
;
}
if
(
taosFsyncFile
(
pIter
->
file
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"sdbiter:%p, failed to fasync file %s since %s"
,
pIter
,
pIter
->
name
,
terrstr
());
goto
_OVER
;
}
taosFsyncFile
(
pIter
->
file
);
taosCloseFile
(
&
pIter
->
file
);
pIter
->
file
=
NULL
;
...
...
@@ -653,14 +658,12 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
if
(
taosRenameFile
(
pIter
->
name
,
datafile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"sdbiter:%p, failed to rename file %s to %s since %s"
,
pIter
,
pIter
->
name
,
datafile
,
terrstr
());
sdbCloseIter
(
pIter
);
return
-
1
;
goto
_OVER
;
}
if
(
sdbReadFile
(
pSdb
)
!=
0
)
{
mError
(
"sdbiter:%p, failed to read from %s since %s"
,
pIter
,
datafile
,
terrstr
());
sdbCloseIter
(
pIter
);
return
-
1
;
goto
_OVER
;
}
if
(
config
>
0
)
{
...
...
@@ -674,8 +677,11 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
}
mInfo
(
"sdbiter:%p, success applyed to sdb"
,
pIter
);
code
=
0
;
_OVER:
sdbCloseIter
(
pIter
);
return
0
;
return
code
;
}
int32_t
sdbDoWrite
(
SSdb
*
pSdb
,
SSdbIter
*
pIter
,
void
*
pBuf
,
int32_t
len
)
{
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
10e7d88e
...
...
@@ -71,31 +71,23 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) {
char
file
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s.bak"
,
realfile
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
sError
(
"vgId:%d, failed to open sync cfg file:%s since %s"
,
pNode
->
vgId
,
realfile
,
terrstr
());
goto
_OVER
;
}
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
pJson
=
tjsonCreateObject
();
if
(
pJson
==
NULL
)
goto
_OVER
;
if
(
tjsonAddObject
(
pJson
,
"RaftCfg"
,
syncEncodeRaftCfg
,
pCfg
)
<
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
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
sError
(
"vgId:%d, failed to rename sync cfg file:%s to %s since %s"
,
pNode
->
vgId
,
file
,
realfile
,
terrstr
());
goto
_OVER
;
}
taosCloseFile
(
&
pFile
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
goto
_OVER
;
code
=
0
;
sInfo
(
"vgId:%d, succeed to write sync cfg file:%s, len:%d"
,
pNode
->
vgId
,
realfile
,
len
);
...
...
@@ -106,6 +98,7 @@ _OVER:
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
if
(
terrno
==
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
sError
(
"vgId:%d, failed to write sync cfg file:%s since %s"
,
pNode
->
vgId
,
realfile
,
terrstr
());
}
return
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录