avoid load volume file with BytesOffset mismatch (#3841)

* avoid load volume file with BytesOffset mismatch

https://github.com/seaweedfs/seaweedfs/issues/2966

* set BytesOffset if has not VolumeInfoFile

* typos fail => failed

* exit if bytesOffset mismatch
This commit is contained in:
Konstantin Lebedev
2022-10-14 12:18:09 +05:00
committed by GitHub
parent f19c9e3d9d
commit 2f72103c83
9 changed files with 291 additions and 250 deletions

View File

@@ -61,22 +61,23 @@ func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeIn
func SaveVolumeInfo(fileName string, volumeInfo *volume_server_pb.VolumeInfo) error {
if exists, _, canWrite, _, _ := util.CheckFile(fileName); exists && !canWrite {
return fmt.Errorf("%s not writable", fileName)
return fmt.Errorf("failed to check %s not writable", fileName)
}
m := jsonpb.MarshalOptions{
AllowPartial: true,
EmitUnpopulated: true,
Indent: " ",
}
text, marshalErr := m.Marshal(volumeInfo)
if marshalErr != nil {
return fmt.Errorf("marshal to %s: %v", fileName, marshalErr)
return fmt.Errorf("failed to marshal %s: %v", fileName, marshalErr)
}
writeErr := util.WriteFile(fileName, text, 0755)
if writeErr != nil {
return fmt.Errorf("fail to write %s : %v", fileName, writeErr)
return fmt.Errorf("failed to write %s: %v", fileName, writeErr)
}
return nil