Skip to content

Commit c1c897e

Browse files
dcherednikGazizonoki
authored andcommitted
Moved commit "Remove session from pool in case of BAD_SESSION and other errors which should trigger removing session from pool" from ydb repo
1 parent 16120ac commit c1c897e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class TTransaction;
130130
class TSession {
131131
friend class TQueryClient;
132132
friend class TTransaction;
133+
friend class TExecuteQueryIterator;
133134
public:
134135
const std::string& GetId() const;
135136

src/client/impl/ydb_internal/session_pool/session_pool.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ NThreading::TFuture<TResponse> InjectSessionStatusInterception(
5151
// Exclude CLIENT_RESOURCE_EXHAUSTED from transport errors which can cause to session disconnect
5252
// since we have guarantee this request wasn't been started to execute.
5353

54-
if (status.IsTransportError() && status.GetStatus() != EStatus::CLIENT_RESOURCE_EXHAUSTED) {
54+
if (status.IsTransportError()
55+
&& status.GetStatus() != EStatus::CLIENT_RESOURCE_EXHAUSTED && status.GetStatus() != EStatus::CLIENT_OUT_OF_RANGE)
56+
{
5557
impl->MarkBroken();
5658
} else if (status.GetStatus() == EStatus::SESSION_BUSY) {
5759
impl->MarkBroken();
@@ -70,6 +72,7 @@ NThreading::TFuture<TResponse> InjectSessionStatusInterception(
7072
impl->ScheduleTimeToTouch(RandomizeThreshold(timeout), impl->GetState() == TKqpSessionCommon::EState::S_ACTIVE);
7173
}
7274
}
75+
7376
if (cb) {
7477
cb(value, *impl);
7578
}

src/client/query/impl/exec_query.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#define INCLUDE_YDB_INTERNAL_H
22
#include "exec_query.h"
3+
#include "client_session.h"
34

45
#include <ydb-cpp-sdk/client/query/client.h>
56
#include <src/client/impl/ydb_internal/make_request/make.h>
67
#include <src/client/impl/ydb_internal/kqp_session_common/kqp_session_common.h>
8+
#include <src/client/impl/ydb_internal/session_pool/session_pool.h>
79
#include <src/client/common_client/impl/client.h>
810
#undef INCLUDE_YDB_INTERNAL_H
911

@@ -59,7 +61,7 @@ class TExecuteQueryIterator::TReaderImpl {
5961
return Finished_;
6062
}
6163

62-
TAsyncExecuteQueryPart ReadNext(std::shared_ptr<TSelf> self) {
64+
TAsyncExecuteQueryPart DoReadNext(std::shared_ptr<TSelf> self) {
6365
auto promise = NThreading::NewPromise<TExecuteQueryPart>();
6466
// Capture self - guarantee no dtor call during the read
6567
auto readCb = [self, promise](TGRpcStatus&& grpcStatus) mutable {
@@ -100,6 +102,18 @@ class TExecuteQueryIterator::TReaderImpl {
100102
StreamProcessor_->Read(&Response_, readCb);
101103
return promise.GetFuture();
102104
}
105+
106+
TAsyncExecuteQueryPart ReadNext(std::shared_ptr<TSelf> self) {
107+
if (!Session_)
108+
return DoReadNext(std::move(self));
109+
110+
return NSessionPool::InjectSessionStatusInterception(
111+
Session_->SessionImpl_,
112+
DoReadNext(std::move(self)),
113+
false, // no need to ping stream session
114+
TDuration::Zero());
115+
}
116+
103117
private:
104118
TStreamProcessorPtr StreamProcessor_;
105119
TResponse Response_;

0 commit comments

Comments
 (0)