Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 11ef215

Browse files
committed
cleanup GC related code
1 parent 9e5eff6 commit 11ef215

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

mdata/aggmetric.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type AggMetric struct {
4141
ttl uint32
4242
lastSaveStart uint32 // last chunk T0 that was added to the write Queue.
4343
lastSaveFinish uint32 // last chunk T0 successfully written to Cassandra.
44-
lastWrite uint32
44+
lastWrite uint32 // wall clock time of when last point was successfully added (possibly to the ROB)
4545
firstTs uint32
4646
}
4747

@@ -331,7 +331,7 @@ func (a *AggMetric) Get(from, to uint32) (Result, error) {
331331
return result, nil
332332
}
333333

334-
// this function must only be called while holding the lock
334+
// caller must hold lock
335335
func (a *AggMetric) addAggregators(ts uint32, val float64) {
336336
for _, agg := range a.aggregators {
337337
log.Debugf("AM: %s pushing %d,%f to aggregator %d", a.Key, ts, val, agg.span)
@@ -340,7 +340,7 @@ func (a *AggMetric) addAggregators(ts uint32, val float64) {
340340
}
341341

342342
// pushToCache adds the chunk into the cache if it is hot
343-
// assumes lock held by caller
343+
// caller must hold lock
344344
func (a *AggMetric) pushToCache(c *chunk.Chunk) {
345345
if a.cachePusher == nil {
346346
return
@@ -355,9 +355,10 @@ func (a *AggMetric) pushToCache(c *chunk.Chunk) {
355355
go a.cachePusher.AddIfHot(a.Key, 0, itergen)
356356
}
357357

358-
// write a chunk to persistent storage. This should only be called while holding a.Lock()
358+
// write a chunk to persistent storage.
359359
// never persist a chunk that may receive further updates!
360360
// (because the stores will read out chunk data on the unlocked chunk)
361+
// caller must hold lock.
361362
func (a *AggMetric) persist(pos int) {
362363
chunk := a.Chunks[pos]
363364
pre := time.Now()
@@ -443,7 +444,7 @@ func (a *AggMetric) Add(ts uint32, val float64) {
443444
}
444445

445446
// don't ever call with a ts of 0, cause we use 0 to mean not initialized!
446-
// assumes a write lock is held by the call-site
447+
// caller must hold write lock
447448
func (a *AggMetric) add(ts uint32, val float64) {
448449
t0 := ts - (ts % a.ChunkSpan)
449450

@@ -546,22 +547,18 @@ func (a *AggMetric) add(ts uint32, val float64) {
546547
// any reasonable realtime stream (e.g. up to 15 min behind wall-clock)
547548
// could add points to the chunk
548549
//
549-
// caller must hold AggMetric lock
550+
// caller must hold lock
550551
func (a *AggMetric) collectable(now, chunkMinTs uint32) bool {
551552

552-
var currentChunk *chunk.Chunk
553-
if len(a.Chunks) != 0 {
554-
currentChunk = a.getChunk(a.CurrentChunkPos)
555-
}
556-
557553
// no chunks at all means "possibly collectable"
558554
// the caller (AggMetric.GC()) still has its own checks to
559555
// handle the "no chunks" correctly later.
560556
// also: we want AggMetric.GC() to go ahead with flushing the ROB in this case
561-
if currentChunk == nil {
557+
if len(a.Chunks) == 0 {
562558
return a.lastWrite < chunkMinTs
563559
}
564560

561+
currentChunk := a.getChunk(a.CurrentChunkPos)
565562
return a.lastWrite < chunkMinTs && currentChunk.Series.T0+a.ChunkSpan+15*60 < now
566563
}
567564

@@ -572,7 +569,7 @@ func (a *AggMetric) GC(now, chunkMinTs, metricMinTs uint32) bool {
572569
a.Lock()
573570
defer a.Unlock()
574571

575-
// abort unless it looks like the AggMetric is collectable
572+
// unless it looks like the AggMetric is collectable, abort and mark as not stale
576573
if !a.collectable(now, chunkMinTs) {
577574
return false
578575
}
@@ -627,6 +624,7 @@ func (a *AggMetric) GC(now, chunkMinTs, metricMinTs uint32) bool {
627624
return false
628625
}
629626

627+
// gcAggregators returns whether all aggregators are stale and can be removed
630628
func (a *AggMetric) gcAggregators(now, chunkMinTs, metricMinTs uint32) bool {
631629
ret := true
632630
for _, agg := range a.aggregators {

mdata/aggregator.go

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func (agg *Aggregator) Add(ts uint32, val float64) {
116116
}
117117
}
118118

119+
// GC returns whether all of the associated series are stale and can be removed
119120
func (agg *Aggregator) GC(now, chunkMinTs, metricMinTs, lastWriteTime uint32) bool {
120121
ret := true
121122

0 commit comments

Comments
 (0)