diff options
author | grigoriypisar <grigoriypisar@yandex-team.com> | 2023-09-07 12:54:28 +0300 |
---|---|---|
committer | grigoriypisar <grigoriypisar@yandex-team.com> | 2023-09-07 14:18:08 +0300 |
commit | 7c128e386594fe82ee10288f9c8aab3475cb31bd (patch) | |
tree | 71b4b7c76fef9f36d7fb1122117ad49ea638cba3 | |
parent | d881bffab3520d7b9915fb97f240e807937e8421 (diff) | |
download | ydb-7c128e386594fe82ee10288f9c8aab3475cb31bd.tar.gz |
Fixed unclosed sessions
Temp problem solution.
-rw-r--r-- | ydb/services/metadata/request/common.h | 6 | ||||
-rw-r--r-- | ydb/services/metadata/request/request_actor_cb.h | 80 |
2 files changed, 82 insertions, 4 deletions
diff --git a/ydb/services/metadata/request/common.h b/ydb/services/metadata/request/common.h index 6bcff29790..2b28216a2b 100644 --- a/ydb/services/metadata/request/common.h +++ b/ydb/services/metadata/request/common.h @@ -45,6 +45,10 @@ enum EEvents { EvCreatePathInternalResponse, EvCreatePathResponse, + EvDeleteSessionRequest, + EvDeleteSessionInternalResponse, + EvDeleteSessionResponse, + EvEnd }; @@ -83,6 +87,8 @@ using TDialogSelect = TDialogPolicyImpl<Ydb::Table::ExecuteDataQueryRequest, Ydb EEvents::EvSelectRequest, EEvents::EvSelectInternalResponse, EEvents::EvSelectResponse>; using TDialogCreateSession = TDialogPolicyImpl<Ydb::Table::CreateSessionRequest, Ydb::Table::CreateSessionResponse, EEvents::EvCreateSessionRequest, EEvents::EvCreateSessionInternalResponse, EEvents::EvCreateSessionResponse>; +using TDialogDeleteSession = TDialogPolicyImpl<Ydb::Table::DeleteSessionRequest, Ydb::Table::DeleteSessionResponse, + EEvents::EvDeleteSessionRequest, EEvents::EvDeleteSessionInternalResponse, EEvents::EvDeleteSessionResponse>; template <ui32 evResult = EEvents::EvGeneralYQLResponse> using TCustomDialogYQLRequest = TDialogPolicyImpl<Ydb::Table::ExecuteDataQueryRequest, Ydb::Table::ExecuteDataQueryResponse, diff --git a/ydb/services/metadata/request/request_actor_cb.h b/ydb/services/metadata/request/request_actor_cb.h index 181a937798..e86558fde7 100644 --- a/ydb/services/metadata/request/request_actor_cb.h +++ b/ydb/services/metadata/request/request_actor_cb.h @@ -91,12 +91,27 @@ public: } }; +class TSessionContext { + TMaybe<TString> SessionId; +public: + using TPtr = std::shared_ptr<TSessionContext>; + + void SetSessionId(const TString& sessionId) { + SessionId = sessionId; + } + + TMaybe<TString> GetSessionId() const { + return SessionId; + } +}; + template <class TDialogPolicy> class TSessionedChainController: public IChainController<TDialogCreateSession, IExternalController<TDialogPolicy>> { private: using TRequest = typename TDialogPolicy::TRequest; using TBase = IChainController<TDialogCreateSession, IExternalController<TDialogPolicy>>; TRequest ProtoRequest; + TSessionContext::TPtr SessionContext; protected: virtual TConclusion<typename TDialogPolicy::TRequest> DoBuildNextRequest(TDialogCreateSession::TResponse&& response) const override { auto result = ProtoRequest; @@ -108,13 +123,15 @@ protected: return TConclusionStatus::Fail("cannot build session for request"); } result.set_session_id(sessionId); + SessionContext->SetSessionId(sessionId); return result; } public: - TSessionedChainController(const TRequest& request, const NACLib::TUserToken& uToken, typename IExternalController<TDialogPolicy>::TPtr externalController) + TSessionedChainController(const TRequest& request, const NACLib::TUserToken& uToken, typename IExternalController<TDialogPolicy>::TPtr externalController, TSessionContext::TPtr sessionContext) : TBase(uToken, externalController) - , ProtoRequest(request) { - + , ProtoRequest(request) + , SessionContext(sessionContext) { + Y_VERIFY(SessionContext); } }; @@ -137,6 +154,59 @@ public: } }; +class TSessionDeleteResponseController: public IExternalController<NMetadata::NRequest::TDialogDeleteSession> { +private: + TSessionContext::TPtr SessionContext; +public: + TSessionDeleteResponseController(TSessionContext::TPtr sessionContext) + : SessionContext(sessionContext) { + } + + virtual void OnRequestResult(typename TDialogPolicy::TResponse&&) override { + } + + virtual void OnRequestFailed(const TString& errorMessage) override { + ALS_ERROR(NKikimrServices::METADATA_PROVIDER) << "cannot close session with id: " << *SessionContext->GetSessionId() << ", reason: " << errorMessage; + } +}; + +template <class TDialogPolicy> +class TSessionDeleteController: public IExternalController<TDialogPolicy> { +private: + TSessionContext::TPtr SessionContext; + typename IExternalController<TDialogPolicy>::TPtr ExternalController; + const NACLib::TUserToken UserToken; + + void CloseSession() const { + auto sessionId = SessionContext->GetSessionId(); + if (sessionId) { + auto deleteRequest = NMetadata::NRequest::TDialogDeleteSession::TRequest(); + deleteRequest.set_session_id(*sessionId); + + auto sessionDeleteResponseController = std::make_shared<NMetadata::NRequest::TSessionDeleteResponseController>(SessionContext); + TYDBOneRequestSender<NMetadata::NRequest::TDialogDeleteSession> request(deleteRequest, UserToken, sessionDeleteResponseController); + request.Start(); + } + } + +public: + TSessionDeleteController(TSessionContext::TPtr sessionContext, const NACLib::TUserToken& userToken, typename IExternalController<TDialogPolicy>::TPtr externalController) + : SessionContext(sessionContext) + , ExternalController(externalController) + , UserToken(userToken) { + } + + virtual void OnRequestResult(typename TDialogPolicy::TResponse&& result) override { + ExternalController->OnRequestResult(std::move(result)); + CloseSession(); + } + + virtual void OnRequestFailed(const TString& errorMessage) override { + ExternalController->OnRequestFailed(errorMessage); + CloseSession(); + } +}; + class TYQLRequestExecutor { private: static TDialogYQLRequest::TRequest BuildRequest(const TString& request, const bool readOnly) { @@ -152,8 +222,10 @@ private: } public: static void Execute(TDialogYQLRequest::TRequest&& request, const NACLib::TUserToken& uToken, IExternalController<TDialogYQLRequest>::TPtr controller) { + auto sessionContext = std::make_shared<TSessionContext>(); + auto sessionDeleteController = std::make_shared<NMetadata::NRequest::TSessionDeleteController<NMetadata::NRequest::TDialogYQLRequest>>(sessionContext, uToken, controller); auto sessionController = std::make_shared<NMetadata::NRequest::TSessionedChainController<NMetadata::NRequest::TDialogYQLRequest>> - (std::move(request), uToken, controller); + (std::move(request), uToken, sessionDeleteController, sessionContext); NMetadata::NRequest::TYDBOneRequestSender<NMetadata::NRequest::TDialogCreateSession> ydbReq(NMetadata::NRequest::TDialogCreateSession::TRequest(), uToken, sessionController); ydbReq.Start(); |