diff --git a/idx/memory/memory.go b/idx/memory/memory.go index 48ac7b1de2..5aa1dc4714 100755 --- a/idx/memory/memory.go +++ b/idx/memory/memory.go @@ -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() }