@@ -36,11 +36,10 @@ void TKafkaReadSessionActor::HandleWakeup(TEvKafka::TEvWakeup::TPtr, const TActo
36
36
return ;
37
37
}
38
38
39
- for (auto & topicToPartitions: NewPartitionsToLockOnTime) {
40
- auto & partitions = topicToPartitions.second ;
39
+ for (auto & [topicName, partitions]: NewPartitionsToLockOnTime) {
41
40
for (auto partitionsIt = partitions.begin (); partitionsIt != partitions.end (); ) {
42
41
if (partitionsIt->LockOn <= ctx.Now ()) {
43
- TopicPartitions[topicToPartitions. first ].ToLock .emplace (partitionsIt->PartitionId );
42
+ TopicPartitions[topicName ].ToLock .emplace (partitionsIt->PartitionId );
44
43
NeedRebalance = true ;
45
44
partitionsIt = partitions.erase (partitionsIt);
46
45
} else {
@@ -408,6 +407,8 @@ void TKafkaReadSessionActor::HandlePipeDestroyed(TEvTabletPipe::TEvClientDestroy
408
407
}
409
408
410
409
void TKafkaReadSessionActor::ProcessBalancerDead (ui64 tabletId, const TActorContext& ctx) {
410
+ NewPartitionsToLockOnTime.clear ();
411
+
411
412
for (auto & [topicName, topicInfo] : TopicsInfo) {
412
413
if (topicInfo.TabletID == tabletId) {
413
414
auto partitionsIt = TopicPartitions.find (topicName);
@@ -579,8 +580,7 @@ void TKafkaReadSessionActor::HandleReleasePartition(TEvPersQueue::TEvReleasePart
579
580
auto newPartitionsToLockCount = newPartitionsToLockIt == NewPartitionsToLockOnTime.end () ? 0 : newPartitionsToLockIt->second .size ();
580
581
581
582
auto topicPartitionsIt = TopicPartitions.find (pathIt->second ->GetInternalName ());
582
- Y_ABORT_UNLESS (topicPartitionsIt != TopicPartitions.end ());
583
- Y_ABORT_UNLESS (record.GetCount () <= topicPartitionsIt->second .ToLock .size () + topicPartitionsIt->second .ReadingNow .size () + newPartitionsToLockCount);
583
+ Y_ABORT_UNLESS (record.GetCount () <= (topicPartitionsIt.IsEnd () ? 0 : topicPartitionsIt->second .ToLock .size () + topicPartitionsIt->second .ReadingNow .size ()) + newPartitionsToLockCount);
584
584
585
585
for (ui32 c = 0 ; c < record.GetCount (); ++c) {
586
586
// if some partition not locked yet, then release it without rebalance
@@ -599,18 +599,19 @@ void TKafkaReadSessionActor::HandleReleasePartition(TEvPersQueue::TEvReleasePart
599
599
}
600
600
601
601
NeedRebalance = true ;
602
- size_t partitionToReleaseIndex = 0 ;
603
- size_t i = 0 ;
602
+ ui32 partitionToRelease = 0 ;
603
+ ui32 i = 0 ;
604
604
605
- for (size_t partIndex = 0 ; partIndex < topicPartitionsIt->second .ReadingNow . size (); partIndex++ ) {
606
- if (!topicPartitionsIt->second .ToRelease .contains (partIndex ) && (group == 0 || partIndex + 1 == group)) {
605
+ for (auto curPartition : topicPartitionsIt->second .ReadingNow ) {
606
+ if (!topicPartitionsIt->second .ToRelease .contains (curPartition ) && (group == 0 || curPartition + 1 == group)) {
607
607
++i;
608
- if (rand () % i == 0 ) { // will lead to 1/n probability for each of n partitions
609
- partitionToReleaseIndex = partIndex ;
608
+ if (rand () % i == 0 ) {
609
+ partitionToRelease = curPartition ;
610
610
}
611
611
}
612
612
}
613
- topicPartitionsIt->second .ToRelease .emplace (partitionToReleaseIndex);
613
+
614
+ topicPartitionsIt->second .ToRelease .emplace (partitionToRelease);
614
615
}
615
616
}
616
617
0 commit comments