Skip to content

Commit 918a246

Browse files
author
zackcao
committed
Merge branch 'dev-auto-retry-request-normal' into 'master' (merge request !62)
[合规重试]普通接口请求支持重试策略 请求 COS 添加自动重试和切换域名功能 - 默认重试 3 次, 通过 m_max_retry_times 控制, 首次请求不算在重试次数中(如 0 表示不重试, 1 表示重试 1 次) - 除 copy 接口外, 其他接口返回 2xx 和 4xx 不重试 - copy 请求, 需要检查请求体, 有 error 则进行重试(不涉及域名切换) - 301/302/307 响应码需要重试, 如果满足域名切换条件, 首次重试就切换域名 - 5xx 响应码需要重试, 如果满足域名切换条件, 则最后一次重试时切换域名 原来的分块上传下载复制任务的重试逻辑也进行了上述逻辑替换,见 https://git.woa.com/cos-sdk/cos-cpp-sdk-v5/-/merge_requests/60 附: 切换域名条件 - 当前域名匹配 myqcloud.com - 响应中不含有request id - 域名切换开关(CosSysConfig::m_retry_change_domain)开启, 默认不开启 =======================================================================================================
2 parents d06e929 + f800cf7 commit 918a246

File tree

11 files changed

+998
-682
lines changed

11 files changed

+998
-682
lines changed

include/cos_params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const char kReqHeaderDate[] = "Date";
5151
const char kReqHeaderServer[] = "Server";
5252
const char kReqHeaderXCosReqId[] = "x-cos-request-id";
5353
const char kReqHeaderXCosTraceId[] = "x-cos-trace-id";
54+
const char kReqHeaderXCosSdkRetry[] = "x-cos-sdk-retry";
5455

5556
// Response Header
5657
const char kRespHeaderLastModified[] = "Last-Modified";

include/op/base_op.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef COS_CPP_SDK_V5_INCLUDE_OP_BASE_OP_H_
33
#define COS_CPP_SDK_V5_INCLUDE_OP_BASE_OP_H_
44

5-
#include <inttypes.h>
65
#include <stdint.h>
76

87
#include <map>
@@ -11,6 +10,7 @@
1110
#include "cos_config.h"
1211
#include "op/cos_result.h"
1312
#include "trsf/transfer_handler.h"
13+
#include "util/base_op_util.h"
1414

1515
namespace qcloud_cos {
1616

@@ -22,7 +22,7 @@ class BaseOp {
2222
/// \brief BaseOp构造函数
2323
///
2424
/// \param cos_conf Cos配置
25-
explicit BaseOp(const SharedConfig& cos_conf) : m_config(cos_conf) {}
25+
explicit BaseOp(const SharedConfig& cos_conf) : m_config(cos_conf), m_op_util(m_config) {}
2626

2727
BaseOp() {}
2828

@@ -51,12 +51,8 @@ class BaseOp {
5151

5252
bool IsDomainSameToHost() const;
5353

54-
bool UseDefaultDomain() const;
55-
5654
bool IsDefaultHost(const std::string &host) const;
5755

58-
std::string ChangeHostSuffix(const std::string &host);
59-
6056
/// \brief 封装了cos Service/Bucket/Object 相关接口的通用操作,
6157
/// 包括签名计算、请求发送、返回内容解析等
6258
///
@@ -128,6 +124,28 @@ class BaseOp {
128124
protected:
129125
bool CheckConfigValidation() const;
130126
SharedConfig m_config;
127+
BaseOpUtil m_op_util;
128+
129+
private:
130+
CosResult NormalRequest(
131+
const std::string& host, const std::string& path, const BaseReq& req,
132+
const std::map<std::string, std::string>& additional_headers,
133+
const std::map<std::string, std::string>& additional_params,
134+
const std::string& req_body, bool check_body, BaseResp* resp,
135+
const uint32_t &request_retry_num, bool is_ci_req = false);
136+
137+
CosResult DownloadRequest(const std::string& host, const std::string& path,
138+
const BaseReq& req, BaseResp* resp, std::ostream& os,
139+
const uint32_t &request_retry_num,
140+
const SharedTransferHandler& handler = nullptr);
141+
142+
CosResult UploadRequest(
143+
const std::string& host, const std::string& path, const BaseReq& req,
144+
const std::map<std::string, std::string>& additional_headers,
145+
const std::map<std::string, std::string>& additional_params,
146+
std::istream& is, BaseResp* resp, const uint32_t &request_retry_num, const SharedTransferHandler& handler = nullptr);
147+
148+
bool NoNeedRetry(const CosResult &result);
131149
};
132150

133151
} // namespace qcloud_cos

include/util/retry_util.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)