Seek implements chunkenc.Iterator.
(t int64)
| 92 | |
| 93 | // Seek implements chunkenc.Iterator. |
| 94 | func (a *iteratorAdapter) Seek(t int64) chunkenc.ValueType { |
| 95 | |
| 96 | // Optimisation: fulfill the seek using current batch if possible. |
| 97 | if a.curr.Length > 0 && a.curr.Index < a.curr.Length { |
| 98 | if t <= a.curr.Timestamps[a.curr.Index] { |
| 99 | //In this case, the interface's requirement is met, so state of this |
| 100 | //iterator does not need any change. |
| 101 | return a.curr.ValType |
| 102 | } else if t <= a.curr.Timestamps[a.curr.Length-1] { |
| 103 | //In this case, some timestamp between current sample and end of batch can fulfill |
| 104 | //the seek. Let's find it. |
| 105 | for a.curr.Index < a.curr.Length && t > a.curr.Timestamps[a.curr.Index] { |
| 106 | a.curr.Index++ |
| 107 | } |
| 108 | return a.curr.ValType |
| 109 | } else if t <= a.underlying.MaxCurrentChunkTime() { |
| 110 | // In this case, some timestamp inside the current underlying chunk can fulfill the seek. |
| 111 | // In this case we will call next until we find the sample as it will be faster than calling |
| 112 | // `a.underlying.Seek` directly as this would cause the iterator to start from the beginning of the chunk. |
| 113 | // See: https://github.com/cortexproject/cortex/blob/f69452975877c67ac307709e5f60b8d20477764c/pkg/querier/batch/chunk.go#L26-L45 |
| 114 | // https://github.com/cortexproject/cortex/blob/f69452975877c67ac307709e5f60b8d20477764c/pkg/chunk/encoding/prometheus_chunk.go#L90-L95 |
| 115 | for { |
| 116 | valType := a.Next() |
| 117 | if valType == chunkenc.ValNone { |
| 118 | break |
| 119 | } |
| 120 | if t <= a.curr.Timestamps[a.curr.Index] { |
| 121 | return valType |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | a.curr.Length = -1 |
| 128 | a.batchSize = 1 |
| 129 | if valType := a.underlying.Seek(t, a.batchSize); valType != chunkenc.ValNone { |
| 130 | a.curr = a.underlying.Batch() |
| 131 | if a.curr.Index < a.curr.Length { |
| 132 | return a.curr.ValType |
| 133 | } |
| 134 | } |
| 135 | return chunkenc.ValNone |
| 136 | } |
| 137 | |
| 138 | // Next implements chunkenc.Iterator. |
| 139 | func (a *iteratorAdapter) Next() chunkenc.ValueType { |
nothing calls this directly
no test coverage detected