Coverage Report

Created: 2024-11-22 21:49

/root/doris/common/cpp/obj_retry_strategy.cpp
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "obj_retry_strategy.h"
19
20
#include <aws/core/http/HttpResponse.h>
21
#include <bvar/reducer.h>
22
23
namespace doris {
24
25
bvar::Adder<int64_t> s3_too_many_request_retry_cnt("s3_too_many_request_retry_cnt");
26
27
1
S3CustomRetryStrategy::S3CustomRetryStrategy(int maxRetries) : DefaultRetryStrategy(maxRetries) {}
28
29
1
S3CustomRetryStrategy::~S3CustomRetryStrategy() = default;
30
31
bool S3CustomRetryStrategy::ShouldRetry(const Aws::Client::AWSError<Aws::Client::CoreErrors>& error,
32
0
                                        long attemptedRetries) const {
33
0
    if (attemptedRetries >= m_maxRetries) {
34
0
        return false;
35
0
    }
36
37
0
    if (Aws::Http::IsRetryableHttpResponseCode(error.GetResponseCode()) || error.ShouldRetry()) {
38
0
        s3_too_many_request_retry_cnt << 1;
39
0
        return true;
40
0
    }
41
42
0
    return false;
43
0
}
44
#ifdef USE_AZURE
45
0
AzureRetryRecordPolicy::AzureRetryRecordPolicy(int retry_cnt) : retry_cnt(retry_cnt) {}
46
47
0
AzureRetryRecordPolicy::~AzureRetryRecordPolicy() = default;
48
49
std::unique_ptr<Azure::Core::Http::RawResponse> AzureRetryRecordPolicy::Send(
50
        Azure::Core::Http::Request& request, Azure::Core::Http::Policies::NextHttpPolicy nextPolicy,
51
0
        Azure::Core::Context const& context) const {
52
0
    auto resp = nextPolicy.Send(request, context);
53
0
    if (retry_cnt != 0 &&
54
0
        resp->GetStatusCode() == Azure::Core::Http::HttpStatusCode::TooManyRequests) {
55
0
        retry_cnt--;
56
0
        s3_too_many_request_retry_cnt << 1;
57
0
    }
58
0
    return resp;
59
0
}
60
61
0
std::unique_ptr<AzureRetryRecordPolicy::HttpPolicy> AzureRetryRecordPolicy::Clone() const {
62
0
    auto ret = std::make_unique<AzureRetryRecordPolicy>(*this);
63
0
    ret->retry_cnt = 0;
64
0
    return ret;
65
0
}
66
#endif
67
} // namespace doris