fix: close file on sdbStopWrite
This commit is contained in:
parent
7607a9788f
commit
e2ac984f61
|
@ -636,31 +636,31 @@ 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;
|
||||
}
|
||||
|
||||
taosFsyncFile(pIter->file);
|
||||
taosCloseFile(&pIter->file);
|
||||
pIter->file = NULL;
|
||||
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;
|
||||
}
|
||||
|
||||
char datafile[PATH_MAX] = {0};
|
||||
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
|
||||
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) {
|
||||
|
@ -675,7 +675,13 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
|
||||
mInfo("sdbiter:%p, success applyed to sdb", pIter);
|
||||
sdbCloseIter(pIter);
|
||||
return 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
taosCloseFile(&pIter->file);
|
||||
pIter->file = NULL;
|
||||
sdbCloseIter(pIter);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||
|
|
Loading…
Reference in New Issue