Skip to content

Commit 93cceb9

Browse files
authored
Keep resource id during configuration change (#32905)
1 parent 5d199f4 commit 93cceb9

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

ydb/core/tx/replication/controller/replication.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,35 @@ class TReplication::TImpl: public TLagProvider {
245245
Issue = TruncatedIssue(issue);
246246
}
247247

248+
static void KeepResourceId(
249+
const NKikimrReplication::TReplicationConfig& oldConfig,
250+
NKikimrReplication::TReplicationConfig& newConfig)
251+
{
252+
const auto& oldParams = oldConfig.GetSrcConnectionParams();
253+
if (!oldParams.HasIamCredentials()) {
254+
return;
255+
}
256+
257+
const auto& oldIam = oldParams.GetIamCredentials();
258+
if (!oldIam.HasResourceId()) {
259+
return;
260+
}
261+
262+
if (!newConfig.HasSrcConnectionParams()) {
263+
return;
264+
}
265+
266+
auto& newParams = *newConfig.MutableSrcConnectionParams();
267+
if (!newParams.HasIamCredentials()) {
268+
return;
269+
}
270+
271+
auto& newIam = *newParams.MutableIamCredentials();
272+
newIam.SetResourceId(oldIam.GetResourceId());
273+
}
274+
248275
void SetConfig(NKikimrReplication::TReplicationConfig&& config) {
276+
KeepResourceId(Config, config);
249277
Config = config;
250278
}
251279

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "replication.h"
2+
3+
#include <ydb/core/protos/replication.pb.h>
4+
5+
#include <library/cpp/testing/unittest/registar.h>
6+
7+
namespace NKikimr::NReplication::NController {
8+
9+
Y_UNIT_TEST_SUITE(Replication) {
10+
Y_UNIT_TEST(ResourceId) {
11+
const ui64 id = 1;
12+
const auto pathId = TPathId(1, 2);
13+
const auto resourceId = "resource-id";
14+
NKikimrReplication::TReplicationConfig config;
15+
16+
// init with resource id
17+
config.MutableSrcConnectionParams()->MutableIamCredentials()->SetResourceId(resourceId);
18+
auto replication = MakeIntrusive<TReplication>(id, pathId, std::move(config), "/Root/db");
19+
UNIT_ASSERT_VALUES_EQUAL(replication->GetConfig().GetSrcConnectionParams().GetIamCredentials().GetResourceId(), resourceId);
20+
21+
// try to change resource id
22+
config.MutableSrcConnectionParams()->MutableIamCredentials()->SetResourceId("");
23+
replication->SetConfig(std::move(config));
24+
UNIT_ASSERT_VALUES_EQUAL(replication->GetConfig().GetSrcConnectionParams().GetIamCredentials().GetResourceId(), resourceId);
25+
26+
// clear iam credentials
27+
config.MutableSrcConnectionParams()->ClearIamCredentials();
28+
replication->SetConfig(std::move(config));
29+
UNIT_ASSERT_VALUES_EQUAL(replication->GetConfig().GetSrcConnectionParams().GetIamCredentials().GetResourceId(), "");
30+
31+
// set resource id back
32+
config.MutableSrcConnectionParams()->MutableIamCredentials()->SetResourceId(resourceId);
33+
replication->SetConfig(std::move(config));
34+
UNIT_ASSERT_VALUES_EQUAL(replication->GetConfig().GetSrcConnectionParams().GetIamCredentials().GetResourceId(), resourceId);
35+
36+
// clear entire connection params
37+
config.ClearSrcConnectionParams();
38+
replication->SetConfig(std::move(config));
39+
UNIT_ASSERT_VALUES_EQUAL(replication->GetConfig().GetSrcConnectionParams().GetIamCredentials().GetResourceId(), "");
40+
}
41+
}
42+
43+
}

ydb/core/tx/replication/controller/tx_alter_replication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TController::TTxAlterReplication: public TTxBase {
4040
bool alter = false;
4141

4242
const auto& oldConfig = Replication->GetConfig();
43-
const auto& newConfig = record.GetConfig();
43+
auto newConfig = std::move(*record.MutableConfig());
4444

4545
if (oldConfig.HasTransferSpecific()) {
4646
auto& oldSpecific = oldConfig.GetTransferSpecific();
@@ -87,12 +87,12 @@ class TController::TTxAlterReplication: public TTxBase {
8787
}
8888
}
8989

90-
Replication->SetConfig(std::move(*record.MutableConfig()));
90+
Replication->SetConfig(std::move(newConfig));
9191
Replication->ResetCredentials(ctx);
9292

9393
NIceDb::TNiceDb db(txc.DB);
9494
db.Table<Schema::Replications>().Key(Replication->GetId()).Update(
95-
NIceDb::TUpdate<Schema::Replications::Config>(record.GetConfig().SerializeAsString()),
95+
NIceDb::TUpdate<Schema::Replications::Config>(Replication->GetConfig().SerializeAsString()),
9696
NIceDb::TUpdate<Schema::Replications::DesiredState>(desiredState),
9797
NIceDb::TUpdate<Schema::Replications::Issue>(issue)
9898
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
UNITTEST_FOR(ydb/core/tx/replication/controller)
2+
3+
FORK_SUBTESTS()
4+
5+
SIZE(SMALL)
6+
7+
TIMEOUT(60)
8+
9+
PEERDIR(
10+
ydb/core/protos
11+
ydb/core/testlib/pg
12+
library/cpp/testing/unittest
13+
)
14+
15+
SRCS(
16+
replication_ut.cpp
17+
)
18+
19+
YQL_LAST_ABI_VERSION()
20+
21+
END()

ydb/core/tx/replication/controller/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ END()
7575
RECURSE_FOR_TESTS(
7676
ut_assign_tx_id
7777
ut_dst_creator
78+
ut_replication
7879
ut_stream_creator
7980
ut_target_discoverer
8081
)

0 commit comments

Comments
 (0)