@@ -396,6 +396,9 @@ void TPartitionFamily::InactivatePartition(ui32 partitionId) {
396
396
}
397
397
398
398
void TPartitionFamily::ChangePartitionCounters (ssize_t active, ssize_t inactive) {
399
+ Y_VERIFY_DEBUG ((ssize_t )ActivePartitionCount + active >= 0 );
400
+ Y_VERIFY_DEBUG ((ssize_t )InactivePartitionCount + inactive >= 0 );
401
+
399
402
ActivePartitionCount += active;
400
403
InactivePartitionCount += inactive;
401
404
@@ -985,7 +988,7 @@ bool TConsumer::SetCommittedState(ui32 partitionId, ui32 generation, ui64 cookie
985
988
return Partitions[partitionId].SetCommittedState (generation, cookie);
986
989
}
987
990
988
- bool TConsumer::ProccessReadingFinished (ui32 partitionId, const TActorContext& ctx) {
991
+ bool TConsumer::ProccessReadingFinished (ui32 partitionId, bool wasInactive, const TActorContext& ctx) {
989
992
if (!ScalingSupport ()) {
990
993
return false ;
991
994
}
@@ -996,7 +999,9 @@ bool TConsumer::ProccessReadingFinished(ui32 partitionId, const TActorContext& c
996
999
if (!family) {
997
1000
return false ;
998
1001
}
999
- family->InactivatePartition (partitionId);
1002
+ if (!wasInactive) {
1003
+ family->InactivatePartition (partitionId);
1004
+ }
1000
1005
1001
1006
if (!family->IsLonely () && partition.Commited ) {
1002
1007
if (BreakUpFamily (family, partitionId, false , ctx)) {
@@ -1065,8 +1070,13 @@ void TConsumer::StartReading(ui32 partitionId, const TActorContext& ctx) {
1065
1070
}
1066
1071
1067
1072
auto * partition = GetPartition (partitionId);
1073
+ if (!partition) {
1074
+ LOG_DEBUG_S (ctx, NKikimrServices::PERSQUEUE_READ_BALANCER,
1075
+ GetPrefix () << " Reading of the partition " << partitionId << " was started by " << ConsumerName << " ." );
1076
+ }
1068
1077
1069
- if (partition && partition->StartReading ()) {
1078
+ auto wasInactive = partition->IsInactive ();
1079
+ if (partition->StartReading ()) {
1070
1080
LOG_DEBUG_S (ctx, NKikimrServices::PERSQUEUE_READ_BALANCER,
1071
1081
GetPrefix () << " Reading of the partition " << partitionId << " was started by " << ConsumerName << " . We stop reading from child partitions." );
1072
1082
@@ -1080,7 +1090,9 @@ void TConsumer::StartReading(ui32 partitionId, const TActorContext& ctx) {
1080
1090
return ;
1081
1091
}
1082
1092
1083
- family->ActivatePartition (partitionId);
1093
+ if (wasInactive) {
1094
+ family->ActivatePartition (partitionId);
1095
+ }
1084
1096
1085
1097
// We releasing all children's partitions because we don't start reading the partition from EndOffset
1086
1098
GetPartitionGraph ().Travers (partitionId, [&](ui32 partitionId) {
@@ -1097,8 +1109,6 @@ void TConsumer::StartReading(ui32 partitionId, const TActorContext& ctx) {
1097
1109
return true ;
1098
1110
});
1099
1111
} else {
1100
- LOG_DEBUG_S (ctx, NKikimrServices::PERSQUEUE_READ_BALANCER,
1101
- GetPrefix () << " Reading of the partition " << partitionId << " was started by " << ConsumerName << " ." );
1102
1112
}
1103
1113
}
1104
1114
@@ -1139,7 +1149,7 @@ void TConsumer::FinishReading(TEvPersQueue::TEvReadingPartitionFinishedRequest::
1139
1149
GetPrefix () << " Reading of the partition " << partitionId << " was finished by " << r.GetConsumer ()
1140
1150
<< " , firstMessage=" << r.GetStartedReadingFromEndOffset () << " , " << GetSdkDebugString0 (r.GetScaleAwareSDK ()));
1141
1151
1142
- if (ProccessReadingFinished (partitionId, ctx)) {
1152
+ if (ProccessReadingFinished (partitionId, false , ctx)) {
1143
1153
ScheduleBalance (ctx);
1144
1154
}
1145
1155
} else if (!partition.IsInactive ()) {
@@ -1540,11 +1550,12 @@ bool TBalancer::SetCommittedState(const TString& consumerName, ui32 partitionId,
1540
1550
return false ;
1541
1551
}
1542
1552
1553
+ auto wasInactive = consumer->IsInactive (partitionId);
1543
1554
if (consumer->SetCommittedState (partitionId, generation, cookie)) {
1544
1555
LOG_DEBUG_S (ctx, NKikimrServices::PERSQUEUE_READ_BALANCER,
1545
1556
GetPrefix () << " The offset of the partition " << partitionId << " was commited by " << consumerName);
1546
1557
1547
- if (consumer->ProccessReadingFinished (partitionId, ctx)) {
1558
+ if (consumer->ProccessReadingFinished (partitionId, wasInactive, ctx)) {
1548
1559
consumer->ScheduleBalance (ctx);
1549
1560
}
1550
1561
0 commit comments