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

Commit

Permalink
prune correctly when series is both leaf and branch
Browse files Browse the repository at this point in the history
-  this issue was discovered in discussions of issue #714
-  this also fixes #797
  • Loading branch information
woodsaj committed Dec 21, 2017
1 parent 4cb8dac commit 34cea4f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions idx/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,24 @@ func (m *MemoryIdx) Prune(orgId int, oldest time.Time) ([]idx.Archive, error) {
}

log.Debug("memory-idx: series %s for orgId:%d is stale. pruning it.", n.Path, org)
defs := m.delete(org, n, true)
statMetricsActive.Dec()
defs := make([]idx.Archive, 0)
if n.HasChildren() {
// this path is a leaf and branch node, so lets remove the defIds to make it just a branch.
for _, id := range n.Defs {
log.Debug("memory-idx: deleting %s from index", id)
defs = append(defs, *m.DefById[id])
delete(m.DefById, id)
}
n.Defs = []string{}
if tagSupport {
for _, def := range defs {
m.deindexTags(&(def.MetricDefinition))
}
}
} else {
defs = m.delete(org, n, true)
}
statMetricsActive.Add(-1 * len(defs))
pruned = append(pruned, defs...)
m.Unlock()
}
Expand Down

0 comments on commit 34cea4f

Please sign in to comment.