@@ -722,11 +722,10 @@ void TPersQueueReadBalancer::HandleOnInit(TEvPersQueue::TEvGetPartitionsLocation
722
722
}
723
723
724
724
void TPersQueueReadBalancer::Handle (TEvPersQueue::TEvGetPartitionsLocation::TPtr& ev, const TActorContext& ctx) {
725
- auto * evResponse = new TEvPersQueue::TEvGetPartitionsLocationResponse ();
726
725
const auto & request = ev->Get ()->Record ;
726
+ auto evResponse = std::make_unique<TEvPersQueue::TEvGetPartitionsLocationResponse>();
727
+
727
728
auto addPartitionToResponse = [&](ui64 partitionId, ui64 tabletId) {
728
- auto * pResponse = evResponse->Record .AddLocations ();
729
- pResponse->SetPartitionId (partitionId);
730
729
if (PipesRequested.contains (tabletId)) {
731
730
return false ;
732
731
}
@@ -735,36 +734,48 @@ void TPersQueueReadBalancer::Handle(TEvPersQueue::TEvGetPartitionsLocation::TPtr
735
734
GetPipeClient (tabletId, ctx);
736
735
return false ;
737
736
}
737
+
738
+ auto * pResponse = evResponse->Record .AddLocations ();
739
+ pResponse->SetPartitionId (partitionId);
738
740
pResponse->SetNodeId (iter->second .NodeId .GetRef ());
739
741
pResponse->SetGeneration (iter->second .Generation .GetRef ());
740
742
741
- PQ_LOG_D (" addPartitionToResponse tabletId " << tabletId << " , partitionId " << partitionId
743
+ PQ_LOG_D (" The partition location was added to response: TabletId " << tabletId << " , PartitionId " << partitionId
742
744
<< " , NodeId " << pResponse->GetNodeId () << " , Generation " << pResponse->GetGeneration ());
745
+
743
746
return true ;
744
747
};
745
- auto sendResponse = [&](bool status) {
746
- evResponse->Record .SetStatus (status);
747
- ctx.Send (ev->Sender , evResponse);
748
+
749
+ auto sendError = [&]() {
750
+ auto response = std::make_unique<TEvPersQueue::TEvGetPartitionsLocationResponse>();
751
+ response->Record .SetStatus (false );
752
+ ctx.Send (ev->Sender , response.release ());
748
753
};
749
- bool ok = true ;
754
+
750
755
if (request.PartitionsSize () == 0 ) {
751
756
if (!PipesRequested.empty () || TabletPipes.size () < TabletsInfo.size ()) {
752
757
// Do not have all pipes connected.
753
- return sendResponse ( false );
758
+ return sendError ( );
754
759
}
755
760
for (const auto & [partitionId, partitionInfo] : PartitionsInfo) {
756
- ok = addPartitionToResponse (partitionId, partitionInfo.TabletId ) && ok;
761
+ if (!addPartitionToResponse (partitionId, partitionInfo.TabletId )) {
762
+ return sendError ();
763
+ }
757
764
}
758
765
} else {
759
766
for (const auto & partitionInRequest : request.GetPartitions ()) {
760
767
auto partitionInfoIter = PartitionsInfo.find (partitionInRequest);
761
768
if (partitionInfoIter == PartitionsInfo.end ()) {
762
- return sendResponse (false );
769
+ return sendError ();
770
+ }
771
+ if (!addPartitionToResponse (partitionInRequest, partitionInfoIter->second .TabletId )) {
772
+ return sendError ();
763
773
}
764
- ok = addPartitionToResponse (partitionInRequest, partitionInfoIter->second .TabletId ) && ok;
765
774
}
766
775
}
767
- return sendResponse (ok);
776
+
777
+ evResponse->Record .SetStatus (true );
778
+ ctx.Send (ev->Sender , evResponse.release ());
768
779
}
769
780
770
781
0 commit comments