@@ -6,11 +6,12 @@ import (
66 "fmt"
77 "io"
88 "math"
9+ "strings"
910 "sync"
10- "sync/atomic"
1111
1212 "github.com/grafana/dskit/multierror"
1313 "github.com/opentracing/opentracing-go"
14+ "github.com/opentracing/opentracing-go/log"
1415 "github.com/segmentio/parquet-go"
1516
1617 "github.com/grafana/phlare/pkg/iter"
@@ -279,22 +280,6 @@ func (t *RowNumber) Next(repetitionLevel, definitionLevel int) {
279280 }
280281}
281282
282- // nextSlow is the original implementation of next. it is kept to test against
283- // the unrolled version above
284- func (t * RowNumber ) nextSlow (repetitionLevel , definitionLevel int ) {
285- t [repetitionLevel ]++
286-
287- // New children up through the definition level
288- for i := repetitionLevel + 1 ; i <= definitionLevel ; i ++ {
289- t [i ] = 0
290- }
291-
292- // // Children past the definition level are undefined
293- for i := definitionLevel + 1 ; i < len (t ); i ++ {
294- t [i ] = - 1
295- }
296- }
297-
298283// Skip rows at the root-level.
299284func (t * RowNumber ) Skip (numRows int64 ) {
300285 t [0 ] += numRows
@@ -391,34 +376,7 @@ func NewErrIterator(err error) Iterator {
391376 return iter.NewErrSeekIterator [* IteratorResult , RowNumberWithDefinitionLevel ](err )
392377}
393378
394- var columnIteratorPool = sync.Pool {
395- New : func () interface {} {
396- return & columnIteratorBuffer {}
397- },
398- }
399-
400- func columnIteratorPoolGet (capacity , len int ) * columnIteratorBuffer {
401- res := columnIteratorPool .Get ().(* columnIteratorBuffer )
402- if cap (res .rowNumbers ) < capacity {
403- res .rowNumbers = make ([]RowNumber , capacity )
404- }
405- if cap (res .values ) < capacity {
406- res .values = make ([]parquet.Value , capacity )
407- }
408- res .rowNumbers = res .rowNumbers [:len ]
409- res .values = res .values [:len ]
410- return res
411- }
412-
413- func columnIteratorPoolPut (b * columnIteratorBuffer ) {
414- b .values = b .values [:cap (b .values )]
415- for i := range b .values {
416- b .values [i ] = parquet.Value {}
417- }
418- columnIteratorPool .Put (b )
419- }
420-
421- var columnIteratorResultPool = sync.Pool {
379+ var iteratorResultPool = sync.Pool {
422380 New : func () interface {} {
423381 return & IteratorResult {Entries : make ([]struct {
424382 k string
@@ -428,48 +386,18 @@ var columnIteratorResultPool = sync.Pool{
428386 },
429387}
430388
431- func columnIteratorResultPoolGet () * IteratorResult {
432- res := columnIteratorResultPool .Get ().(* IteratorResult )
389+ func iteratorResultPoolGet () * IteratorResult {
390+ res := iteratorResultPool .Get ().(* IteratorResult )
433391 return res
434392}
435393
436- func columnIteratorResultPoolPut (r * IteratorResult ) {
394+ func iteratorResultPoolPut (r * IteratorResult ) {
437395 if r != nil {
438396 r .Reset ()
439- columnIteratorResultPool .Put (r )
397+ iteratorResultPool .Put (r )
440398 }
441399}
442400
443- // ColumnIterator asynchronously iterates through the given row groups and column. Applies
444- // the optional predicate to each chunk, page, and value. Results are read by calling
445- // Next() until it returns nil.
446- type ColumnIterator struct {
447- rgs []parquet.RowGroup
448- col int
449- colName string
450- filter * InstrumentedPredicate
451-
452- selectAs string
453- seekTo atomic.Value
454-
455- metrics * Metrics
456- table string
457- quit chan struct {}
458- ch chan * columnIteratorBuffer
459-
460- curr * columnIteratorBuffer
461- currN int
462-
463- result * IteratorResult
464- err error
465- }
466-
467- type columnIteratorBuffer struct {
468- rowNumbers []RowNumber
469- values []parquet.Value
470- err error
471- }
472-
473401type BinaryJoinIterator struct {
474402 left Iterator
475403 right Iterator
@@ -506,7 +434,7 @@ func (bj *BinaryJoinIterator) Next() bool {
506434
507435 if cmp := CompareRowNumbers (bj .definitionLevel , resLeft .RowNumber , resRight .RowNumber ); cmp == 0 {
508436 // we have a found an element
509- bj .res = columnIteratorResultPoolGet ()
437+ bj .res = iteratorResultPoolGet ()
510438 bj .res .RowNumber = resLeft .RowNumber
511439 bj .res .Append (resLeft )
512440 bj .res .Append (resRight )
@@ -644,7 +572,7 @@ func (j *JoinIterator) seekAll(to RowNumberWithDefinitionLevel) {
644572 to .RowNumber = TruncateRowNumber (to )
645573 for iterNum , iter := range j .iters {
646574 if j .peeks [iterNum ] == nil || CompareRowNumbers (to .DefinitionLevel , j .peeks [iterNum ].RowNumber , to .RowNumber ) == - 1 {
647- columnIteratorResultPoolPut (j .peeks [iterNum ])
575+ iteratorResultPoolPut (j .peeks [iterNum ])
648576 if iter .Seek (to ) {
649577 j .peeks [iterNum ] = iter .At ()
650578 } else {
@@ -667,15 +595,15 @@ func (j *JoinIterator) peek(iterNum int) *IteratorResult {
667595// the next row (according to the configured definition level)
668596// or are exhausted.
669597func (j * JoinIterator ) collect (rowNumber RowNumber ) * IteratorResult {
670- result := columnIteratorResultPoolGet ()
598+ result := iteratorResultPoolGet ()
671599 result .RowNumber = rowNumber
672600
673601 for i := range j .iters {
674602 for j .peeks [i ] != nil && CompareRowNumbers (j .definitionLevel , j .peeks [i ].RowNumber , rowNumber ) == 0 {
675603
676604 result .Append (j .peeks [i ])
677605
678- columnIteratorResultPoolPut (j .peeks [i ])
606+ iteratorResultPoolPut (j .peeks [i ])
679607
680608 if j .iters [i ].Next () {
681609 j .peeks [i ] = j .iters [i ].At ()
@@ -809,15 +737,15 @@ func (u *UnionIterator) peek(iterNum int) *IteratorResult {
809737// the next row (according to the configured definition level)
810738// or are exhausted.
811739func (u * UnionIterator ) collect (iterNums []int , rowNumber RowNumber ) * IteratorResult {
812- result := columnIteratorResultPoolGet ()
740+ result := iteratorResultPoolGet ()
813741 result .RowNumber = rowNumber
814742
815743 for _ , iterNum := range iterNums {
816744 for u .peeks [iterNum ] != nil && CompareRowNumbers (u .definitionLevel , u .peeks [iterNum ].RowNumber , rowNumber ) == 0 {
817745
818746 result .Append (u .peeks [iterNum ])
819747
820- columnIteratorResultPoolPut (u .peeks [iterNum ])
748+ iteratorResultPoolPut (u .peeks [iterNum ])
821749
822750 if u .iters [iterNum ].Next () {
823751 u .peeks [iterNum ] = u .iters [iterNum ].At ()
@@ -928,7 +856,7 @@ func (r *RowNumberIterator[T]) Next() bool {
928856 if ! r .Iterator .Next () {
929857 return false
930858 }
931- r .current = columnIteratorResultPoolGet ()
859+ r .current = iteratorResultPoolGet ()
932860 r .current .Reset ()
933861 rowGetter , ok := any (r .Iterator .At ()).(RowGetter )
934862 if ! ok {
@@ -975,6 +903,7 @@ type SyncIterator struct {
975903 // Config
976904 column int
977905 columnName string
906+ table string
978907 rgs []parquet.RowGroup
979908 rgsMin []RowNumber
980909 rgsMax []RowNumber // Exclusive, row number of next one past the row group
@@ -984,6 +913,7 @@ type SyncIterator struct {
984913
985914 // Status
986915 span opentracing.Span
916+ metrics * Metrics
987917 curr RowNumber
988918 currRowGroup parquet.RowGroup
989919 currRowGroupMin RowNumber
@@ -1045,6 +975,8 @@ func NewSyncIterator(ctx context.Context, rgs []parquet.RowGroup, column int, co
1045975 })
1046976
1047977 return & SyncIterator {
978+ table : strings .ToLower (rgs [0 ].Schema ().Name ()) + "s" ,
979+ metrics : getMetricsFromContext (ctx ),
1048980 span : span ,
1049981 column : column ,
1050982 columnName : columnName ,
@@ -1209,6 +1141,12 @@ func (c *SyncIterator) seekPages(seekTo RowNumber, definitionLevel int) (done bo
12091141 c .closeCurrRowGroup ()
12101142 return true , err
12111143 }
1144+ c .metrics .pageReadsTotal .WithLabelValues (c .table , c .columnName ).Add (1 )
1145+ c .span .LogFields (
1146+ log .String ("msg" , "reading page" ),
1147+ log .Int64 ("page_num_values" , pg .NumValues ()),
1148+ log .Int64 ("page_size" , pg .Size ()),
1149+ )
12121150
12131151 // Skip based on row number?
12141152 newRN := c .curr
@@ -1365,7 +1303,7 @@ func (c *SyncIterator) closeCurrRowGroup() {
13651303}
13661304
13671305func (c * SyncIterator ) makeResult (t RowNumber , v * parquet.Value ) * IteratorResult {
1368- r := columnIteratorResultPoolGet ()
1306+ r := iteratorResultPoolGet ()
13691307 r .RowNumber = t
13701308 if c .selectAs != "" {
13711309 r .AppendValue (c .selectAs , v .Clone ())
0 commit comments