remove struct SecondaryHostReplicaStatus, to simplify context use (#1913)
# Pull Request Checklist Please leverage this checklist as a reminder to address commonly occurring feedback when submitting a pull request to make sure your PR can be reviewed quickly: See the detailed list in the [contributing guide](https://github.com/Azure/azure-sdk-for-cpp/blob/master/CONTRIBUTING.md#pull-requests). - [x] [C++ Guidelines](https://azure.github.io/azure-sdk/cpp_introduction.html) - [x] Doxygen docs - [x] Unit tests - [x] No unwanted commits/changes - [x] Descriptive title/description - [x] PR is single purpose - [x] Related issue listed - [x] Comments in source - [x] No typos - [x] Update changelog - [x] Not work-in-progress - [x] External references or docs updated - [x] Self review of PR done - [x] Any breaking changes?
This commit is contained in:
parent
9c7d4c61e4
commit
7cade913bc
@ -13,15 +13,9 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
static constexpr const char* SecondaryHostReplicaStatusKey
|
||||
= "AzureSdkStorageSecondaryHostReplicaStatusKey";
|
||||
|
||||
struct SecondaryHostReplicaStatus
|
||||
{
|
||||
bool replicated = true;
|
||||
};
|
||||
|
||||
inline Azure::Core::Context WithReplicaStatus(const Azure::Core::Context& context)
|
||||
{
|
||||
return context.WithValue(
|
||||
SecondaryHostReplicaStatusKey, std::make_unique<SecondaryHostReplicaStatus>());
|
||||
return context.WithValue(SecondaryHostReplicaStatusKey, std::make_shared<bool>(true));
|
||||
}
|
||||
|
||||
class StorageSwitchToSecondaryPolicy : public Azure::Core::Http::Policies::HttpPolicy {
|
||||
|
||||
@ -10,17 +10,15 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
Azure::Core::Http::Policies::NextHttpPolicy nextHttpPolicy,
|
||||
const Azure::Core::Context& ctx) const
|
||||
{
|
||||
SecondaryHostReplicaStatus* replicaStatus = nullptr;
|
||||
std::shared_ptr<bool> replicaStatus;
|
||||
if (ctx.HasKey(SecondaryHostReplicaStatusKey))
|
||||
{
|
||||
replicaStatus
|
||||
= ctx.Get<std::unique_ptr<SecondaryHostReplicaStatus>>(SecondaryHostReplicaStatusKey)
|
||||
.get();
|
||||
replicaStatus = ctx.Get<std::shared_ptr<bool>>(SecondaryHostReplicaStatusKey);
|
||||
}
|
||||
|
||||
bool considerSecondary = (request.GetMethod() == Azure::Core::Http::HttpMethod::Get
|
||||
|| request.GetMethod() == Azure::Core::Http::HttpMethod::Head)
|
||||
&& !m_secondaryHost.empty() && replicaStatus && replicaStatus->replicated;
|
||||
&& !m_secondaryHost.empty() && replicaStatus && *replicaStatus;
|
||||
|
||||
if (considerSecondary && Azure::Core::Http::Policies::RetryPolicy::GetRetryNumber(ctx) > 0)
|
||||
{
|
||||
@ -42,7 +40,7 @@ namespace Azure { namespace Storage { namespace _internal {
|
||||
|| response->GetStatusCode() == Core::Http::HttpStatusCode::PreconditionFailed)
|
||||
&& request.GetUrl().GetHost() == m_secondaryHost)
|
||||
{
|
||||
replicaStatus->replicated = false;
|
||||
*replicaStatus = false;
|
||||
// switch back
|
||||
request.GetUrl().SetHost(m_primaryHost);
|
||||
response = nextHttpPolicy.Send(request, ctx);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user