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

this might fix an OOM problem in cache.searchForward #696

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mdata/cache/ccache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (

"github.com/raintank/metrictank/mdata/cache/accnt"
"github.com/raintank/metrictank/mdata/chunk"
"github.com/raintank/metrictank/stats"
"github.com/raintank/worldping-api/pkg/log"
"github.com/rakyll/globalconf"
)

var (
maxSize uint64
maxSize uint64
cacheMetricBug = stats.NewCounter32("cache.ops.metric.searchForward-bug-surpressed")
)

func init() {
Expand Down Expand Up @@ -150,7 +152,7 @@ func (c *CCache) Search(metric string, from, until uint32) *CCSearchResult {
return res
}

cm.Search(res, from, until)
cm.Search(metric, res, from, until)
if len(res.Start) == 0 && len(res.End) == 0 {
accnt.CacheMetricMiss.Inc()
} else {
Expand Down
11 changes: 8 additions & 3 deletions mdata/cache/ccache_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (mc *CCacheMetric) seekDesc(ts uint32) (uint32, bool) {
return 0, false
}

func (mc *CCacheMetric) searchForward(from, until uint32, res *CCSearchResult) {
func (mc *CCacheMetric) searchForward(metric string, from, until uint32, res *CCSearchResult) {
ts, ok := mc.seekAsc(from)
if !ok {
return
Expand All @@ -202,6 +202,11 @@ func (mc *CCacheMetric) searchForward(from, until uint32, res *CCSearchResult) {
res.Complete = true
break
}
if ts >= mc.chunks[ts].Next {
log.Warn("CCacheMetric: suspected bug suppressed. searchForward(%q, %d, %d, res) ts is %d while Next is %d", metric, from, until, ts, mc.chunks[ts].Next)
cacheMetricBug.Inc()
break
}
}
}

Expand Down Expand Up @@ -236,15 +241,15 @@ func (mc *CCacheMetric) searchBackward(from, until uint32, res *CCSearchResult)
// cache: |---|---|---| | | | | |---|---|---|---|---|---|
// chunks returned: |---| |---|---|---|
//
func (mc *CCacheMetric) Search(res *CCSearchResult, from, until uint32) {
func (mc *CCacheMetric) Search(metric string, res *CCSearchResult, from, until uint32) {
mc.RLock()
defer mc.RUnlock()

if len(mc.chunks) < 1 {
return
}

mc.searchForward(from, until, res)
mc.searchForward(metric, from, until, res)
if !res.Complete {
mc.searchBackward(from, until, res)
}
Expand Down