Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update followers in 24-3 #12683

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ydb/core/mind/hive/data_center_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "hive.h"
#include "hive_events.h"

namespace NKikimr {
namespace NHive {

struct TDataCenterInfo {
using TFullFollowerGroupId = std::pair<TTabletId, TFollowerGroupId>;
using TFollowerIter = TList<TFollowerTabletInfo>::iterator; // list iterators are not invalidated

std::unordered_set<TNodeId> RegisteredNodes;
bool UpdateScheduled = false;
std::unordered_map<TFullFollowerGroupId, std::vector<TFollowerIter>> Followers;

bool IsRegistered() const {
return !RegisteredNodes.empty();
}
};

} // NHive
} // NKikimr
11 changes: 11 additions & 0 deletions ydb/core/mind/hive/follower_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ struct TFollowerGroup {
}
}

ui32 GetFollowerCountForDataCenter(const TDataCenterId& dc) const {
if (!FollowerCountPerDataCenter) {
return 0;
}
if (NodeFilter.IsAllowedDataCenter(dc)) {
return FollowerCount;
} else {
return 0;
}
}

void SetFollowerCount(ui32 followerCount) {
FollowerCount = followerCount;
}
Expand Down
11 changes: 9 additions & 2 deletions ydb/core/mind/hive/hive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ NMetrics::EResource GetDominantResourceType(const TResourceNormalizedValues& nor
}

TNodeFilter::TNodeFilter(const THive& hive)
: Hive(hive)
: Hive(&hive)
{}

TArrayRef<const TSubDomainKey> TNodeFilter::GetEffectiveAllowedDomains() const {
const auto* objectDomainInfo = Hive.FindDomain(ObjectDomain);
const auto* objectDomainInfo = Hive->FindDomain(ObjectDomain);

if (!objectDomainInfo) {
return {AllowedDomains.begin(), AllowedDomains.end()};
Expand All @@ -100,6 +100,13 @@ TArrayRef<const TSubDomainKey> TNodeFilter::GetEffectiveAllowedDomains() const {
}
}

bool TNodeFilter::IsAllowedDataCenter(TDataCenterId dc) const {
if (AllowedDataCenters.empty()) {
return true;
}
return std::find(AllowedDataCenters.begin(), AllowedDataCenters.end(), dc) != AllowedDataCenters.end();
}

template <typename K, typename V>
std::unordered_map<V, K> MakeReverseMap(const std::unordered_map<K, V>& map) {
std::unordered_map<V, K> result;
Expand Down
44 changes: 43 additions & 1 deletion ydb/core/mind/hive/hive.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,55 @@ struct TNodeFilter {
TSubDomainKey ObjectDomain;
TTabletTypes::EType TabletType = TTabletTypes::TypeInvalid;

const THive& Hive;
const THive* Hive;

explicit TNodeFilter(const THive& hive);

TArrayRef<const TSubDomainKey> GetEffectiveAllowedDomains() const;

bool IsAllowedDataCenter(TDataCenterId dc) const;
};

struct TFollowerUpdates {
enum class EAction {
Create,
Update,
Delete,
};

struct TUpdate {
EAction Action;
TFullTabletId TabletId;
TFollowerGroupId GroupId;
TDataCenterId DataCenter;
};

std::deque<TUpdate> Updates;

bool Empty() const {
return Updates.empty();
}

void Create(TFullTabletId leaderTablet, TFollowerGroupId group, TDataCenterId dc) {
Updates.emplace_back(EAction::Create, leaderTablet, group, dc);
}

void Update(TFullTabletId tablet, TDataCenterId dc) {
Updates.emplace_back(EAction::Update, tablet, 0, dc);
}

void Delete(TFullTabletId tablet, TFollowerGroupId group, TDataCenterId dc) {
Updates.emplace_back(EAction::Delete, tablet, group, dc);
}

TUpdate Pop() {
TUpdate update = Updates.front();
Updates.pop_front();
return update;
}
};


} // NHive
} // NKikimr

Expand Down
11 changes: 11 additions & 0 deletions ydb/core/mind/hive/hive_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ struct TEvPrivate {
EvDeleteNode,
EvCanMoveTablets,
EvRefreshScaleRecommendation,
EvUpdateDataCenterFollowers,
EvUpdateFollowers,
EvEnd
};

Expand Down Expand Up @@ -123,6 +125,15 @@ struct TEvPrivate {
struct TEvCanMoveTablets : TEventLocal<TEvCanMoveTablets, EvCanMoveTablets> {};

struct TEvRefreshScaleRecommendation : TEventLocal<TEvRefreshScaleRecommendation, EvRefreshScaleRecommendation> {};

struct TEvUpdateDataCenterFollowers : TEventLocal<TEvUpdateDataCenterFollowers, EvUpdateDataCenterFollowers> {
TDataCenterId DataCenter;

TEvUpdateDataCenterFollowers(TDataCenterId dataCenter) : DataCenter(dataCenter) {};
};

struct TEvUpdateFollowers : TEventLocal<TEvUpdateFollowers, EvUpdateFollowers> {
};
};

} // NHive
Expand Down
Loading
Loading