diff options
| author | Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> | 2022-10-14 12:18:09 +0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-14 00:18:09 -0700 |
| commit | 2f72103c831f8a5227613436ed87f9464825f995 (patch) | |
| tree | f82dbfe60f1999da257d291b0366c5e796efbb6a /weed/storage | |
| parent | f19c9e3d9d83daa9fa48eaeb8b23cc69215bacb5 (diff) | |
| download | seaweedfs-2f72103c831f8a5227613436ed87f9464825f995.tar.xz seaweedfs-2f72103c831f8a5227613436ed87f9464825f995.zip | |
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
Diffstat (limited to 'weed/storage')
| -rw-r--r-- | weed/storage/store.go | 4 | ||||
| -rw-r--r-- | weed/storage/volume_info/volume_info.go | 7 | ||||
| -rw-r--r-- | weed/storage/volume_loading.go | 6 | ||||
| -rw-r--r-- | weed/storage/volume_tier.go | 18 |
4 files changed, 28 insertions, 7 deletions
diff --git a/weed/storage/store.go b/weed/storage/store.go index aa5c1809f..3be0f58bf 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -548,12 +548,12 @@ func (s *Store) ConfigureVolume(i needle.VolumeId, replication string) error { vifFile := filepath.Join(location.Directory, baseFileName+".vif") volumeInfo, _, _, err := volume_info.MaybeLoadVolumeInfo(vifFile) if err != nil { - return fmt.Errorf("volume %d fail to load vif: %v", i, err) + return fmt.Errorf("volume %d failed to load vif: %v", i, err) } volumeInfo.Replication = replication err = volume_info.SaveVolumeInfo(vifFile, volumeInfo) if err != nil { - return fmt.Errorf("volume %d fail to save vif: %v", i, err) + return fmt.Errorf("volume %d failed to save vif: %v", i, err) } return nil } diff --git a/weed/storage/volume_info/volume_info.go b/weed/storage/volume_info/volume_info.go index 7f8663be2..3dbcc6e1a 100644 --- a/weed/storage/volume_info/volume_info.go +++ b/weed/storage/volume_info/volume_info.go @@ -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 diff --git a/weed/storage/volume_loading.go b/weed/storage/volume_loading.go index 97b69ad71..dac0e22a2 100644 --- a/weed/storage/volume_loading.go +++ b/weed/storage/volume_loading.go @@ -2,6 +2,7 @@ package storage import ( "fmt" + "github.com/seaweedfs/seaweedfs/weed/storage/types" "os" "github.com/syndtr/goleveldb/leveldb/opt" @@ -193,7 +194,10 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind if !hasVolumeInfoFile { v.volumeInfo.Version = uint32(v.SuperBlock.Version) - v.SaveVolumeInfo() + v.volumeInfo.BytesOffset = uint32(types.OffsetSize) + if err := v.SaveVolumeInfo(); err != nil { + glog.Warningf("volume %d failed to save file info: %v", v.Id, err) + } } stats.VolumeServerVolumeCounter.WithLabelValues(v.Collection, "volume").Inc() diff --git a/weed/storage/volume_tier.go b/weed/storage/volume_tier.go index e9bd079c1..22cace51c 100644 --- a/weed/storage/volume_tier.go +++ b/weed/storage/volume_tier.go @@ -6,7 +6,8 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/backend" _ "github.com/seaweedfs/seaweedfs/weed/storage/backend/s3_backend" "github.com/seaweedfs/seaweedfs/weed/storage/needle" - volume_info "github.com/seaweedfs/seaweedfs/weed/storage/volume_info" + "github.com/seaweedfs/seaweedfs/weed/storage/types" + "github.com/seaweedfs/seaweedfs/weed/storage/volume_info" ) func (v *Volume) GetVolumeInfo() *volume_server_pb.VolumeInfo { @@ -25,6 +26,21 @@ func (v *Volume) maybeLoadVolumeInfo() (found bool) { if v.hasRemoteFile { glog.V(0).Infof("volume %d is tiered to %s as %s and read only", v.Id, v.volumeInfo.Files[0].BackendName(), v.volumeInfo.Files[0].Key) + } else { + if v.volumeInfo.BytesOffset == 0 { + v.volumeInfo.BytesOffset = uint32(types.OffsetSize) + } + } + + if v.volumeInfo.BytesOffset != 0 && v.volumeInfo.BytesOffset != uint32(types.OffsetSize) { + var m string + if types.OffsetSize == 5 { + m = "without" + } else { + m = "with" + } + glog.Exitf("BytesOffset mismatch in volume info file %s, try use binary version %s large_disk", v.FileName(".vif"), m) + return } if err != nil { |
