1212#include < ydb/library/yverify_stream/yverify_stream.h>
1313
1414#include < util/generic/hash.h>
15+ #include < util/generic/hash_set.h>
1516#include < util/generic/ptr.h>
1617
1718namespace NKikimr ::NReplication::NController {
@@ -28,10 +29,10 @@ class TReplication::TImpl {
2829 }
2930
3031 template <typename ... Args>
31- ITarget* CreateTarget (ui64 id, ETargetKind kind, Args&&... args) const {
32+ ITarget* CreateTarget (TReplication::TPtr self, ui64 id, ETargetKind kind, Args&&... args) const {
3233 switch (kind) {
3334 case ETargetKind::Table:
34- return new TTableTarget (id, std::forward<Args>(args)...);
35+ return new TTableTarget (self, id, std::forward<Args>(args)...);
3536 }
3637 }
3738
@@ -59,9 +60,9 @@ class TReplication::TImpl {
5960 }
6061 }
6162
62- void ProgressTargets (TReplication::TPtr self, const TActorContext& ctx) {
63+ void ProgressTargets (const TActorContext& ctx) {
6364 for (auto & [_, target] : Targets) {
64- target->Progress (self, ctx);
65+ target->Progress (ctx);
6566 }
6667 }
6768
@@ -75,15 +76,15 @@ class TReplication::TImpl {
7576 }
7677
7778 template <typename ... Args>
78- ui64 AddTarget (ui64 id, ETargetKind kind, Args&&... args) {
79- const auto res = Targets.emplace (id, CreateTarget (id, kind, std::forward<Args>(args)...));
79+ ui64 AddTarget (TReplication::TPtr self, ui64 id, ETargetKind kind, Args&&... args) {
80+ const auto res = Targets.emplace (id, CreateTarget (self, id, kind, std::forward<Args>(args)...));
8081 Y_VERIFY_S (res.second , " Duplicate target: " << id);
8182 return id;
8283 }
8384
8485 template <typename ... Args>
85- ui64 AddTarget (ETargetKind kind, Args&&... args) {
86- return AddTarget (NextTargetId++, kind, std::forward<Args>(args)...);
86+ ui64 AddTarget (TReplication::TPtr self, ETargetKind kind, Args&&... args) {
87+ return AddTarget (self, NextTargetId++, kind, std::forward<Args>(args)...);
8788 }
8889
8990 ITarget* FindTarget (ui64 id) {
@@ -97,7 +98,7 @@ class TReplication::TImpl {
9798 Targets.erase (id);
9899 }
99100
100- void Progress (TReplication::TPtr self, const TActorContext& ctx) {
101+ void Progress (const TActorContext& ctx) {
101102 if (!YdbProxy) {
102103 THolder<IActor> ydbProxy;
103104 const auto & params = Config.GetSrcConnectionParams ();
@@ -136,14 +137,15 @@ class TReplication::TImpl {
136137 if (!Targets) {
137138 return DiscoverTargets (ctx);
138139 } else {
139- return ProgressTargets (self, ctx);
140+ return ProgressTargets (ctx);
140141 }
141142 case EState::Removing:
142143 if (!Targets) {
143144 return (void )ctx.Send (ctx.SelfID , new TEvPrivate::TEvDropReplication (ReplicationId));
144145 } else {
145- return ProgressTargets (self, ctx);
146+ return ProgressTargets (ctx);
146147 }
148+ case EState::Done:
147149 case EState::Error:
148150 return ;
149151 }
@@ -180,6 +182,7 @@ class TReplication::TImpl {
180182 TString Issue;
181183 ui64 NextTargetId = 1 ;
182184 THashMap<ui64, THolder<ITarget>> Targets;
185+ THashSet<ui64> PendingAlterTargets;
183186 TActorId SecretResolver;
184187 TActorId YdbProxy;
185188 TActorId TenantResolver;
@@ -209,11 +212,11 @@ TReplication::TReplication(ui64 id, const TPathId& pathId, const TString& config
209212}
210213
211214ui64 TReplication::AddTarget (ETargetKind kind, const TString& srcPath, const TString& dstPath) {
212- return Impl->AddTarget (kind, srcPath, dstPath);
215+ return Impl->AddTarget (this , kind, srcPath, dstPath);
213216}
214217
215218TReplication::ITarget* TReplication::AddTarget (ui64 id, ETargetKind kind, const TString& srcPath, const TString& dstPath) {
216- Impl->AddTarget (id, kind, srcPath, dstPath);
219+ Impl->AddTarget (this , id, kind, srcPath, dstPath);
217220 return Impl->FindTarget (id);
218221}
219222
@@ -230,7 +233,7 @@ void TReplication::RemoveTarget(ui64 id) {
230233}
231234
232235void TReplication::Progress (const TActorContext& ctx) {
233- Impl->Progress (this , ctx);
236+ Impl->Progress (ctx);
234237}
235238
236239void TReplication::Shutdown (const TActorContext& ctx) {
@@ -308,6 +311,18 @@ const std::optional<TReplication::TDropOp>& TReplication::GetDropOp() const {
308311 return DropOp;
309312}
310313
314+ void TReplication::AddPendingAlterTarget (ui64 id) {
315+ Impl->PendingAlterTargets .insert (id);
316+ }
317+
318+ void TReplication::RemovePendingAlterTarget (ui64 id) {
319+ Impl->PendingAlterTargets .erase (id);
320+ }
321+
322+ bool TReplication::CheckAlterDone () const {
323+ return Impl->State == EState::Ready && Impl->PendingAlterTargets .empty ();
324+ }
325+
311326}
312327
313328Y_DECLARE_OUT_SPEC (, NKikimrReplication::TReplicationConfig::TargetCase, stream, value) {
0 commit comments