Skip to content

Commit b7d3520

Browse files
authored
Merge pull request #543 from dinal/master
dev -> master
2 parents 097c220 + 943d197 commit b7d3520

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

pkg/appender/appender.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type MetricState struct {
5656
store *chunkStore
5757
err error
5858
retryCount uint8
59-
newName bool
59+
created bool
6060
isVariant bool
6161

6262
shouldGetState bool
@@ -147,7 +147,6 @@ func NewMetricsCache(container v3io.Container, logger logger.Logger, cfg *config
147147
newCache.newUpdates = make(chan int, 1000)
148148
newCache.stopChan = make(chan int, 3)
149149

150-
newCache.NameLabelMap = map[string]bool{}
151150
newCache.performanceReporter = performance.ReporterInstanceFromConfig(cfg)
152151

153152
return &newCache
@@ -182,10 +181,6 @@ func (mc *MetricsCache) getMetric(hash uint64) (*MetricState, bool) {
182181
// create a new metric and save in the map
183182
func (mc *MetricsCache) addMetric(hash uint64, name string, metric *MetricState) {
184183
mc.cacheMetricMap.Add(hash, metric)
185-
if _, ok := mc.NameLabelMap[name]; !ok {
186-
metric.newName = true
187-
mc.NameLabelMap[name] = true
188-
}
189184
}
190185

191186
// Push append to async channel

pkg/appender/ingest.go

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ func (mc *MetricsCache) postMetricUpdates(metric *MetricState) {
241241
if !sent {
242242
if metric.store.samplesQueueLength() == 0 {
243243
metric.setState(storeStateReady)
244+
if metric.store.numNotProcessed == 0 {
245+
mc.cacheMetricMap.ResetMetric(metric.hash)
246+
}
244247
} else {
245248
if mc.metricQueue.length() > 0 {
246249
atomic.AddInt64(&mc.outstandingUpdates, 1)

pkg/appender/lru_cache.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,31 @@ func NewCache(max int) *Cache {
3535
func (c *Cache) Add(key uint64, value *MetricState) {
3636
c.mtx.Lock()
3737
defer c.mtx.Unlock()
38-
if ee, ok := c.cache[key]; ok {
39-
c.free.Remove(ee)
40-
//check if element was already in list and if not push to front
41-
c.used.MoveToFront(ee)
42-
if c.used.Front() != ee {
43-
c.used.PushFront(ee)
44-
}
45-
ee.Value.(*entry).value = value
46-
return
38+
if ele, ok := c.cache[key]; ok {
39+
//deleting from both lists as a workaround to not knowing which list actually contains the elem
40+
//if the elem is not present in the list Remove won't do anything
41+
// Remove clears ele's head,prev and next pointers so it can't be reused
42+
c.free.Remove(ele)
43+
c.used.Remove(ele)
4744
}
48-
ele := c.used.PushFront(&entry{key, value})
49-
c.cache[key] = ele
45+
c.cache[key] = c.used.PushFront(&entry{key, value})
5046
if c.maxEntries != 0 && c.free.Len()+c.used.Len() > c.maxEntries {
5147
c.removeOldest()
5248
}
49+
5350
}
5451

5552
// Get looks up a key's value from the cache.
5653
func (c *Cache) Get(key uint64) (value *MetricState, ok bool) {
5754
c.mtx.Lock()
5855
defer c.mtx.Unlock()
5956
if ele, hit := c.cache[key]; hit {
57+
//deleting from both lists as a workaround to not knowing which list actually contains the elem
58+
//if the elem is not present in the list Remove won't do anything
59+
// Remove clears ele's head,prev and next pointers so it can't be reused
6060
c.free.Remove(ele)
61-
//check if element was already in list and if not push to front
62-
c.used.MoveToFront(ele)
63-
if c.used.Front() != ele {
64-
c.used.PushFront(ele)
65-
}
61+
c.used.Remove(ele)
62+
c.cache[key] = c.used.PushFront(&entry{key, ele.Value.(*entry).value})
6663
return ele.Value.(*entry).value, true
6764
}
6865
return
@@ -73,8 +70,7 @@ func (c *Cache) removeOldest() {
7370
ele := c.free.Back()
7471
if ele != nil {
7572
c.free.Remove(ele)
76-
kv := ele.Value.(*clist.Element).Value.(*entry)
77-
delete(c.cache, kv.key)
73+
delete(c.cache, ele.Value.(*entry).key)
7874
return
7975
}
8076
c.cond.Wait()
@@ -85,8 +81,12 @@ func (c *Cache) ResetMetric(key uint64) {
8581
c.mtx.Lock()
8682
defer c.mtx.Unlock()
8783
if ele, ok := c.cache[key]; ok {
84+
//deleting from both lists as a workaround to not knowing which list actually contains the elem
85+
//if the elem is not present in the list Remove won't do anything
86+
// Remove clears ele's head,prev and next pointers so it can't be reused
8887
c.used.Remove(ele)
89-
c.free.PushFront(ele)
88+
c.free.Remove(ele)
89+
c.cache[key] = c.free.PushFront(&entry{key, ele.Value.(*entry).value})
9090
c.cond.Signal()
9191
}
9292
}

pkg/appender/store.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ func (cs *chunkStore) processGetResp(mc *MetricsCache, metric *MetricState, resp
186186

187187
if resp.Error != nil {
188188
if utils.IsNotExistsError(resp.Error) {
189-
if metric.newName {
189+
if !metric.created {
190+
metric.created = true
190191
path := filepath.Join(mc.cfg.TablePath, config.NamesDirectory, metric.name)
191192
putInput := v3io.PutItemInput{Path: path, Attributes: map[string]interface{}{}}
192193

0 commit comments

Comments
 (0)