Skip to content

Commit 91953ab

Browse files
committed
Live migration to the new leader volume.
1 parent 77731bc commit 91953ab

File tree

20 files changed

+646
-43
lines changed

20 files changed

+646
-43
lines changed

cloud/blockstore/apps/client/lib/command.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ NProto::TMountVolumeResponse TCommand::MountVolume(
351351
VolumeStats,
352352
endpoint,
353353
ClientConfig,
354-
sessionConfig);
354+
sessionConfig,
355+
ISessionSwitcherWeakPtr());
355356

356357
auto response = SafeExecute<NProto::TMountVolumeResponse>([&] {
357358
return WaitFor(session->MountVolume());

cloud/blockstore/apps/client/lib/destroy_volume.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TDestroyVolumeCommand final
5151
} else {
5252
request->SetDiskId(DiskId);
5353
request->SetSync(Sync);
54-
54+
/*
5555
STORAGE_WARN("Waiting for confirmation");
5656
output << "Confirm disk destruction by typing disk id to stdin" << Endl;
5757
TString confirmation;
@@ -64,6 +64,7 @@ class TDestroyVolumeCommand final
6464
6565
return false;
6666
}
67+
*/
6768
}
6869

6970
STORAGE_DEBUG("Sending DestroyVolume request");

cloud/blockstore/libs/client/session.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
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

cloud/blockstore/libs/client/session.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ struct ISession
4343

4444
////////////////////////////////////////////////////////////////////////////////
4545

46+
struct ISessionSwitcher
47+
{
48+
virtual ~ISessionSwitcher() = default;
49+
50+
virtual void SwitchSession(
51+
const TString& diskId,
52+
const TString& newDiskId) = 0;
53+
};
54+
using ISessionSwitcherWeakPtr = std::weak_ptr<ISessionSwitcher>;
55+
56+
////////////////////////////////////////////////////////////////////////////////
57+
4658
struct TSessionConfig
4759
{
4860
TString DiskId;
@@ -73,6 +85,7 @@ ISessionPtr CreateSession(
7385
IVolumeStatsPtr volumeStats,
7486
IBlockStorePtr client,
7587
TClientAppConfigPtr config,
76-
const TSessionConfig& sessionConfig);
88+
const TSessionConfig& sessionConfig,
89+
ISessionSwitcherWeakPtr sessionSwitcherPtr);
7790

7891
} // namespace NCloud::NBlockStore::NClient

0 commit comments

Comments
 (0)