@@ -10,7 +10,6 @@ namespace NKikimr::NOlap::NReader::NSimple {
1010
1111void TScanHead::OnSourceReady (const std::shared_ptr<IDataSource>& source, std::shared_ptr<arrow::Table>&& tableExt, const ui32 startIndex,
1212 const ui32 recordsCount, TPlainReadData& reader) {
13-
1413 source->MutableResultRecordsCount () += tableExt ? tableExt->num_rows () : 0 ;
1514 if (!tableExt || !tableExt->num_rows ()) {
1615 AFL_DEBUG (NKikimrServices::TX_COLUMNSHARD_SCAN)(" empty_source" , source->DebugJson ().GetStringRobust ());
@@ -56,10 +55,11 @@ void TScanHead::OnSourceReady(const std::shared_ptr<IDataSource>& source, std::s
5655 AFL_VERIFY (FetchingSourcesByIdx.erase (frontSource->GetSourceIdx ()));
5756 FetchingSources.pop_front ();
5857 frontSource->ClearResult ();
59- if (Context->GetCommonContext ()->GetReadMetadata ()->HasLimit () && SortedSources. size () && frontSource-> GetResultRecordsCount () ) {
58+ if (Context->GetCommonContext ()->GetReadMetadata ()->HasLimit ()) {
6059 AFL_VERIFY (FetchingInFlightSources.erase (frontSource));
6160 AFL_VERIFY (FinishedSources.emplace (frontSource).second );
62- while (FinishedSources.size () && (*FinishedSources.begin ())->GetFinish () < SortedSources.front ()->GetStart ()) {
61+ while (FinishedSources.size () &&
62+ (SortedSources.empty () || (*FinishedSources.begin ())->GetFinish () < SortedSources.front ()->GetStart ())) {
6363 auto finishedSource = *FinishedSources.begin ();
6464 if (!finishedSource->GetResultRecordsCount () && InFlightLimit < MaxInFlight) {
6565 InFlightLimit = 2 * InFlightLimit;
@@ -90,10 +90,8 @@ TConclusionStatus TScanHead::Start() {
9090
9191TScanHead::TScanHead (std::deque<std::shared_ptr<IDataSource>>&& sources, const std::shared_ptr<TSpecialReadContext>& context)
9292 : Context(context) {
93- if (HasAppData ()) {
94- if (AppDataVerified ().ColumnShardConfig .HasMaxInFlightIntervalsOnRequest ()) {
95- MaxInFlight = AppDataVerified ().ColumnShardConfig .GetMaxInFlightIntervalsOnRequest ();
96- }
93+ if (HasAppData () && AppDataVerified ().ColumnShardConfig .HasMaxInFlightIntervalsOnRequest ()) {
94+ MaxInFlight = AppDataVerified ().ColumnShardConfig .GetMaxInFlightIntervalsOnRequest ();
9795 }
9896 if (Context->GetReadMetadata ()->HasLimit ()) {
9997 InFlightLimit = 1 ;
@@ -121,45 +119,51 @@ TConclusion<bool> TScanHead::BuildNextInterval() {
121119 if (!Context->IsActive ()) {
122120 return false ;
123121 }
124- if (InFlightLimit <= IntervalsInFlightCount) {
125- return false ;
126- }
127122 if (SortedSources.size () == 0 ) {
128123 return false ;
129124 }
130125 bool changed = false ;
131- ui32 inFlightCountLocal = 0 ;
132- if (SortedSources.size ()) {
126+ if (!Context->GetCommonContext ()->GetReadMetadata ()->HasLimit ()) {
127+ while (SortedSources.size () && FetchingSources.size () < InFlightLimit) {
128+ SortedSources.front ()->StartProcessing (SortedSources.front ());
129+ FetchingSources.emplace_back (SortedSources.front ());
130+ AFL_VERIFY (FetchingSourcesByIdx.emplace (SortedSources.front ()->GetSourceIdx (), SortedSources.front ()).second );
131+ SortedSources.pop_front ();
132+ changed = true ;
133+ }
134+ } else {
135+ if (InFlightLimit <= IntervalsInFlightCount) {
136+ return false ;
137+ }
138+ ui32 inFlightCountLocal = 0 ;
133139 for (auto it = FetchingInFlightSources.begin (); it != FetchingInFlightSources.end (); ++it) {
134- if ((*it)->GetFinish () < SortedSources.front ()->GetStart ()) {
140+ if (SortedSources. empty () || (*it)->GetFinish () < SortedSources.front ()->GetStart ()) {
135141 ++inFlightCountLocal;
136142 } else {
137143 break ;
138144 }
139145 }
140- }
141- AFL_VERIFY (IntervalsInFlightCount == inFlightCountLocal)(" count_global" , IntervalsInFlightCount)(" count_local" , inFlightCountLocal);
142- while (SortedSources.size () && inFlightCountLocal < InFlightLimit) {
143- SortedSources.front ()->StartProcessing (SortedSources.front ());
144- FetchingSources.emplace_back (SortedSources.front ());
145- FetchingSourcesByIdx.emplace (SortedSources.front ()->GetSourceIdx (), SortedSources.front ());
146- AFL_VERIFY (FetchingInFlightSources.emplace (SortedSources.front ()).second );
147- SortedSources.pop_front ();
148- if (SortedSources.size ()) {
146+ AFL_VERIFY (IntervalsInFlightCount == inFlightCountLocal)(" count_global" , IntervalsInFlightCount)(" count_local" , inFlightCountLocal);
147+ while (SortedSources.size () && inFlightCountLocal < InFlightLimit) {
148+ SortedSources.front ()->StartProcessing (SortedSources.front ());
149+ FetchingSources.emplace_back (SortedSources.front ());
150+ AFL_VERIFY (FetchingSourcesByIdx.emplace (SortedSources.front ()->GetSourceIdx (), SortedSources.front ()).second );
151+ AFL_VERIFY (FetchingInFlightSources.emplace (SortedSources.front ()).second );
152+ SortedSources.pop_front ();
149153 ui32 inFlightCountLocalNew = 0 ;
150154 for (auto it = FetchingInFlightSources.begin (); it != FetchingInFlightSources.end (); ++it) {
151- if ((*it)->GetFinish () < SortedSources.front ()->GetStart ()) {
155+ if (SortedSources. empty () || (*it)->GetFinish () < SortedSources.front ()->GetStart ()) {
152156 ++inFlightCountLocalNew;
153157 } else {
154158 break ;
155159 }
156160 }
157161 AFL_VERIFY (inFlightCountLocal <= inFlightCountLocalNew);
158162 inFlightCountLocal = inFlightCountLocalNew;
163+ changed = true ;
159164 }
160- changed = true ;
165+ IntervalsInFlightCount = inFlightCountLocal ;
161166 }
162- IntervalsInFlightCount = inFlightCountLocal;
163167 return changed;
164168}
165169
0 commit comments