mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
9790aa98ac
This adds a position mapper that takes series from a head block in the order they were appended and creates a mapping representing them in order of their label sets. Write-repair of the postings list would cause very expensive writing. Hence, we keep them as they are and only apply the postition mapping at the very end, after a postings list has been sufficienctly reduced through intersections etc.
36 lines
558 B
Go
36 lines
558 B
Go
package tsdb
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPositionMapper(t *testing.T) {
|
|
cases := []struct {
|
|
in []int
|
|
res []int
|
|
}{
|
|
{
|
|
in: []int{5, 4, 3, 2, 1, 0},
|
|
res: []int{5, 4, 3, 2, 1, 0},
|
|
},
|
|
{
|
|
in: []int{1, 2, 0, 3},
|
|
res: []int{1, 2, 0, 3},
|
|
},
|
|
{
|
|
in: []int{1, 2, 0, 3, 10, 100, -10},
|
|
res: []int{2, 3, 1, 4, 5, 6, 0},
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
m := newPositionMapper(sort.IntSlice(c.in))
|
|
|
|
require.True(t, sort.IsSorted(m.sortable))
|
|
require.Equal(t, c.res, m.fw)
|
|
}
|
|
}
|