Merge pull request #13107 from taosdata/feature/3.0_mhli

fix(sync) raftCfgPersist
This commit is contained in:
Li Minghao 2022-05-27 22:34:03 +08:00 committed by GitHub
commit e2416e40d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View File

@ -27,6 +27,8 @@ extern "C" {
#include "syncInt.h"
#include "taosdef.h"
#define CONFIG_FILE_LEN 1024
typedef struct SRaftCfg {
SSyncCfg cfg;
TdFilePtr pFile;

View File

@ -50,10 +50,18 @@ int32_t raftCfgPersist(SRaftCfg *pRaftCfg) {
char *s = raftCfg2Str(pRaftCfg);
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);
return 0;
}
@ -163,8 +171,16 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, int8_t isStandBy, const char *path) {
raftCfg.cfg = *pCfg;
raftCfg.isStandBy = isStandBy;
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);
taosCloseFile(&pFile);