@@ -76,14 +76,19 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
76
76
const auto & domainKey = ev->Get ()->DomainKey ;
77
77
const auto & pathId = ev->Get ()->PathId ;
78
78
79
+ SVLOG_T (" TEvSysView::TEvSetPartitioning: domainKey " << domainKey
80
+ << " pathId " << pathId
81
+ << " path " << ev->Get ()->Path
82
+ << " ShardIndices size " << ev->Get ()->ShardIndices .size ());
83
+
79
84
auto & tables = DomainTables[domainKey];
80
85
auto tableFound = tables.Stats .find (pathId);
81
86
if (tableFound != tables.Stats .end ()) {
82
87
auto & table = tableFound->second ;
83
88
84
89
auto & oldPartitions = table.Partitions ;
85
90
std::unordered_map<TShardIdx, TPartitionStats> newPartitions;
86
- std::unordered_set<TShardIdx > overloaded;
91
+ std::set<TOverloadedFollower > overloaded;
87
92
88
93
for (auto shardIdx : ev->Get ()->ShardIndices ) {
89
94
auto old = oldPartitions.find (shardIdx);
@@ -92,7 +97,7 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
92
97
93
98
for (const auto & followerStat: old->second .FollowerStats ) {
94
99
if (IsPartitionOverloaded (followerStat.second ))
95
- overloaded.insert (shardIdx);
100
+ overloaded.insert ({ shardIdx, followerStat. first } );
96
101
}
97
102
}
98
103
}
@@ -148,12 +153,13 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
148
153
149
154
auto & followerStats = partitionStats.FollowerStats [followerId];
150
155
156
+ TOverloadedFollower overloadedFollower = {shardIdx, followerId};
151
157
if (IsPartitionOverloaded (newStats)) {
152
- tables.Overloaded [pathId].insert (shardIdx );
158
+ tables.Overloaded [pathId].insert (overloadedFollower );
153
159
} else {
154
160
auto overloadedFound = tables.Overloaded .find (pathId);
155
161
if (overloadedFound != tables.Overloaded .end ()) {
156
- overloadedFound->second .erase (shardIdx );
162
+ overloadedFound->second .erase (overloadedFollower );
157
163
if (overloadedFound->second .empty ()) {
158
164
tables.Overloaded .erase (pathId);
159
165
}
@@ -373,15 +379,16 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
373
379
struct TPartition {
374
380
TPathId PathId;
375
381
TShardIdx ShardIdx;
382
+ ui32 FollowerId;
376
383
double CPUCores;
377
384
};
378
385
std::vector<TPartition> sorted;
379
386
380
- for (const auto & [pathId, shardIndices ] : domainTables.Overloaded ) {
381
- for (const auto & shardIdx : shardIndices ) {
387
+ for (const auto & [pathId, overloadedFollowers ] : domainTables.Overloaded ) {
388
+ for (const TOverloadedFollower& overloadedFollower : overloadedFollowers ) {
382
389
const auto & table = domainTables.Stats [pathId];
383
- const auto & partition = table.Partitions .at (shardIdx ).FollowerStats .at (0 );
384
- sorted.emplace_back (TPartition{pathId, shardIdx , partition.GetCPUCores ()});
390
+ const auto & partition = table.Partitions .at (overloadedFollower. ShardIdx ).FollowerStats .at (overloadedFollower. FollowerId );
391
+ sorted.emplace_back (TPartition{pathId, overloadedFollower. ShardIdx , overloadedFollower. FollowerId , partition.GetCPUCores ()});
385
392
}
386
393
}
387
394
@@ -395,18 +402,21 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
395
402
auto sendEvent = MakeHolder<TEvSysView::TEvSendTopPartitions>();
396
403
for (const auto & entry : sorted) {
397
404
const auto & table = domainTables.Stats [entry.PathId ];
398
- const auto & partition = table.Partitions .at (entry.ShardIdx ).FollowerStats .at (0 );
405
+ const auto & followerStats = table.Partitions .at (entry.ShardIdx ).FollowerStats ;
406
+ const auto & partition = followerStats.at (entry.FollowerId );
407
+ const auto & leaderPartition = followerStats.at (0 );
399
408
400
409
auto * result = sendEvent->Record .AddPartitions ();
401
410
result->SetTabletId (partition.GetTabletId ());
402
411
result->SetPath (table.Path );
403
412
result->SetPeakTimeUs (nowUs);
404
413
result->SetCPUCores (partition.GetCPUCores ());
405
414
result->SetNodeId (partition.GetNodeId ());
406
- result->SetDataSize (partition .GetDataSize ());
407
- result->SetRowCount (partition .GetRowCount ());
408
- result->SetIndexSize (partition .GetIndexSize ());
415
+ result->SetDataSize (leaderPartition .GetDataSize ());
416
+ result->SetRowCount (leaderPartition .GetRowCount ());
417
+ result->SetIndexSize (leaderPartition .GetIndexSize ());
409
418
result->SetInFlightTxCount (partition.GetInFlightTxCount ());
419
+ result->SetFollowerId (partition.GetFollowerId ());
410
420
411
421
if (++count == TOP_PARTITIONS_COUNT) {
412
422
break ;
@@ -438,8 +448,7 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
438
448
}
439
449
440
450
bool IsPartitionOverloaded (const NKikimrSysView::TPartitionStats& stats) const {
441
- return stats.GetCPUCores () >= OverloadedPartitionBound
442
- && !stats.GetFollowerId ();
451
+ return stats.GetCPUCores () >= OverloadedPartitionBound;
443
452
}
444
453
445
454
private:
@@ -452,8 +461,10 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
452
461
double OverloadedPartitionBound = 0.7 ;
453
462
TDuration ProcessOverloadedInterval = TDuration::Seconds(15 );
454
463
464
+ typedef ui32 TFollowerId;
465
+
455
466
struct TPartitionStats {
456
- std::unordered_map<ui32 , NKikimrSysView::TPartitionStats> FollowerStats;
467
+ std::unordered_map<TFollowerId , NKikimrSysView::TPartitionStats> FollowerStats;
457
468
};
458
469
459
470
struct TTableStats {
@@ -462,9 +473,22 @@ class TPartitionStatsCollector : public TActorBootstrapped<TPartitionStatsCollec
462
473
TString Path;
463
474
};
464
475
476
+ struct TOverloadedFollower {
477
+ TShardIdx ShardIdx;
478
+ TFollowerId FollowerId;
479
+
480
+ bool operator <(const TOverloadedFollower &other) const {
481
+ return std::tie (ShardIdx, FollowerId) < std::tie (other.ShardIdx , other.FollowerId );
482
+ }
483
+
484
+ bool operator ==(const TOverloadedFollower &other) const {
485
+ return std::tie (ShardIdx, FollowerId) == std::tie (other.ShardIdx , other.FollowerId );
486
+ }
487
+ };
488
+
465
489
struct TDomainTables {
466
490
std::map<TPathId, TTableStats> Stats;
467
- std::unordered_map<TPathId, std::unordered_set<TShardIdx >> Overloaded;
491
+ std::unordered_map<TPathId, std::set<TOverloadedFollower >> Overloaded;
468
492
};
469
493
std::unordered_map<TPathId, TDomainTables> DomainTables;
470
494
0 commit comments