@@ -51,6 +51,10 @@ type IndexSnapshotTermFieldReader struct {
5151 bytesRead uint64
5252 ctx context.Context
5353 unadorned bool
54+ // flag to indicate whether to increment our bytesRead
55+ // value after creation of the TFR while iterating our postings
56+ // lists
57+ updateBytesRead bool
5458}
5559
5660func (i * IndexSnapshotTermFieldReader ) incrementBytesRead (val uint64 ) {
@@ -83,10 +87,15 @@ func (i *IndexSnapshotTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*in
8387 if rv == nil {
8488 rv = & index.TermFieldDoc {}
8589 }
90+ var prevBytesRead uint64
8691 // find the next hit
8792 for i .segmentOffset < len (i .iterators ) {
88- prevBytesRead := i .iterators [i .segmentOffset ].BytesRead ()
89- next , err := i .iterators [i .segmentOffset ].Next ()
93+ // get our current postings iterator
94+ curItr := i .iterators [i .segmentOffset ]
95+ if i .updateBytesRead {
96+ prevBytesRead = curItr .BytesRead ()
97+ }
98+ next , err := curItr .Next ()
9099 if err != nil {
91100 return nil , err
92101 }
@@ -99,13 +108,15 @@ func (i *IndexSnapshotTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*in
99108
100109 i .currID = rv .ID
101110 i .currPosting = next
102- // postingsIterators is maintain the bytesRead stat in a cumulative fashion.
103- // this is because there are chances of having a series of loadChunk calls,
104- // and they have to be added together before sending the bytesRead at this point
105- // upstream.
106- bytesRead := i .iterators [i .segmentOffset ].BytesRead ()
107- if bytesRead > prevBytesRead {
108- i .incrementBytesRead (bytesRead - prevBytesRead )
111+ if i .updateBytesRead {
112+ // postingsIterators is maintain the bytesRead stat in a cumulative fashion.
113+ // this is because there are chances of having a series of loadChunk calls,
114+ // and they have to be added together before sending the bytesRead at this point
115+ // upstream.
116+ bytesRead := curItr .BytesRead ()
117+ if bytesRead > prevBytesRead {
118+ i .incrementBytesRead (bytesRead - prevBytesRead )
119+ }
109120 }
110121 return rv , nil
111122 }
0 commit comments