Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2ee3be

Browse files
committedSep 11, 2017
add a method to completely flush the whole cache
1 parent b518ca9 commit c2ee3be

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed
 

‎api/ccache.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,28 @@ func (s *Server) ccacheDelete(ctx *middleware.Context, req models.CCacheDelete)
2525
}
2626
}
2727

28+
fullFlush := false
2829
for _, pattern := range req.Patterns {
29-
nodes, err := s.MetricIndex.Find(req.OrgId, pattern, 0)
30-
if err != nil {
31-
res.Errors += 1
32-
code = 500
33-
} else {
34-
for _, node := range nodes {
35-
for _, def := range node.Defs {
36-
delResult := s.Cache.DelMetric(def.Id)
37-
res.DeletedSeries += delResult.Series
38-
res.DeletedArchives += delResult.Archives
30+
if pattern == "**" {
31+
fullFlush = true
32+
}
33+
}
34+
35+
if fullFlush {
36+
s.Cache.Reset()
37+
} else {
38+
for _, pattern := range req.Patterns {
39+
nodes, err := s.MetricIndex.Find(req.OrgId, pattern, 0)
40+
if err != nil {
41+
res.Errors += 1
42+
code = 500
43+
} else {
44+
for _, node := range nodes {
45+
for _, def := range node.Defs {
46+
delResult := s.Cache.DelMetric(def.Id)
47+
res.DeletedSeries += delResult.Series
48+
res.DeletedArchives += delResult.Archives
49+
}
3950
}
4051
}
4152
}

‎mdata/cache/accnt/flat_accnt.go

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func (a *FlatAccnt) eventLoop() {
173173
a.metrics = make(map[string]*FlatAccntMet)
174174
a.total = 0
175175
a.lru.reset()
176+
cacheSizeUsed.SetUint64(a.total)
176177
}
177178

178179
// evict until we're below the max

‎mdata/cache/cache_mock.go

+2
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ func (mc *MockCache) DelMetric(key string) *CCDelMetricResult {
5757
mc.DelMetricKeys = append(mc.DelMetricKeys, key)
5858
return &mc.DelMetricRes
5959
}
60+
61+
func (mc *MockCache) Reset() {}

‎mdata/cache/ccache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ func (c *CCache) Add(metric, rawMetric string, cons consolidation.Consolidator,
153153
}
154154

155155
func (cc *CCache) Reset() {
156-
cc.accnt.Reset()
157156
cc.Lock()
157+
cc.accnt.Reset()
158158
cc.metricCache = make(map[string]*CCacheMetric)
159159
cc.metricRawKeys = make(map[string]map[consolidation.Consolidator]string)
160160
cc.Unlock()

‎mdata/cache/if.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Cache interface {
1313
Stop()
1414
Search(context.Context, string, uint32, uint32) *CCSearchResult
1515
DelMetric(string) *CCDelMetricResult
16+
Reset()
1617
}
1718

1819
type CachePusher interface {

0 commit comments

Comments
 (0)
This repository has been archived.