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

Commit

Permalink
acquire/release lock for each series when pruning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Anthony Woods committed Sep 23, 2018
1 parent 4b0b8c1 commit 65e7229
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions idx/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down

0 comments on commit 65e7229

Please sign in to comment.