Skip to content

Commit 8cf6418

Browse files
CyberROFLydbot
authored andcommitted
Keep resource id during configuration change (#32905)
1 parent d13b925 commit 8cf6418

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
@@ -235,7 +235,35 @@ class TReplication::TImpl: public TLagProvider {
235235
Issue = TruncatedIssue(issue);
236236
}
237237

238+
static void KeepResourceId(
239+
const NKikimrReplication::TReplicationConfig& oldConfig,
240+
NKikimrReplication::TReplicationConfig& newConfig)
241+
{
242+
const auto& oldParams = oldConfig.GetSrcConnectionParams();
243+
if (!oldParams.HasIamCredentials()) {
244+
return;
245+
}
246+
247+
const auto& oldIam = oldParams.GetIamCredentials();
248+
if (!oldIam.HasResourceId()) {
249+
return;
250+
}
251+
252+
if (!newConfig.HasSrcConnectionParams()) {
253+
return;
254+
}
255+
256+
auto& newParams = *newConfig.MutableSrcConnectionParams();
257+
if (!newParams.HasIamCredentials()) {
258+
return;
259+
}
260+
261+
auto& newIam = *newParams.MutableIamCredentials();
262+
newIam.SetResourceId(oldIam.GetResourceId());
263+
}
264+
238265
void SetConfig(NKikimrReplication::TReplicationConfig&& config) {
266+
KeepResourceId(Config, config);
239267
Config = config;
240268
}
241269

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
@@ -74,6 +74,7 @@ END()
7474
RECURSE_FOR_TESTS(
7575
ut_assign_tx_id
7676
ut_dst_creator
77+
ut_replication
7778
ut_stream_creator
7879
ut_target_discoverer
7980
)

0 commit comments

Comments
 (0)