Skip to content

Commit 0466eb5

Browse files
committed
fix NBS shadow disk issue #3097
1 parent a549acc commit 0466eb5

File tree

8 files changed

+402
-18
lines changed

8 files changed

+402
-18
lines changed

cloud/blockstore/libs/diagnostics/critical_events.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace NCloud::NBlockStore {
6565
xxx(ErrorWasSentToTheGuestForNonReliableDisk) \
6666
xxx(MirroredDiskResyncChecksumMismatch) \
6767
xxx(DiskAgentInconsistentMultiWriteResponse) \
68+
xxx(ReleaseShadowDiskError) \
6869
// BLOCKSTORE_CRITICAL_EVENTS
6970

7071
#define BLOCKSTORE_DISK_AGENT_CRITICAL_EVENTS(xxx) \

cloud/blockstore/libs/storage/disk_agent/model/device_client.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ NCloud::NProto::TError TDeviceClient::ReleaseDevices(
257257
STORAGE_INFO("Device %s was released by client %s for writing.",
258258
uuid.Quote().c_str(), clientId.c_str());
259259
deviceState->WriterSession = {};
260+
} else if (clientId == AnyReaderClientId) {
261+
STORAGE_INFO(
262+
"Device %s was released by client %s for reading.",
263+
uuid.Quote().c_str(),
264+
clientId.c_str());
265+
deviceState->ReaderSessions = {};
260266
}
261267
}
262268

cloud/blockstore/libs/storage/disk_agent/model/device_client_ut.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,40 @@ Y_UNIT_TEST_SUITE(TDeviceClientTest)
816816
E_REJECTED,
817817
client.GetDeviceIOErrorCode("uuid2").value());
818818
}
819+
820+
Y_UNIT_TEST_F(TestReleaseDevicesForAnyReader, TFixture)
821+
{
822+
auto client = CreateClient({.Devices = {"uuid1", "uuid2"}});
823+
824+
// acquire devices for reading
825+
auto error = AcquireDevices(
826+
client,
827+
TAcquireParamsBuilder()
828+
.SetUuids({"uuid1", "uuid2"})
829+
.SetClientId("reader")
830+
.SetAccessMode(NProto::VOLUME_ACCESS_READ_ONLY)
831+
.SetDiskId("vol0")
832+
.SetVolumeGeneration(1));
833+
UNIT_ASSERT_VALUES_EQUAL_C(S_OK, error.GetCode(), error.GetMessage());
834+
835+
// check that reading sessions exist
836+
UNIT_ASSERT_UNEQUAL(client.GetReaderSessions("uuid1").size(), 0);
837+
UNIT_ASSERT_UNEQUAL(client.GetReaderSessions("uuid2").size(), 0);
838+
839+
// release should success
840+
error = ReleaseDevices(
841+
client,
842+
TReleaseParamsBuilder()
843+
.SetUuids({"uuid1", "uuid2"})
844+
.SetClientId(TString(AnyReaderClientId))
845+
.SetDiskId("vol0")
846+
.SetVolumeGeneration(1));
847+
UNIT_ASSERT_VALUES_EQUAL_C(S_OK, error.GetCode(), error.GetMessage());
848+
849+
// check that all reading sessions was realesed
850+
UNIT_ASSERT_EQUAL(client.GetReaderSessions("uuid1").size(), 0);
851+
UNIT_ASSERT_EQUAL(client.GetReaderSessions("uuid2").size(), 0);
852+
}
819853
}
820854

821855
} // namespace NCloud::NBlockStore::NStorage

cloud/blockstore/libs/storage/disk_agent/model/public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ constexpr TStringBuf AnyWriterClientId = "any-writer";
2020
constexpr TStringBuf ShadowDiskClientId = "shadow-disk-client";
2121
constexpr TStringBuf CheckRangeClientId = "check-range";
2222
constexpr TStringBuf CopyVolumeClientId = "copy-volume-client";
23+
constexpr TStringBuf AnyReaderClientId = "any-reader";
2324

2425
} // namespace NCloud::NBlockStore::NStorage

cloud/blockstore/libs/storage/volume/model/checkpoint.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ bool TCheckpointStore::NeedShadowActor(const TString& checkpointId) const
209209
// Do not need to create the shadow disk actor if the shadow disk is being
210210
// deleted.
211211
if (const TCheckpointRequest* checkpointRequest =
212-
CheckpointRequests.FindPtr(CheckpointRequestInProgress))
212+
CheckpointRequests.FindPtr(CheckpointRequestInProgress);
213+
checkpointRequest != nullptr &&
214+
checkpointRequest->CheckpointId == checkpointId)
213215
{
214216
if (checkpointRequest->ReqType == ECheckpointRequestType::Delete ||
215217
checkpointRequest->ReqType == ECheckpointRequestType::DeleteData)

0 commit comments

Comments
 (0)