mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #216 from prometheus/sortedPostings
Order postings lists in index file by key
This commit is contained in:
commit
df4657bcc5
|
@ -589,7 +589,7 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta,
|
|||
}
|
||||
}
|
||||
|
||||
for l := range postings.m {
|
||||
for _, l := range postings.sortedKeys() {
|
||||
if err := indexw.WritePostings(l.Name, l.Value, postings.get(l.Name, l.Value)); err != nil {
|
||||
return errors.Wrap(err, "write postings")
|
||||
}
|
||||
|
|
19
postings.go
19
postings.go
|
@ -50,6 +50,25 @@ func newUnorderedMemPostings() *memPostings {
|
|||
}
|
||||
}
|
||||
|
||||
// sortedKeys returns a list of sorted label keys of the postings.
|
||||
func (p *memPostings) sortedKeys() []labels.Label {
|
||||
p.mtx.RLock()
|
||||
keys := make([]labels.Label, 0, len(p.m))
|
||||
|
||||
for l := range p.m {
|
||||
keys = append(keys, l)
|
||||
}
|
||||
p.mtx.RUnlock()
|
||||
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
if d := strings.Compare(keys[i].Name, keys[j].Name); d != 0 {
|
||||
return d < 0
|
||||
}
|
||||
return keys[i].Value < keys[j].Value
|
||||
})
|
||||
return keys
|
||||
}
|
||||
|
||||
// Postings returns an iterator over the postings list for s.
|
||||
func (p *memPostings) get(name, value string) Postings {
|
||||
p.mtx.RLock()
|
||||
|
|
Loading…
Reference in a new issue