aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorserg-belyakov <serg-belyakov@yandex-team.com>2023-01-30 16:49:34 +0300
committerserg-belyakov <serg-belyakov@yandex-team.com>2023-01-30 16:49:34 +0300
commit6fd86d7a8a8d3312cc9cf935a2c3e6ec50bb6009 (patch)
tree458f8cd15ef6f4bb07764fe67e0d3a58f8363b7d
parent9dcc4b43f691712172d5156d718dc9f0a930af0b (diff)
downloadydb-6fd86d7a8a8d3312cc9cf935a2c3e6ec50bb6009.tar.gz
Parsing old version info format mechanism and UT,
Initial
-rw-r--r--ydb/core/driver_lib/version/version.cpp259
-rw-r--r--ydb/core/driver_lib/version/version.h7
-rw-r--r--ydb/core/driver_lib/version/version_ut.cpp290
3 files changed, 430 insertions, 126 deletions
diff --git a/ydb/core/driver_lib/version/version.cpp b/ydb/core/driver_lib/version/version.cpp
index e37ddb87d2..9dfe532272 100644
--- a/ydb/core/driver_lib/version/version.cpp
+++ b/ydb/core/driver_lib/version/version.cpp
@@ -1,13 +1,22 @@
#include <library/cpp/svnversion/svnversion.h>
#include "version.h"
-NKikimrConfig::TCurrentCompatibilityInfo* TCompatibilityInfo::CompatibilityInfo = nullptr;
+using TCurrent = NKikimrConfig::TCurrentCompatibilityInfo;
+using TStored = NKikimrConfig::TStoredCompatibilityInfo;
+
+
+/////////////////////////////////////////////////////////////
+// Global definitions
+/////////////////////////////////////////////////////////////
+
+// new version control
+TCurrent* TCompatibilityInfo::CompatibilityInfo = nullptr;
TSpinLock TCompatibilityInfo::LockCurrent = TSpinLock();
-const NKikimrConfig::TCurrentCompatibilityInfo* TCompatibilityInfo::GetCurrent() {
+const TCurrent* TCompatibilityInfo::GetCurrent() {
TGuard<TSpinLock> g(TCompatibilityInfo::LockCurrent);
if (!CompatibilityInfo) {
- CompatibilityInfo = new NKikimrConfig::TCurrentCompatibilityInfo();
+ CompatibilityInfo = new TCurrent();
// Look for protobuf message format in ydb/core/protos/config.proto
// To be changed in new release:
CompatibilityInfo->SetBuild("trunk");
@@ -16,16 +25,32 @@ const NKikimrConfig::TCurrentCompatibilityInfo* TCompatibilityInfo::GetCurrent()
return CompatibilityInfo;
}
+// obsolete version control
+TMaybe<NActors::TInterconnectProxyCommon::TVersionInfo> VERSION = NActors::TInterconnectProxyCommon::TVersionInfo{
+ // version of this binary
+ "trunk",
+
+ // compatible versions; must include all compatible old ones, including this one; version verification occurs on both
+ // peers and connection is accepted if at least one of peers accepts the version of the other peer
+ {
+ "trunk"
+ }
+};
+
+/////////////////////////////////////////////////////////////
+// Implementation
+/////////////////////////////////////////////////////////////
+
// Last stable YDB release, which doesn't include version control change
// When the compatibility information is not present in component's data,
// we assume component's version to be this version
-NKikimrConfig::TStoredCompatibilityInfo* TCompatibilityInfo::UnknownYdbRelease = nullptr;
-const NKikimrConfig::TStoredCompatibilityInfo* TCompatibilityInfo::GetUnknown() {
+TStored* TCompatibilityInfo::UnknownYdbRelease = nullptr;
+const TStored* TCompatibilityInfo::GetUnknown() {
static TSpinLock lock;
TGuard<TSpinLock> g(lock);
if (!UnknownYdbRelease) {
- UnknownYdbRelease = new NKikimrConfig::TStoredCompatibilityInfo();
+ UnknownYdbRelease = new TStored();
UnknownYdbRelease->SetBuild("ydb");
auto* version = UnknownYdbRelease->MutableYdbVersion();
@@ -38,11 +63,10 @@ const NKikimrConfig::TStoredCompatibilityInfo* TCompatibilityInfo::GetUnknown()
return UnknownYdbRelease;
}
-NKikimrConfig::TStoredCompatibilityInfo TCompatibilityInfo::MakeStored(ui32 componentId,
- const NKikimrConfig::TCurrentCompatibilityInfo* current) {
+TStored TCompatibilityInfo::MakeStored(ui32 componentId, const TCurrent* current) {
Y_VERIFY(current);
- NKikimrConfig::TStoredCompatibilityInfo stored;
+ TStored stored;
stored.SetBuild(current->GetBuild());
if (current->HasYdbVersion()) {
stored.MutableYdbVersion()->CopyFrom(current->GetYdbVersion());
@@ -65,8 +89,7 @@ NKikimrConfig::TStoredCompatibilityInfo TCompatibilityInfo::MakeStored(ui32 comp
return stored;
}
-NKikimrConfig::TStoredCompatibilityInfo TCompatibilityInfo::MakeStored(
- NKikimrConfig::TCompatibilityRule::EComponentId componentId) {
+TStored TCompatibilityInfo::MakeStored(NKikimrConfig::TCompatibilityRule::EComponentId componentId) {
return MakeStored((ui32)componentId, GetCurrent());
}
@@ -126,8 +149,8 @@ i32 CompareVersions(const NKikimrConfig::TYdbVersion& left, const NKikimrConfig:
// If StoredCompatibilityInfo is not present, we:
// compare current to UnknownYdbRelease, if current version is stable, otherwise
// we consider versions compatible
-bool CheckNonPresent(const NKikimrConfig::TCurrentCompatibilityInfo* current,
- ui32 componentId, TString& errorReason) {
+bool CheckNonPresent(const TCurrent* current, ui32 componentId, TString& errorReason) {
+ Y_VERIFY(current);
if (!current->HasYdbVersion()) {
return true;
}
@@ -155,37 +178,48 @@ bool CheckDefaultRules(TString currentBuild, const NKikimrConfig::TYdbVersion* c
if (!currentYdbVersion->HasYear() || !storedYdbVersion->HasYear()) {
return true;
}
+ if (currentYdbVersion->GetYear() != storedYdbVersion->GetYear()) {
+ return false;
+ }
if (!currentYdbVersion->HasMajor() || !storedYdbVersion->HasMajor()) {
return true;
}
- return currentYdbVersion->GetYear() == storedYdbVersion->GetYear() &&
- std::abs((i32)currentYdbVersion->GetMajor() - (i32)storedYdbVersion->GetMajor()) <= 1;
+ return std::abs((i32)currentYdbVersion->GetMajor() - (i32)storedYdbVersion->GetMajor()) <= 1;
}
return false;
}
-bool CheckRule(TString build, const NKikimrConfig::TYdbVersion* version,
- const NKikimrConfig::TCompatibilityRule& rule) {
- if (rule.HasBuild()) {
- if (rule.GetBuild() != build) {
- return false;
- }
- if (version == nullptr) {
- return true;
+bool CheckRule(std::optional<TString> build, const NKikimrConfig::TYdbVersion* version, const NKikimrConfig::TCompatibilityRule& rule) {
+ if (build) {
+ if (rule.HasBuild()) {
+ if (rule.GetBuild() != *build) {
+ return false;
+ }
+ if (version == nullptr) {
+ return true;
+ }
+ } else {
+ // non-stable build is incompatible with stable
+ if (version == nullptr) {
+ return false;
+ }
}
} else {
if (version == nullptr) {
return false;
}
+ if (rule.HasBuild()) {
+ return false;
+ }
}
return (!rule.HasBottomLimit() || CompareVersions(*version, rule.GetBottomLimit()) > -1) &&
(!rule.HasUpperLimit() || CompareVersions(*version, rule.GetUpperLimit()) < 1);
}
-bool TCompatibilityInfo::CheckCompatibility(const NKikimrConfig::TCurrentCompatibilityInfo* current,
- const NKikimrConfig::TStoredCompatibilityInfo* stored, ui32 componentId, TString& errorReason) {
+bool TCompatibilityInfo::CheckCompatibility(const TCurrent* current, const TStored* stored, ui32 componentId, TString& errorReason) {
+ Y_VERIFY(current);
if (stored == nullptr) {
// version record is not found
return CheckNonPresent(current, componentId, errorReason);
@@ -248,28 +282,15 @@ bool TCompatibilityInfo::CheckCompatibility(const NKikimrConfig::TCurrentCompati
}
}
-bool TCompatibilityInfo::CheckCompatibility(const NKikimrConfig::TStoredCompatibilityInfo* stored,
- ui32 componentId, TString& errorReason) {
+bool TCompatibilityInfo::CheckCompatibility(const TStored* stored, ui32 componentId, TString& errorReason) {
return CheckCompatibility(GetCurrent(), stored, componentId, errorReason);
}
-void TCompatibilityInfo::Reset(NKikimrConfig::TCurrentCompatibilityInfo* newCurrent) {
+void TCompatibilityInfo::Reset(TCurrent* newCurrent) {
TGuard<TSpinLock> g(TCompatibilityInfo::LockCurrent);
CompatibilityInfo = newCurrent;
}
-// obsolete version control
-TMaybe<NActors::TInterconnectProxyCommon::TVersionInfo> VERSION = NActors::TInterconnectProxyCommon::TVersionInfo{
- // version of this binary
- "trunk",
-
- // compatible versions; must include all compatible old ones, including this one; version verification occurs on both
- // peers and connection is accepted if at least one of peers accepts the version of the other peer
- {
- "trunk"
- }
-};
-
TString GetBranchName(TString url) {
bool found = false;
for (const char *prefix : {"arcadia.yandex.ru/arc/", "arcadia/arc/", "arcadia.arc.yandex.ru/arc/"}) {
@@ -317,3 +338,161 @@ void CheckVersionTag() {
}
}
}
+
+using TOldFormat = NActors::TInterconnectProxyCommon::TVersionInfo;
+
+std::optional<NKikimrConfig::TYdbVersion> ParseYdbVersionFromTag(TString tag) {
+ NKikimrConfig::TYdbVersion version;
+ TVector<TString> splitted;
+ ui32 partsCount = Split(tag, "-", splitted);
+
+ ui32 year;
+ ui32 major;
+
+ // at least "stable", year and major should be present
+ if (partsCount < 3 || splitted[0] != "stable" ||
+ !TryIntFromString<10, ui32>(splitted[1], year) ||
+ !TryIntFromString<10, ui32>(splitted[2], major)) {
+ // if we cannot parse ydb version, we assume that tag name is build name and version is non-stable
+ return std::nullopt;
+ }
+ version.SetYear(year);
+ version.SetMajor(major);
+
+ if (partsCount == 3) {
+ version.SetMinor(1);
+ version.SetHotfix(0);
+ return version;
+ }
+
+ ui32 minor;
+ if (!TryIntFromString<10, ui32>(splitted[3], minor)) {
+ version.SetMinor(1);
+ version.SetHotfix(0);
+ return version;
+ }
+ version.SetMinor(minor);
+
+ ui32 hotfix;
+
+ if (partsCount == 4) {
+ // example: stable-23-1-1 == 23.1.1.0
+ version.SetHotfix(0);
+ } else if (partsCount == 5 && TryIntFromString<10, ui32>(splitted[4], hotfix)) {
+ // example: stable-23-1-1-4 == 23.1.1.4
+ version.SetHotfix(hotfix);
+ } else if (splitted[4] == "hotfix" || splitted[4] == "fix") {
+ if (partsCount == 5) {
+ // example: stable-23-1-1-hotfix == 23.1.1.1
+ version.SetHotfix(1);
+ } else if (partsCount == 6 && TryIntFromString<10, ui32>(splitted[5], hotfix)) {
+ // example: stable-23-1-1-hotfix-7 == 23.1.1.7
+ version.SetHotfix(hotfix);
+ } else {
+ // stable-23-1-1-hotfix-some-bug == 23.1.1.1
+ version.SetHotfix(1);
+ }
+ } else {
+ // example: stable-23-1-1-cool-release == 23.1.1.0
+ version.SetHotfix(0);
+ }
+
+ return version;
+}
+
+bool TCompatibilityInfo::CheckCompatibility(const NKikimrConfig::TCurrentCompatibilityInfo* current,
+ const TOldFormat& stored, ui32 componentId, TString& errorReason) {
+ Y_VERIFY(current);
+
+ std::optional<TString> storedBuild;
+
+ auto storedVersion = ParseYdbVersionFromTag(stored.Tag);
+ if (!storedVersion) {
+ // non-stable version is stored
+ if (current->GetBuild() == stored.Tag) {
+ return true;
+ }
+ storedBuild = stored.Tag;
+ }
+
+ bool permitted = false;
+ bool useDefault = true;
+
+ for (ui32 i = 0; i < current->CanLoadFromSize(); ++i) {
+ const auto rule = current->GetCanLoadFrom(i);
+ if (!rule.HasComponentId() || rule.GetComponentId() == componentId ||
+ rule.GetComponentId() == (ui32)NKikimrConfig::TCompatibilityRule::Any) {
+ if (!rule.HasBuild()) {
+ useDefault = false;
+ }
+ if (CheckRule(storedBuild, &*storedVersion, rule)) {
+ if (rule.HasForbidden() && rule.GetForbidden()) {
+ errorReason = "Stored version is explicitly prohibited";
+ return false;
+ } else {
+ permitted = true;
+ }
+ }
+ }
+ }
+
+ if (permitted) {
+ return true;
+ }
+
+ const auto* currentVersion = current->HasYdbVersion() ? &current->GetYdbVersion() : nullptr;
+ for (const auto& tag : stored.AcceptedTags) {
+ auto version = ParseYdbVersionFromTag(tag);
+ if (storedVersion && currentVersion) {
+ if (version->GetYear() == currentVersion->GetYear() &&
+ version->GetMajor() == currentVersion->GetMajor() &&
+ version->GetMinor() == currentVersion->GetMinor() &&
+ version->GetHotfix() == currentVersion->GetHotfix()) {
+ return true;
+ }
+ } else if (!storedVersion && !currentVersion) {
+ if (current->GetBuild() == tag) {
+ return true;
+ }
+ }
+ }
+
+ if (useDefault) {
+ if (current->HasYdbVersion() && storedVersion) {
+ auto currentYdbVersion = current->GetYdbVersion();
+ if (!currentYdbVersion.HasYear() || !storedVersion->HasYear()) {
+ return true;
+ }
+ if (currentYdbVersion.GetYear() != storedVersion->GetYear()) {
+ errorReason = "Default rules used, stored's and current's Year differ";
+ return false;
+ }
+ if (!currentYdbVersion.HasMajor() || !storedVersion->HasMajor()) {
+ return true;
+ }
+ if (std::abs((i32)currentYdbVersion.GetMajor() - (i32)storedVersion->GetMajor()) <= 1) {
+ return true;
+ } else {
+ errorReason = "Default rules used, stored's and current's Major difference is more than 1";
+ return false;
+ }
+ } else if (!current->HasYdbVersion() && !storedVersion) {
+ if (*storedBuild == current->GetBuild()) {
+ return true;
+ } else {
+ errorReason = "Default rules used, both versions are non-stable, stored's and current's Build differ";
+ return false;
+ }
+ } else {
+ errorReason = "Default rules used, stable and non-stable versions are incompatible";
+ return false;
+ }
+ }
+
+ errorReason = "Version tag doesn't match any current compatibility rule, current version is not in accepted tags list";
+ return false;
+}
+
+bool TCompatibilityInfo::CheckCompatibility(const TOldFormat& stored, ui32 componentId, TString& errorReason) {
+ return CheckCompatibility(GetCurrent(), stored, componentId, errorReason);
+}
diff --git a/ydb/core/driver_lib/version/version.h b/ydb/core/driver_lib/version/version.h
index 3c8d82f7fa..ae7dfb266f 100644
--- a/ydb/core/driver_lib/version/version.h
+++ b/ydb/core/driver_lib/version/version.h
@@ -5,6 +5,7 @@
class TCompatibilityInfo {
friend class TCompatibilityInfoTest;
+ using TOldFormat = NActors::TInterconnectProxyCommon::TVersionInfo;
public:
TCompatibilityInfo() = delete;
@@ -15,10 +16,12 @@ public:
static bool CheckCompatibility(const NKikimrConfig::TStoredCompatibilityInfo* stored,
ui32 componentId, TString& errorReason);
+ static bool CheckCompatibility(const NKikimrConfig::TCurrentCompatibilityInfo* current,
+ const NKikimrConfig::TStoredCompatibilityInfo* stored, ui32 componentId, TString& errorReason);
+ static bool CheckCompatibility(const TOldFormat& stored, ui32 componentId, TString& errorReason);
static bool CheckCompatibility(const NKikimrConfig::TCurrentCompatibilityInfo* current,
- const NKikimrConfig::TStoredCompatibilityInfo* stored,
- ui32 componentId, TString& errorReason);
+ const TOldFormat& stored, ui32 componentId, TString& errorReason);
static NKikimrConfig::TStoredCompatibilityInfo MakeStored(ui32 componentId,
const NKikimrConfig::TCurrentCompatibilityInfo* current);
diff --git a/ydb/core/driver_lib/version/version_ut.cpp b/ydb/core/driver_lib/version/version_ut.cpp
index df1e6b1818..97e3b8e2e4 100644
--- a/ydb/core/driver_lib/version/version_ut.cpp
+++ b/ydb/core/driver_lib/version/version_ut.cpp
@@ -19,105 +19,107 @@ Y_UNIT_TEST_SUITE(VersionParser) {
}
}
-Y_UNIT_TEST_SUITE(YdbVersion) {
- using EComponentId = NKikimrConfig::TCompatibilityRule;
- struct TYdbVersion {
- std::optional<ui32> Year;
- std::optional<ui32> Major;
- std::optional<ui32> Minor;
- std::optional<ui32> Hotfix;
-
- NKikimrConfig::TYdbVersion ToPB() {
- NKikimrConfig::TYdbVersion res;
- if (Year) {
- res.SetYear(*Year);
- }
- if (Major) {
- res.SetMajor(*Major);
- }
- if (Minor) {
- res.SetMinor(*Minor);
- }
- if (Hotfix) {
- res.SetHotfix(*Hotfix);
- }
+using EComponentId = NKikimrConfig::TCompatibilityRule;
+using TOldFormat = NActors::TInterconnectProxyCommon::TVersionInfo;
+struct TYdbVersion {
+ std::optional<ui32> Year;
+ std::optional<ui32> Major;
+ std::optional<ui32> Minor;
+ std::optional<ui32> Hotfix;
- return res;
+ NKikimrConfig::TYdbVersion ToPB() {
+ NKikimrConfig::TYdbVersion res;
+ if (Year) {
+ res.SetYear(*Year);
+ }
+ if (Major) {
+ res.SetMajor(*Major);
+ }
+ if (Minor) {
+ res.SetMinor(*Minor);
+ }
+ if (Hotfix) {
+ res.SetHotfix(*Hotfix);
}
- };
- struct TCompatibilityRule {
- std::optional<std::string> Build;
- std::optional<TYdbVersion> BottomLimit;
- std::optional<TYdbVersion> UpperLimit;
- std::optional<ui32> ComponentId;
- std::optional<bool> Forbidden;
+ return res;
+ }
+};
- NKikimrConfig::TCompatibilityRule ToPB() {
- NKikimrConfig::TCompatibilityRule res;
- if (Build) {
- res.SetBuild(Build->data());
- }
- if (BottomLimit) {
- res.MutableBottomLimit()->CopyFrom(BottomLimit->ToPB());
- }
- if (UpperLimit) {
- res.MutableUpperLimit()->CopyFrom(UpperLimit->ToPB());
- }
- if (ComponentId) {
- res.SetComponentId(*ComponentId);
- }
- if (Forbidden) {
- res.SetForbidden(*Forbidden);
- }
+struct TCompatibilityRule {
+ std::optional<std::string> Build;
+ std::optional<TYdbVersion> BottomLimit;
+ std::optional<TYdbVersion> UpperLimit;
+ std::optional<ui32> ComponentId;
+ std::optional<bool> Forbidden;
- return res;
+ NKikimrConfig::TCompatibilityRule ToPB() {
+ NKikimrConfig::TCompatibilityRule res;
+ if (Build) {
+ res.SetBuild(Build->data());
+ }
+ if (BottomLimit) {
+ res.MutableBottomLimit()->CopyFrom(BottomLimit->ToPB());
+ }
+ if (UpperLimit) {
+ res.MutableUpperLimit()->CopyFrom(UpperLimit->ToPB());
+ }
+ if (ComponentId) {
+ res.SetComponentId(*ComponentId);
+ }
+ if (Forbidden) {
+ res.SetForbidden(*Forbidden);
}
- };
- struct TCurrentCompatibilityInfo {
- std::string Build = "ydb";
- std::optional<TYdbVersion> YdbVersion;
- std::vector<TCompatibilityRule> CanLoadFrom;
- std::vector<TCompatibilityRule> StoresReadableBy;
+ return res;
+ }
+};
- NKikimrConfig::TCurrentCompatibilityInfo ToPB() {
- NKikimrConfig::TCurrentCompatibilityInfo res;
- res.SetBuild(Build.data());
- if (YdbVersion) {
- res.MutableYdbVersion()->CopyFrom(YdbVersion->ToPB());
- }
+struct TCurrentCompatibilityInfo {
+ std::string Build = "ydb";
+ std::optional<TYdbVersion> YdbVersion;
+ std::vector<TCompatibilityRule> CanLoadFrom;
+ std::vector<TCompatibilityRule> StoresReadableBy;
- for (auto canLoadFrom : CanLoadFrom) {
- res.AddCanLoadFrom()->CopyFrom(canLoadFrom.ToPB());
- }
- for (auto storesReadableBy : StoresReadableBy) {
- res.AddStoresReadableBy()->CopyFrom(storesReadableBy.ToPB());
- }
+ NKikimrConfig::TCurrentCompatibilityInfo ToPB() {
+ NKikimrConfig::TCurrentCompatibilityInfo res;
+ res.SetBuild(Build.data());
+ if (YdbVersion) {
+ res.MutableYdbVersion()->CopyFrom(YdbVersion->ToPB());
+ }
- return res;
+ for (auto canLoadFrom : CanLoadFrom) {
+ res.AddCanLoadFrom()->CopyFrom(canLoadFrom.ToPB());
+ }
+ for (auto storesReadableBy : StoresReadableBy) {
+ res.AddStoresReadableBy()->CopyFrom(storesReadableBy.ToPB());
}
- };
- struct TStoredCompatibilityInfo {
- std::string Build = "ydb";
- std::optional<TYdbVersion> YdbVersion;
- std::vector<TCompatibilityRule> ReadableBy;
+ return res;
+ }
+};
- NKikimrConfig::TStoredCompatibilityInfo ToPB() {
- NKikimrConfig::TStoredCompatibilityInfo res;
- res.SetBuild(Build.data());
- if (YdbVersion) {
- res.MutableYdbVersion()->CopyFrom(YdbVersion->ToPB());
- }
+struct TStoredCompatibilityInfo {
+ std::string Build = "ydb";
+ std::optional<TYdbVersion> YdbVersion;
+ std::vector<TCompatibilityRule> ReadableBy;
- for (auto readableBy : ReadableBy) {
- res.AddReadableBy()->CopyFrom(readableBy.ToPB());
- }
+ NKikimrConfig::TStoredCompatibilityInfo ToPB() {
+ NKikimrConfig::TStoredCompatibilityInfo res;
+ res.SetBuild(Build.data());
+ if (YdbVersion) {
+ res.MutableYdbVersion()->CopyFrom(YdbVersion->ToPB());
+ }
- return res;
+ for (auto readableBy : ReadableBy) {
+ res.AddReadableBy()->CopyFrom(readableBy.ToPB());
}
- };
+
+ return res;
+ }
+};
+
+Y_UNIT_TEST_SUITE(YdbVersion) {
void Test(TCurrentCompatibilityInfo current, TCurrentCompatibilityInfo store, bool expected) {
TString errorReason;
@@ -125,7 +127,7 @@ Y_UNIT_TEST_SUITE(YdbVersion) {
auto storePB = store.ToPB();
auto storedPB = TCompatibilityInfo::MakeStored((ui32)NKikimrConfig::TCompatibilityRule::Test1, &storePB);
UNIT_ASSERT_EQUAL_C(TCompatibilityInfo::CheckCompatibility(&currentPB, &storedPB,
- (ui32)NKikimrConfig::TCompatibilityRule::Test1, errorReason), expected, errorReason);
+ (ui32)EComponentId::Test1, errorReason), expected, errorReason);
}
Y_UNIT_TEST(DefaultSameVersion) {
@@ -638,3 +640,123 @@ Y_UNIT_TEST_SUITE(YdbVersion) {
UNIT_ASSERT_C(TCompatibilityInfo::CheckCompatibility(&stored, EComponentId::Test1, errorReason), errorReason);
}
}
+
+Y_UNIT_TEST_SUITE(OldFormat) {
+ void TestOldFormat(TCurrentCompatibilityInfo current, TOldFormat stored, bool expected) {
+ TString errorReason;
+ auto currentPB = current.ToPB();
+ UNIT_ASSERT_EQUAL_C(TCompatibilityInfo::CheckCompatibility(&currentPB, stored,
+ (ui32)EComponentId::Interconnect, errorReason), expected, errorReason);
+ }
+
+ Y_UNIT_TEST(SameVersion) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .YdbVersion = TYdbVersion{ .Year = 22, .Major = 4, .Minor = 1, .Hotfix = 0 }
+ },
+ TOldFormat{
+ .Tag = "stable-22-4-1",
+ .AcceptedTags = { "stable-22-4-1" }
+ },
+ true
+ );
+ }
+
+ Y_UNIT_TEST(DefaultRules) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .YdbVersion = TYdbVersion{ .Year = 22, .Major = 5, .Minor = 1, .Hotfix = 0 }
+ },
+ TOldFormat{
+ .Tag = "stable-22-4",
+ .AcceptedTags = { "stable-22-4" }
+ },
+ true
+ );
+ }
+
+ Y_UNIT_TEST(PrevYear) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .YdbVersion = TYdbVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 },
+ .CanLoadFrom = {
+ TCompatibilityRule{
+ .BottomLimit = TYdbVersion{ .Year = 22, .Major = 5 },
+ .UpperLimit = TYdbVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 },
+ },
+ }
+ },
+ TOldFormat{
+ .Tag = "stable-22-5-1",
+ .AcceptedTags = { "stable-22-5-1" }
+ },
+ true
+ );
+ }
+
+ Y_UNIT_TEST(Trunk) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .Build = "trunk"
+ },
+ TOldFormat{
+ .Tag = "trunk",
+ .AcceptedTags = { "trunk" }
+ },
+ true
+ );
+ }
+
+ Y_UNIT_TEST(UnexpectedTrunk) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .YdbVersion = TYdbVersion{ .Year = 22, .Major = 4, .Minor = 1, .Hotfix = 0 },
+ },
+ TOldFormat{
+ .Tag = "trunk",
+ .AcceptedTags = { "trunk" }
+ },
+ false
+ );
+ }
+
+ Y_UNIT_TEST(TooOld) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .YdbVersion = TYdbVersion{ .Year = 22, .Major = 4, .Minor = 1, .Hotfix = 0 },
+ },
+ TOldFormat{
+ .Tag = "stable-22-2",
+ .AcceptedTags = { "stable-22-2" }
+ },
+ false
+ );
+ }
+
+ Y_UNIT_TEST(OldNbs) {
+ TestOldFormat(
+ TCurrentCompatibilityInfo{
+ .YdbVersion = TYdbVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 },
+ .CanLoadFrom = {
+ TCompatibilityRule{
+ .BottomLimit = TYdbVersion{ .Year = 22, .Major = 4 },
+ .UpperLimit = TYdbVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 },
+ .ComponentId = (ui32)EComponentId::Interconnect
+ },
+ },
+ .StoresReadableBy = {
+ TCompatibilityRule{
+ .BottomLimit = TYdbVersion{ .Year = 22, .Major = 4 },
+ .UpperLimit = TYdbVersion{ .Year = 23, .Major = 1, .Minor = 1, .Hotfix = 0 },
+ .ComponentId = (ui32)EComponentId::Interconnect
+ },
+ }
+ },
+ TOldFormat{
+ .Tag = "stable-22-4-1",
+ .AcceptedTags = { "stable-22-4-1" }
+ },
+ true
+ );
+ }
+}