Merge pull request #10435 from taosdata/fix/ZhiqiangWang/TD-13062-file-system-write-fsync-error
[TD-13062]<fix>: file system write fsync error
This commit is contained in:
commit
3bbb71a5dc
|
@ -2,6 +2,7 @@
|
||||||
#include "syncIO.h"
|
#include "syncIO.h"
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
void *pingFunc(void *param) {
|
void *pingFunc(void *param) {
|
||||||
SSyncIO *io = (SSyncIO *)param;
|
SSyncIO *io = (SSyncIO *)param;
|
||||||
|
@ -26,32 +27,32 @@ int main() {
|
||||||
sFatal("sync log test: fatal");
|
sFatal("sync log test: fatal");
|
||||||
|
|
||||||
SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json");
|
SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json");
|
||||||
assert(pRaftStore != NULL);
|
// assert(pRaftStore != NULL);
|
||||||
|
|
||||||
raftStorePrint(pRaftStore);
|
// raftStorePrint(pRaftStore);
|
||||||
|
|
||||||
pRaftStore->currentTerm = 100;
|
// pRaftStore->currentTerm = 100;
|
||||||
pRaftStore->voteFor.addr = 200;
|
// pRaftStore->voteFor.addr = 200;
|
||||||
pRaftStore->voteFor.vgId = 300;
|
// pRaftStore->voteFor.vgId = 300;
|
||||||
|
|
||||||
raftStorePrint(pRaftStore);
|
// raftStorePrint(pRaftStore);
|
||||||
|
|
||||||
raftStorePersist(pRaftStore);
|
// raftStorePersist(pRaftStore);
|
||||||
|
|
||||||
sDebug("sync test");
|
// sDebug("sync test");
|
||||||
|
|
||||||
SSyncIO *syncIO = syncIOCreate();
|
// SSyncIO *syncIO = syncIOCreate();
|
||||||
assert(syncIO != NULL);
|
// assert(syncIO != NULL);
|
||||||
|
|
||||||
syncIO->start(syncIO);
|
// syncIO->start(syncIO);
|
||||||
|
|
||||||
sleep(2);
|
// sleep(2);
|
||||||
|
|
||||||
pthread_t tid;
|
// pthread_t tid;
|
||||||
pthread_create(&tid, NULL, pingFunc, syncIO);
|
// pthread_create(&tid, NULL, pingFunc, syncIO);
|
||||||
|
|
||||||
while (1) {
|
// while (1) {
|
||||||
sleep(1);
|
// sleep(1);
|
||||||
}
|
// }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,6 +240,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fflush((*ppFile)->fp);
|
fflush((*ppFile)->fp);
|
||||||
|
fsync((*ppFile)->fd);
|
||||||
close((*ppFile)->fd);
|
close((*ppFile)->fd);
|
||||||
(*ppFile)->fd = -1;
|
(*ppFile)->fd = -1;
|
||||||
(*ppFile)->fp = NULL;
|
(*ppFile)->fp = NULL;
|
||||||
|
@ -295,12 +296,16 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
fflush(pFile->fp);
|
||||||
|
fsync(pFile->fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
nleft -= nwritten;
|
nleft -= nwritten;
|
||||||
tbuf += nwritten;
|
tbuf += nwritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fflush(pFile->fp);
|
||||||
|
fsync(pFile->fd);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue