blob: a937ac8939d486c5590b7b67e3ae91e2b9884b1f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#pragma once
#include "expected_error_guard.h"
#include "retry_lib.h"
#include "wait_proxy.h"
#include <yt/cpp/mapreduce/interface/errors.h>
#include <yt/cpp/mapreduce/interface/fwd.h>
#include <yt/cpp/mapreduce/interface/logging/yt_log.h>
#include <util/generic/guid.h>
namespace NYT::NDetail {
////////////////////////////////////////////////////////////////////////////////
template <typename TResult>
TResult RequestWithRetry(
IRequestRetryPolicyPtr retryPolicy,
std::function<TResult(TMutationId&)> func)
{
bool useSameMutationId = false;
TMutationId mutationId;
while (true) {
try {
retryPolicy->NotifyNewAttempt();
if constexpr (std::is_same_v<TResult, void>) {
func(mutationId);
return;
} else {
return func(mutationId);
}
} catch (const TErrorResponse& e) {
// NB(achains): Do not log expected error in stderr.
if (TExpectedErrorGuard::IsErrorExpected(e)) {
YT_LOG_INFO("Received expected error, retry failed %v - %v",
e.GetError().GetMessage(),
retryPolicy->GetAttemptDescription());
} else {
YT_LOG_ERROR("Retry failed %v - %v",
e.GetError().GetMessage(),
retryPolicy->GetAttemptDescription());
}
useSameMutationId = e.IsTransportError();
if (!IsRetriable(e)) {
throw;
}
auto maybeRetryTimeout = retryPolicy->OnRetriableError(e);
if (maybeRetryTimeout) {
TWaitProxy::Get()->Sleep(*maybeRetryTimeout);
} else {
throw;
}
} catch (const std::exception& e) {
YT_LOG_ERROR("Retry failed %v - %v",
e.what(),
retryPolicy->GetAttemptDescription());
useSameMutationId = true;
if (!IsRetriable(e)) {
throw;
}
auto maybeRetryTimeout = retryPolicy->OnGenericError(e);
if (maybeRetryTimeout) {
TWaitProxy::Get()->Sleep(*maybeRetryTimeout);
} else {
throw;
}
}
if (!useSameMutationId) {
mutationId = {};
}
}
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NDetail
|