fix(sync) raftCfgPersist
This commit is contained in:
parent
3a1be0c58a
commit
b10f8e4aa2
|
@ -27,6 +27,8 @@ extern "C" {
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
|
#define CONFIG_FILE_LEN 1024
|
||||||
|
|
||||||
typedef struct SRaftCfg {
|
typedef struct SRaftCfg {
|
||||||
SSyncCfg cfg;
|
SSyncCfg cfg;
|
||||||
TdFilePtr pFile;
|
TdFilePtr pFile;
|
||||||
|
|
|
@ -50,10 +50,18 @@ int32_t raftCfgPersist(SRaftCfg *pRaftCfg) {
|
||||||
|
|
||||||
char *s = raftCfg2Str(pRaftCfg);
|
char *s = raftCfg2Str(pRaftCfg);
|
||||||
taosLSeekFile(pRaftCfg->pFile, 0, SEEK_SET);
|
taosLSeekFile(pRaftCfg->pFile, 0, SEEK_SET);
|
||||||
int64_t ret = taosWriteFile(pRaftCfg->pFile, s, strlen(s) + 1);
|
|
||||||
assert(ret == strlen(s) + 1);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
|
|
||||||
|
char buf[CONFIG_FILE_LEN];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
ASSERT(strlen(s) + 1 <= CONFIG_FILE_LEN);
|
||||||
|
snprintf(buf, sizeof(buf), "%s", s);
|
||||||
|
int64_t ret = taosWriteFile(pRaftCfg->pFile, buf, sizeof(buf));
|
||||||
|
assert(ret == sizeof(buf));
|
||||||
|
|
||||||
|
//int64_t ret = taosWriteFile(pRaftCfg->pFile, s, strlen(s) + 1);
|
||||||
|
//assert(ret == strlen(s) + 1);
|
||||||
|
|
||||||
|
taosMemoryFree(s);
|
||||||
taosFsyncFile(pRaftCfg->pFile);
|
taosFsyncFile(pRaftCfg->pFile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -163,8 +171,16 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, int8_t isStandBy, const char *path) {
|
||||||
raftCfg.cfg = *pCfg;
|
raftCfg.cfg = *pCfg;
|
||||||
raftCfg.isStandBy = isStandBy;
|
raftCfg.isStandBy = isStandBy;
|
||||||
char * s = raftCfg2Str(&raftCfg);
|
char * s = raftCfg2Str(&raftCfg);
|
||||||
int64_t ret = taosWriteFile(pFile, s, strlen(s) + 1);
|
|
||||||
assert(ret == strlen(s) + 1);
|
char buf[CONFIG_FILE_LEN];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
ASSERT(strlen(s) + 1 <= CONFIG_FILE_LEN);
|
||||||
|
snprintf(buf, sizeof(buf), "%s", s);
|
||||||
|
int64_t ret = taosWriteFile(pFile, buf, sizeof(buf));
|
||||||
|
assert(ret == sizeof(buf));
|
||||||
|
|
||||||
|
//int64_t ret = taosWriteFile(pFile, s, strlen(s) + 1);
|
||||||
|
//assert(ret == strlen(s) + 1);
|
||||||
|
|
||||||
taosMemoryFree(s);
|
taosMemoryFree(s);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
|
|
Loading…
Reference in New Issue