88#include < cloud/blockstore/libs/service/context.h>
99#include < cloud/blockstore/libs/service/request_helpers.h>
1010#include < cloud/blockstore/libs/service/service.h>
11+ #include < cloud/blockstore/libs/storage/model/volume_label.h>
12+
1113#include < cloud/storage/core/libs/common/error.h>
1214#include < cloud/storage/core/libs/common/scheduler.h>
1315#include < cloud/storage/core/libs/common/timer.h>
@@ -122,6 +124,7 @@ class TSession final
122124 const IBlockStorePtr Client;
123125 const TClientAppConfigPtr Config;
124126 TSessionConfig SessionConfig;
127+ ISessionSwitcherWeakPtr SessionSwitcherPtr;
125128
126129 TLog Log;
127130 TSessionInfo SessionInfo;
@@ -135,7 +138,8 @@ class TSession final
135138 IVolumeStatsPtr volumeStats,
136139 IBlockStorePtr client,
137140 TClientAppConfigPtr config,
138- const TSessionConfig& sessionConfig);
141+ const TSessionConfig& sessionConfig,
142+ ISessionSwitcherWeakPtr sessionSwitcherPtr);
139143
140144 ui32 GetMaxTransfer () const override ;
141145
@@ -251,7 +255,8 @@ TSession::TSession(
251255 IVolumeStatsPtr volumeStats,
252256 IBlockStorePtr client,
253257 TClientAppConfigPtr config,
254- const TSessionConfig& sessionConfig)
258+ const TSessionConfig& sessionConfig,
259+ ISessionSwitcherWeakPtr sessionSwitcherPtr)
255260 : Timer(std::move(timer))
256261 , Scheduler(std::move(scheduler))
257262 , Logging(std::move(logging))
@@ -260,6 +265,7 @@ TSession::TSession(
260265 , Client(std::move(client))
261266 , Config(std::move(config))
262267 , SessionConfig(sessionConfig)
268+ , SessionSwitcherPtr(std::move(sessionSwitcherPtr))
263269 , Log(Logging->CreateLog (" BLOCKSTORE_CLIENT" ))
264270{}
265271
@@ -629,6 +635,18 @@ void TSession::ProcessMountResponse(
629635 SessionConfig.InstanceId )
630636 << " complete request" );
631637
638+ if (response.GetVolume ().GetPrincipalDiskId ()) {
639+ Y_DEBUG_ABORT_UNLESS (
640+ response.GetVolume ().GetPrincipalDiskId () ==
641+ NStorage::GetNextDiskId (response.GetVolume().GetDiskId()));
642+
643+ if (auto switcher = SessionSwitcherPtr.lock ()) {
644+ switcher->SwitchSession (
645+ response.GetVolume ().GetDiskId (),
646+ response.GetVolume ().GetPrincipalDiskId ());
647+ }
648+ }
649+
632650 SessionInfo.MountState = EMountState::MountCompleted;
633651 SessionInfo.BlockSize = response.GetVolume ().GetBlockSize ();
634652 SessionInfo.SessionId = response.GetSessionId ();
@@ -964,6 +982,15 @@ void TSession::HandleResponse(
964982
965983 ForceVolumeRemount (sessionId);
966984 HandleRequest<T>(std::move (callContext), std::move (request), response);
985+
986+ if (HasProtoFlag (errorFlags, NProto::EF_OUTDATED_VOLUME)) {
987+ if (auto switcher = SessionSwitcherPtr.lock ()) {
988+ switcher->SwitchSession (
989+ SessionConfig.DiskId ,
990+ NStorage::GetNextDiskId (SessionConfig.DiskId));
991+ }
992+ }
993+
967994 return ;
968995 }
969996
@@ -1020,7 +1047,8 @@ ISessionPtr CreateSession(
10201047 IVolumeStatsPtr volumeStats,
10211048 IBlockStorePtr client,
10221049 TClientAppConfigPtr config,
1023- const TSessionConfig& sessionConfig)
1050+ const TSessionConfig& sessionConfig,
1051+ ISessionSwitcherWeakPtr sessionSwitcherPtr)
10241052{
10251053 return std::make_shared<TSession>(
10261054 std::move (timer),
@@ -1030,7 +1058,8 @@ ISessionPtr CreateSession(
10301058 std::move (volumeStats),
10311059 std::move (client),
10321060 std::move (config),
1033- sessionConfig);
1061+ sessionConfig,
1062+ std::move (sessionSwitcherPtr));
10341063}
10351064
10361065} // namespace NCloud::NBlockStore::NClient
0 commit comments