fix(meta): execute sync func only when error is nil. #22883730

Signed-off-by: Victor1319 <zengxuewei@oppo.com>
This commit is contained in:
Victor1319 2024-12-11 19:16:46 +08:00 committed by AmazingChi
parent 684ca7787f
commit c9685d9713
2 changed files with 29 additions and 9 deletions

View File

@ -755,6 +755,7 @@ func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) {
log.LogFlush()
panic(err)
}
i.Reserved = reserved
}()
if err = binary.Write(buff, binary.BigEndian, &i.Type); err != nil {

View File

@ -930,7 +930,9 @@ func (mp *metaPartition) storeApplyID(rootDir string, sm *storeMsg) (err error)
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
fp.Close()
}()
@ -938,6 +940,7 @@ func (mp *metaPartition) storeApplyID(rootDir string, sm *storeMsg) (err error)
if _, err = fp.WriteString(fmt.Sprintf("%d|%d", sm.applyIndex, cursor)); err != nil {
return
}
log.LogWarnf("storeApplyID: store complete: partitionID(%v) volume(%v) applyID(%v) cursor(%v)",
mp.config.PartitionId, mp.config.VolName, sm.applyIndex, cursor)
return
@ -951,7 +954,9 @@ func (mp *metaPartition) storeTxID(rootDir string, sm *storeMsg) (err error) {
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
fp.Close()
}()
if _, err = fp.WriteString(fmt.Sprintf("%d", sm.txId)); err != nil {
@ -969,7 +974,9 @@ func (mp *metaPartition) storeTxRbDentry(rootDir string, sm *storeMsg) (crc uint
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
// TODO Unhandled errors
fp.Close()
}()
@ -1013,7 +1020,9 @@ func (mp *metaPartition) storeTxRbInode(rootDir string, sm *storeMsg) (crc uint3
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
// TODO Unhandled errors
fp.Close()
}()
@ -1057,7 +1066,9 @@ func (mp *metaPartition) storeTxInfo(rootDir string, sm *storeMsg) (crc uint32,
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
// TODO Unhandled errors
fp.Close()
}()
@ -1106,7 +1117,9 @@ func (mp *metaPartition) storeInode(rootDir string,
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
// TODO Unhandled errors
fp.Close()
}()
@ -1167,7 +1180,9 @@ func (mp *metaPartition) storeDentry(rootDir string,
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
// TODO Unhandled errors
fp.Close()
}()
@ -1348,7 +1363,9 @@ func (mp *metaPartition) doStoreUniqID(rootDir string, uniqId uint64) (err error
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
fp.Close()
}()
if _, err = fp.WriteString(fmt.Sprintf("%d", uniqId)); err != nil {
@ -1371,7 +1388,9 @@ func (mp *metaPartition) storeUniqChecker(rootDir string, sm *storeMsg) (crc uin
return
}
defer func() {
err = fp.Sync()
if err == nil {
err = fp.Sync()
}
fp.Close()
}()