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

Commit 8bbc022

Browse files
authored
Merge pull request #1062 from grafana/fixIdxPruning
acquire/release lock for each series when pruning
2 parents 4b0b8c1 + 65e7229 commit 8bbc022

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

idx/memory/memory.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -1318,20 +1318,23 @@ DEFS:
13181318
pruned = append(pruned, defs...)
13191319
}
13201320

1321+
ORGS:
13211322
for org, paths := range toPruneUntagged {
13221323
if len(paths) == 0 {
13231324
continue
13241325
}
13251326

1326-
m.Lock()
1327-
tree, ok := m.tree[org]
1328-
if !ok {
1329-
m.Unlock()
1330-
continue
1331-
}
1332-
13331327
for path := range paths {
1328+
m.Lock()
1329+
tree, ok := m.tree[org]
1330+
1331+
if !ok {
1332+
m.Unlock()
1333+
continue ORGS
1334+
}
1335+
13341336
n, ok := tree.Items[path]
1337+
13351338
if !ok {
13361339
m.Unlock()
13371340
log.Debug("memory-idx: series %s for orgId:%d was identified for pruning but cannot be found.", path, org)
@@ -1340,9 +1343,10 @@ DEFS:
13401343

13411344
log.Debug("memory-idx: series %s for orgId:%d is stale. pruning it.", n.Path, org)
13421345
defs := m.delete(org, n, true, false)
1346+
m.Unlock()
13431347
pruned = append(pruned, defs...)
13441348
}
1345-
m.Unlock()
1349+
13461350
}
13471351

13481352
statMetricsActive.Add(-1 * len(pruned))

0 commit comments

Comments
 (0)