volume: serialize vid stamp writes and fsync the directory (#11763)

This commit is contained in:
Chris Lu
2026-10-19 03:09:25 -07:00
parent b9e8c7f9c4
commit 4fdb7f4cf1
2 changed files with 8 additions and 1 deletions
+1
View File
@@ -100,6 +100,7 @@ type Store struct {
maxVolumeIdSeen atomic.Uint32
lastSeenTopologyId atomic.Value // string
vidStampReady atomic.Bool
vidStampLock sync.Mutex
}
func (s *Store) String() (str string) {
+7 -1
View File
@@ -7,6 +7,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/util"
)
const vidStampFileName = ".vid_stamp"
@@ -90,6 +91,8 @@ func (s *Store) bootstrapMaxVolumeIdSeen() {
}
func (s *Store) saveVidStamps() {
s.vidStampLock.Lock()
defer s.vidStampLock.Unlock()
stamp, err := json.Marshal(vidStamp{
MaxVolumeId: s.maxVolumeIdSeen.Load(),
TopologyId: s.LastSeenTopologyId(),
@@ -133,5 +136,8 @@ func writeVidStamp(dir string, stamp []byte) error {
if err := f.Close(); err != nil {
return err
}
return os.Rename(tmp, filepath.Join(dir, vidStampFileName))
if err := os.Rename(tmp, filepath.Join(dir, vidStampFileName)); err != nil {
return err
}
return util.FsyncDir(dir)
}