| 1 |
#ifndef AWS_S3_CLIENT_IMPL_H |
| 2 |
#define AWS_S3_CLIENT_IMPL_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include "aws/s3/s3_client.h" |
| 10 |
|
| 11 |
#include <aws/common/atomics.h> |
| 12 |
#include <aws/common/byte_buf.h> |
| 13 |
#include <aws/common/hash_table.h> |
| 14 |
#include <aws/common/linked_list.h> |
| 15 |
#include <aws/common/mutex.h> |
| 16 |
#include <aws/common/ref_count.h> |
| 17 |
#include <aws/common/task_scheduler.h> |
| 18 |
#include <aws/http/connection.h> |
| 19 |
#include <aws/http/connection_manager.h> |
| 20 |
#include <aws/http/proxy.h> |
| 21 |
|
| 22 |
|
| 23 |
#define AWS_S3_CLIENT_VERSION "0.1.x" |
| 24 |
|
| 25 |
struct aws_http_connection; |
| 26 |
struct aws_http_connection_manager; |
| 27 |
struct aws_host_resolver; |
| 28 |
struct aws_s3_endpoint; |
| 29 |
struct aws_priority_queue; |
| 30 |
|
| 31 |
enum aws_s3_connection_finish_code { |
| 32 |
AWS_S3_CONNECTION_FINISH_CODE_SUCCESS, |
| 33 |
AWS_S3_CONNECTION_FINISH_CODE_FAILED, |
| 34 |
AWS_S3_CONNECTION_FINISH_CODE_RETRY, |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
typedef void(aws_s3_endpoint_shutdown_fn)(void *user_data); |
| 39 |
|
| 40 |
struct aws_s3_endpoint_options { |
| 41 |
|
| 42 |
struct aws_string *host_name; |
| 43 |
|
| 44 |
|
| 45 |
aws_s3_endpoint_shutdown_fn *shutdown_callback; |
| 46 |
|
| 47 |
|
| 48 |
struct aws_client_bootstrap *client_bootstrap; |
| 49 |
|
| 50 |
|
| 51 |
const struct aws_tls_connection_options *tls_connection_options; |
| 52 |
|
| 53 |
|
| 54 |
size_t dns_host_address_ttl_seconds; |
| 55 |
|
| 56 |
|
| 57 |
struct aws_s3_client *client; |
| 58 |
|
| 59 |
|
| 60 |
uint32_t max_connections; |
| 61 |
|
| 62 |
|
| 63 |
uint32_t port; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
struct aws_http_proxy_config *proxy_config; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
struct proxy_env_var_settings *proxy_ev_settings; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
uint32_t connect_timeout_ms; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
struct aws_s3_tcp_keep_alive_options *tcp_keep_alive_options; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
struct aws_http_connection_monitoring_options *monitoring_options; |
| 98 |
|
| 99 |
|
| 100 |
const struct aws_byte_cursor *network_interface_names_array; |
| 101 |
size_t num_network_interface_names; |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
struct aws_s3_endpoint_system_vtable { |
| 106 |
void (*acquire)(struct aws_s3_endpoint *endpoint, bool already_holding_lock); |
| 107 |
void (*release)(struct aws_s3_endpoint *endpoint); |
| 108 |
}; |
| 109 |
|
| 110 |
struct aws_s3_endpoint { |
| 111 |
struct { |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
size_t ref_count; |
| 116 |
} client_synced_data; |
| 117 |
|
| 118 |
|
| 119 |
struct aws_allocator *allocator; |
| 120 |
|
| 121 |
|
| 122 |
struct aws_string *host_name; |
| 123 |
|
| 124 |
|
| 125 |
struct aws_http_connection_manager *http_connection_manager; |
| 126 |
|
| 127 |
|
| 128 |
struct aws_s3_client *client; |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
struct aws_s3_connection { |
| 133 |
|
| 134 |
struct aws_s3_endpoint *endpoint; |
| 135 |
|
| 136 |
|
| 137 |
struct aws_http_connection *http_connection; |
| 138 |
|
| 139 |
|
| 140 |
struct aws_s3_request *request; |
| 141 |
|
| 142 |
|
| 143 |
struct aws_retry_token *retry_token; |
| 144 |
}; |
| 145 |
|
| 146 |
struct aws_s3_client_vtable { |
| 147 |
|
| 148 |
struct aws_s3_meta_request *( |
| 149 |
*meta_request_factory)(struct aws_s3_client *client, const struct aws_s3_meta_request_options *options); |
| 150 |
|
| 151 |
void (*create_connection_for_request)(struct aws_s3_client *client, struct aws_s3_request *request); |
| 152 |
|
| 153 |
void (*acquire_http_connection)( |
| 154 |
struct aws_http_connection_manager *conn_manager, |
| 155 |
aws_http_connection_manager_on_connection_setup_fn *on_connection_acquired_callback, |
| 156 |
void *user_data); |
| 157 |
|
| 158 |
size_t (*get_host_address_count)( |
| 159 |
struct aws_host_resolver *host_resolver, |
| 160 |
const struct aws_string *host_name, |
| 161 |
uint32_t flags); |
| 162 |
|
| 163 |
void (*schedule_process_work_synced)(struct aws_s3_client *client); |
| 164 |
|
| 165 |
void (*process_work)(struct aws_s3_client *client); |
| 166 |
|
| 167 |
void (*endpoint_shutdown_callback)(struct aws_s3_client *client); |
| 168 |
|
| 169 |
void (*finish_destroy)(struct aws_s3_client *client); |
| 170 |
|
| 171 |
struct aws_parallel_input_stream *(*parallel_input_stream_new_from_file)( |
| 172 |
struct aws_allocator *allocator, |
| 173 |
struct aws_byte_cursor file_name, |
| 174 |
struct aws_event_loop_group *reading_elg, |
| 175 |
bool direct_io_read); |
| 176 |
|
| 177 |
struct aws_http_stream *(*http_connection_make_request)( |
| 178 |
struct aws_http_connection *client_connection, |
| 179 |
const struct aws_http_make_request_options *options); |
| 180 |
|
| 181 |
#ifdef AWS_C_S3_ENABLE_TEST_STUBS |
| 182 |
|
| 183 |
void (*after_prepare_upload_part_finish_stub)(struct aws_s3_request *request, struct aws_http_message *message); |
| 184 |
#endif |
| 185 |
}; |
| 186 |
|
| 187 |
struct aws_s3_upload_part_timeout_stats { |
| 188 |
bool stop_timeout; |
| 189 |
|
| 190 |
|
| 191 |
uint64_t num_successful_upload_requests; |
| 192 |
|
| 193 |
|
| 194 |
struct { |
| 195 |
uint64_t sum_ns; |
| 196 |
uint64_t num_samples; |
| 197 |
bool collecting_p90; |
| 198 |
struct aws_priority_queue p90_samples; |
| 199 |
} initial_request_time; |
| 200 |
|
| 201 |
|
| 202 |
struct { |
| 203 |
uint64_t num_completed; |
| 204 |
uint64_t num_failed; |
| 205 |
} timeout_rate_tracking; |
| 206 |
|
| 207 |
|
| 208 |
struct { |
| 209 |
uint64_t sum_ns; |
| 210 |
uint64_t num_samples; |
| 211 |
} response_to_first_byte_time; |
| 212 |
}; |
| 213 |
|
| 214 |
|
| 215 |
struct aws_s3_client { |
| 216 |
struct aws_allocator *allocator; |
| 217 |
|
| 218 |
struct aws_s3_buffer_pool *buffer_pool; |
| 219 |
|
| 220 |
struct aws_s3_client_vtable *vtable; |
| 221 |
|
| 222 |
struct aws_ref_count ref_count; |
| 223 |
|
| 224 |
|
| 225 |
struct aws_client_bootstrap *client_bootstrap; |
| 226 |
|
| 227 |
|
| 228 |
struct aws_event_loop *process_work_event_loop; |
| 229 |
|
| 230 |
|
| 231 |
struct aws_event_loop_group *body_streaming_elg; |
| 232 |
|
| 233 |
|
| 234 |
struct aws_string *region; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
const size_t part_size; |
| 239 |
|
| 240 |
bool part_size_set; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
const uint64_t max_part_size; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
const uint64_t optimal_range_size; |
| 250 |
|
| 251 |
|
| 252 |
bool fio_options_set; |
| 253 |
struct aws_s3_file_io_options fio_opts; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
const uint64_t multipart_upload_threshold; |
| 260 |
|
| 261 |
|
| 262 |
struct aws_tls_connection_options *tls_connection_options; |
| 263 |
|
| 264 |
|
| 265 |
struct aws_cached_signing_config_aws *cached_signing_config; |
| 266 |
|
| 267 |
|
| 268 |
aws_s3express_provider_factory_fn *s3express_provider_factory; |
| 269 |
void *factory_user_data; |
| 270 |
struct aws_s3express_credentials_provider *s3express_provider; |
| 271 |
|
| 272 |
|
| 273 |
const double throughput_target_gbps; |
| 274 |
|
| 275 |
|
| 276 |
const uint32_t ideal_connection_count; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
const enum aws_s3_meta_request_compute_content_md5 compute_content_md5; |
| 284 |
|
| 285 |
|
| 286 |
const uint32_t max_active_connections_override; |
| 287 |
|
| 288 |
struct aws_atomic_var max_allowed_connections; |
| 289 |
|
| 290 |
|
| 291 |
struct aws_retry_strategy *retry_strategy; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
struct aws_http_proxy_config *proxy_config; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
struct proxy_env_var_settings *proxy_ev_settings; |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
uint32_t connect_timeout_ms; |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
struct aws_s3_tcp_keep_alive_options *tcp_keep_alive_options; |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
struct aws_http_connection_monitoring_options monitoring_options; |
| 326 |
|
| 327 |
|
| 328 |
struct aws_tls_connection_options *proxy_ev_tls_options; |
| 329 |
|
| 330 |
|
| 331 |
aws_s3_client_shutdown_complete_callback_fn *shutdown_callback; |
| 332 |
void *shutdown_callback_user_data; |
| 333 |
|
| 334 |
|
| 335 |
const bool enable_read_backpressure; |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
const size_t initial_read_window; |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
struct aws_atomic_var upload_timeout_ms; |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
struct aws_array_list network_interface_names; |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
struct aws_byte_cursor *network_interface_names_cursor_array; |
| 357 |
size_t num_network_interface_names; |
| 358 |
|
| 359 |
struct { |
| 360 |
|
| 361 |
struct aws_atomic_var num_requests_in_flight; |
| 362 |
|
| 363 |
|
| 364 |
struct aws_atomic_var num_requests_network_io[AWS_S3_META_REQUEST_TYPE_MAX]; |
| 365 |
|
| 366 |
|
| 367 |
struct aws_atomic_var num_requests_stream_queued_waiting; |
| 368 |
|
| 369 |
|
| 370 |
struct aws_atomic_var num_requests_streaming_response; |
| 371 |
|
| 372 |
|
| 373 |
struct aws_atomic_var num_requests_streaming_request_body; |
| 374 |
} stats; |
| 375 |
|
| 376 |
struct { |
| 377 |
struct aws_mutex lock; |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
struct aws_hash_table endpoints; |
| 382 |
|
| 383 |
|
| 384 |
uint32_t num_failed_prepare_requests; |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
struct aws_linked_list pending_meta_request_work; |
| 389 |
|
| 390 |
|
| 391 |
struct aws_linked_list prepared_requests; |
| 392 |
|
| 393 |
|
| 394 |
struct aws_task process_work_task; |
| 395 |
|
| 396 |
|
| 397 |
struct aws_task trim_buffer_pool_task; |
| 398 |
|
| 399 |
|
| 400 |
struct aws_task endpoints_cleanup_task; |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
uint32_t num_endpoints_allocated; |
| 405 |
|
| 406 |
|
| 407 |
uint32_t active : 1; |
| 408 |
|
| 409 |
|
| 410 |
uint32_t start_destroy_executing : 1; |
| 411 |
|
| 412 |
|
| 413 |
uint32_t process_work_task_scheduled : 1; |
| 414 |
|
| 415 |
|
| 416 |
uint32_t process_work_task_in_progress : 1; |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
uint32_t body_streaming_elg_allocated : 1; |
| 421 |
|
| 422 |
|
| 423 |
uint32_t s3express_provider_active : 1; |
| 424 |
|
| 425 |
|
| 426 |
uint32_t finish_destroy : 1; |
| 427 |
|
| 428 |
|
| 429 |
uint32_t endpoints_cleanup_task_scheduled : 1; |
| 430 |
|
| 431 |
struct aws_s3_upload_part_timeout_stats upload_part_stats; |
| 432 |
} synced_data; |
| 433 |
|
| 434 |
struct { |
| 435 |
|
| 436 |
struct aws_linked_list request_queue; |
| 437 |
|
| 438 |
|
| 439 |
struct aws_linked_list meta_requests; |
| 440 |
|
| 441 |
|
| 442 |
uint32_t request_queue_size; |
| 443 |
|
| 444 |
|
| 445 |
uint32_t num_requests_being_prepared; |
| 446 |
|
| 447 |
|
| 448 |
uint32_t trim_buffer_pool_task_scheduled : 1; |
| 449 |
} threaded_data; |
| 450 |
}; |
| 451 |
|
| 452 |
struct aws_s3_meta_request_resume_token { |
| 453 |
struct aws_allocator *allocator; |
| 454 |
struct aws_ref_count ref_count; |
| 455 |
|
| 456 |
enum aws_s3_meta_request_type type; |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
struct aws_string *multipart_upload_id; |
| 462 |
size_t part_size; |
| 463 |
size_t total_num_parts; |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
size_t num_parts_completed; |
| 469 |
}; |
| 470 |
|
| 471 |
void aws_s3_client_notify_connection_finished( |
| 472 |
struct aws_s3_client *client, |
| 473 |
struct aws_s3_connection *connection, |
| 474 |
int error_code, |
| 475 |
enum aws_s3_connection_finish_code finish_code); |
| 476 |
|
| 477 |
AWS_EXTERN_C_BEGIN |
| 478 |
|
| 479 |
AWS_S3_API |
| 480 |
struct aws_s3_meta_request_resume_token *aws_s3_meta_request_resume_token_new(struct aws_allocator *allocator); |
| 481 |
|
| 482 |
AWS_S3_API |
| 483 |
void aws_s3_set_dns_ttl(size_t ttl); |
| 484 |
|
| 485 |
AWS_S3_API |
| 486 |
uint32_t aws_s3_client_get_max_requests_prepare(struct aws_s3_client *client); |
| 487 |
|
| 488 |
AWS_S3_API |
| 489 |
uint32_t aws_s3_client_get_max_active_connections( |
| 490 |
struct aws_s3_client *client, |
| 491 |
struct aws_s3_meta_request *meta_request); |
| 492 |
|
| 493 |
AWS_S3_API |
| 494 |
uint32_t aws_s3_client_get_max_requests_in_flight(struct aws_s3_client *client); |
| 495 |
|
| 496 |
AWS_S3_API |
| 497 |
uint32_t aws_s3_client_queue_requests_threaded( |
| 498 |
struct aws_s3_client *client, |
| 499 |
struct aws_linked_list *request_list, |
| 500 |
bool queue_front); |
| 501 |
|
| 502 |
AWS_S3_API |
| 503 |
struct aws_s3_request *aws_s3_client_dequeue_request_threaded(struct aws_s3_client *client); |
| 504 |
|
| 505 |
AWS_S3_API |
| 506 |
void aws_s3_client_schedule_process_work(struct aws_s3_client *client); |
| 507 |
|
| 508 |
AWS_S3_API |
| 509 |
void aws_s3_client_update_meta_requests_threaded(struct aws_s3_client *client); |
| 510 |
|
| 511 |
AWS_S3_API |
| 512 |
void aws_s3_client_update_connections_threaded(struct aws_s3_client *client); |
| 513 |
|
| 514 |
AWS_S3_API |
| 515 |
struct aws_s3_endpoint *aws_s3_endpoint_new( |
| 516 |
struct aws_allocator *allocator, |
| 517 |
const struct aws_s3_endpoint_options *options); |
| 518 |
|
| 519 |
AWS_S3_API void aws_s3_client_lock_synced_data(struct aws_s3_client *client); |
| 520 |
|
| 521 |
AWS_S3_API |
| 522 |
void aws_s3_client_unlock_synced_data(struct aws_s3_client *client); |
| 523 |
|
| 524 |
|
| 525 |
AWS_S3_API |
| 526 |
void aws_s3_endpoint_set_system_vtable(const struct aws_s3_endpoint_system_vtable *vtable); |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
struct aws_s3_endpoint *aws_s3_endpoint_acquire(struct aws_s3_endpoint *endpoint, bool already_holding_lock); |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
void aws_s3_endpoint_release(struct aws_s3_endpoint *endpoint); |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
void aws_s3_endpoint_destroy(struct aws_s3_endpoint *endpoint); |
| 543 |
|
| 544 |
AWS_S3_API |
| 545 |
extern const uint32_t g_min_num_connections; |
| 546 |
|
| 547 |
AWS_S3_API |
| 548 |
extern const size_t g_expect_timeout_offset_ms; |
| 549 |
|
| 550 |
AWS_S3_API |
| 551 |
void aws_s3_client_update_upload_part_timeout( |
| 552 |
struct aws_s3_client *client, |
| 553 |
struct aws_s3_request *finished_upload_part_request, |
| 554 |
int finished_error_code); |
| 555 |
|
| 556 |
AWS_EXTERN_C_END |
| 557 |
|
| 558 |
#endif |