Skip to content

Commit

Permalink
Merge pull request cubefs#691 from LeeYubo/list_multipart_order
Browse files Browse the repository at this point in the history
Fix: issue on sorting list multipart upload result
  • Loading branch information
mervinkid authored Jun 27, 2020
2 parents d9d062e + d99b635 commit fc3e1d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 22 additions & 11 deletions docker/s3tests/test_list_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# permissions and limitations under the License.

# -*- coding: utf-8 -*-
import uuid
from env import BUCKET
from base import S3TestCase, get_env_s3_client

Expand Down Expand Up @@ -48,22 +49,31 @@ def setUpClass(cls):
cls.abort_previous_upload()
# create new test multipart uploads
for i in range(INIT_NUMBERS):
key = str(i) + ".txt"
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=key)
upload = UploadInfo(upload_id=res["UploadId"], key=key)
prefix_key = KEY_PREFIX + str(i)
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=prefix_key)
upload = UploadInfo(upload_id=res["UploadId"], key=prefix_key)
ListMultipartTest.uploadInfos.append(upload)
ListMultipartTest.commonUploadInfos.append(upload)

for i in range(INIT_NUMBERS):
key = KEY_PREFIX_ONE + str(i) + ".txt"
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=key)
upload = UploadInfo(upload_id=res["UploadId"], key=key)
prefix_one_key = KEY_PREFIX_ONE + str(i)
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=prefix_one_key)
upload = UploadInfo(upload_id=res["UploadId"], key=prefix_one_key)
ListMultipartTest.uploadInfos.append(upload)
ListMultipartTest.prefixUploadInfos.append(upload)

for i in range(INIT_NUMBERS):
key = KEY_PREFIX_TWO + str(i) + ".txt"
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=key)
upload = UploadInfo(upload_id=res["UploadId"], key=key)
prefix_two_key = KEY_PREFIX_TWO + str(i)
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=prefix_two_key)
upload = UploadInfo(upload_id=res["UploadId"], key=prefix_two_key)
ListMultipartTest.uploadInfos.append(upload)

for i in range(INIT_NUMBERS):
random_key = str(uuid.uuid4())
res = cls.s3.create_multipart_upload(Bucket=BUCKET, Key=random_key)
upload = UploadInfo(upload_id=res["UploadId"], key=random_key)
ListMultipartTest.uploadInfos.append(upload)
ListMultipartTest.commonUploadInfos.append(upload)

ListMultipartTest.uploadInfos = sorted(ListMultipartTest.uploadInfos,
key=lambda upload_info: upload_info.key, )
ListMultipartTest.prefixUploadInfos = sorted(ListMultipartTest.prefixUploadInfos,
Expand Down Expand Up @@ -146,7 +156,7 @@ def test_list_size_and_order(self):
if not is_truncated:
break
# check the key list size
self.assertEqual(INIT_NUMBERS * 3, response_list_size)
self.assertEqual(INIT_NUMBERS * 4, response_list_size)

def test_prefix(self):
"""
Expand Down Expand Up @@ -195,6 +205,7 @@ def test_prefix_delimiter(self):
Prefix=KEY_PREFIX,
Delimiter=delimiter)
# prefix
self.assertEqual(len(response["Uploads"]), len(self.commonUploadInfos))
self.assertEqual(len(response["CommonPrefixes"]), 2)
self.assertEqual(response["CommonPrefixes"][0]["Prefix"], "list/test/one/")
self.assertEqual(response["CommonPrefixes"][1]["Prefix"], "list/test/two/")
2 changes: 1 addition & 1 deletion sdk/meta/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ func (mw *MetaWrapper) ListMultipart_ll(prefix, delimiter, keyMarker string, mul

// reorder sessions by path
sort.SliceStable(sessions, func(i, j int) bool {
return sessions[i].Path+sessions[i].ID < sessions[j].Path+sessions[j].ID
return (sessions[i].Path < sessions[j].Path) || ((sessions[i].Path == sessions[j].Path) && (sessions[i].ID < sessions[j].ID))
})
return sessions, nil
}
Expand Down

0 comments on commit fc3e1d9

Please sign in to comment.