@@ -46,6 +46,7 @@ class ISourcesCollection {
46
46
}
47
47
48
48
void OnSourceFinished (const std::shared_ptr<IDataSource>& source) {
49
+ AFL_VERIFY (source);
49
50
SourcesInFlightCount.Dec ();
50
51
DoOnSourceFinished (source);
51
52
}
@@ -61,11 +62,14 @@ class ISourcesCollection {
61
62
ISourcesCollection (const std::shared_ptr<TSpecialReadContext>& context);
62
63
};
63
64
64
- class TNotSortedFullScanCollection : public ISourcesCollection {
65
+ class TNotSortedCollection : public ISourcesCollection {
65
66
private:
66
67
using TBase = ISourcesCollection;
68
+ std::optional<ui32> Limit;
69
+ ui32 InFlightLimit = 1 ;
67
70
std::deque<TSourceConstructor> Sources;
68
71
TPositiveControlInteger InFlightCount;
72
+ ui32 FetchedCount = 0 ;
69
73
virtual void DoClear () override {
70
74
Sources.clear ();
71
75
}
@@ -81,16 +85,31 @@ class TNotSortedFullScanCollection: public ISourcesCollection {
81
85
return result;
82
86
}
83
87
virtual bool DoCheckInFlightLimits () const override {
84
- return InFlightCount < GetMaxInFlight () ;
88
+ return InFlightCount < InFlightLimit ;
85
89
}
86
- virtual void DoOnSourceFinished (const std::shared_ptr<IDataSource>& /* source*/ ) override {
90
+ virtual void DoOnSourceFinished (const std::shared_ptr<IDataSource>& source) override {
91
+ if (!source->GetResultRecordsCount () && InFlightLimit * 2 < GetMaxInFlight ()) {
92
+ InFlightLimit *= 2 ;
93
+ }
94
+ FetchedCount += source->GetResultRecordsCount ();
95
+ if (Limit && *Limit <= FetchedCount && Sources.size ()) {
96
+ AFL_NOTICE (NKikimrServices::TX_COLUMNSHARD)(" event" , " limit_exhausted" )(" limit" , Limit)(" fetched" , FetchedCount);
97
+ Sources.clear ();
98
+ }
87
99
InFlightCount.Dec ();
88
100
}
89
101
90
102
public:
91
- TNotSortedFullScanCollection (const std::shared_ptr<TSpecialReadContext>& context, std::deque<TSourceConstructor>&& sources,
92
- const std::shared_ptr<IScanCursor>& cursor)
93
- : TBase(context) {
103
+ TNotSortedCollection (const std::shared_ptr<TSpecialReadContext>& context, std::deque<TSourceConstructor>&& sources,
104
+ const std::shared_ptr<IScanCursor>& cursor, const std::optional<ui32> limit)
105
+ : TBase(context)
106
+ , Limit(limit)
107
+ {
108
+ if (Limit) {
109
+ InFlightLimit = 1 ;
110
+ } else {
111
+ InFlightLimit = GetMaxInFlight ();
112
+ }
94
113
if (cursor && cursor->IsInitialized ()) {
95
114
while (sources.size ()) {
96
115
bool usage = false ;
0 commit comments