diff options
author | serg-belyakov <serg-belyakov@yandex-team.com> | 2023-08-23 14:12:27 +0300 |
---|---|---|
committer | serg-belyakov <serg-belyakov@yandex-team.com> | 2023-08-23 14:37:52 +0300 |
commit | 276ba4f2a303225398cd3bd2a7e7091a231bd520 (patch) | |
tree | 89fdfab3ca511572b4231f6fa35674e73208e93b | |
parent | b535c1811522075554ead9d18ae9f6497bd06b12 (diff) | |
download | ydb-276ba4f2a303225398cd3bd2a7e7091a231bd520.tar.gz |
Add CanConnectTo list for more intuitive IC compatibility settings, KIKIMR-15989
Add CanConnectTo list for more intuitive IC compatibility settings
Intermediate
-rw-r--r-- | ydb/core/actorlib_impl/test_interconnect_ut.cpp | 4 | ||||
-rw-r--r-- | ydb/core/driver_lib/version/ut/version_ut.cpp | 60 | ||||
-rw-r--r-- | ydb/core/driver_lib/version/version.cpp | 131 | ||||
-rw-r--r-- | ydb/core/driver_lib/version/version.h | 4 | ||||
-rw-r--r-- | ydb/core/protos/config.proto | 1 |
5 files changed, 113 insertions, 87 deletions
diff --git a/ydb/core/actorlib_impl/test_interconnect_ut.cpp b/ydb/core/actorlib_impl/test_interconnect_ut.cpp index 8d0bad32bd..29d4ba26f5 100644 --- a/ydb/core/actorlib_impl/test_interconnect_ut.cpp +++ b/ydb/core/actorlib_impl/test_interconnect_ut.cpp @@ -765,7 +765,7 @@ Y_UNIT_TEST_SUITE(TInterconnectTest) { version->SetHotfix(0); { - auto* nbsRule = node1->AddCanLoadFrom(); + auto* nbsRule = node1->AddCanConnectTo(); nbsRule->SetApplication("nbs"); nbsRule->SetComponentId((ui32)NKikimrConfig::TCompatibilityRule::Interconnect); @@ -795,7 +795,7 @@ Y_UNIT_TEST_SUITE(TInterconnectTest) { version->SetHotfix(0); { - auto* rule = node0->AddCanLoadFrom(); + auto* rule = node0->AddCanConnectTo(); rule->SetComponentId((ui32)NKikimrConfig::TCompatibilityRule::Interconnect); auto* lowerLimit = rule->MutableLowerLimit(); diff --git a/ydb/core/driver_lib/version/ut/version_ut.cpp b/ydb/core/driver_lib/version/ut/version_ut.cpp index 8dbeecbf56..4b013f56a9 100644 --- a/ydb/core/driver_lib/version/ut/version_ut.cpp +++ b/ydb/core/driver_lib/version/ut/version_ut.cpp @@ -377,15 +377,17 @@ Y_UNIT_TEST_SUITE(YdbVersion) { TCurrentCompatibilityInfo{ .Application = "ydb", .Version = TVersion{ .Year = 1, .Major = 3, .Minor = 3, .Hotfix = 1 }, - .StoresReadableBy = { + .CanConnectTo = { TCompatibilityRule{ .Application = "nbs", .LowerLimit = TVersion{ .Year = 1, .Major = 1 }, - .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 3, .Hotfix = 1 } + .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 3, .Hotfix = 1 }, + .ComponentId = EComponentId::Interconnect, } } }, - true + true, + EComponentId::Interconnect ); } Y_UNIT_TEST(OldNbsIncompatibleStored) { @@ -397,15 +399,17 @@ Y_UNIT_TEST_SUITE(YdbVersion) { TCurrentCompatibilityInfo{ .Application = "ydb", .Version = TVersion{ .Year = 1, .Major = 3, .Minor = 3, .Hotfix = 1 }, - .StoresReadableBy = { + .CanConnectTo = { TCompatibilityRule{ .Application = "nbs", .LowerLimit = TVersion{ .Year = 1, .Major = 1 }, - .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 3, .Hotfix = 1 } + .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 3, .Hotfix = 1 }, + .ComponentId = EComponentId::Interconnect, } } }, - false + false, + EComponentId::Interconnect ); } Y_UNIT_TEST(NewNbsCurrent) { @@ -413,11 +417,12 @@ Y_UNIT_TEST_SUITE(YdbVersion) { TCurrentCompatibilityInfo{ .Application = "nbs", .Version = TVersion{ .Year = 1, .Major = 3, .Minor = 2, .Hotfix = 0 }, - .CanLoadFrom = { + .CanConnectTo = { TCompatibilityRule{ .Application = "ydb", .LowerLimit = TVersion{ .Year = 1, .Major = 1 }, - .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 2, .Hotfix = 0 } + .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 2, .Hotfix = 0 }, + .ComponentId = EComponentId::Interconnect, } } }, @@ -425,7 +430,8 @@ Y_UNIT_TEST_SUITE(YdbVersion) { .Application = "ydb", .Version = TVersion{ .Year = 1, .Major = 1, .Minor = 3, .Hotfix = 2 }, }, - true + true, + EComponentId::Interconnect ); } Y_UNIT_TEST(NewNbsIncompatibleCurrent) { @@ -433,11 +439,12 @@ Y_UNIT_TEST_SUITE(YdbVersion) { TCurrentCompatibilityInfo{ .Application = "nbs", .Version = TVersion{ .Year = 1, .Major = 3, .Minor = 2, .Hotfix = 0 }, - .CanLoadFrom = { + .CanConnectTo = { TCompatibilityRule{ .Application = "ydb", .LowerLimit = TVersion{ .Year = 1, .Major = 1 }, - .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 2, .Hotfix = 0 } + .UpperLimit = TVersion{ .Year = 1, .Major = 3, .Minor = 2, .Hotfix = 0 }, + .ComponentId = EComponentId::Interconnect, } } }, @@ -606,15 +613,7 @@ Y_UNIT_TEST_SUITE(YdbVersion) { TCurrentCompatibilityInfo{ .Application = "ydb", .Version = TVersion{ .Year = 24, .Major = 2, .Minor = 3, .Hotfix = 0 }, - .CanLoadFrom = { - TCompatibilityRule{ - .Application = "nbs", - .LowerLimit = TVersion{ .Year = 23, .Major = 3 }, - .UpperLimit = TVersion{ .Year = 24, .Major = 2 }, - .ComponentId = EComponentId::Interconnect, - }, - }, - .StoresReadableBy = { + .CanConnectTo = { TCompatibilityRule{ .Application = "nbs", .LowerLimit = TVersion{ .Year = 23, .Major = 3 }, @@ -729,6 +728,18 @@ Y_UNIT_TEST_SUITE(OldFormat) { .LowerLimit = TVersion{ .Year = 22, .Major = 5 }, .UpperLimit = TVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 }, }, + }, + .StoresReadableBy = { + TCompatibilityRule{ + .LowerLimit = TVersion{ .Year = 22, .Major = 5 }, + .UpperLimit = TVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 }, + }, + }, + .CanConnectTo = { + TCompatibilityRule{ + .LowerLimit = TVersion{ .Year = 22, .Major = 5 }, + .UpperLimit = TVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 }, + }, } }, TOldFormat{ @@ -785,14 +796,7 @@ Y_UNIT_TEST_SUITE(OldFormat) { TCurrentCompatibilityInfo{ .Application = "ydb", .Version = TVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 }, - .CanLoadFrom = { - TCompatibilityRule{ - .LowerLimit = TVersion{ .Year = 22, .Major = 4 }, - .UpperLimit = TVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 }, - .ComponentId = (ui32)EComponentId::Interconnect - }, - }, - .StoresReadableBy = { + .CanConnectTo = { TCompatibilityRule{ .LowerLimit = TVersion{ .Year = 22, .Major = 4 }, .UpperLimit = TVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 }, diff --git a/ydb/core/driver_lib/version/version.cpp b/ydb/core/driver_lib/version/version.cpp index 31d39326ff..a1acbb8467 100644 --- a/ydb/core/driver_lib/version/version.cpp +++ b/ydb/core/driver_lib/version/version.cpp @@ -110,6 +110,14 @@ TString PrintStoredAndCurrent(const TOldFormat& peer, const TCurrent* current) { return str.Str(); } +bool CheckComponentId(const NKikimrConfig::TCompatibilityRule& rule, TComponentId componentId) { + if (!rule.HasComponentId()) { + return true; + } + const auto ruleComponentId = TComponentId(rule.GetComponentId()); + return ruleComponentId == EComponentId::Any || ruleComponentId == componentId; +} + TStored TCompatibilityInfo::MakeStored(TComponentId componentId, const TCurrent* current) const { Y_VERIFY(current); @@ -119,17 +127,24 @@ TStored TCompatibilityInfo::MakeStored(TComponentId componentId, const TCurrent* stored.MutableVersion()->CopyFrom(current->GetVersion()); } - for (const auto& rule : current->GetStoresReadableBy()) { - const auto ruleComponentId = TComponentId(rule.GetComponentId()); - if (!rule.HasComponentId() || ruleComponentId == componentId || ruleComponentId == EComponentId::Any) { - auto *newRule = stored.AddReadableBy(); - if (rule.HasApplication()) { - newRule->SetApplication(rule.GetApplication()); + auto copyFromList = [&](const auto& current, auto& stored) { + for (const auto& rule : current) { + if (CheckComponentId(rule, componentId)) { + auto *newRule = stored.AddReadableBy(); + if (rule.HasApplication()) { + newRule->SetApplication(rule.GetApplication()); + } + newRule->MutableUpperLimit()->CopyFrom(rule.GetUpperLimit()); + newRule->MutableLowerLimit()->CopyFrom(rule.GetLowerLimit()); + newRule->SetForbidden(rule.GetForbidden()); } - newRule->MutableUpperLimit()->CopyFrom(rule.GetUpperLimit()); - newRule->MutableLowerLimit()->CopyFrom(rule.GetLowerLimit()); - newRule->SetForbidden(rule.GetForbidden()); } + }; + + if (componentId == EComponentId::Interconnect) { + copyFromList(current->GetCanConnectTo(), stored); + } else { + copyFromList(current->GetStoresReadableBy(), stored); } return stored; } @@ -278,32 +293,34 @@ bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TStor bool permitted = false; - for (const auto& rule : current->GetCanLoadFrom()) { - const auto ruleComponentId = TComponentId(rule.GetComponentId()); - if (!rule.HasComponentId() || ruleComponentId == componentId || ruleComponentId == EComponentId::Any) { - if (CheckRule(storedApplication, storedVersion, rule)) { - if (rule.HasForbidden() && rule.GetForbidden()) { - errorReason = "Stored version is explicitly prohibited, " + PrintStoredAndCurrent(stored, current); - return false; - } else { - permitted = true; + auto checkRuleList = [&](const auto& rules, const TString& application, const NKikimrConfig::TYdbVersion* version, const TString& errorPrefix) { + for (const auto& rule : rules) { + if (CheckComponentId(rule, componentId)) { + if (CheckRule(application, version, rule)) { + if (rule.HasForbidden() && rule.GetForbidden()) { + errorReason = errorPrefix + PrintStoredAndCurrent(stored, current); + return false; + } else { + permitted = true; + } } } } + return true; + }; + + if (componentId == EComponentId::Interconnect) { + if (!checkRuleList(current->GetCanConnectTo(), storedApplication, storedVersion, "Peer version is explicitly prohibited, ")) { + return false; + } + } else { + if (!checkRuleList(current->GetCanLoadFrom(), storedApplication, storedVersion, "Stored version is explicitly prohibited, ")) { + return false; + } } - for (const auto& rule : stored->GetReadableBy()) { - const auto ruleComponentId = TComponentId(rule.GetComponentId()); - if (!rule.HasComponentId() || ruleComponentId == componentId || ruleComponentId == EComponentId::Any) { - if (CheckRule(currentApplication, currentVersion, rule)) { - if (rule.HasForbidden() && rule.GetForbidden()) { - errorReason = "Current version is explicitly prohibited, " + PrintStoredAndCurrent(stored, current); - return false; - } else { - permitted = true; - } - } - } + if (!checkRuleList(stored->GetReadableBy(), currentApplication, currentVersion, "Current version is explicitly prohibited, ")) { + return false; } if (permitted) { @@ -538,29 +555,29 @@ void CheckVersionTag() { } } -bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TOldFormat& stored, TComponentId componentId, TString& errorReason) const { +bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TOldFormat& peer, TComponentId componentId, TString& errorReason) const { // stored version is peer version in terms of Interconnect Y_VERIFY(current); + Y_VERIFY(componentId == EComponentId::Interconnect); // old version control is only implemented in IC - std::optional<TString> storedApplication; + std::optional<TString> peerApplication; - auto storedVersion = ParseVersionFromTag(stored.Tag); - if (!storedVersion) { - // non-stable version is stored - if (current->GetApplication() == stored.Tag) { + auto peerVersion = ParseVersionFromTag(peer.Tag); + if (!peerVersion) { + // non-stable version is peer + if (current->GetApplication() == peer.Tag) { return true; } - storedApplication = stored.Tag; + peerApplication = peer.Tag; } bool permitted = false; - for (const auto& rule : current->GetCanLoadFrom()) { - const auto ruleComponentId = TComponentId(rule.GetComponentId()); - if (!rule.HasComponentId() || ruleComponentId == componentId || ruleComponentId == EComponentId::Any) { - if (CheckRule(storedApplication, &*storedVersion, rule)) { + for (const auto& rule : current->GetCanConnectTo()) { + if (CheckComponentId(rule, componentId)) { + if (CheckRule(peerApplication, &*peerVersion, rule)) { if (rule.HasForbidden() && rule.GetForbidden()) { - errorReason = "Stored version is explicitly prohibited, " + PrintStoredAndCurrent(stored, current); + errorReason = "Peer version is explicitly prohibited, " + PrintStoredAndCurrent(peer, current); return false; } else { permitted = true; @@ -573,7 +590,7 @@ bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TOldF return true; } - for (const auto& tag : stored.AcceptedTags) { + for (const auto& tag : peer.AcceptedTags) { auto version = ParseVersionFromTag(tag); if (version && current->HasVersion()) { if (CompareVersions(*version, current->GetVersion()) == 0) { @@ -587,47 +604,47 @@ bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TOldF } // use common rule - if (current->HasVersion() && storedVersion) { + if (current->HasVersion() && peerVersion) { const auto& currentVersion = current->GetVersion(); - if (!currentVersion.HasYear() || !storedVersion->HasYear()) { + if (!currentVersion.HasYear() || !peerVersion->HasYear()) { return true; } - if (currentVersion.GetYear() != storedVersion->GetYear()) { + if (currentVersion.GetYear() != peerVersion->GetYear()) { errorReason = "Incompatible by common rule: peer's and current's Year differ, " - + PrintStoredAndCurrent(stored, current); + + PrintStoredAndCurrent(peer, current); return false; } - if (!currentVersion.HasMajor() || !storedVersion->HasMajor()) { + if (!currentVersion.HasMajor() || !peerVersion->HasMajor()) { return true; } - if (std::abs((i32)currentVersion.GetMajor() - (i32)storedVersion->GetMajor()) <= 1) { + if (std::abs((i32)currentVersion.GetMajor() - (i32)peerVersion->GetMajor()) <= 1) { return true; } else { errorReason = "Incompatible by common rule: peer's and current's Major differ by more than 1, " - + PrintStoredAndCurrent(stored, current); + + PrintStoredAndCurrent(peer, current); return false; } - } else if (!current->HasVersion() && !storedVersion) { - if (*storedApplication == current->GetApplication()) { + } else if (!current->HasVersion() && !peerVersion) { + if (*peerApplication == current->GetApplication()) { return true; } else { errorReason = "Incompatible by common rule: both versions are non-stable, peer's and current's Build differ, " - + PrintStoredAndCurrent(stored, current); + + PrintStoredAndCurrent(peer, current); return false; } } else { errorReason = "Incompatible by common rule: one tag is stable and other is non-stable, " - + PrintStoredAndCurrent(stored, current); + + PrintStoredAndCurrent(peer, current); return false; } errorReason = "Peer version tag doesn't match any current compatibility rule, current version is not in accepted tags list, " - + PrintStoredAndCurrent(stored, current); + + PrintStoredAndCurrent(peer, current); return false; } -bool TCompatibilityInfo::CheckCompatibility(const TOldFormat& stored, TComponentId componentId, TString& errorReason) const { - return CheckCompatibility(GetCurrent(), stored, componentId, errorReason); +bool TCompatibilityInfo::CheckCompatibility(const TOldFormat& peer, TComponentId componentId, TString& errorReason) const { + return CheckCompatibility(GetCurrent(), peer, componentId, errorReason); } } diff --git a/ydb/core/driver_lib/version/version.h b/ydb/core/driver_lib/version/version.h index 49cde05dcf..ea2d43d678 100644 --- a/ydb/core/driver_lib/version/version.h +++ b/ydb/core/driver_lib/version/version.h @@ -75,6 +75,7 @@ public: std::optional<TVersion> Version; std::vector<TCompatibilityRule> CanLoadFrom; std::vector<TCompatibilityRule> StoresReadableBy; + std::vector<TCompatibilityRule> CanConnectTo; NKikimrConfig::TCurrentCompatibilityInfo ToPB() { NKikimrConfig::TCurrentCompatibilityInfo res; @@ -90,6 +91,9 @@ public: for (auto storesReadableBy : StoresReadableBy) { res.AddStoresReadableBy()->CopyFrom(storesReadableBy.ToPB()); } + for (auto canConnectTo : CanConnectTo) { + res.AddCanConnectTo()->CopyFrom(canConnectTo.ToPB()); + } return res; } diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index a00afc3861..c06cb45f37 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -2046,6 +2046,7 @@ message TCurrentCompatibilityInfo { repeated TCompatibilityRule CanLoadFrom = 3; repeated TCompatibilityRule StoresReadableBy = 4; + repeated TCompatibilityRule CanConnectTo = 5; } message TStoredCompatibilityInfo { |