From 65e72295abada917d1cfd2f8d4eb46ae1dc55ef3 Mon Sep 17 00:00:00 2001 From: Anthony Woods Date: Mon, 24 Sep 2018 02:23:24 +0800 Subject: [PATCH] acquire/release lock for each series when pruning To prevent the lock from being held for a really long time, acquire a lock for each individual series to be deleted, rather then for all series that are stale. --- idx/memory/memory.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/idx/memory/memory.go b/idx/memory/memory.go index 592f79c187..c827529052 100755 --- a/idx/memory/memory.go +++ b/idx/memory/memory.go @@ -1318,20 +1318,23 @@ DEFS: pruned = append(pruned, defs...) } +ORGS: for org, paths := range toPruneUntagged { if len(paths) == 0 { continue } - m.Lock() - tree, ok := m.tree[org] - if !ok { - m.Unlock() - continue - } - for path := range paths { + m.Lock() + tree, ok := m.tree[org] + + if !ok { + m.Unlock() + continue ORGS + } + n, ok := tree.Items[path] + if !ok { m.Unlock() log.Debug("memory-idx: series %s for orgId:%d was identified for pruning but cannot be found.", path, org) @@ -1340,9 +1343,10 @@ DEFS: log.Debug("memory-idx: series %s for orgId:%d is stale. pruning it.", n.Path, org) defs := m.delete(org, n, true, false) + m.Unlock() pruned = append(pruned, defs...) } - m.Unlock() + } statMetricsActive.Add(-1 * len(pruned))