|
2 | 2 |
|
3 | 3 | #include <cloud/blockstore/libs/service/context.h> |
4 | 4 | #include <cloud/blockstore/libs/service/service_method.h> |
5 | | -#include <cloud/blockstore/libs/storage/model/volume_label.h> |
6 | 5 |
|
7 | 6 | #include <cloud/storage/core/libs/common/helpers.h> |
8 | 7 | #include <cloud/storage/core/libs/diagnostics/logging.h> |
@@ -44,6 +43,11 @@ class TDeferredRequestsHolder |
44 | 43 | TVector<TRequestInfo> Requests; |
45 | 44 |
|
46 | 45 | public: |
| 46 | + ~TDeferredRequestsHolder() |
| 47 | + { |
| 48 | + Y_DEBUG_ABORT_UNLESS(Requests.empty()); |
| 49 | + } |
| 50 | + |
47 | 51 | TFuture<TResponse> SaveRequest( |
48 | 52 | TCallContextPtr callContext, |
49 | 53 | std::shared_ptr<TRequest> request) |
@@ -132,9 +136,15 @@ class TSwitchableBlockStore final |
132 | 136 |
|
133 | 137 | void BeforeSwitching() override |
134 | 138 | { |
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 | + } |
138 | 148 | } |
139 | 149 |
|
140 | 150 | void Switch( |
@@ -277,19 +287,16 @@ class TSwitchableBlockStore final |
277 | 287 | std::move(request)); |
278 | 288 |
|
279 | 289 | return future.Apply( |
280 | | - [sessionSwitcher = SessionSwitcher, |
281 | | - diskId = PrimaryClientInfo.DiskId] // |
| 290 | + [weakSelf = weak_from_this()] // |
282 | 291 | (TFuture<TResponse> future) -> TResponse |
283 | 292 | { |
284 | 293 | TResponse response = future.ExtractValue(); |
285 | 294 |
|
286 | 295 | if (HasError(response)) { |
287 | 296 | const auto errorFlags = response.GetError().GetFlags(); |
288 | 297 | 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(); |
293 | 300 | } |
294 | 301 | } |
295 | 302 | } |
@@ -317,11 +324,6 @@ class TSwitchableBlockStore final |
317 | 324 | if (!HasError(response) && |
318 | 325 | response.GetVolume().GetPrincipalDiskId()) |
319 | 326 | { |
320 | | - Y_DEBUG_ABORT_UNLESS( |
321 | | - response.GetVolume().GetPrincipalDiskId() == |
322 | | - NStorage::GetNextDiskId( |
323 | | - response.GetVolume().GetDiskId())); |
324 | | - |
325 | 327 | if (auto switcher = sessionSwitcher.lock()) { |
326 | 328 | switcher->SwitchSession( |
327 | 329 | response.GetVolume().GetDiskId(), |
|
0 commit comments