Skip to content

Commit df3e4fd

Browse files
committed
fix the hack
1 parent bc5336e commit df3e4fd

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

source/s3_parallel_input_stream.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ static int s_aws_s3_part_streaming_input_stream_read(struct aws_input_stream *st
168168
AWS_CONTAINER_OF(stream, struct aws_s3_part_streaming_input_stream_impl, base);
169169
int rt = aws_input_stream_read(test_input_stream->base_stream, dest);
170170
test_input_stream->length_read += dest->len;
171+
if (test_input_stream->length_read > test_input_stream->total_length) {
172+
size_t gap = test_input_stream->length_read - test_input_stream->total_length;
173+
size_t new_len = dest->len - gap;
174+
dest->len = new_len;
175+
test_input_stream->length_read = test_input_stream->total_length;
176+
}
171177
return rt;
172178
}
173179

@@ -226,13 +232,12 @@ struct aws_input_stream *aws_input_stream_new_from_parallel(
226232
&test_input_stream->base.ref_count,
227233
test_input_stream,
228234
(aws_simple_completion_callback *)s_aws_s3_part_streaming_input_stream_destroy);
229-
235+
test_input_stream->allocator = allocator;
230236
test_input_stream->base.vtable = &s_aws_s3_part_streaming_input_stream_vtable;
231-
struct aws_parallel_input_stream_from_file_impl *impl = parallel_stream->impl;
232-
aws_mem_calloc(allocator, 1, sizeof(struct aws_parallel_input_stream_from_file_impl));
233-
aws_parallel_input_stream_init_base(&impl->base, allocator, &s_parallel_input_stream_from_file_vtable, impl);
234237

238+
struct aws_parallel_input_stream_from_file_impl *impl = parallel_stream->impl;
235239
test_input_stream->base_stream = aws_input_stream_new_from_file(allocator, aws_string_c_str(impl->file_path));
240+
AWS_FATAL_ASSERT(test_input_stream->base_stream != NULL);
236241
test_input_stream->total_length = request_body_size;
237242
test_input_stream->offset = offset;
238243
test_input_stream->length_read = 0;

source/s3_request.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ struct aws_s3_request *aws_s3_request_new(
3737

3838
request->part_number = part_number;
3939
request->record_response_headers = (flags & AWS_S3_REQUEST_FLAG_RECORD_RESPONSE_HEADERS) != 0;
40-
request->should_allocate_buffer_from_pool = (flags & AWS_S3_REQUEST_FLAG_ALLOCATE_BUFFER_FROM_POOL) != 0;
40+
/* TODO: if the request is streaming, we are not allocating buffer from pool/ This will avoid the allocation buffer
41+
* to be the bottleneck when streaming. */
42+
request->should_allocate_buffer_from_pool = false;
4143
request->always_send = (flags & AWS_S3_REQUEST_FLAG_ALWAYS_SEND) != 0;
4244

4345
return request;
@@ -132,6 +134,7 @@ static void s_s3_request_destroy(void *user_data) {
132134
aws_byte_buf_clean_up(&request->request_body);
133135
aws_s3_buffer_ticket_release(request->ticket);
134136
aws_string_destroy(request->operation_name);
137+
aws_input_stream_release(request->request_stream);
135138
aws_s3_meta_request_release(request->meta_request);
136139

137140
aws_mem_release(request->allocator, request);

source/s3_request_messages.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,6 @@ struct aws_http_message *aws_s3_upload_part_message_new_streaming(
394394
}
395395

396396
aws_http_message_set_body_stream(message, input_stream);
397-
/* Let the message take the full ownership */
398-
aws_input_stream_release(input_stream);
399-
400397
return message;
401398

402399
error_clean_up:
@@ -660,12 +657,13 @@ static const struct aws_byte_cursor s_complete_payload_begin = AWS_BYTE_CUR_INIT
660657
static const struct aws_byte_cursor s_complete_payload_end =
661658
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("</CompleteMultipartUpload>");
662659

663-
static const struct aws_byte_cursor s_part_section_string_0 = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" <Part>\n"
664-
" <ETag>");
660+
static const struct aws_byte_cursor s_part_section_string_0 = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(
661+
" <Part>\n"
662+
" <ETag>");
665663

666-
static const struct aws_byte_cursor s_part_section_string_1 =
667-
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("</ETag>\n"
668-
" <PartNumber>");
664+
static const struct aws_byte_cursor s_part_section_string_1 = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(
665+
"</ETag>\n"
666+
" <PartNumber>");
669667

670668
static const struct aws_byte_cursor s_close_part_number_tag = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("</PartNumber>\n");
671669
static const struct aws_byte_cursor s_close_part_tag = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(" </Part>\n");

0 commit comments

Comments
 (0)