diff --git a/include/ydb-cpp-sdk/client/query/client.h b/include/ydb-cpp-sdk/client/query/client.h index dbf611825b..a25f83531a 100644 --- a/include/ydb-cpp-sdk/client/query/client.h +++ b/include/ydb-cpp-sdk/client/query/client.h @@ -14,7 +14,11 @@ namespace NYdb { namespace NRetry::Async { template class TRetryContext; - } + } // namespace NRetry::Async + namespace NRetry::Sync { + template + class TRetryContext; + } // namespace NRetry::Sync } namespace NYdb::NQuery { @@ -55,10 +59,15 @@ class TSession; class TQueryClient { friend class TSession; friend class NRetry::Async::TRetryContext; + friend class NRetry::Async::TRetryContext; + friend class NRetry::Sync::TRetryContext; public: - using TQueryFunc = std::function; - using TQueryWithoutSessionFunc = std::function; + using TQueryResultFunc = std::function; + using TQueryFunc = std::function; + using TQuerySyncFunc = std::function; + using TQueryWithoutSessionFunc = std::function; + using TQueryWithoutSessionSyncFunc = std::function; using TSettings = TClientSettings; using TSession = TSession; using TCreateSessionSettings = TCreateSessionSettings; @@ -79,7 +88,15 @@ class TQueryClient { TAsyncExecuteQueryIterator StreamExecuteQuery(const std::string& query, const TTxControl& txControl, const TParams& params, const TExecuteQuerySettings& settings = TExecuteQuerySettings()); - TAsyncExecuteQueryResult RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings()); + TAsyncExecuteQueryResult RetryQuery(TQueryResultFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings()); + + TAsyncStatus RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings()); + + TAsyncStatus RetryQuery(TQueryWithoutSessionFunc&& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings()); + + TStatus RetryQuery(const TQuerySyncFunc& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings()); + + TStatus RetryQuery(const TQueryWithoutSessionSyncFunc& queryFunc, TRetryOperationSettings settings = TRetryOperationSettings()); TAsyncExecuteQueryResult RetryQuery(const std::string& query, const TTxControl& txControl, TDuration timeout, bool isIndempotent); diff --git a/src/client/query/client.cpp b/src/client/query/client.cpp index 03fccfb8bc..6f3e6636f4 100644 --- a/src/client/query/client.cpp +++ b/src/client/query/client.cpp @@ -21,7 +21,8 @@ namespace NYdb::NQuery { -using TRetryContextAsync = NRetry::Async::TRetryContext; +using TRetryContextResultAsync = NRetry::Async::TRetryContext; +using TRetryContextAsync = NRetry::Async::TRetryContext; NYdb::NRetry::TRetryOperationSettings GetRetrySettings(TDuration timeout, bool isIndempotent) { return NYdb::NRetry::TRetryOperationSettings() @@ -577,12 +578,32 @@ int64_t TQueryClient::GetCurrentPoolSize() const { return Impl_->GetCurrentPoolSize(); } -TAsyncExecuteQueryResult TQueryClient::RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings) +TAsyncExecuteQueryResult TQueryClient::RetryQuery(TQueryResultFunc&& queryFunc, TRetryOperationSettings settings) { + TRetryContextResultAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings)); + return ctx->Execute(); +} + +TAsyncStatus TQueryClient::RetryQuery(TQueryFunc&& queryFunc, TRetryOperationSettings settings) { TRetryContextAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings)); return ctx->Execute(); } +TAsyncStatus TQueryClient::RetryQuery(TQueryWithoutSessionFunc&& queryFunc, TRetryOperationSettings settings) { + TRetryContextAsync::TPtr ctx(new NRetry::Async::TRetryWithoutSession(*this, std::move(queryFunc), settings)); + return ctx->Execute(); +} + +TStatus TQueryClient::RetryQuery(const TQuerySyncFunc& queryFunc, TRetryOperationSettings settings) { + NRetry::Sync::TRetryWithSession ctx(*this, queryFunc, settings); + return ctx.Execute(); +} + +TStatus TQueryClient::RetryQuery(const TQueryWithoutSessionSyncFunc& queryFunc, TRetryOperationSettings settings) { + NRetry::Sync::TRetryWithoutSession ctx(*this, queryFunc, settings); + return ctx.Execute(); +} + TAsyncExecuteQueryResult TQueryClient::RetryQuery(const std::string& query, const TTxControl& txControl, TDuration timeout, bool isIndempotent) { @@ -590,7 +611,7 @@ TAsyncExecuteQueryResult TQueryClient::RetryQuery(const std::string& query, cons auto queryFunc = [&query, &txControl](TSession session, TDuration duration) -> TAsyncExecuteQueryResult { return session.ExecuteQuery(query, txControl, TExecuteQuerySettings().ClientTimeout(duration)); }; - TRetryContextAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings)); + TRetryContextResultAsync::TPtr ctx(new NRetry::Async::TRetryWithSession(*this, std::move(queryFunc), settings)); return ctx->Execute(); }