Skip to content

Commit 772c4a0

Browse files
committed
apply the dynamic size
1 parent f0ee675 commit 772c4a0

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

include/aws/s3/private/s3_auto_ranged_get.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ struct aws_s3_auto_ranged_get {
2323

2424
/* Estimated object stored part size based on ETag analysis */
2525
uint64_t estimated_object_stored_part_size;
26+
/* Part size was set or not from user for this meta request. */
27+
bool part_size_set;
2628

2729
bool initial_message_has_start_range;
2830
bool initial_message_has_end_range;
@@ -77,6 +79,7 @@ AWS_S3_API struct aws_s3_meta_request *aws_s3_meta_request_auto_ranged_get_new(
7779
struct aws_allocator *allocator,
7880
struct aws_s3_client *client,
7981
size_t part_size,
82+
bool part_size_set,
8083
const struct aws_s3_meta_request_options *options);
8184

8285
AWS_EXTERN_C_END

include/aws/s3/private/s3_client_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ struct aws_s3_client {
234234
* to meta requests for use. */
235235
const size_t part_size;
236236

237+
bool part_size_set;
238+
237239
/* Size of parts for files when doing gets or puts. This exists on the client as configurable option that is passed
238240
* to meta requests for use. */
239241
const uint64_t max_part_size;

source/s3_auto_ranged_get.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct aws_s3_meta_request *aws_s3_meta_request_auto_ranged_get_new(
6262
struct aws_allocator *allocator,
6363
struct aws_s3_client *client,
6464
size_t part_size,
65+
bool part_size_set,
6566
const struct aws_s3_meta_request_options *options) {
6667
AWS_PRECONDITION(allocator);
6768
AWS_PRECONDITION(client);
@@ -91,6 +92,7 @@ struct aws_s3_meta_request *aws_s3_meta_request_auto_ranged_get_new(
9192
return NULL;
9293
}
9394

95+
auto_ranged_get->part_size_set = part_size_set;
9496
struct aws_http_headers *headers = aws_http_message_get_headers(auto_ranged_get->base.initial_request_message);
9597
AWS_ASSERT(headers != NULL);
9698

@@ -319,8 +321,12 @@ static bool s_s3_auto_ranged_get_update(
319321
* we could end up stuck in a situation where the user is
320322
* waiting for more bytes before they'll open the window,
321323
* and this implementation is waiting for more window before it will send more parts. */
322-
uint64_t read_data_requested =
323-
auto_ranged_get->synced_data.num_parts_requested * meta_request->part_size;
324+
uint64_t read_data_requested = 0;
325+
if (auto_ranged_get->synced_data.num_parts_requested > 0) {
326+
read_data_requested =
327+
(auto_ranged_get->synced_data.num_parts_requested - 1) * meta_request->part_size +
328+
auto_ranged_get->synced_data.first_part_size;
329+
}
324330
if (read_data_requested >= meta_request->synced_data.read_window_running_total) {
325331

326332
/* Avoid spamming users with this DEBUG message */
@@ -805,6 +811,20 @@ static void s_s3_auto_ranged_get_request_finished(
805811
error_code = AWS_ERROR_SUCCESS;
806812
found_object_size = true;
807813

814+
if (!auto_ranged_get->part_size_set && !meta_request->client->part_size_set) {
815+
/* No part size has been set from user. Now we use the optimal part size based on the throughput and memory
816+
* limit */
817+
uint64_t out_request_optimal_range_size = 0;
818+
int error = aws_s3_calculate_request_optimal_range_size(
819+
meta_request->client->optimal_range_size,
820+
auto_ranged_get->estimated_object_stored_part_size,
821+
&out_request_optimal_range_size);
822+
if (!error) {
823+
/* Override the part size to be */
824+
*((size_t *)&meta_request->part_size) = (size_t)out_request_optimal_range_size;
825+
}
826+
}
827+
808828
/* Check for checksums if requested to */
809829
if (meta_request->checksum_config.validate_response_checksum) {
810830
if (aws_s3_check_headers_for_checksum(

source/s3_client.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ struct aws_s3_client *aws_s3_client_new(
403403
} else {
404404
part_size = (size_t)client_config->part_size;
405405
}
406+
client->part_size_set = true;
406407
}
407408

408409
/* default max part size is the smallest of either half of mem limit or default max part size */
@@ -1279,12 +1280,14 @@ static struct aws_s3_meta_request *s_s3_client_meta_request_factory_default(
12791280
return NULL;
12801281
}
12811282
size_t part_size = client->part_size;
1283+
bool part_size_set = false;
12821284
if (options->part_size != 0) {
12831285
if (options->part_size > SIZE_MAX) {
12841286
part_size = SIZE_MAX;
12851287
} else {
12861288
part_size = (size_t)options->part_size;
12871289
}
1290+
part_size_set = true;
12881291
}
12891292

12901293
/* Call the appropriate meta-request new function. */
@@ -1318,7 +1321,8 @@ static struct aws_s3_meta_request *s_s3_client_meta_request_factory_default(
13181321
}
13191322
}
13201323
}
1321-
return aws_s3_meta_request_auto_ranged_get_new(client->allocator, client, part_size, options);
1324+
return aws_s3_meta_request_auto_ranged_get_new(
1325+
client->allocator, client, part_size, part_size_set, options);
13221326
}
13231327
case AWS_S3_META_REQUEST_TYPE_PUT_OBJECT: {
13241328
if (body_source_count == 0) {

tests/s3_client_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ TEST_CASE(s3_calculate_client_optimal_range_size) {
489489
/* Verify optimal range size is calculated and within expected bounds */
490490
ASSERT_TRUE(client->optimal_range_size >= MB_TO_BYTES(8)); /* At least 8MiB minimum */
491491
ASSERT_TRUE(client->optimal_range_size <= GB_TO_BYTES(1)); /* At most 1GB maximum */
492-
492+
493493
/* Verify it's properly initialized (not zero) */
494494
ASSERT_TRUE(client->optimal_range_size > 0);
495495

@@ -521,7 +521,7 @@ TEST_CASE(s3_calculate_client_optimal_range_size) {
521521
{
522522
struct aws_s3_client_config client_config = {
523523
.part_size = MB_TO_BYTES(8),
524-
.throughput_target_gbps = 100.0, /* High throughput = more connections */
524+
.throughput_target_gbps = 100.0, /* High throughput = more connections */
525525
.memory_limit_in_bytes = MB_TO_BYTES(512), /* Low memory */
526526
};
527527

tests/s3_meta_request_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TEST_CASE(meta_request_auto_ranged_get_new_error_handling) {
4343
.type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
4444
};
4545
struct aws_s3_meta_request *meta_request =
46-
aws_s3_meta_request_auto_ranged_get_new(allocator, client, SIZE_MAX, &options);
46+
aws_s3_meta_request_auto_ranged_get_new(allocator, client, SIZE_MAX, false, &options);
4747

4848
ASSERT_NULL(meta_request);
4949
aws_http_message_release(message);

0 commit comments

Comments
 (0)