Skip to content

Commit 429746c

Browse files
committed
Tracking signs that you need to switch sessions in the TSwitchableBlockStore
1 parent 294b2f4 commit 429746c

File tree

16 files changed

+285
-256
lines changed

16 files changed

+285
-256
lines changed

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

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

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

cloud/blockstore/libs/client/session.cpp

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

1312
#include <cloud/storage/core/libs/common/error.h>
1413
#include <cloud/storage/core/libs/common/scheduler.h>
@@ -124,7 +123,6 @@ class TSession final
124123
const IBlockStorePtr Client;
125124
const TClientAppConfigPtr Config;
126125
TSessionConfig SessionConfig;
127-
ISessionSwitcherWeakPtr SessionSwitcherPtr;
128126

129127
TLog Log;
130128
TSessionInfo SessionInfo;
@@ -138,8 +136,7 @@ class TSession final
138136
IVolumeStatsPtr volumeStats,
139137
IBlockStorePtr client,
140138
TClientAppConfigPtr config,
141-
const TSessionConfig& sessionConfig,
142-
ISessionSwitcherWeakPtr sessionSwitcherPtr);
139+
const TSessionConfig& sessionConfig);
143140

144141
ui32 GetMaxTransfer() const override;
145142

@@ -255,8 +252,7 @@ TSession::TSession(
255252
IVolumeStatsPtr volumeStats,
256253
IBlockStorePtr client,
257254
TClientAppConfigPtr config,
258-
const TSessionConfig& sessionConfig,
259-
ISessionSwitcherWeakPtr sessionSwitcherPtr)
255+
const TSessionConfig& sessionConfig)
260256
: Timer(std::move(timer))
261257
, Scheduler(std::move(scheduler))
262258
, Logging(std::move(logging))
@@ -265,7 +261,6 @@ TSession::TSession(
265261
, Client(std::move(client))
266262
, Config(std::move(config))
267263
, SessionConfig(sessionConfig)
268-
, SessionSwitcherPtr(std::move(sessionSwitcherPtr))
269264
, Log(Logging->CreateLog("BLOCKSTORE_CLIENT"))
270265
{}
271266

@@ -635,18 +630,6 @@ void TSession::ProcessMountResponse(
635630
SessionConfig.InstanceId)
636631
<< " complete request");
637632

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-
650633
SessionInfo.MountState = EMountState::MountCompleted;
651634
SessionInfo.BlockSize = response.GetVolume().GetBlockSize();
652635
SessionInfo.SessionId = response.GetSessionId();
@@ -982,15 +965,6 @@ void TSession::HandleResponse(
982965

983966
ForceVolumeRemount(sessionId);
984967
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-
994968
return;
995969
}
996970

@@ -1047,8 +1021,7 @@ ISessionPtr CreateSession(
10471021
IVolumeStatsPtr volumeStats,
10481022
IBlockStorePtr client,
10491023
TClientAppConfigPtr config,
1050-
const TSessionConfig& sessionConfig,
1051-
ISessionSwitcherWeakPtr sessionSwitcherPtr)
1024+
const TSessionConfig& sessionConfig)
10521025
{
10531026
return std::make_shared<TSession>(
10541027
std::move(timer),
@@ -1058,8 +1031,7 @@ ISessionPtr CreateSession(
10581031
std::move(volumeStats),
10591032
std::move(client),
10601033
std::move(config),
1061-
sessionConfig,
1062-
std::move(sessionSwitcherPtr));
1034+
sessionConfig);
10631035
}
10641036

10651037
} // namespace NCloud::NBlockStore::NClient

cloud/blockstore/libs/client/session.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ 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-
5846
struct TSessionConfig
5947
{
6048
TString DiskId;
@@ -85,7 +73,6 @@ ISessionPtr CreateSession(
8573
IVolumeStatsPtr volumeStats,
8674
IBlockStorePtr client,
8775
TClientAppConfigPtr config,
88-
const TSessionConfig& sessionConfig,
89-
ISessionSwitcherWeakPtr sessionSwitcherPtr);
76+
const TSessionConfig& sessionConfig);
9077

9178
} // namespace NCloud::NBlockStore::NClient

cloud/blockstore/libs/client/session_ut.cpp

Lines changed: 13 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
#include "client.h"
44
#include "config.h"
55

6-
#include <cloud/storage/core/libs/common/helpers.h>
76
#include <cloud/blockstore/libs/diagnostics/request_stats.h>
87
#include <cloud/blockstore/libs/diagnostics/volume_stats.h>
98
#include <cloud/blockstore/libs/service/context.h>
109
#include <cloud/blockstore/libs/service/service_test.h>
11-
#include <cloud/blockstore/libs/storage/model/volume_label.h>
1210

1311
#include <cloud/storage/core/libs/common/error.h>
1412
#include <cloud/storage/core/libs/common/scheduler_test.h>
@@ -37,26 +35,6 @@ static constexpr ui32 DefaultBlocksCount = 1024;
3735

3836
////////////////////////////////////////////////////////////////////////////////
3937

40-
struct TTestSessionSwitcher
41-
: public ISessionSwitcher
42-
, public std::enable_shared_from_this<TTestSessionSwitcher>
43-
{
44-
struct TSwitchInfo
45-
{
46-
TString DiskId;
47-
TString NewDiskId;
48-
};
49-
TVector<TSwitchInfo> Switches;
50-
51-
void SwitchSession(const TString& diskId, const TString& newDiskId) override
52-
{
53-
Switches.push_back(
54-
TSwitchInfo{.DiskId = diskId, .NewDiskId = newDiskId});
55-
}
56-
};
57-
using TTestSessionSwitcherPtr = std::shared_ptr<TTestSessionSwitcher>;
58-
59-
////////////////////////////////////////////////////////////////////////////////
6038
class TBootstrap
6139
{
6240
ITimerPtr Timer;
@@ -66,9 +44,6 @@ class TBootstrap
6644

6745
IBlockStorePtr Client;
6846

69-
TTestSessionSwitcherPtr SessionSwitcher =
70-
std::make_shared<TTestSessionSwitcher>();
71-
7247
ISessionPtr Session;
7348

7449
public:
@@ -84,19 +59,19 @@ class TBootstrap
8459
, Config(std::make_shared<TClientAppConfig>())
8560
, Client(std::move(client))
8661
, Session(CreateSession(
87-
Timer,
88-
Scheduler,
89-
Logging,
90-
CreateRequestStatsStub(),
91-
CreateVolumeStatsStub(),
92-
Client,
93-
Config,
94-
TSessionConfig{
95-
.DiskId = DefaultDiskId,
96-
.MountToken = DefaultMountToken,
97-
.ClientVersionInfo = std::move(clientVersionInfo),
98-
.MountSeqNumber = mountSeqNumber},
99-
SessionSwitcher))
62+
Timer,
63+
Scheduler,
64+
Logging,
65+
CreateRequestStatsStub(),
66+
CreateVolumeStatsStub(),
67+
Client,
68+
Config,
69+
TSessionConfig{
70+
.DiskId = DefaultDiskId,
71+
.MountToken = DefaultMountToken,
72+
.ClientVersionInfo = std::move(clientVersionInfo),
73+
.MountSeqNumber = mountSeqNumber
74+
}))
10075
{}
10176

10277
void Start()
@@ -158,11 +133,6 @@ class TBootstrap
158133
{
159134
return Session.get();
160135
}
161-
162-
TTestSessionSwitcher& GetSessionSwitcher()
163-
{
164-
return *SessionSwitcher;
165-
}
166136
};
167137

168138
////////////////////////////////////////////////////////////////////////////////
@@ -351,9 +321,6 @@ Y_UNIT_TEST_SUITE(TSessionTest)
351321
{
352322
auto res = session->MountVolume().GetValueSync();
353323
UNIT_ASSERT_C(!HasError(res), res);
354-
UNIT_ASSERT_VALUES_EQUAL(
355-
0ul,
356-
bootstrap->GetSessionSwitcher().Switches.size());
357324
}
358325

359326
{
@@ -1851,146 +1818,6 @@ Y_UNIT_TEST_SUITE(TSessionTest)
18511818

18521819
bootstrap->Stop();
18531820
}
1854-
1855-
Y_UNIT_TEST(ShouldSwitchSessionIfMountContainsPrincipalDiskId)
1856-
{
1857-
auto client = std::make_shared<TTestService>();
1858-
1859-
size_t sessionNum = 0;
1860-
client->MountVolumeHandler =
1861-
[&](std::shared_ptr<NProto::TMountVolumeRequest> request)
1862-
{
1863-
UNIT_ASSERT_EQUAL(request->GetDiskId(), DefaultDiskId);
1864-
UNIT_ASSERT_EQUAL(request->GetToken(), DefaultMountToken);
1865-
1866-
NProto::TMountVolumeResponse response;
1867-
response.SetSessionId(ToString(++sessionNum));
1868-
1869-
auto& volume = *response.MutableVolume();
1870-
volume.SetDiskId(request->GetDiskId());
1871-
volume.SetBlockSize(DefaultBlockSize);
1872-
volume.SetBlocksCount(DefaultBlocksCount);
1873-
volume.SetPrincipalDiskId(
1874-
NStorage::GetNextDiskId(request->GetDiskId()));
1875-
1876-
return MakeFuture(response);
1877-
};
1878-
1879-
client->UnmountVolumeHandler =
1880-
[](std::shared_ptr<NProto::TUnmountVolumeRequest> request)
1881-
{
1882-
UNIT_ASSERT_EQUAL(request->GetDiskId(), DefaultDiskId);
1883-
UNIT_ASSERT_EQUAL(request->GetSessionId(), "2");
1884-
1885-
return MakeFuture<NProto::TUnmountVolumeResponse>();
1886-
};
1887-
1888-
auto bootstrap = CreateBootstrap(client);
1889-
1890-
auto* session = bootstrap->GetSession();
1891-
1892-
bootstrap->Start();
1893-
1894-
auto res = session->MountVolume().GetValueSync();
1895-
UNIT_ASSERT_C(!HasError(res), res);
1896-
UNIT_ASSERT_EQUAL(sessionNum, 1);
1897-
1898-
UNIT_ASSERT_VALUES_EQUAL(
1899-
1ul,
1900-
bootstrap->GetSessionSwitcher().Switches.size());
1901-
1902-
auto switchInfo = bootstrap->GetSessionSwitcher().Switches[0];
1903-
UNIT_ASSERT_VALUES_EQUAL(DefaultDiskId, switchInfo.DiskId);
1904-
UNIT_ASSERT_VALUES_EQUAL(
1905-
NStorage::GetNextDiskId(DefaultDiskId),
1906-
switchInfo.NewDiskId);
1907-
1908-
bootstrap->Stop();
1909-
}
1910-
1911-
Y_UNIT_TEST(ShouldSwitchSessionIfResponseContains_EF_OUTDATED_VOLUME)
1912-
{
1913-
auto client = std::make_shared<TTestService>();
1914-
1915-
size_t sessionNum = 0;
1916-
client->MountVolumeHandler =
1917-
[&](std::shared_ptr<NProto::TMountVolumeRequest> request)
1918-
{
1919-
UNIT_ASSERT_EQUAL(request->GetDiskId(), DefaultDiskId);
1920-
UNIT_ASSERT_EQUAL(request->GetToken(), DefaultMountToken);
1921-
1922-
NProto::TMountVolumeResponse response;
1923-
response.SetSessionId(ToString(++sessionNum));
1924-
1925-
auto& volume = *response.MutableVolume();
1926-
volume.SetDiskId(request->GetDiskId());
1927-
volume.SetBlockSize(DefaultBlockSize);
1928-
volume.SetBlocksCount(DefaultBlocksCount);
1929-
1930-
return MakeFuture(response);
1931-
};
1932-
1933-
client->UnmountVolumeHandler =
1934-
[](std::shared_ptr<NProto::TUnmountVolumeRequest> request)
1935-
{
1936-
UNIT_ASSERT_EQUAL(request->GetDiskId(), DefaultDiskId);
1937-
UNIT_ASSERT_EQUAL(request->GetSessionId(), "2");
1938-
1939-
return MakeFuture<NProto::TUnmountVolumeResponse>();
1940-
};
1941-
1942-
client->WriteBlocksLocalHandler =
1943-
[](std::shared_ptr<NProto::TWriteBlocksLocalRequest> request)
1944-
{
1945-
UNIT_ASSERT_EQUAL(request->GetDiskId(), DefaultDiskId);
1946-
if (request->GetSessionId() == "1") {
1947-
ui32 flags = 0;
1948-
SetProtoFlag(flags, NProto::EF_OUTDATED_VOLUME);
1949-
return MakeFuture<NProto::TWriteBlocksLocalResponse>(
1950-
TErrorResponse(
1951-
E_BS_INVALID_SESSION,
1952-
"reconnect to principal disk",
1953-
flags));
1954-
}
1955-
1956-
return MakeFuture<NProto::TWriteBlocksLocalResponse>();
1957-
};
1958-
1959-
auto bootstrap = CreateBootstrap(client);
1960-
1961-
auto* session = bootstrap->GetSession();
1962-
1963-
bootstrap->Start();
1964-
1965-
{
1966-
auto res = session->MountVolume().GetValueSync();
1967-
UNIT_ASSERT_C(!HasError(res), res);
1968-
UNIT_ASSERT_EQUAL(sessionNum, 1);
1969-
}
1970-
1971-
{
1972-
auto res = WriteBlocks(session);
1973-
UNIT_ASSERT_C(!HasError(res), res);
1974-
UNIT_ASSERT_EQUAL(sessionNum, 2);
1975-
1976-
UNIT_ASSERT_VALUES_EQUAL(
1977-
1ul,
1978-
bootstrap->GetSessionSwitcher().Switches.size());
1979-
1980-
auto switchInfo = bootstrap->GetSessionSwitcher().Switches[0];
1981-
UNIT_ASSERT_VALUES_EQUAL(DefaultDiskId, switchInfo.DiskId);
1982-
UNIT_ASSERT_VALUES_EQUAL(
1983-
NStorage::GetNextDiskId(DefaultDiskId),
1984-
switchInfo.NewDiskId);
1985-
}
1986-
1987-
{
1988-
auto res = session->UnmountVolume().GetValueSync();
1989-
UNIT_ASSERT_C(!HasError(res), res);
1990-
}
1991-
1992-
bootstrap->Stop();
1993-
}
19941821
}
19951822

19961823
} // namespace NCloud::NBlockStore::NClient

0 commit comments

Comments
 (0)