Skip to content

Commit dc2fcaf

Browse files
authored
optimize initializiton of allocation units (#10969)
1 parent 2c76553 commit dc2fcaf

11 files changed

+112
-10
lines changed

ydb/core/mind/hive/hive_events.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct TEvPrivate {
3434
EvDeleteNode,
3535
EvCanMoveTablets,
3636
EvUpdateDataCenterFollowers,
37+
EvGenerateTestData,
3738
EvRefreshScaleRecommendation,
3839
EvEnd
3940
};
@@ -129,6 +130,8 @@ struct TEvPrivate {
129130
TEvUpdateDataCenterFollowers(TDataCenterId dataCenter) : DataCenter(dataCenter) {};
130131
};
131132

133+
struct TEvGenerateTestData : TEventLocal<TEvGenerateTestData, EvGenerateTestData> {};
134+
132135
struct TEvRefreshScaleRecommendation : TEventLocal<TEvRefreshScaleRecommendation, EvRefreshScaleRecommendation> {};
133136
};
134137

ydb/core/mind/hive/hive_impl.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,8 @@ void THive::ProcessEvent(std::unique_ptr<IEventHandle> event) {
30643064
hFunc(TEvHive::TEvRequestTabletDistribution, Handle);
30653065
hFunc(TEvPrivate::TEvUpdateDataCenterFollowers, Handle);
30663066
hFunc(TEvHive::TEvRequestScaleRecommendation, Handle);
3067-
hFunc(TEvPrivate::TEvRefreshScaleRecommendation, Handle)
3067+
hFunc(TEvPrivate::TEvGenerateTestData, Handle);
3068+
hFunc(TEvPrivate::TEvRefreshScaleRecommendation, Handle);
30683069
}
30693070
}
30703071

@@ -3169,6 +3170,7 @@ STFUNC(THive::StateWork) {
31693170
fFunc(TEvHive::TEvRequestTabletDistribution::EventType, EnqueueIncomingEvent);
31703171
fFunc(TEvPrivate::TEvUpdateDataCenterFollowers::EventType, EnqueueIncomingEvent);
31713172
fFunc(TEvHive::TEvRequestScaleRecommendation::EventType, EnqueueIncomingEvent);
3173+
fFunc(TEvPrivate::TEvGenerateTestData::EventType, EnqueueIncomingEvent);
31723174
fFunc(TEvPrivate::TEvRefreshScaleRecommendation::EventType, EnqueueIncomingEvent);
31733175
hFunc(TEvPrivate::TEvProcessIncomingEvent, Handle);
31743176
default:
@@ -3628,6 +3630,12 @@ void THive::Handle(TEvHive::TEvRequestScaleRecommendation::TPtr& ev) {
36283630
Send(ev->Sender, response.release());
36293631
}
36303632

3633+
void THive::Handle(TEvPrivate::TEvGenerateTestData::TPtr&) {
3634+
for (int i = 0; i < 4; ++i) {
3635+
Execute(CreateGenerateTestData(i));
3636+
}
3637+
}
3638+
36313639
TVector<TNodeId> THive::GetNodesForWhiteboardBroadcast(size_t maxNodesToReturn) {
36323640
TVector<TNodeId> nodes;
36333641
TNodeId selfNodeId = SelfId().NodeId();

ydb/core/mind/hive/hive_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
304304
ITransaction* CreateUpdateTabletsObject(TEvHive::TEvUpdateTabletsObject::TPtr event);
305305
ITransaction* CreateUpdateDomain(TSubDomainKey subdomainKey, TEvHive::TEvUpdateDomain::TPtr event = {});
306306
ITransaction* CreateUpdateDcFollowers(const TDataCenterId& dc);
307+
ITransaction* CreateGenerateTestData(uint64_t seed);
307308
ITransaction* CreateDeleteNode(TNodeId nodeId);
308309

309310
public:
@@ -580,6 +581,7 @@ class THive : public TActor<THive>, public TTabletExecutedFlat, public THiveShar
580581
void Handle(TEvHive::TEvRequestTabletDistribution::TPtr& ev);
581582
void Handle(TEvPrivate::TEvUpdateDataCenterFollowers::TPtr& ev);
582583
void Handle(TEvHive::TEvRequestScaleRecommendation::TPtr& ev);
584+
void Handle(TEvPrivate::TEvGenerateTestData::TPtr& ev);
583585
void Handle(TEvPrivate::TEvRefreshScaleRecommendation::TPtr& ev);
584586

585587
protected:

ydb/core/mind/hive/hive_ut.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace {
6060
using namespace NActors;
6161

6262
void SetupLogging(TTestActorRuntime& runtime) {
63-
NActors::NLog::EPriority priority = ENABLE_DETAILED_HIVE_LOG ? NLog::PRI_DEBUG : NLog::PRI_ERROR;
63+
NActors::NLog::EPriority priority = ENABLE_DETAILED_HIVE_LOG ? NLog::PRI_DEBUG : NLog::PRI_NOTICE;
6464
NActors::NLog::EPriority otherPriority = NLog::PRI_DEBUG;
6565

6666
if (ENABLE_DETAILED_HIVE_LOG) {
@@ -6841,6 +6841,32 @@ Y_UNIT_TEST_SUITE(THiveTest) {
68416841
}
68426842
}
68436843

6844+
Y_UNIT_TEST_SUITE(THeavyPerfTest) {
6845+
Y_UNIT_TEST(TTestLoadEverything) {
6846+
TTestBasicRuntime runtime(2, false);
6847+
Setup(runtime, true);
6848+
const ui64 hiveTablet = MakeDefaultHiveID();
6849+
CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
6850+
NTestSuiteTHiveTest::MakeSureTabletIsUp(runtime, hiveTablet, 0);
6851+
TActorId senderB = runtime.AllocateEdgeActor(0);
6852+
runtime.SendToPipe(hiveTablet, senderB, new NHive::TEvPrivate::TEvGenerateTestData(), 0, GetPipeConfigWithRetries());
6853+
{
6854+
TDispatchOptions options;
6855+
options.FinalEvents.emplace_back(TEvTablet::TEvCommit::EventType, 2);
6856+
runtime.DispatchEvents(options);
6857+
}
6858+
6859+
runtime.Register(CreateTabletKiller(hiveTablet));
6860+
6861+
{
6862+
TDispatchOptions options;
6863+
options.FinalEvents.emplace_back(NHive::TEvPrivate::EvBootTablets);
6864+
runtime.DispatchEvents(options);
6865+
}
6866+
6867+
}
6868+
}
6869+
68446870
Y_UNIT_TEST_SUITE(TStorageBalanceTest) {
68456871
static constexpr i64 DEFAULT_BIND_SIZE = 100'000'000;
68466872
const std::vector<TString> STORAGE_POOLS = {"def1"};

ydb/core/mind/hive/leader_tablet_info.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ TActorId TLeaderTabletInfo::SetLockedToActor(const TActorId& actor, const TDurat
201201
}
202202

203203
void TLeaderTabletInfo::AcquireAllocationUnits() {
204-
for (ui32 channel = 0; channel < TabletStorageInfo->Channels.size(); ++channel) {
205-
AcquireAllocationUnit(channel);
204+
for (const auto& channel : TabletStorageInfo->Channels) {
205+
if (!channel.History.empty()) {
206+
TStoragePoolInfo& storagePool = Hive.GetStoragePool(channel.StoragePool);
207+
storagePool.AcquireAllocationUnit(this, channel.Channel, channel.History.back().GroupID);
208+
}
206209
}
207210
}
208211

ydb/core/mind/hive/leader_tablet_info.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ struct TTabletCategoryInfo {
2323
struct TStoragePoolInfo;
2424

2525
struct TLeaderTabletInfo : TTabletInfo {
26-
protected:
26+
public:
2727
static TString DEFAULT_STORAGE_POOL_NAME;
2828

29-
public:
3029
struct TChannel {
3130
TTabletId TabletId;
3231
ui32 ChannelId;

ydb/core/mind/hive/storage_group_info.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "hive.h"
44
#include "leader_tablet_info.h"
55

6+
#include <library/cpp/containers/absl_flat_hash/flat_hash_set.h>
7+
68
namespace NKikimr {
79
namespace NHive {
810

@@ -42,7 +44,7 @@ struct TChannelHash {
4244
struct TStorageGroupInfo {
4345
const TStoragePoolInfo& StoragePool;
4446
TStorageGroupId Id;
45-
std::unordered_set<TLeaderTabletInfo::TChannel, TChannelHash> Units;
47+
absl::flat_hash_set<TLeaderTabletInfo::TChannel, TChannelHash> Units;
4648
TStorageResources AcquiredResources;
4749
TStorageResources MaximumResources;
4850
NKikimrBlobStorage::TEvControllerSelectGroupsResult::TGroupParameters GroupParameters;

ydb/core/mind/hive/storage_pool_info.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ TStoragePoolInfo::TStoragePoolInfo(const TString& name, THiveSharedSettings* hiv
1414
}
1515

1616
TStorageGroupInfo& TStoragePoolInfo::GetStorageGroup(TStorageGroupId groupId) {
17-
auto it = Groups.find(groupId);
17+
decltype(Groups)::insert_ctx ctx;
18+
auto it = Groups.find(groupId, ctx);
1819
if (it == Groups.end()) {
19-
it = Groups.emplace(std::piecewise_construct, std::tuple<TStorageGroupId>(groupId), std::tuple<const TStoragePoolInfo&, TStorageGroupId>(*this, groupId)).first;
20+
it = Groups.emplace_direct(ctx, std::piecewise_construct, std::tuple<TStorageGroupId>(groupId), std::tuple<const TStoragePoolInfo&, TStorageGroupId>(*this, groupId));
2021
}
2122
return it->second;
2223
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "hive_impl.h"
2+
#include "hive_log.h"
3+
4+
namespace NKikimr {
5+
namespace NHive {
6+
7+
class TTxGenerateTestData : public TTransactionBase<THive> {
8+
public:
9+
TTxGenerateTestData(THive *hive, uint64_t seed)
10+
: TBase(hive)
11+
, Seed(seed)
12+
{}
13+
14+
TTxType GetTxType() const override { return -1; }
15+
16+
const std::vector<TString> STORAGE_POOLS = {"def1", "def2", "def3", "def4", "def5", "def6", "def7"};
17+
static constexpr size_t NUM_TABLETS = 250'000;
18+
static constexpr size_t NUM_GROUPS = 30'000;
19+
20+
uint64_t Seed;
21+
22+
bool Execute(TTransactionContext &txc, const TActorContext&) override {
23+
NIceDb::TNiceDb db(txc.DB);
24+
25+
std::mt19937 engine(Seed);
26+
TTabletId nextTabletId = 0x10000 + NUM_TABLETS * Seed;
27+
std::uniform_int_distribution<size_t> getNumChannels(1, 10);
28+
std::uniform_int_distribution<TStorageGroupId> getGroup(1, NUM_GROUPS);
29+
30+
31+
for (size_t i = 0; i < NUM_TABLETS; ++i) {
32+
auto tabletId = nextTabletId++;
33+
db.Table<Schema::Tablet>().Key(tabletId).Update<Schema::Tablet::KnownGeneration>(1);
34+
auto numChannels = getNumChannels(engine);
35+
for (size_t channel = 0; channel < numChannels; ++channel) {
36+
auto groupId = getGroup(engine);
37+
auto storagePool = STORAGE_POOLS[(groupId - 1) * STORAGE_POOLS.size() / NUM_GROUPS];
38+
db.Table<Schema::TabletChannel>().Key(tabletId, channel).Update<Schema::TabletChannel::StoragePool>(storagePool);
39+
db.Table<Schema::TabletChannelGen>().Key(tabletId, channel, 1).Update<Schema::TabletChannelGen::Group>(groupId);
40+
}
41+
}
42+
43+
return true;
44+
}
45+
46+
void Complete(const TActorContext&) override {}
47+
};
48+
49+
ITransaction* THive::CreateGenerateTestData(uint64_t seed) {
50+
return new TTxGenerateTestData(this, seed);
51+
}
52+
53+
} // NHive
54+
} // NKikimr

ydb/core/mind/hive/tx__load_everything.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class TTxLoadEverything : public TTransactionBase<THive> {
201201
auto end = owners.GetValue<Schema::TabletOwners::End>();
202202
auto ownerId = owners.GetValue<Schema::TabletOwners::OwnerId>();
203203

204-
Self->Keeper.AddOwnedSequence(ownerId, {begin, end});
204+
Self->Keeper.AddOwnedSequence(ownerId, {begin, end});
205205
if (!owners.Next()) {
206206
return false;
207207
}
@@ -489,6 +489,9 @@ class TTxLoadEverything : public TTransactionBase<THive> {
489489
if (tablet) {
490490
ui32 channelId = tabletChannelRowset.GetValue<Schema::TabletChannel::Channel>();
491491
TString storagePool = tabletChannelRowset.GetValue<Schema::TabletChannel::StoragePool>();
492+
if (storagePool.empty()) {
493+
storagePool = TLeaderTabletInfo::DEFAULT_STORAGE_POOL_NAME;
494+
}
492495
Y_ABORT_UNLESS(tablet->BoundChannels.size() == channelId);
493496
tablet->BoundChannels.emplace_back();
494497
NKikimrStoragePool::TChannelBind& bind = tablet->BoundChannels.back();

0 commit comments

Comments
 (0)