Coverage Report

Created: 2025-06-13 16:38

/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
#include <glog/logging.h>
23
24
namespace doris {
25
26
bvar::Adder<int64_t> object_request_retry_count("object_request_retry_count");
27
28
1
S3CustomRetryStrategy::S3CustomRetryStrategy(int maxRetries) : DefaultRetryStrategy(maxRetries) {}
29
30
1
S3CustomRetryStrategy::~S3CustomRetryStrategy() = default;
31
32
bool S3CustomRetryStrategy::ShouldRetry(const Aws::Client::AWSError<Aws::Client::CoreErrors>& error,
33
0
                                        long attemptedRetries) const {
34
0
    if (attemptedRetries >= m_maxRetries) {
35
0
        return false;
36
0
    }
37
38
0
    if (Aws::Http::IsRetryableHttpResponseCode(error.GetResponseCode()) || error.ShouldRetry()) {
39
0
        object_request_retry_count << 1;
40
0
        LOG(INFO) << "retry due to error: " << error << ", attempt: " << attemptedRetries + 1 << "/"
41
0
                  << m_maxRetries;
42
0
        return true;
43
0
    }
44
45
0
    return false;
46
0
}
47
#ifdef USE_AZURE
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
    // https://learn.microsoft.com/en-us/azure/developer/cpp/sdk/fundamentals/http-pipelines-and-retries
53
54
0
    std::unique_ptr<Azure::Core::Http::RawResponse> response = nextPolicy.Send(request, context);
55
0
    int32_t retry_count =
56
0
            Azure::Core::Http::Policies::_internal::RetryPolicy::GetRetryCount(context);
57
58
0
    if (static_cast<int>(response->GetStatusCode()) > 299 ||
59
0
        static_cast<int>(response->GetStatusCode()) < 200) {
60
0
        if (retry_count > 0) {
61
0
            object_request_retry_count << 1;
62
0
        }
63
64
        // If the response is not successful, we log the retry attempt and status code.
65
0
        LOG(INFO) << "azure retry retry_count: " << retry_count
66
0
                  << ", status code: " << static_cast<int>(response->GetStatusCode())
67
0
                  << ", reason: " << response->GetReasonPhrase();
68
0
    }
69
70
0
    return response;
71
0
}
72
73
0
std::unique_ptr<AzureRetryRecordPolicy::HttpPolicy> AzureRetryRecordPolicy::Clone() const {
74
0
    return std::make_unique<AzureRetryRecordPolicy>(*this);
75
0
}
76
#endif
77
} // namespace doris