Skip to content

Commit

Permalink
abort dangling multipart uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Oct 21, 2024
1 parent 1bb40c4 commit 2ad084a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/mock/storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/proc/delete_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (dh *BasicDeleteHandler) HandleDeleteGarbage(msg message.DeleteMessage) err
return errors.Wrap(err, "failed to move some files")
}

if err := dh.StorageInterractor.AbortMultipartUploads(); err != nil {
return err
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ func (s *FileStorageInteractor) MoveObject(from string, to string) error {
func (s *FileStorageInteractor) DeleteObject(key string) error {
return os.Remove(path.Join(s.cnf.StoragePrefix, key))
}

func (s *FileStorageInteractor) AbortMultipartUploads() error {
return nil
}
40 changes: 40 additions & 0 deletions pkg/storage/s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,43 @@ func (s *S3StorageInteractor) MoveObject(from string, to string) error {
}
return s.DeleteObject(from)
}

func (s *S3StorageInteractor) AbortMultipartUploads() error {
sess, err := s.pool.GetSession(context.TODO())
if err != nil {
return err
}

uploads := make([]*s3.MultipartUpload, 0)
var keyMarker *string
for {
out, err := sess.ListMultipartUploads(&s3.ListMultipartUploadsInput{
Bucket: aws.String(s.cnf.StorageBucket),
KeyMarker: keyMarker,
})
if err != nil {
return err
}

uploads = append(uploads, out.Uploads...)

if !*out.IsTruncated {
break
}

keyMarker = out.NextKeyMarker
}

for i := 0; i < len(uploads); i++ {
_, err := sess.AbortMultipartUpload(&s3.AbortMultipartUploadInput{
Bucket: aws.String(s.cnf.StorageBucket),
UploadId: uploads[i].UploadId,
Key: uploads[i].Key,
})
if err != nil {
return err
}
}

return nil
}
1 change: 1 addition & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type StorageLister interface {
type StorageMover interface {
MoveObject(from string, to string) error
DeleteObject(key string) error
AbortMultipartUploads() error
}

//go:generate mockgen -destination=pkg/mock/storage.go -package=mock
Expand Down

0 comments on commit 2ad084a

Please sign in to comment.