Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,7 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
/**
* @brief HTTP retry policy.
*/
class RetryPolicy
#if !defined(_azure_TESTING_BUILD)
final
#endif
: public HttpPolicy {
class RetryPolicy : public HttpPolicy {
Comment thread
Jinming-Hu marked this conversation as resolved.
private:
RetryOptions m_retryOptions;

Expand Down
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(
inc/azure/storage/common/internal/storage_bearer_token_auth.hpp
inc/azure/storage/common/internal/storage_bearer_token_authentication_policy.hpp
inc/azure/storage/common/internal/storage_per_retry_policy.hpp
inc/azure/storage/common/internal/storage_retry_policy.hpp
inc/azure/storage/common/internal/storage_service_version_policy.hpp
inc/azure/storage/common/internal/storage_switch_to_secondary_policy.hpp
inc/azure/storage/common/internal/xml_wrapper.hpp
Expand All @@ -76,6 +77,7 @@ set(
src/storage_credential.cpp
src/storage_exception.cpp
src/storage_per_retry_policy.cpp
src/storage_retry_policy.cpp
src/storage_switch_to_secondary_policy.cpp
src/xml_wrapper.cpp
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#pragma once

#include <azure/core/http/policies/policy.hpp>

namespace Azure { namespace Storage { namespace _internal {

class StorageRetryPolicy final : public Core::Http::Policies::_internal::RetryPolicy {
public:
explicit StorageRetryPolicy(Core::Http::Policies::RetryOptions options)
: RetryPolicy(options), m_options(std::move(options))
{
}
~StorageRetryPolicy() override {}

protected:
bool ShouldRetryOnResponse(
const Core::Http::RawResponse& response,
const Core::Http::Policies::RetryOptions& retryOptions,
int32_t attempt,
std::chrono::milliseconds& retryAfter,
double jitterFactor = -1) const override;

private:
Core::Http::Policies::RetryOptions m_options;
};

}}} // namespace Azure::Storage::_internal
44 changes: 44 additions & 0 deletions sdk/storage/azure-storage-common/src/storage_retry_policy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include "azure/storage/common/internal/storage_retry_policy.hpp"

namespace Azure { namespace Storage { namespace _internal {

bool StorageRetryPolicy::ShouldRetryOnResponse(
Core::Http::RawResponse const& response,
Core::Http::Policies::RetryOptions const& retryOptions,
int32_t attempt,
std::chrono::milliseconds& retryAfter,
double jitterFactor) const
{
bool ret = RetryPolicy::ShouldRetryOnResponse(
response, retryOptions, attempt, retryAfter, jitterFactor);
if (ret)
{
return true;
}

if (attempt > m_options.MaxRetries)
Comment thread
Jinming-Hu marked this conversation as resolved.
Outdated
{
return false;
}

if (static_cast<std::underlying_type_t<Core::Http::HttpStatusCode>>(response.GetStatusCode())
>= 400)
{
const auto& headers = response.GetHeaders();
auto ite = headers.find("x-ms-copy-source-status-code");
Comment thread
Jinming-Hu marked this conversation as resolved.
if (ite != headers.end())
{
auto innerStatusCode = static_cast<Core::Http::HttpStatusCode>(std::stoi(ite->second));
if (m_options.StatusCodes.find(innerStatusCode) != m_options.StatusCodes.end())
{
return true;
}
Comment thread
Jinming-Hu marked this conversation as resolved.
}
}
return false;
}

}}} // namespace Azure::Storage::_internal