@@ -154,7 +154,7 @@ func (mc *CCacheMetric) AddRange(prev uint32, itergens []chunk.IterGen) {
154
154
if _ , ok := mc .chunks [ts ]; ! ok {
155
155
156
156
// if nextTs() can't figure out the end date it returns ts
157
- next := mc .nextTsCore (itergen , ts , prev , 0 )
157
+ next := mc .nextTsCore (itergen , prev , 0 )
158
158
if next == ts {
159
159
next = 0
160
160
} else {
@@ -231,12 +231,7 @@ func (mc *CCacheMetric) Add(prev uint32, itergen chunk.IterGen) {
231
231
}
232
232
}
233
233
234
- mc .addKey (ts )
235
-
236
- return
237
- }
238
-
239
- func (mc * CCacheMetric ) addKey (ts uint32 ) {
234
+ // assure key is added to mc.keys
240
235
241
236
// if no keys yet, just add it and it's sorted
242
237
if len (mc .keys ) == 0 {
@@ -266,17 +261,17 @@ func (mc *CCacheMetric) generateKeys() {
266
261
// assumes we already have at least a read lock
267
262
func (mc * CCacheMetric ) nextTs (ts uint32 ) uint32 {
268
263
chunk := mc .chunks [ts ]
269
- return mc .nextTsCore (chunk .Itgen , chunk .Ts , chunk . Prev , chunk .Next )
264
+ return mc .nextTsCore (chunk .Itgen , chunk .Prev , chunk .Next )
270
265
}
271
266
272
267
// nextTsCore returns the ts of the next chunk, given a chunks key properties
273
268
// (to the extent we know them). It guesses if necessary.
274
269
// assumes we already have at least a read lock
275
- func (mc * CCacheMetric ) nextTsCore (itgen chunk.IterGen , ts , prev , next uint32 ) uint32 {
270
+ func (mc * CCacheMetric ) nextTsCore (itgen chunk.IterGen , prev , next uint32 ) uint32 {
276
271
span := itgen .Span
277
272
if span > 0 {
278
273
// if the chunk is span-aware we don't need anything else
279
- return ts + span
274
+ return itgen . Ts + span
280
275
}
281
276
282
277
// if chunk has a next chunk, then that's the ts we need
@@ -285,10 +280,10 @@ func (mc *CCacheMetric) nextTsCore(itgen chunk.IterGen, ts, prev, next uint32) u
285
280
}
286
281
// if chunk has no next chunk, but has a previous one, we assume the length of this one is same as the previous one
287
282
if prev != 0 {
288
- return ts + (ts - prev )
283
+ return itgen . Ts + (itgen . Ts - prev )
289
284
}
290
285
// if a chunk has no next and no previous chunk we have to assume it's length is 0
291
- return ts
286
+ return itgen . Ts
292
287
}
293
288
294
289
// lastTs returns the last Ts of this metric cache
0 commit comments