diff --git a/weed/storage/volume.go b/weed/storage/volume.go index eaeed4e77..946f044eb 100644 --- a/weed/storage/volume.go +++ b/weed/storage/volume.go @@ -225,6 +225,9 @@ func (v *Volume) ToVolumeInformationMessage() *master_pb.VolumeInformationMessag } func (v *Volume) RemoteStorageNameKey() (storageName, storageKey string) { + if v.volumeTierInfo == nil { + return + } if len(v.volumeTierInfo.GetFiles()) == 0 { return } diff --git a/weed/storage/volume_read_write.go b/weed/storage/volume_read_write.go index 7fe913869..6cca8d6cf 100644 --- a/weed/storage/volume_read_write.go +++ b/weed/storage/volume_read_write.go @@ -46,6 +46,12 @@ func (v *Volume) Destroy() (err error) { err = fmt.Errorf("volume %d is compacting", v.Id) return } + storageName, storageKey := v.RemoteStorageNameKey() + if v.HasRemoteFile() && storageName != "" && storageKey != "" { + if backendStorage, found := backend.BackendStorages[storageName]; found { + backendStorage.DeleteFile(storageKey) + } + } v.Close() os.Remove(v.FileName() + ".dat") os.Remove(v.FileName() + ".idx") diff --git a/weed/storage/volume_tier.go b/weed/storage/volume_tier.go index 8406ab321..fecbd13ce 100644 --- a/weed/storage/volume_tier.go +++ b/weed/storage/volume_tier.go @@ -66,6 +66,14 @@ func (v *Volume) maybeLoadVolumeTierInfo() bool { return true } +func (v *Volume) HasRemoteFile() bool { + if v.DataBackend == nil { + return false + } + _, ok := v.DataBackend.(*backend.DiskFile) + return !ok +} + func (v *Volume) LoadRemoteFile() error { tierFile := v.volumeTierInfo.GetFiles()[0] backendStorage := backend.BackendStorages[tierFile.BackendName()]