Skip to content

Commit 9204fc6

Browse files
committed
only apply the backpressure to get object
1 parent e797c43 commit 9204fc6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

include/aws/s3/s3_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ struct aws_future_void *aws_s3_meta_request_write(
12201220
* no backpressure is being applied and data is being downloaded as fast as possible.
12211221
*
12221222
* WARNING: This feature is experimental.
1223-
* Currently, backpressure is only applied to GetObject requests which are split into multiple parts,
1223+
* Currently, backpressure is applied to GetObject requests,
12241224
* - If you set body_callback, no more data will be delivered once the window reaches 0.
12251225
* - If you set body_callback_ex, you may still receive some data after the window reaches 0. TODO: fix it.
12261226
*/

source/s3_meta_request.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,23 @@ static struct aws_s3_request_metrics *s_s3_request_finish_up_and_release_metrics
19851985
return NULL;
19861986
}
19871987

1988+
static bool s_apply_backpressure(struct aws_s3_request *request) {
1989+
struct aws_s3_meta_request *meta_request = request->meta_request;
1990+
if (!meta_request->body_callback) {
1991+
return false;
1992+
}
1993+
if (!meta_request->client->enable_read_backpressure) {
1994+
return false;
1995+
}
1996+
if (meta_request->type == AWS_S3_META_REQUEST_TYPE_GET_OBJECT) {
1997+
return true;
1998+
}
1999+
if (aws_string_eq_c_str(request->operation_name, "GetObject")) {
2000+
return true;
2001+
}
2002+
return false;
2003+
}
2004+
19882005
/* Deliver events in event_delivery_array.
19892006
* This task runs on the meta-request's io_event_loop thread. */
19902007
static void s_s3_meta_request_event_delivery_task(struct aws_task *task, void *arg, enum aws_task_status task_status) {
@@ -2059,9 +2076,8 @@ static void s_s3_meta_request_event_delivery_task(struct aws_task *task, void *a
20592076
break;
20602077
}
20612078

2062-
if (meta_request->body_callback && meta_request->client->enable_read_backpressure) {
2063-
/* If customer set the body callback, make sure we are not delivery them more than asked via the
2064-
* callback. */
2079+
if (s_apply_backpressure(request)) {
2080+
/* Apply backpressure for the request, only deliver the bytes that allowed to deliver. */
20652081
aws_byte_cursor_advance(&response_body, bytes_delivered_for_request);
20662082
if (response_body.len > (size_t)bytes_allowed_to_deliver) {
20672083
response_body.len = (size_t)bytes_allowed_to_deliver;

0 commit comments

Comments
 (0)