From f4d098fb133adc1eddd9470ff3d819aff97d39f5 Mon Sep 17 00:00:00 2001 From: woodsaj Date: Thu, 21 Dec 2017 22:28:10 +0800 Subject: [PATCH] prune correctly when series is both leaf and branch - this issue was discovered in discussions of issue #714 - this also fixes #797 --- idx/memory/memory.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/idx/memory/memory.go b/idx/memory/memory.go index 48ac7b1de2..a6a14d8705 100755 --- a/idx/memory/memory.go +++ b/idx/memory/memory.go @@ -1136,8 +1136,19 @@ 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{} + } else { + defs = m.delete(org, n, true) + } + statMetricsActive.Add(-1 * len(defs)) pruned = append(pruned, defs...) m.Unlock() }