@@ -38,11 +38,11 @@ type AggMetric struct {
38
38
Chunks []* chunk.Chunk
39
39
aggregators []* Aggregator
40
40
dropFirstChunk bool
41
- firstChunkT0 uint32
42
41
ttl uint32
43
42
lastSaveStart uint32 // last chunk T0 that was added to the write Queue.
44
43
lastSaveFinish uint32 // last chunk T0 successfully written to Cassandra.
45
44
lastWrite uint32
45
+ firstTs uint32
46
46
}
47
47
48
48
// NewAggMetric creates a metric with given key, it retains the given number of chunks each chunkSpan seconds long
@@ -268,27 +268,16 @@ func (a *AggMetric) Get(from, to uint32) (Result, error) {
268
268
return result , ErrNilChunk
269
269
}
270
270
271
- // The first chunk is likely only a partial chunk. If we are not the primary node
272
- // we should not serve data from this chunk, and should instead get the chunk from cassandra.
273
- // if we are the primary node, then there is likely no data in Cassandra anyway.
274
- if ! cluster .Manager .IsPrimary () && oldestChunk .T0 == a .firstChunkT0 {
275
- oldestPos ++
276
- if oldestPos >= len (a .Chunks ) {
277
- oldestPos = 0
278
- }
279
- oldestChunk = a .getChunk (oldestPos )
280
- if oldestChunk == nil {
281
- log .Error (3 , "%s" , ErrNilChunk )
282
- return result , ErrNilChunk
283
- }
284
- }
285
-
286
271
if to <= oldestChunk .T0 {
287
272
// the requested time range ends before any data we have.
288
273
if LogLevel < 2 {
289
274
log .Debug ("AM %s Get(): no data for requested range" , a .Key )
290
275
}
291
- result .Oldest = oldestChunk .T0
276
+ if oldestChunk .First {
277
+ result .Oldest = a .firstTs
278
+ } else {
279
+ result .Oldest = oldestChunk .T0
280
+ }
292
281
return result , nil
293
282
}
294
283
@@ -342,8 +331,13 @@ func (a *AggMetric) Get(from, to uint32) (Result, error) {
342
331
}
343
332
}
344
333
334
+ if oldestChunk .First {
335
+ result .Oldest = a .firstTs
336
+ } else {
337
+ result .Oldest = oldestChunk .T0
338
+ }
339
+
345
340
memToIterDuration .Value (time .Now ().Sub (pre ))
346
- result .Oldest = oldestChunk .T0
347
341
return result , nil
348
342
}
349
343
@@ -483,12 +477,11 @@ func (a *AggMetric) add(ts uint32, val float64) {
483
477
484
478
if len (a .Chunks ) == 0 {
485
479
chunkCreate .Inc ()
486
- // no data has been added to this metric at all.
487
- a .Chunks = append (a .Chunks , chunk .New (t0 ))
488
-
489
- // The first chunk is typically going to be a partial chunk
490
- // so we keep a record of it.
491
- a .firstChunkT0 = t0
480
+ // no data has been added to this AggMetric yet.
481
+ // note that we may not be aware of prior data that belongs into this chunk
482
+ // so we should track this cutoff point
483
+ a .Chunks = append (a .Chunks , chunk .NewFirst (t0 ))
484
+ a .firstTs = ts
492
485
493
486
if err := a .Chunks [0 ].Push (ts , val ); err != nil {
494
487
panic (fmt .Sprintf ("FATAL ERROR: this should never happen. Pushing initial value <%d,%f> to new chunk at pos 0 failed: %q" , ts , val , err ))
0 commit comments