Skip to content

Commit bdae7bc

Browse files
committed
Reboot after switch to outdated state
1 parent c85af52 commit bdae7bc

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

cloud/blockstore/libs/client/switchable_client.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <cloud/blockstore/libs/service/context.h>
44
#include <cloud/blockstore/libs/service/service_method.h>
5-
#include <cloud/blockstore/libs/storage/model/volume_label.h>
65

76
#include <cloud/storage/core/libs/common/helpers.h>
87
#include <cloud/storage/core/libs/diagnostics/logging.h>
@@ -44,6 +43,11 @@ class TDeferredRequestsHolder
4443
TVector<TRequestInfo> Requests;
4544

4645
public:
46+
~TDeferredRequestsHolder()
47+
{
48+
Y_DEBUG_ABORT_UNLESS(Requests.empty());
49+
}
50+
4751
TFuture<TResponse> SaveRequest(
4852
TCallContextPtr callContext,
4953
std::shared_ptr<TRequest> request)
@@ -132,9 +136,15 @@ class TSwitchableBlockStore final
132136

133137
void BeforeSwitching() override
134138
{
135-
Y_ABORT_UNLESS(!WillSwitchToSecondary);
136-
STORAGE_INFO("Will switch from " << PrimaryClientInfo.DiskId.Quote());
137-
WillSwitchToSecondary = true;
139+
if (WillSwitchToSecondary) {
140+
return;
141+
}
142+
143+
bool expected = false;
144+
if (WillSwitchToSecondary.compare_exchange_strong(expected, true)) {
145+
STORAGE_INFO(
146+
"Will switch from " << PrimaryClientInfo.DiskId.Quote());
147+
}
138148
}
139149

140150
void Switch(
@@ -277,19 +287,16 @@ class TSwitchableBlockStore final
277287
std::move(request));
278288

279289
return future.Apply(
280-
[sessionSwitcher = SessionSwitcher,
281-
diskId = PrimaryClientInfo.DiskId] //
290+
[weakSelf = weak_from_this()] //
282291
(TFuture<TResponse> future) -> TResponse
283292
{
284293
TResponse response = future.ExtractValue();
285294

286295
if (HasError(response)) {
287296
const auto errorFlags = response.GetError().GetFlags();
288297
if (HasProtoFlag(errorFlags, NProto::EF_OUTDATED_VOLUME)) {
289-
if (auto switcher = sessionSwitcher.lock()) {
290-
switcher->SwitchSession(
291-
diskId,
292-
NStorage::GetNextDiskId(diskId));
298+
if (auto self = weakSelf.lock()) {
299+
self->BeforeSwitching();
293300
}
294301
}
295302
}
@@ -317,11 +324,6 @@ class TSwitchableBlockStore final
317324
if (!HasError(response) &&
318325
response.GetVolume().GetPrincipalDiskId())
319326
{
320-
Y_DEBUG_ABORT_UNLESS(
321-
response.GetVolume().GetPrincipalDiskId() ==
322-
NStorage::GetNextDiskId(
323-
response.GetVolume().GetDiskId()));
324-
325327
if (auto switcher = sessionSwitcher.lock()) {
326328
switcher->SwitchSession(
327329
response.GetVolume().GetDiskId(),

cloud/blockstore/libs/storage/volume/actors/follower_disk_actor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ void TFollowerDiskActor::HandleUpdateFollowerStateResponse(
378378
const auto* msg = ev->Get();
379379
FollowerDiskInfo = msg->Follower;
380380
ApplyLinkState(ctx);
381+
if (State == EState::LeadershipTransferredAndPersisted) {
382+
RebootLeaderVolume(ctx, TDuration());
383+
}
381384
}
382385

383386
void TFollowerDiskActor::HandlePropagateLeadershipToFollowerResponse(

0 commit comments

Comments
 (0)