Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

cleanly destroy remote files

Chris Lu35393b4a028a
diff --git a/weed/storage/volume.go b/weed/storage/volume.go
index eaeed4e771..946f044ebc 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 7fe9138690..6cca8d6cfd 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 8406ab3219..fecbd13cea 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()]