diff options
author | Alexey Efimov <xeno@prnwatch.com> | 2022-07-04 16:50:38 +0300 |
---|---|---|
committer | Alexey Efimov <xeno@prnwatch.com> | 2022-07-04 16:50:38 +0300 |
commit | c74c2090fa0a89f3b4d84dfdbc8f4fd162421276 (patch) | |
tree | 65dc33f127588f336045ccd6ef4fc93fd8c52095 | |
parent | 25f54d9216201e9ff973229d275d26046fe4a6eb (diff) | |
download | ydb-c74c2090fa0a89f3b4d84dfdbc8f4fd162421276.tar.gz |
cleanup followers KIKIMR-15244
ref:1ceb7e9a7afb417943fa6ea2a506acf4033fd98a
-rw-r--r-- | ydb/core/mind/hive/leader_tablet_info.cpp | 10 | ||||
-rw-r--r-- | ydb/core/mind/hive/leader_tablet_info.h | 17 | ||||
-rw-r--r-- | ydb/core/mind/hive/tx__create_tablet.cpp | 13 |
3 files changed, 26 insertions, 14 deletions
diff --git a/ydb/core/mind/hive/leader_tablet_info.cpp b/ydb/core/mind/hive/leader_tablet_info.cpp index 87205b6cfed..6345caa4db3 100644 --- a/ydb/core/mind/hive/leader_tablet_info.cpp +++ b/ydb/core/mind/hive/leader_tablet_info.cpp @@ -140,6 +140,16 @@ TFollowerGroup& TLeaderTabletInfo::AddFollowerGroup(TFollowerGroupId followerGro return followerGroup; } +ui32 TLeaderTabletInfo::GetActualFollowerCount(TFollowerGroupId followerGroupId) const { + ui32 count = 0; + for (const auto& follower : Followers) { + if (follower.FollowerGroup.Id == followerGroupId) { + ++count; + } + } + return count; +} + TActorId TLeaderTabletInfo::SetLockedToActor(const TActorId& actor, const TDuration& timeout) { TActorId previousOwner = LockedToActor; if (LockedToActor != actor) { diff --git a/ydb/core/mind/hive/leader_tablet_info.h b/ydb/core/mind/hive/leader_tablet_info.h index 7ae56f6c00e..fd7057339d0 100644 --- a/ydb/core/mind/hive/leader_tablet_info.h +++ b/ydb/core/mind/hive/leader_tablet_info.h @@ -247,17 +247,11 @@ public: template <template <typename, typename...> class Cont, typename Type, typename... Types> static decltype(Type::Id) GenerateId(const Cont<Type, Types...>& items) { - decltype(Type::Id) id = 1; - bool retry; - do { - retry = false; - for (const auto& item : items) { - if (item.Id == id) { - ++id; - retry = true; - } - } - } while (retry); + decltype(Type::Id) id = 0; + for (const auto& item : items) { + id = std::max<decltype(Type::Id)>(id, item.Id); + } + ++id; return id; } @@ -268,6 +262,7 @@ public: TFollowerTabletInfo& AddFollower(TFollowerGroup& followerGroup, TFollowerId followerId = 0); TFollowerGroupId GenerateFollowerGroupId() const; TFollowerGroup& AddFollowerGroup(TFollowerGroupId followerGroupId = 0); + ui32 GetActualFollowerCount(TFollowerGroupId followerGroupId) const; TFollowerGroup& GetFollowerGroup(TFollowerGroupId followerGroupId) { auto it = std::find(FollowerGroups.begin(), FollowerGroups.end(), followerGroupId); diff --git a/ydb/core/mind/hive/tx__create_tablet.cpp b/ydb/core/mind/hive/tx__create_tablet.cpp index 3bccb638882..8e92d92e53a 100644 --- a/ydb/core/mind/hive/tx__create_tablet.cpp +++ b/ydb/core/mind/hive/tx__create_tablet.cpp @@ -274,7 +274,7 @@ public: auto itFollowerGroup = tablet->FollowerGroups.begin(); for (const auto& srcFollowerGroup : FollowerGroups) { TFollowerGroup& followerGroup = itFollowerGroup != tablet->FollowerGroups.end() ? *itFollowerGroup : tablet->AddFollowerGroup(); - ui32 oldFollowerCount = followerGroup.GetComputedFollowerCount(Self->GetDataCenters()); + ui32 oldFollowerCount = tablet->GetActualFollowerCount(followerGroup.Id); followerGroup = srcFollowerGroup; TVector<ui32> allowedDataCenters; @@ -302,10 +302,17 @@ public: } for (ui32 i = followerGroup.GetComputedFollowerCount(Self->GetDataCenters()); i < oldFollowerCount; ++i) { - TFollowerTabletInfo& follower = tablet->Followers.back(); + auto itFollower = tablet->Followers.rbegin(); + while (itFollower != tablet->Followers.rend() && itFollower->FollowerGroup.Id != followerGroup.Id) { + ++itFollower; + } + if (itFollower == tablet->Followers.rend()) { + break; + } + TFollowerTabletInfo& follower = *itFollower; db.Table<Schema::TabletFollowerTablet>().Key(TabletId, follower.Id).Delete(); follower.InitiateStop(SideEffects); - tablet->Followers.pop_back(); + tablet->Followers.erase(std::prev(itFollower.base())); } ++itFollowerGroup; } |