cleanly destroy remote files

This commit is contained in:
Chris Lu 2019-12-25 16:17:58 -08:00
parent eecad6062a
commit 35393b4a02
3 changed files with 17 additions and 0 deletions

View file

@ -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
}

View file

@ -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")

View file

@ -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()]