Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trie/realtime: set wspConfigRetriever when realtime index is enabled #395 #396

Merged
merged 2 commits into from
Jan 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions carbon/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,25 @@ func (app *App) Start(version string) (err error) {
carbonserver.SetPercentiles(conf.Carbonserver.Percentiles)
// carbonserver.SetQueryTimeout(conf.Carbonserver.QueryTimeout.Value())

var setConfigRetriever bool
if conf.Carbonserver.CacheScan {
carbonserver.SetCacheGetMetricsFunc(core.GetRecentNewMetrics)

retriever := &wspConfigRetriever{
getRetentionFunc: app.Persister.GetRetentionPeriod,
getAggrNameFunc: app.Persister.GetAggrConf,
}
carbonserver.SetConfigRetriever(retriever)
setConfigRetriever = true
}

if conf.Carbonserver.RealtimeIndex > 0 {
ch := carbonserver.SetRealtimeIndex(conf.Carbonserver.RealtimeIndex)
core.SetNewMetricsChan(ch)

setConfigRetriever = true
}
if setConfigRetriever {
retriever := &wspConfigRetriever{
getRetentionFunc: app.Persister.GetRetentionPeriod,
getAggrNameFunc: app.Persister.GetAggrConf,
}
carbonserver.SetConfigRetriever(retriever)
}

if conf.Prometheus.Enabled {
Expand Down
7 changes: 6 additions & 1 deletion carbonserver/carbonserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,12 @@ uloop:
fidx := listener.CurrentFileIndex()
if listener.trieIndex && listener.concurrentIndex && fidx != nil && fidx.trieIdx != nil {
metric := filepath.Clean(strings.ReplaceAll(m, ".", "/") + ".wsp")

if err := fidx.trieIdx.insert(metric); err != nil {
listener.logger.Warn("failed to insert new metrics for realtime indexing", zap.String("metric", metric), zap.Error(err))
}

cacheMetrics[metric] = struct{}{}
}
continue uloop
}
Expand Down Expand Up @@ -773,7 +776,9 @@ func (listener *CarbonserverListener) updateFileList(dir string, cacheMetricName

// use cacheMetricNames to check and prevent appending duplicate metrics
// into the index when cacheMetricNamesIndex is enabled
if _, present := cacheMetricNames[trimmedName]; !present {
if _, present := cacheMetricNames[trimmedName]; present {
delete(cacheMetricNames, trimmedName)
} else {
if listener.trieIndex {
if err := trieIdx.insert(trimmedName); err != nil {
return fmt.Errorf("updateFileList.trie: %s", err)
Expand Down