mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-12-21 11:00:08 +08:00
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:
committed by
GitHub
parent
f19c9e3d9d
commit
2f72103c83
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user