Skip to content

Commit 5c4dfb9

Browse files
stanislav-shchetininGazizonoki
authored andcommitted
Moved commit "Added new versions of RetryQuery" from ydb repo
1 parent f74c4e8 commit 5c4dfb9

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

include/ydb-cpp-sdk/client/query/client.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ namespace NYdb {
1414
namespace NRetry::Async {
1515
template <typename TClient, typename TAsyncStatusType>
1616
class TRetryContext;
17-
}
17+
} // namespace NRetry::Async
18+
namespace NRetry::Sync {
19+
template <typename TClient, typename TStatusType>
20+
class TRetryContext;
21+
} // namespace NRetry::Sync
1822
}
1923

2024
namespace NYdb::NQuery {
@@ -55,10 +59,15 @@ class TSession;
5559
class TQueryClient {
5660
friend class TSession;
5761
friend class NRetry::Async::TRetryContext<TQueryClient, TAsyncExecuteQueryResult>;
62+
friend class NRetry::Async::TRetryContext<TQueryClient, TAsyncStatus>;
63+
friend class NRetry::Sync::TRetryContext<TQueryClient, TStatus>;
5864

5965
public:
60-
using TQueryFunc = std::function<TAsyncExecuteQueryResult(TSession session)>;
61-
using TQueryWithoutSessionFunc = std::function<TAsyncExecuteQueryResult(TQueryClient& client)>;
66+
using TQueryResultFunc = std::function<TAsyncExecuteQueryResult(TSession session)>;
67+
using TQueryFunc = std::function<TAsyncStatus(TSession session)>;
68+
using TQuerySyncFunc = std::function<TStatus(TSession session)>;
69+
using TQueryWithoutSessionFunc = std::function<TAsyncStatus(TQueryClient& client)>;
70+
using TQueryWithoutSessionSyncFunc = std::function<TStatus(TQueryClient& client)>;
6271
using TSettings = TClientSettings;
6372
using TSession = TSession;
6473
using TCreateSessionSettings = TCreateSessionSettings;
@@ -79,7 +88,15 @@ class TQueryClient {
7988
TAsyncExecuteQueryIterator StreamExecuteQuery(const std::string& query, const TTxControl& txControl,
8089
const TParams& params, const TExecuteQuerySettings& settings = TExecuteQuerySettings());
8190

82-
TAsyncExecuteQueryResult RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings());
91+
TAsyncExecuteQueryResult RetryQuery(TQueryResultFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings());
92+
93+
TAsyncStatus RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings());
94+
95+
TAsyncStatus RetryQuery(TQueryWithoutSessionFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings());
96+
97+
TStatus RetryQuery(const TQuerySyncFunc& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings());
98+
99+
TStatus RetryQuery(const TQueryWithoutSessionSyncFunc& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings());
83100

84101
TAsyncExecuteQueryResult RetryQuery(const std::string& query, const TTxControl& txControl,
85102
TDuration timeout, bool isIndempotent);

src/client/query/client.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
namespace NYdb::NQuery {
2323

24-
using TRetryContextAsync = NRetry::Async::TRetryContext<TQueryClient, TAsyncExecuteQueryResult>;
24+
using TRetryContextResultAsync = NRetry::Async::TRetryContext<TQueryClient, TAsyncExecuteQueryResult>;
25+
using TRetryContextAsync = NRetry::Async::TRetryContext<TQueryClient, TAsyncStatus>;
2526

2627
NYdb::NRetry::TRetryOperationSettings GetRetrySettings(TDuration timeout, bool isIndempotent) {
2728
return NYdb::NRetry::TRetryOperationSettings()
@@ -577,20 +578,40 @@ int64_t TQueryClient::GetCurrentPoolSize() const {
577578
return Impl_->GetCurrentPoolSize();
578579
}
579580

580-
TAsyncExecuteQueryResult TQueryClient::RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings)
581+
TAsyncExecuteQueryResult TQueryClient::RetryQuery(TQueryResultFunc&& queryFunc, TRetryOperationSettings settings)
581582
{
583+
TRetryContextResultAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings));
584+
return ctx->Execute();
585+
}
586+
587+
TAsyncStatus TQueryClient::RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings) {
582588
TRetryContextAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings));
583589
return ctx->Execute();
584590
}
585591

592+
TAsyncStatus TQueryClient::RetryQuery(TQueryWithoutSessionFunc&& queryFunc, TRetryOperationSettings settings) {
593+
TRetryContextAsync::TPtr ctx(new NRetry::Async::TRetryWithoutSession(*this, std::move(queryFunc), settings));
594+
return ctx->Execute();
595+
}
596+
597+
TStatus TQueryClient::RetryQuery(const TQuerySyncFunc& queryFunc, TRetryOperationSettings settings) {
598+
NRetry::Sync::TRetryWithSession ctx(*this, queryFunc, settings);
599+
return ctx.Execute();
600+
}
601+
602+
TStatus TQueryClient::RetryQuery(const TQueryWithoutSessionSyncFunc& queryFunc, TRetryOperationSettings settings) {
603+
NRetry::Sync::TRetryWithoutSession ctx(*this, queryFunc, settings);
604+
return ctx.Execute();
605+
}
606+
586607
TAsyncExecuteQueryResult TQueryClient::RetryQuery(const std::string& query, const TTxControl& txControl,
587608
TDuration timeout, bool isIndempotent)
588609
{
589610
auto settings = GetRetrySettings(timeout, isIndempotent);
590611
auto queryFunc = [&query, &txControl](TSession session, TDuration duration) -> TAsyncExecuteQueryResult {
591612
return session.ExecuteQuery(query, txControl, TExecuteQuerySettings().ClientTimeout(duration));
592613
};
593-
TRetryContextAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings));
614+
TRetryContextResultAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings));
594615
return ctx->Execute();
595616
}
596617

0 commit comments

Comments
 (0)