@@ -21,15 +21,16 @@ class S3
21
21
MAX_MULTIPART_PARTS = 10_000
22
22
MAX_OBJECT_SIZE = 5 * 1024 * 1024 * 1024 * 1024
23
23
24
- attr_reader :client , :bucket , :prefix , :upload_options , :limits , :concurrency
24
+ attr_reader :client , :bucket , :prefix , :upload_options , :limits
25
25
26
26
# Initializes an aws-sdk-s3 client with the given credentials.
27
27
def initialize ( bucket :, prefix : nil , upload_options : { } , limits : { } , concurrency : { } , thread_count : nil , **client_options )
28
28
fail ArgumentError , "the :bucket option was nil" unless bucket
29
29
30
30
if thread_count
31
- warn "[Tus-Ruby-Server] :thread_count is deprecated and will be removed in the next major version, use :concurrency instead, e.g `concurrency: { concatenation: 20 }`"
32
- concurrency [ :concatenation ] = thread_count
31
+ warn "[Tus-Ruby-Server] :thread_count option is obsolete and will be removed in the next major version"
32
+ elsif concurrency . any?
33
+ warn "[Tus-Ruby-Server] :concurrency option is obsolete and will be removed in the next major version"
33
34
end
34
35
35
36
resource = Aws ::S3 ::Resource . new ( **client_options )
@@ -39,7 +40,6 @@ def initialize(bucket:, prefix: nil, upload_options: {}, limits: {}, concurrency
39
40
@prefix = prefix
40
41
@upload_options = upload_options
41
42
@limits = limits
42
- @concurrency = concurrency
43
43
end
44
44
45
45
# Initiates multipart upload for the given upload, and stores its
@@ -262,64 +262,28 @@ def delete(objects)
262
262
end
263
263
264
264
# Creates multipart parts for the specified multipart upload by copying
265
- # given objects into them. It uses a queue and a fixed-size thread pool
266
- # which consumes that queue.
265
+ # given objects into them.
267
266
def copy_parts ( objects , multipart_upload )
268
- parts = compute_parts ( objects , multipart_upload )
269
- input = Queue . new
270
- results = Queue . new
271
-
272
- parts . each { |part | input << part }
273
- input . close
274
-
275
- thread_count = concurrency [ :concatenation ] || 10
276
- threads = thread_count . times . map { copy_part_thread ( input , results ) }
277
-
278
- errors = threads . map ( &:value ) . compact
279
- fail errors . first if errors . any?
280
-
281
- part_results = Array . new ( results . size ) { results . pop } # convert Queue into an Array
282
- part_results . sort_by { |part | part . fetch ( "part_number" ) }
283
- end
284
-
285
- # Computes data required for copying objects into new multipart parts.
286
- def compute_parts ( objects , multipart_upload )
287
- objects . map . with_index do |object , idx |
288
- {
289
- bucket : multipart_upload . bucket_name ,
290
- key : multipart_upload . object_key ,
291
- upload_id : multipart_upload . id ,
292
- copy_source : [ object . bucket_name , object . key ] . join ( "/" ) ,
293
- part_number : idx + 1 ,
294
- }
267
+ threads = objects . map . with_index do |object , idx |
268
+ Thread . new { copy_part ( object , idx + 1 , multipart_upload ) }
295
269
end
296
- end
297
270
298
- # Consumes the queue for new multipart part information and issues the
299
- # copy requests.
300
- def copy_part_thread ( input , results )
301
- Thread . new do
302
- begin
303
- loop do
304
- part = input . pop or break
305
- part_result = copy_part ( part )
306
- results << part_result
307
- end
308
- nil
309
- rescue => error
310
- input . clear # clear other work
311
- error
312
- end
313
- end
271
+ threads . map ( &:value )
314
272
end
315
273
316
274
# Creates a new multipart part by copying the object specified in the
317
275
# given data. Returns part number and ETag that will be required later
318
276
# for completing the multipart upload.
319
- def copy_part ( part )
320
- response = client . upload_part_copy ( part )
321
-
322
- { "part_number" => part [ :part_number ] , "etag" => response . copy_part_result . etag }
277
+ def copy_part ( object , part_number , multipart_upload )
278
+ response = client . upload_part_copy (
279
+ bucket : multipart_upload . bucket_name ,
280
+ key : multipart_upload . object_key ,
281
+ upload_id : multipart_upload . id ,
282
+ copy_source : [ object . bucket_name , object . key ] . join ( "/" ) ,
283
+ part_number : part_number ,
284
+ )
285
+
286
+ { "part_number" => part_number , "etag" => response . copy_part_result . etag }
323
287
end
324
288
325
289
# Retuns an Aws::S3::Object with the prefix applied.
0 commit comments