@@ -228,32 +228,32 @@ public void close() {
228228 }
229229
230230 class SegmentsIterator {
231- private final PriorityQueue <Leaf > mainQueue ;
232- private final PriorityQueue <Leaf > oneTsidQueue ;
231+ private final PriorityQueue <LeafIterator > mainQueue ;
232+ private final PriorityQueue <LeafIterator > oneTsidQueue ;
233233 final int [] docPerSegments ;
234234 final LuceneSlice luceneSlice ;
235235
236236 SegmentsIterator (LuceneSlice luceneSlice ) throws IOException {
237237 this .luceneSlice = luceneSlice ;
238238 this .mainQueue = new PriorityQueue <>(luceneSlice .numLeaves ()) {
239239 @ Override
240- protected boolean lessThan (Leaf a , Leaf b ) {
240+ protected boolean lessThan (LeafIterator a , LeafIterator b ) {
241241 return a .timeSeriesHash .compareTo (b .timeSeriesHash ) < 0 ;
242242 }
243243 };
244244 Weight weight = luceneSlice .weight ();
245245 int maxSegmentOrd = 0 ;
246246 for (var leafReaderContext : luceneSlice .leaves ()) {
247- Leaf leaf = new Leaf (weight , leafReaderContext .leafReaderContext ());
248- leaf .nextDoc ();
249- if (leaf .docID != DocIdSetIterator .NO_MORE_DOCS ) {
250- mainQueue .add (leaf );
251- maxSegmentOrd = Math .max (maxSegmentOrd , leaf .segmentOrd );
247+ LeafIterator leafIterator = new LeafIterator (weight , leafReaderContext .leafReaderContext ());
248+ leafIterator .nextDoc ();
249+ if (leafIterator .docID != DocIdSetIterator .NO_MORE_DOCS ) {
250+ mainQueue .add (leafIterator );
251+ maxSegmentOrd = Math .max (maxSegmentOrd , leafIterator .segmentOrd );
252252 }
253253 }
254254 this .oneTsidQueue = new PriorityQueue <>(mainQueue .size ()) {
255255 @ Override
256- protected boolean lessThan (Leaf a , Leaf b ) {
256+ protected boolean lessThan (LeafIterator a , LeafIterator b ) {
257257 return a .timestamp > b .timestamp ;
258258 }
259259 };
@@ -264,14 +264,14 @@ protected boolean lessThan(Leaf a, Leaf b) {
264264 void readDocsForNextPage () throws IOException {
265265 Arrays .fill (docPerSegments , 0 );
266266 Thread executingThread = Thread .currentThread ();
267- for (Leaf leaf : mainQueue ) {
267+ for (LeafIterator leaf : mainQueue ) {
268268 leaf .reinitializeIfNeeded (executingThread );
269269 }
270- for (Leaf leaf : oneTsidQueue ) {
270+ for (LeafIterator leaf : oneTsidQueue ) {
271271 leaf .reinitializeIfNeeded (executingThread );
272272 }
273273 do {
274- PriorityQueue <Leaf > sub = subQueueForNextTsid ();
274+ PriorityQueue <LeafIterator > sub = subQueueForNextTsid ();
275275 if (sub .size () == 0 ) {
276276 break ;
277277 }
@@ -282,9 +282,9 @@ void readDocsForNextPage() throws IOException {
282282 } while (mainQueue .size () > 0 );
283283 }
284284
285- private boolean readValuesForOneTsid (PriorityQueue <Leaf > sub ) throws IOException {
285+ private boolean readValuesForOneTsid (PriorityQueue <LeafIterator > sub ) throws IOException {
286286 do {
287- Leaf top = sub .top ();
287+ LeafIterator top = sub .top ();
288288 currentPagePos ++;
289289 remainingDocs --;
290290 segmentsBuilder .appendInt (top .segmentOrd );
@@ -306,9 +306,9 @@ private boolean readValuesForOneTsid(PriorityQueue<Leaf> sub) throws IOException
306306 return false ;
307307 }
308308
309- private PriorityQueue <Leaf > subQueueForNextTsid () {
309+ private PriorityQueue <LeafIterator > subQueueForNextTsid () {
310310 if (oneTsidQueue .size () == 0 && mainQueue .size () > 0 ) {
311- Leaf last = mainQueue .pop ();
311+ LeafIterator last = mainQueue .pop ();
312312 oneTsidQueue .add (last );
313313 while (mainQueue .size () > 0 ) {
314314 var top = mainQueue .top ();
@@ -327,10 +327,10 @@ boolean completed() {
327327 }
328328 }
329329
330- static class Leaf {
330+ static class LeafIterator {
331331 private final int segmentOrd ;
332332 private final Weight weight ;
333- private final LeafReaderContext leaf ;
333+ private final LeafReaderContext leafContext ;
334334 private SortedDocValues tsids ;
335335 private NumericDocValues timestamps ;
336336 private DocIdSetIterator disi ;
@@ -341,14 +341,14 @@ static class Leaf {
341341 private BytesRef timeSeriesHash ;
342342 private int docID = -1 ;
343343
344- Leaf (Weight weight , LeafReaderContext leaf ) throws IOException {
345- this .segmentOrd = leaf .ord ;
344+ LeafIterator (Weight weight , LeafReaderContext leafContext ) throws IOException {
345+ this .segmentOrd = leafContext .ord ;
346346 this .weight = weight ;
347- this .leaf = leaf ;
347+ this .leafContext = leafContext ;
348348 this .createdThread = Thread .currentThread ();
349- tsids = leaf .reader ().getSortedDocValues ("_tsid" );
350- timestamps = DocValues .unwrapSingleton (leaf .reader ().getSortedNumericDocValues ("@timestamp" ));
351- final Scorer scorer = weight .scorer (leaf );
349+ tsids = leafContext .reader ().getSortedDocValues ("_tsid" );
350+ timestamps = DocValues .unwrapSingleton (leafContext .reader ().getSortedNumericDocValues ("@timestamp" ));
351+ final Scorer scorer = weight .scorer (leafContext );
352352 disi = scorer != null ? scorer .iterator () : DocIdSetIterator .empty ();
353353 }
354354
@@ -375,9 +375,9 @@ boolean nextDoc() throws IOException {
375375
376376 void reinitializeIfNeeded (Thread executingThread ) throws IOException {
377377 if (executingThread != createdThread ) {
378- tsids = leaf .reader ().getSortedDocValues ("_tsid" );
379- timestamps = DocValues .unwrapSingleton (leaf .reader ().getSortedNumericDocValues ("@timestamp" ));
380- final Scorer scorer = weight .scorer (leaf );
378+ tsids = leafContext .reader ().getSortedDocValues ("_tsid" );
379+ timestamps = DocValues .unwrapSingleton (leafContext .reader ().getSortedNumericDocValues ("@timestamp" ));
380+ final Scorer scorer = weight .scorer (leafContext );
381381 disi = scorer != null ? scorer .iterator () : DocIdSetIterator .empty ();
382382 if (docID != -1 ) {
383383 disi .advance (docID );
0 commit comments