diff options
| author | Kirill Vasilenko <[email protected]> | 2026-07-10 17:36:21 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-10 17:36:21 +0300 |
| commit | da52e426ab330c925a88c3b26659e685447f0afa (patch) | |
| tree | 095723195f0903de6fa81e83acc8d80bf7eeecc7 | |
| parent | 7df011cf6d13a5e4a465aff4f7bea1009f87edbd (diff) | |
fix null reference in SnapshotRegistry (#46123)
Co-authored-by: Kirill Vasilenko <[email protected]>
5 files changed, 52 insertions, 3 deletions
diff --git a/ydb/core/tx/columnshard/scan_snapshot_guard.cpp b/ydb/core/tx/columnshard/scan_snapshot_guard.cpp index 461032766fd..a1383fb27d7 100644 --- a/ydb/core/tx/columnshard/scan_snapshot_guard.cpp +++ b/ydb/core/tx/columnshard/scan_snapshot_guard.cpp @@ -166,9 +166,10 @@ std::unique_ptr<IScanSnapshotGuard> CreateScanSnapshotGuard(ui64 passedStep, ui6 } if (const auto holder = AppDataVerified().SnapshotRegistryHolder) { - if (const auto registry = holder->Get()) { + auto registry = holder->Get(); + if (registry.get()) { return CreateRegistryScanSnapshotGuard( - passedStep, schemeShardId, lastCleanupSnapshot, pathIdTranslator, registry, AppDataVerified().LongTxServiceConfig); + passedStep, schemeShardId, lastCleanupSnapshot, pathIdTranslator, std::move(registry), AppDataVerified().LongTxServiceConfig); } } diff --git a/ydb/core/tx/long_tx_service/public/snapshot_registry.cpp b/ydb/core/tx/long_tx_service/public/snapshot_registry.cpp index 1640353c92f..97cdfeb2c43 100644 --- a/ydb/core/tx/long_tx_service/public/snapshot_registry.cpp +++ b/ydb/core/tx/long_tx_service/public/snapshot_registry.cpp @@ -90,7 +90,10 @@ namespace { } void Set(std::unique_ptr<IImmutableSnapshotRegistry>&& registry) override { - TTrueAtomicSharedPtr<IImmutableSnapshotRegistry> newRegistry(registry.release()); + TTrueAtomicSharedPtr<IImmutableSnapshotRegistry> newRegistry; + if (registry) { + newRegistry = TTrueAtomicSharedPtr<IImmutableSnapshotRegistry>(registry.release()); + } Registry.swap(newRegistry); } private: diff --git a/ydb/core/tx/long_tx_service/public/ut/snapshot_registry_ut.cpp b/ydb/core/tx/long_tx_service/public/ut/snapshot_registry_ut.cpp new file mode 100644 index 00000000000..e4927bb6c28 --- /dev/null +++ b/ydb/core/tx/long_tx_service/public/ut/snapshot_registry_ut.cpp @@ -0,0 +1,43 @@ +#include <ydb/core/tx/long_tx_service/public/snapshot_registry.h> + +#include <library/cpp/testing/unittest/registar.h> + +namespace NKikimr { + +Y_UNIT_TEST_SUITE(TImmutableSnapshotRegistryHolderTest) { + std::unique_ptr<IImmutableSnapshotRegistry> BuildRegistry() { + auto builder = CreateImmutableSnapshotRegistryBuilder(); + builder->SetSnapshotBorder(TRowVersion(100, 0)); + builder->SetOldestCollectionTime(TInstant::MilliSeconds(50)); + return std::move(*builder).Build(); + } + + Y_UNIT_TEST(EmptyByDefault) { + auto holder = CreateImmutableSnapshotRegistryHolder(); + const auto& registry = holder->Get(); + UNIT_ASSERT(!registry); + UNIT_ASSERT(registry.get() == nullptr); + } + + Y_UNIT_TEST(SetAndGet) { + auto holder = CreateImmutableSnapshotRegistryHolder(); + holder->Set(BuildRegistry()); + const auto& registry = holder->Get(); + UNIT_ASSERT(registry); + UNIT_ASSERT(registry.get() != nullptr); + UNIT_ASSERT_VALUES_EQUAL(registry->GetBorder(), TRowVersion(100, 0)); + } + + Y_UNIT_TEST(SetNullClearsRegistry) { + auto holder = CreateImmutableSnapshotRegistryHolder(); + holder->Set(BuildRegistry()); + UNIT_ASSERT(holder->Get()); + + holder->Set(nullptr); + const auto& registry = holder->Get(); + UNIT_ASSERT(!registry); + UNIT_ASSERT(registry.get() == nullptr); + } +} + +} // namespace NKikimr diff --git a/ydb/core/tx/long_tx_service/public/ut/ya.make b/ydb/core/tx/long_tx_service/public/ut/ya.make index e14b1dec683..02cc6bb8f1f 100644 --- a/ydb/core/tx/long_tx_service/public/ut/ya.make +++ b/ydb/core/tx/long_tx_service/public/ut/ya.make @@ -1,6 +1,7 @@ UNITTEST_FOR(ydb/core/tx/long_tx_service/public) SRCS( + snapshot_registry_ut.cpp types_ut.cpp ) diff --git a/ydb/core/tx/long_tx_service/public/ya.make b/ydb/core/tx/long_tx_service/public/ya.make index dba07d5ccac..1602fbae88b 100644 --- a/ydb/core/tx/long_tx_service/public/ya.make +++ b/ydb/core/tx/long_tx_service/public/ya.make @@ -14,6 +14,7 @@ PEERDIR( library/cpp/uri ydb/core/base ydb/core/protos + ydb/core/scheme ydb/core/util yql/essentials/public/issue ) |
