Skip to content

Commit d0f9d45

Browse files
committed
Fixed TRetryPolicy, updated import script and fixed CMakeLists
1 parent fa2f1e1 commit d0f9d45

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

.github/scripts/copy_sources.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cp -r $1/ydb/public/api/grpc $tmp_dir/src/api
3131
cp -r $1/ydb/public/api/protos $tmp_dir/src/api
3232

3333
rm -r $tmp_dir/src/api/protos/out
34-
rm $tmp_dir/include/ydb-cpp-sdk/type_switcher.h $tmp_dir/src/version.h
34+
rm $tmp_dir/include/ydb-cpp-sdk/type_switcher.h $tmp_dir/include/ydb-cpp-sdk/client/proto/private.h $tmp_dir/src/version.h
3535

3636
cp -r $2/util $tmp_dir
3737
cp -r $2/library $tmp_dir
@@ -53,6 +53,7 @@ cp $2/LICENSE $tmp_dir
5353
cp $2/README.md $tmp_dir
5454

5555
cp $2/include/ydb-cpp-sdk/type_switcher.h $tmp_dir/include/ydb-cpp-sdk/type_switcher.h
56+
cp $2/include/ydb-cpp-sdk/client/proto/private.h $tmp_dir/include/ydb-cpp-sdk/client/proto/private.h
5657
cp $2/src/version.h $tmp_dir/src/version.h
5758

5859
cd $2
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
#pragma once
2-
3-
#include <src/api/protos/draft/ydb_replication.pb.h>
4-
#include <src/api/protos/draft/ydb_view.pb.h>
5-
6-
#include <ydb-cpp-sdk/client/draft/ydb_replication.h>
7-
#include <ydb-cpp-sdk/client/draft/ydb_view.h>

include/ydb-cpp-sdk/library/retry/retry_policy.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <util/datetime/base.h>
4+
#include <util/generic/maybe.h>
45
#include <util/generic/typetraits.h>
56
#include <util/random/random.h>
67

@@ -41,7 +42,7 @@ struct IRetryPolicy {
4142

4243
//! Calculate delay before next retry if next retry is allowed.
4344
//! Returns empty maybe if retry is not allowed anymore.
44-
[[nodiscard]] virtual std::optional<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam... args) = 0;
45+
[[nodiscard]] virtual TMaybe<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam... args) = 0;
4546
};
4647

4748
virtual ~IRetryPolicy() = default;
@@ -81,8 +82,8 @@ struct TNoRetryPolicy : IRetryPolicy<TArgs...> {
8182
using IRetryState = typename IRetryPolicy<TArgs...>::IRetryState;
8283

8384
struct TNoRetryState : IRetryState {
84-
std::optional<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam...) override {
85-
return std::nullopt;
85+
TMaybe<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam...) override {
86+
return {};
8687
}
8788
};
8889

@@ -123,10 +124,10 @@ struct TExponentialBackoffPolicy : IRetryPolicy<TArgs...> {
123124
{
124125
}
125126

126-
std::optional<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam... args) override {
127+
TMaybe<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam... args) override {
127128
const ERetryErrorClass errorClass = RetryClassFunction(args...);
128129
if (errorClass == ERetryErrorClass::NoRetry || AttemptsDone >= MaxRetries || StartTime && TInstant::Now() - StartTime >= MaxTime) {
129-
return std::nullopt;
130+
return {};
130131
}
131132

132133
if (errorClass == ERetryErrorClass::LongRetry) {
@@ -212,10 +213,10 @@ struct TFixedIntervalPolicy : IRetryPolicy<TArgs...> {
212213
{
213214
}
214215

215-
std::optional<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam... args) override {
216+
TMaybe<TDuration> GetNextRetryDelay(typename TTypeTraits<TArgs>::TFuncParam... args) override {
216217
const ERetryErrorClass errorClass = RetryClassFunction(args...);
217218
if (errorClass == ERetryErrorClass::NoRetry || AttemptsDone >= MaxRetries || StartTime && TInstant::Now() - StartTime >= MaxTime) {
218-
return std::nullopt;
219+
return {};
219220
}
220221

221222
const TDuration delay = NRetryDetails::RandomizeDelay(errorClass == ERetryErrorClass::LongRetry ? LongRetryDelay : Delay);

src/client/topic/impl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ target_sources(client-ydb_topic-impl
2828
PRIVATE
2929
common.cpp
3030
deferred_commit.cpp
31+
direct_reader.cpp
3132
event_handlers.cpp
3233
offsets_collector.cpp
3334
proto_accessor.cpp

src/library/retry/retry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class TRetryOptionsWithRetCodePolicy : public IRetryPolicy<bool> {
1717
{
1818
}
1919

20-
std::optional<TDuration> GetNextRetryDelay(bool ret) override {
20+
TMaybe<TDuration> GetNextRetryDelay(bool ret) override {
2121
if (ret || Attempt == Opts.RetryCount) {
22-
return std::nullopt;
22+
return {};
2323
}
2424
return Opts.GetTimeToSleep(Attempt++);
2525
}

src/library/retry/retry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ class TRetryOptionsPolicy : public IRetryPolicy<const TException&> {
104104
{
105105
}
106106

107-
std::optional<TDuration> GetNextRetryDelay(const TException&) override {
107+
TMaybe<TDuration> GetNextRetryDelay(const TException&) override {
108108
if (Attempt == Opts.RetryCount) {
109-
return std::nullopt;
109+
return {};
110110
}
111111
return Opts.GetTimeToSleep(Attempt++);
112112
}
@@ -151,7 +151,7 @@ std::optional<TResult> DoWithRetry(std::function<TResult()> func, const typename
151151
retryState = retryPolicy->CreateRetryState();
152152
}
153153

154-
if (const std::optional<TDuration> delay = retryState->GetNextRetryDelay(ex)) {
154+
if (const TMaybe<TDuration> delay = retryState->GetNextRetryDelay(ex)) {
155155
if (*delay) {
156156
if (sleepFunction) {
157157
sleepFunction(*delay);
@@ -167,7 +167,7 @@ std::optional<TResult> DoWithRetry(std::function<TResult()> func, const typename
167167
}
168168
}
169169
}
170-
return std::nullopt;
170+
return {};
171171
}
172172

173173
template <typename TResult, typename TException = yexception>
@@ -204,7 +204,7 @@ TRetCode DoWithRetryOnRetCode(std::function<TRetCode()> func, const typename IRe
204204
auto retryState = retryPolicy->CreateRetryState();
205205
while (true) {
206206
TRetCode code = func();
207-
if (const std::optional<TDuration> delay = retryState->GetNextRetryDelay(code)) {
207+
if (const TMaybe<TDuration> delay = retryState->GetNextRetryDelay(code)) {
208208
if (*delay) {
209209
if (sleepFunction) {
210210
sleepFunction(*delay);

0 commit comments

Comments
 (0)