Make sure empty segments in Swift are deleted on upload cancelation

This commit is contained in:
Joseph Schorr 2018-09-27 15:12:04 -04:00
parent b894d8e58c
commit b1411d4d52
2 changed files with 8 additions and 1 deletions

View file

@ -408,6 +408,10 @@ class SwiftStorage(BaseStorage):
for segment in SwiftStorage._segment_list_from_metadata(storage_metadata, key=_SEGMENTS_KEY): for segment in SwiftStorage._segment_list_from_metadata(storage_metadata, key=_SEGMENTS_KEY):
self.remove(segment.path) self.remove(segment.path)
for segment in SwiftStorage._segment_list_from_metadata(storage_metadata,
key=_EMPTY_SEGMENTS_KEY):
self.remove(segment.path)
def copy_to(self, destination, path): def copy_to(self, destination, path):
if (self.__class__ == destination.__class__ and if (self.__class__ == destination.__class__ and
self._swift_user == destination._swift_user and self._swift_user == destination._swift_user and

View file

@ -7,7 +7,7 @@ from collections import defaultdict
from mock import MagicMock, patch from mock import MagicMock, patch
from storage import StorageContext from storage import StorageContext
from storage.swift import SwiftStorage from storage.swift import SwiftStorage, _EMPTY_SEGMENTS_KEY
from swiftclient.client import ClientException from swiftclient.client import ClientException
base_args = { base_args = {
@ -278,6 +278,9 @@ def test_cancel_chunked_upload():
for segment in SwiftStorage._segment_list_from_metadata(metadata): for segment in SwiftStorage._segment_list_from_metadata(metadata):
assert not swift.exists(segment.path) assert not swift.exists(segment.path)
for segment in SwiftStorage._segment_list_from_metadata(metadata, key=_EMPTY_SEGMENTS_KEY):
assert not swift.exists(segment.path)
def test_empty_chunks_queued_for_deletion(): def test_empty_chunks_queued_for_deletion():
chunk_cleanup_queue = FakeQueue() chunk_cleanup_queue = FakeQueue()
args = dict(base_args) args = dict(base_args)