MCPcopy Create free account
hub / github.com/cortexproject/cortex / Seek

Method Seek

pkg/querier/batch/merge.go:87–126  ·  view source on GitHub ↗
(t int64, size int)

Source from the content-addressed store, hash-verified

85}
86
87func (c *mergeIterator) Seek(t int64, size int) chunkenc.ValueType {
88
89 // Optimisation to see if the seek is within our current caches batches.
90found:
91 for len(c.batches) > 0 {
92 batch := &c.batches[0]
93 if t >= batch.Timestamps[0] && t <= batch.Timestamps[batch.Length-1] {
94 batch.Index = 0
95 for batch.Index < batch.Length && t > batch.Timestamps[batch.Index] {
96 batch.Index++
97 }
98 break found
99 }
100 copy(c.batches, c.batches[1:])
101 c.batches = c.batches[:len(c.batches)-1]
102 }
103
104 // If we didn't find anything in the current set of batches, reset the heap
105 // and seek.
106 if len(c.batches) == 0 {
107 c.h = c.h[:0]
108 c.batches = c.batches[:0]
109
110 for _, iter := range c.its {
111 if iter.Seek(t, size) != chunkenc.ValNone {
112 c.h = append(c.h, iter)
113 continue
114 }
115
116 if err := iter.Err(); err != nil {
117 c.currErr = err
118 return chunkenc.ValNone
119 }
120 }
121
122 heap.Init(&c.h)
123 }
124
125 return c.buildNextBatch(size)
126}
127
128func (c *mergeIterator) Next(size int) chunkenc.ValueType {
129 // Pop the last built batch in a way that doesn't extend the slice.

Callers

nothing calls this directly

Calls 3

buildNextBatchMethod · 0.95
SeekMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected