oss_resumable.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef LIBOSS_RESUMABLE_H
  2. #define LIBOSS_RESUMABLE_H
  3. #include "aos_define.h"
  4. #include "aos_string.h"
  5. #include "aos_status.h"
  6. #include "apr_atomic.h"
  7. #include "apr_queue.h"
  8. #include "apr_thread_pool.h"
  9. #include "oss_define.h"
  10. AOS_CPP_START
  11. #define OSS_CP_UPLOAD 1
  12. #define OSS_CP_DOWNLOAD 2
  13. typedef struct {
  14. int32_t index; // the index of part, start from 0
  15. int64_t offset; // the offset point of part
  16. int64_t size; // the size of part
  17. int completed; // AOS_TRUE completed, AOS_FALSE uncompleted
  18. aos_string_t etag; // the etag of part, for upload
  19. uint64_t crc64;
  20. } oss_checkpoint_part_t;
  21. typedef struct {
  22. aos_string_t md5; // the md5 of checkout content
  23. int cp_type; // 1 upload, 2 download
  24. apr_file_t *thefile; // the handle of checkpoint file
  25. aos_string_t file_path; // local file path
  26. int64_t file_size; // local file size, for upload
  27. apr_time_t file_last_modified; // local file last modified time, for upload
  28. aos_string_t file_md5; // the md5 of the local file content, for upload, reserved
  29. aos_string_t object_name; // object name
  30. int64_t object_size; // object size, for download
  31. aos_string_t object_last_modified; // object last modified time, for download
  32. aos_string_t object_etag; // object etag, for download
  33. aos_string_t upload_id; // upload id
  34. int part_num; // the total number of parts
  35. int64_t part_size; // the part size, byte
  36. oss_checkpoint_part_t *parts; // the parts of local or object, from 0
  37. } oss_checkpoint_t;
  38. typedef struct {
  39. oss_checkpoint_part_t *part;
  40. aos_status_t *s;
  41. aos_string_t etag;
  42. uint64_t crc64;
  43. } oss_part_task_result_t;
  44. typedef struct {
  45. oss_request_options_t options;
  46. aos_string_t *bucket;
  47. aos_string_t *object;
  48. aos_string_t *upload_id;
  49. aos_string_t *filepath;
  50. oss_checkpoint_part_t *part;
  51. oss_part_task_result_t *result;
  52. apr_uint32_t *launched; // the number of launched part tasks, use atomic
  53. apr_uint32_t *failed; // the number of failed part tasks, use atomic
  54. apr_uint32_t *completed; // the number of completed part tasks, use atomic
  55. apr_queue_t *failed_parts; // the queue of failed parts tasks, thread safe
  56. apr_queue_t *completed_parts; // the queue of completed parts tasks, thread safe
  57. apr_queue_t *task_result_queue;
  58. } oss_thread_params_t;
  59. int32_t oss_get_thread_num(oss_resumable_clt_params_t *clt_params);
  60. void oss_get_upload_checkpoint_path(oss_resumable_clt_params_t *clt_params, const aos_string_t *filepath,
  61. aos_pool_t *pool, aos_string_t *checkpoint_path);
  62. void oss_get_download_checkpoint_path(oss_resumable_clt_params_t *clt_params, const aos_string_t *filepath,
  63. aos_pool_t *pool, aos_string_t *checkpoint_path);
  64. int oss_get_file_info(const aos_string_t *filepath, aos_pool_t *pool, apr_finfo_t *finfo);
  65. int oss_does_file_exist(const aos_string_t *filepath, aos_pool_t *pool);
  66. int oss_open_checkpoint_file(aos_pool_t *pool, aos_string_t *checkpoint_path, oss_checkpoint_t *checkpoint);
  67. int oss_open_checkpoint_file(aos_pool_t *pool, aos_string_t *checkpoint_path, oss_checkpoint_t *checkpoint);
  68. int oss_get_part_num(int64_t file_size, int64_t part_size);
  69. void oss_build_parts(int64_t file_size, int64_t part_size, oss_checkpoint_part_t *parts);
  70. void oss_build_thread_params(oss_thread_params_t *thr_params, int part_num,
  71. aos_pool_t *parent_pool, oss_request_options_t *options,
  72. aos_string_t *bucket, aos_string_t *object, aos_string_t *filepath,
  73. aos_string_t *upload_id, oss_checkpoint_part_t *parts,
  74. oss_part_task_result_t *result);
  75. void oss_destroy_thread_pool(oss_thread_params_t *thr_params, int part_num);
  76. void oss_set_task_tracker(oss_thread_params_t *thr_params, int part_num,
  77. apr_uint32_t *launched, apr_uint32_t *failed, apr_uint32_t *completed,
  78. apr_queue_t *failed_parts, apr_queue_t *completed_parts);
  79. int oss_verify_checkpoint_md5(aos_pool_t *pool, const oss_checkpoint_t *checkpoint);
  80. void oss_build_upload_checkpoint(aos_pool_t *pool, oss_checkpoint_t *checkpoint, aos_string_t *file_path,
  81. apr_finfo_t *finfo, aos_string_t *upload_id, int64_t part_size);
  82. void oss_build_download_checkpoint(aos_pool_t *pool, oss_checkpoint_t *checkpoint, aos_string_t *file_path,
  83. const char *object_name, int64_t object_size, const char *object_last_modified,
  84. const char *object_etag, int64_t part_size);
  85. int oss_dump_checkpoint(aos_pool_t *pool, const oss_checkpoint_t *checkpoint);
  86. int oss_load_checkpoint(aos_pool_t *pool, const aos_string_t *filepath, oss_checkpoint_t *checkpoint);
  87. int oss_is_upload_checkpoint_valid(aos_pool_t *pool, oss_checkpoint_t *checkpoint, apr_finfo_t *finfo);
  88. void oss_update_checkpoint(aos_pool_t *pool, oss_checkpoint_t *checkpoint, int32_t part_index,
  89. aos_string_t *etag, uint64_t crc64);
  90. void oss_get_checkpoint_todo_parts(oss_checkpoint_t *checkpoint, int *part_num, oss_checkpoint_part_t *parts);
  91. void *APR_THREAD_FUNC upload_part(apr_thread_t *thd, void *data);
  92. aos_status_t *oss_resumable_upload_file_without_cp(oss_request_options_t *options,
  93. aos_string_t *bucket,
  94. aos_string_t *object,
  95. aos_string_t *filepath,
  96. aos_table_t *headers,
  97. aos_table_t *params,
  98. int32_t thread_num,
  99. int64_t part_size,
  100. apr_finfo_t *finfo,
  101. oss_progress_callback progress_callback,
  102. aos_table_t **resp_headers,
  103. aos_list_t *resp_body);
  104. aos_status_t *oss_resumable_upload_file_with_cp(oss_request_options_t *options,
  105. aos_string_t *bucket,
  106. aos_string_t *object,
  107. aos_string_t *filepath,
  108. aos_table_t *headers,
  109. aos_table_t *params,
  110. int32_t thread_num,
  111. int64_t part_size,
  112. aos_string_t *checkpoint_path,
  113. apr_finfo_t *finfo,
  114. oss_progress_callback progress_callback,
  115. aos_table_t **resp_headers,
  116. aos_list_t *resp_body);
  117. aos_status_t *oss_resumable_download_file_internal(oss_request_options_t *options,
  118. aos_string_t *bucket,
  119. aos_string_t *object,
  120. aos_string_t *filepath,
  121. aos_table_t *headers,
  122. aos_table_t *params,
  123. int32_t thread_num,
  124. int64_t part_size,
  125. aos_string_t *checkpoint_path,
  126. oss_progress_callback progress_callback,
  127. aos_table_t **resp_headers);
  128. AOS_CPP_END
  129. #endif