From 8ec690566925dac8739a4d940659c387bbd8ef49 Mon Sep 17 00:00:00 2001 From: Ilnaz Nizametdinov Date: Wed, 29 May 2024 18:14:14 +0300 Subject: [PATCH] Create replicated tables with the same owner as the replication itself (#4983) --- .../tx/replication/controller/dst_creator.cpp | 9 +++++++ .../replication/controller/dst_creator_ut.cpp | 27 +++++++++++++++++++ ydb/core/tx/replication/ut_helpers/test_env.h | 5 ++++ 3 files changed, 41 insertions(+) diff --git a/ydb/core/tx/replication/controller/dst_creator.cpp b/ydb/core/tx/replication/controller/dst_creator.cpp index 1e80b079b544..9b3e7b672782 100644 --- a/ydb/core/tx/replication/controller/dst_creator.cpp +++ b/ydb/core/tx/replication/controller/dst_creator.cpp @@ -67,6 +67,10 @@ class TDstCreator: public TActorBootstrapped { return Error(NKikimrScheme::StatusSchemeError, "Empty domain info"); } + if (entry.SecurityObject) { + Owner = entry.SecurityObject->GetOwnerSID(); + } + DomainKey = entry.DomainInfo->DomainKey; Resolve(DomainKey); } else { @@ -212,6 +216,10 @@ class TDstCreator: public TActorBootstrapped { auto ev = MakeHolder(TxId, SchemeShardId); *ev->Record.AddTransaction() = TxBody; + if (Owner) { + ev->Record.SetOwner(Owner); + } + Send(PipeCache, new TEvPipeCache::TEvForward(ev.Release(), SchemeShardId, true)); Become(&TThis::StateCreateDst); } @@ -554,6 +562,7 @@ class TDstCreator: public TActorBootstrapped { TPathId DomainKey; TString Database; + TString Owner; TTableProfiles TableProfiles; ui64 TxId = 0; NKikimrSchemeOp::TModifyScheme TxBody; diff --git a/ydb/core/tx/replication/controller/dst_creator_ut.cpp b/ydb/core/tx/replication/controller/dst_creator_ut.cpp index 8f2ba1a24cc5..c54e59393ac7 100644 --- a/ydb/core/tx/replication/controller/dst_creator_ut.cpp +++ b/ydb/core/tx/replication/controller/dst_creator_ut.cpp @@ -66,6 +66,33 @@ Y_UNIT_TEST_SUITE(DstCreator) { Basic("/Root/Dir/Replicated"); } + Y_UNIT_TEST(SameOwner) { + TEnv env; + env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE); + + env.ModifyOwner("/", "Root", "user@builtin"); + env.CreateTable("/Root", *MakeTableDescription({ + .Name = "Table", + .KeyColumns = {"key"}, + .Columns = { + {.Name = "key", .Type = "Uint32"}, + {.Name = "value", .Type = "Utf8"}, + }, + .ReplicationConfig = Nothing(), + })); + env.GetRuntime().Register(CreateDstCreator( + env.GetSender(), env.GetSchemeshardId("/Root/Table"), env.GetYdbProxy(), env.GetPathId("/Root"), + 1 /* rid */, 1 /* tid */, TReplication::ETargetKind::Table, "/Root/Table", "/Root/Replicated" + )); + + auto ev = env.GetRuntime().GrabEdgeEvent(env.GetSender()); + UNIT_ASSERT_VALUES_EQUAL(ev->Get()->Status, NKikimrScheme::StatusSuccess); + + auto desc = env.GetDescription("/Root/Replicated"); + const auto& replicatedSelf = desc.GetPathDescription().GetSelf(); + UNIT_ASSERT_VALUES_EQUAL(replicatedSelf.GetOwner(), "user@builtin"); + } + Y_UNIT_TEST(NonExistentSrc) { TEnv env; env.GetRuntime().SetLogPriority(NKikimrServices::REPLICATION_CONTROLLER, NLog::PRI_TRACE); diff --git a/ydb/core/tx/replication/ut_helpers/test_env.h b/ydb/core/tx/replication/ut_helpers/test_env.h index e077759aedf8..d315d1626914 100644 --- a/ydb/core/tx/replication/ut_helpers/test_env.h +++ b/ydb/core/tx/replication/ut_helpers/test_env.h @@ -110,6 +110,11 @@ class TEnv { } } + template + auto ModifyOwner(Args&&... args) { + return Client.ModifyOwner(std::forward(args)...); + } + template auto Describe(Args&&... args) { return Client.Ls(std::forward(args)...);