aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinnokentii <innokentii@yandex-team.com>2022-11-10 21:06:59 +0300
committerinnokentii <innokentii@yandex-team.com>2022-11-10 21:06:59 +0300
commit027efb8ed21c4bd6aaabded79cfd1ca1669ba971 (patch)
tree2dbbc6c17de1112ac88d86e3a0f2d85340f591f8
parent27861ff30998a509903c4213f30192757f483dc1 (diff)
downloadydb-027efb8ed21c4bd6aaabded79cfd1ca1669ba971.tar.gz
Fix sentinel behavior for single-node per rack case
fix sentinel behavior for single-node per rack case
-rw-r--r--ydb/core/cms/sentinel.cpp4
-rw-r--r--ydb/core/cms/sentinel_impl.h2
-rw-r--r--ydb/core/cms/sentinel_ut.cpp47
3 files changed, 32 insertions, 21 deletions
diff --git a/ydb/core/cms/sentinel.cpp b/ydb/core/cms/sentinel.cpp
index bed56b79fd..530202795a 100644
--- a/ydb/core/cms/sentinel.cpp
+++ b/ydb/core/cms/sentinel.cpp
@@ -200,6 +200,7 @@ void TClusterMap::AddPDisk(const TPDiskID& id) {
ByDataCenter[location.HasKey(TNodeLocation::TKeys::DataCenter) ? location.GetDataCenterId() : ""].insert(id);
ByRoom[location.HasKey(TNodeLocation::TKeys::Module) ? location.GetModuleId() : ""].insert(id);
ByRack[location.HasKey(TNodeLocation::TKeys::Rack) ? location.GetRackId() : ""].insert(id);
+ NodeByRack[location.HasKey(TNodeLocation::TKeys::Rack) ? location.GetRackId() : ""].insert(id.NodeId);
}
/// TGuardian
@@ -251,7 +252,8 @@ TClusterMap::TPDiskIDSet TGuardian::GetAllowedPDisks(const TClusterMap& all, TSt
for (const auto& kv : ByRack) {
Y_VERIFY(all.ByRack.contains(kv.first));
// ignore check if there is only one node in a rack
- if (kv.second.size() == 1) {
+ auto it = NodeByRack.find(kv.first);
+ if (it != NodeByRack.end() && it->second.size() == 1) {
continue;
}
if (kv.first && !CheckRatio(kv, all.ByRack, RackRatio)) {
diff --git a/ydb/core/cms/sentinel_impl.h b/ydb/core/cms/sentinel_impl.h
index 7158a1f4ec..c634865943 100644
--- a/ydb/core/cms/sentinel_impl.h
+++ b/ydb/core/cms/sentinel_impl.h
@@ -106,11 +106,13 @@ class TClusterMap {
public:
using TPDiskIDSet = THashSet<TPDiskID, TPDiskIDHash>;
using TDistribution = THashMap<TString, TPDiskIDSet>;
+ using TNodeIDSet = THashSet<ui32>;
TCmsStatePtr State;
TDistribution ByDataCenter;
TDistribution ByRoom;
TDistribution ByRack;
+ THashMap<TString, TNodeIDSet> NodeByRack;
TClusterMap(TCmsStatePtr state);
diff --git a/ydb/core/cms/sentinel_ut.cpp b/ydb/core/cms/sentinel_ut.cpp
index f916cf6005..0ad3a65f22 100644
--- a/ydb/core/cms/sentinel_ut.cpp
+++ b/ydb/core/cms/sentinel_ut.cpp
@@ -136,7 +136,7 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
}
}
- TCmsStatePtr MockCmsState(ui16 numDataCenter, ui16 racksPerDataCenter, ui16 nodesPerRack, bool anyDC, bool anyRack) {
+ TCmsStatePtr MockCmsState(ui16 numDataCenter, ui16 racksPerDataCenter, ui16 nodesPerRack, ui16 pdisksPerNode, bool anyDC, bool anyRack) {
TCmsStatePtr state = new TCmsState;
state->ClusterInfo = new TClusterInfo;
@@ -157,11 +157,13 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
state->ClusterInfo->AddNode(TEvInterconnect::TNodeInfo(id, name, name, name, 10000, TNodeLocation(location)), nullptr);
- NKikimrBlobStorage::TBaseConfig::TPDisk pdisk;
- pdisk.SetNodeId(id);
- pdisk.SetPDiskId(0);
- pdisk.SetPath("pdisk.data");
- state->ClusterInfo->AddPDisk(pdisk);
+ for (ui64 npdisk : xrange(pdisksPerNode)) {
+ NKikimrBlobStorage::TBaseConfig::TPDisk pdisk;
+ pdisk.SetNodeId(id);
+ pdisk.SetPDiskId(npdisk);
+ pdisk.SetPath(TString("pdisk") + ToString(npdisk) + ".data");
+ state->ClusterInfo->AddPDisk(pdisk);
+ }
}
}
}
@@ -173,7 +175,7 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
UNIT_ASSERT(!anyDC || numDataCenter == 1);
for (ui16 nodesPerDataCenter : nodesPerDataCenterVariants) {
- TCmsStatePtr state = MockCmsState(numDataCenter, nodesPerDataCenter, 1, anyDC, false);
+ TCmsStatePtr state = MockCmsState(numDataCenter, nodesPerDataCenter, 1, 1, anyDC, false);
TGuardian all(state);
TGuardian changed(state, 50);
THashSet<TPDiskID, TPDiskIDHash> changedSet;
@@ -229,9 +231,9 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
GuardianDataCenterRatio(1, {3, 4, 5}, true);
}
- void GuardianRackRatio(ui16 numRacks, const TVector<ui16>& nodesPerRackVariants, bool anyRack) {
+ void GuardianRackRatio(ui16 numRacks, const TVector<ui16>& nodesPerRackVariants, ui16 numPDisks, bool anyRack) {
for (ui16 nodesPerRack : nodesPerRackVariants) {
- TCmsStatePtr state = MockCmsState(1, numRacks, nodesPerRack, false, anyRack);
+ TCmsStatePtr state = MockCmsState(1, numRacks, nodesPerRack, numPDisks, false, anyRack);
TGuardian all(state);
TGuardian changed(state, 100, 100, 50);
@@ -242,12 +244,14 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
TVector<ui32> changedCount(numRacks);
for (const auto& node : nodes) {
const ui64 nodeId = node.second->NodeId;
- const TPDiskID id(nodeId, 0);
+ for (ui16 pdiskId : xrange(numPDisks)) {
+ const TPDiskID id(nodeId, pdiskId);
- all.AddPDisk(id);
- if (changedCount[nodeId >> 16]++ < nodesPerRack / 2) {
- changed.AddPDisk(id);
- changedSet.insert(id);
+ all.AddPDisk(id);
+ if (changedCount[nodeId >> 16]++ < nodesPerRack * numPDisks / 2) {
+ changed.AddPDisk(id);
+ changedSet.insert(id);
+ }
}
}
@@ -261,11 +265,13 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
changedCount.assign(numRacks, 0);
for (const auto& node : nodes) {
const ui64 nodeId = node.second->NodeId;
- const TPDiskID id(nodeId, 0);
+ for (ui16 pdiskId : xrange(numPDisks)) {
+ const TPDiskID id(nodeId, pdiskId);
- if (changedCount[nodeId >> 16]++ < nodesPerRack / 2 + 1) {
- changed.AddPDisk(id);
- changedSet.insert(id);
+ if (changedCount[nodeId >> 16]++ < nodesPerRack * numPDisks / 2 + 1) {
+ changed.AddPDisk(id);
+ changedSet.insert(id);
+ }
}
}
@@ -287,8 +293,9 @@ Y_UNIT_TEST_SUITE(TSentinelBaseTests) {
Y_UNIT_TEST(GuardianRackRatio) {
for (int anyRack = 0; anyRack < 2; ++anyRack) {
for (int numRacks = 1; numRacks < 5; ++numRacks) {
- GuardianRackRatio(numRacks, {1, 2, 3, 4, 5}, anyRack);
-
+ for (int numPDisks = 1; numPDisks < 4; ++numPDisks) {
+ GuardianRackRatio(numRacks, {1, 2, 3, 4, 5}, numPDisks, anyRack);
+ }
}
}
}