diff options
author | serg-belyakov <serg-belyakov@yandex-team.com> | 2023-07-27 16:39:19 +0300 |
---|---|---|
committer | serg-belyakov <serg-belyakov@yandex-team.com> | 2023-07-27 16:39:19 +0300 |
commit | de9b9c06b0ce47ad95f436a6b4a0e9e6692452a0 (patch) | |
tree | ed4b64328b90849d49b0c6be0892a9181bd036a6 | |
parent | 167afc90e4aca5fd228c06378da864f5ef4742c8 (diff) | |
download | ydb-de9b9c06b0ce47ad95f436a6b4a0e9e6692452a0.tar.gz |
Improve deafault rules logic for CompatibilityInfo, KIKIMR-15989
Only apply default rules when there are no rules for stored build
-rw-r--r-- | ydb/core/driver_lib/version/ut/version_ut.cpp | 117 | ||||
-rw-r--r-- | ydb/core/driver_lib/version/version.cpp | 16 |
2 files changed, 127 insertions, 6 deletions
diff --git a/ydb/core/driver_lib/version/ut/version_ut.cpp b/ydb/core/driver_lib/version/ut/version_ut.cpp index eceda543acd..3103421a6ca 100644 --- a/ydb/core/driver_lib/version/ut/version_ut.cpp +++ b/ydb/core/driver_lib/version/ut/version_ut.cpp @@ -485,6 +485,26 @@ Y_UNIT_TEST_SUITE(YdbVersion) { false ); } + Y_UNIT_TEST(DefaultRulesWithExtraForbidden) { + Test( + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 1, .Major = 2, .Minor = 2, .Hotfix = 0 }, + .CanLoadFrom = { + TCompatibilityRule{ + .LowerLimit = TYdbVersion{ .Year = 1, .Major = 1, .Minor = 3 }, + .UpperLimit = TYdbVersion{ .Year = 1, .Major = 1, .Minor = 3 }, + .Forbidden = true + } + } + }, + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 1, .Major = 1, .Minor = 4 }, + }, + true + ); + } Y_UNIT_TEST(ExtraAndForbidden) { Test( TCurrentCompatibilityInfo{ @@ -574,6 +594,103 @@ Y_UNIT_TEST_SUITE(YdbVersion) { ); } + + Y_UNIT_TEST(YDBAndNbs) { + Test( + TCurrentCompatibilityInfo{ + .Build = "nbs", + .YdbVersion = TYdbVersion{ .Year = 23, .Major = 3, .Minor = 2, .Hotfix = 0 }, + }, + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 24, .Major = 2, .Minor = 3, .Hotfix = 0 }, + .CanLoadFrom = { + TCompatibilityRule{ + .Build = "nbs", + .LowerLimit = TYdbVersion{ .Year = 23, .Major = 3 }, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 2 }, + }, + }, + .StoresReadableBy = { + TCompatibilityRule{ + .Build = "nbs", + .LowerLimit = TYdbVersion{ .Year = 23, .Major = 3 }, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 2 }, + }, + } + }, + true + ); + } + + Y_UNIT_TEST(DifferentYdbVersionsWithNBSRules) { + Test( + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 24, .Major = 3, .Minor = 1, .Hotfix = 0 }, + .CanLoadFrom = { + TCompatibilityRule{ + .Build = "nbs", + .LowerLimit = TYdbVersion{ .Year = 23, .Major = 3 }, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 3 }, + }, + }, + .StoresReadableBy = { + TCompatibilityRule{ + .Build = "nbs", + .LowerLimit = TYdbVersion{ .Year = 23, .Major = 3 }, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 3 }, + }, + } + }, + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 24, .Major = 2, .Minor = 3, .Hotfix = 0 }, + .CanLoadFrom = { + TCompatibilityRule{ + .Build = "nbs", + .LowerLimit = TYdbVersion{ .Year = 23, .Major = 3 }, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 2 }, + }, + }, + .StoresReadableBy = { + TCompatibilityRule{ + .Build = "nbs", + .LowerLimit = TYdbVersion{ .Year = 23, .Major = 3 }, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 2 }, + }, + } + }, + true + ); + } + + Y_UNIT_TEST(RestrictedCompatibilitySameBuild) { + Test( + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 24, .Major = 3, .Minor = 1, .Hotfix = 0 }, + .CanLoadFrom = { + TCompatibilityRule{ + .LowerLimit = TYdbVersion{ .Year = 24, .Major = 2, .Minor = 4}, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 3 }, + }, + }, + .StoresReadableBy = { + TCompatibilityRule{ + .LowerLimit = TYdbVersion{ .Year = 24, .Major = 2, .Minor = 4}, + .UpperLimit = TYdbVersion{ .Year = 24, .Major = 3 }, + }, + } + }, + TCurrentCompatibilityInfo{ + .Build = "ydb", + .YdbVersion = TYdbVersion{ .Year = 24, .Major = 2, .Minor = 1, .Hotfix = 0 }, + }, + false + ); + } + Y_UNIT_TEST(CompatibleWithSelf) { auto stored = CompatibilityInfo.MakeStored(EComponentId::Test1); TString errorReason; diff --git a/ydb/core/driver_lib/version/version.cpp b/ydb/core/driver_lib/version/version.cpp index 1c8056066f3..71dcb0cf007 100644 --- a/ydb/core/driver_lib/version/version.cpp +++ b/ydb/core/driver_lib/version/version.cpp @@ -271,8 +271,8 @@ bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TStor return CheckNonPresent(current, componentId, errorReason); } - const auto currentBuild = current->GetBuild(); - const auto storedBuild = stored->GetBuild(); + const auto& currentBuild = current->GetBuild(); + const auto& storedBuild = stored->GetBuild(); const auto* currentYdbVersion = current->HasYdbVersion() ? ¤t->GetYdbVersion() : nullptr; const auto* storedYdbVersion = stored->HasYdbVersion() ? &stored->GetYdbVersion() : nullptr; @@ -283,9 +283,12 @@ bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TStor const auto rule = current->GetCanLoadFrom(i); const auto ruleComponentId = TComponentId(rule.GetComponentId()); if (!rule.HasComponentId() || ruleComponentId == componentId || ruleComponentId == EComponentId::Any) { - useDefault = false; + bool isForbidding = rule.HasForbidden() && rule.GetForbidden(); + if ((!rule.HasBuild() || rule.GetBuild() == storedBuild) && !isForbidding) { + useDefault = false; + } if (CheckRule(storedBuild, storedYdbVersion, rule)) { - if (rule.HasForbidden() && rule.GetForbidden()) { + if (isForbidding) { errorReason = "Stored version is explicitly prohibited, " + PrintStoredAndCurrent(stored, current); return false; } else { @@ -566,11 +569,12 @@ bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TOldF const auto rule = current->GetCanLoadFrom(i); const auto ruleComponentId = TComponentId(rule.GetComponentId()); if (!rule.HasComponentId() || ruleComponentId == componentId || ruleComponentId == EComponentId::Any) { - if (!rule.HasBuild()) { + bool isForbidding = rule.HasForbidden() && rule.GetForbidden(); + if (!rule.HasBuild() && !isForbidding) { useDefault = false; } if (CheckRule(storedBuild, &*storedVersion, rule)) { - if (rule.HasForbidden() && rule.GetForbidden()) { + if (isForbidding) { errorReason = "Stored version is explicitly prohibited, " + PrintStoredAndCurrent(stored, current); return false; } else { |