2017-04-10 18:59:45 +00:00
|
|
|
// Copyright 2017 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-11-30 14:34:49 +00:00
|
|
|
package index
|
2016-12-27 10:32:10 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-27 10:16:55 +00:00
|
|
|
"encoding/binary"
|
2017-10-05 20:22:14 +00:00
|
|
|
"fmt"
|
2017-03-27 10:16:55 +00:00
|
|
|
"math/rand"
|
2017-10-05 20:22:14 +00:00
|
|
|
"sort"
|
2016-12-27 10:32:10 +00:00
|
|
|
"testing"
|
2017-03-27 10:16:55 +00:00
|
|
|
|
2017-12-07 01:12:38 +00:00
|
|
|
"github.com/prometheus/tsdb/testutil"
|
2016-12-27 10:32:10 +00:00
|
|
|
)
|
|
|
|
|
2017-09-20 16:08:57 +00:00
|
|
|
func TestMemPostings_addFor(t *testing.T) {
|
2017-11-30 14:34:49 +00:00
|
|
|
p := NewMemPostings()
|
2018-11-02 14:27:19 +00:00
|
|
|
p.m[allPostingsKey.Name] = map[string][]uint64{}
|
|
|
|
p.m[allPostingsKey.Name][allPostingsKey.Value] = []uint64{1, 2, 3, 4, 6, 7, 8}
|
2017-09-20 16:08:57 +00:00
|
|
|
|
|
|
|
p.addFor(5, allPostingsKey)
|
|
|
|
|
2018-11-02 14:27:19 +00:00
|
|
|
testutil.Equals(t, []uint64{1, 2, 3, 4, 5, 6, 7, 8}, p.m[allPostingsKey.Name][allPostingsKey.Value])
|
2017-09-20 16:08:57 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 20:22:14 +00:00
|
|
|
func TestMemPostings_ensureOrder(t *testing.T) {
|
2017-11-30 14:34:49 +00:00
|
|
|
p := NewUnorderedMemPostings()
|
2018-11-02 14:27:19 +00:00
|
|
|
p.m["a"] = map[string][]uint64{}
|
2017-10-05 20:22:14 +00:00
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
l := make([]uint64, 100)
|
|
|
|
for j := range l {
|
|
|
|
l[j] = rand.Uint64()
|
|
|
|
}
|
|
|
|
v := fmt.Sprintf("%d", i)
|
|
|
|
|
2018-11-02 14:27:19 +00:00
|
|
|
p.m["a"][v] = l
|
2017-10-05 20:22:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 14:34:49 +00:00
|
|
|
p.EnsureOrder()
|
2017-10-05 20:22:14 +00:00
|
|
|
|
2018-11-02 14:27:19 +00:00
|
|
|
for _, e := range p.m {
|
|
|
|
for _, l := range e {
|
|
|
|
ok := sort.SliceIsSorted(l, func(i, j int) bool {
|
|
|
|
return l[i] < l[j]
|
|
|
|
})
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("postings list %v is not sorted", l)
|
|
|
|
}
|
2017-10-05 20:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-28 10:02:19 +00:00
|
|
|
func TestIntersect(t *testing.T) {
|
2019-03-21 16:23:00 +00:00
|
|
|
a := newListPostings(1, 2, 3)
|
|
|
|
b := newListPostings(2, 3, 4)
|
|
|
|
|
2016-12-27 10:32:10 +00:00
|
|
|
var cases = []struct {
|
2019-03-21 16:23:00 +00:00
|
|
|
in []Postings
|
|
|
|
|
|
|
|
res Postings
|
2016-12-27 10:32:10 +00:00
|
|
|
}{
|
|
|
|
{
|
2019-03-21 16:23:00 +00:00
|
|
|
in: []Postings{},
|
|
|
|
res: EmptyPostings(),
|
2016-12-27 10:32:10 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-21 16:23:00 +00:00
|
|
|
in: []Postings{a, b, EmptyPostings()},
|
|
|
|
res: EmptyPostings(),
|
2016-12-27 10:32:10 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-21 16:23:00 +00:00
|
|
|
in: []Postings{b, a, EmptyPostings()},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{EmptyPostings(), b, a},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{EmptyPostings(), a, b},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{a, EmptyPostings(), b},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{b, EmptyPostings(), a},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{b, EmptyPostings(), a, a, b, a, a, a},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 5),
|
|
|
|
newListPostings(6, 7, 8, 9, 10),
|
|
|
|
},
|
|
|
|
res: newListPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 5),
|
|
|
|
newListPostings(4, 5, 6, 7, 8),
|
|
|
|
},
|
|
|
|
res: newListPostings(4, 5),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 9, 10),
|
|
|
|
newListPostings(1, 4, 5, 6, 7, 8, 10, 11),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 4, 10),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1),
|
|
|
|
newListPostings(0, 1),
|
|
|
|
},
|
|
|
|
res: newListPostings(1),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1),
|
|
|
|
},
|
|
|
|
res: newListPostings(1),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1),
|
|
|
|
newListPostings(),
|
|
|
|
},
|
|
|
|
res: newListPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(),
|
|
|
|
newListPostings(),
|
|
|
|
},
|
|
|
|
res: newListPostings(),
|
2016-12-27 10:32:10 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-04-08 15:12:29 +00:00
|
|
|
for _, c := range cases {
|
2019-03-21 16:23:00 +00:00
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
if c.res == nil {
|
|
|
|
t.Fatal("intersect result expectancy cannot be nil")
|
|
|
|
}
|
2016-12-27 10:32:10 +00:00
|
|
|
|
2019-03-21 16:23:00 +00:00
|
|
|
expected, err := ExpandPostings(c.res)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
|
|
|
|
i := Intersect(c.in...)
|
|
|
|
|
|
|
|
if c.res == EmptyPostings() {
|
|
|
|
testutil.Equals(t, EmptyPostings(), i)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if i == EmptyPostings() {
|
|
|
|
t.Fatal("intersect unexpected result: EmptyPostings sentinel")
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := ExpandPostings(i)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, expected, res)
|
|
|
|
})
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiIntersect(t *testing.T) {
|
|
|
|
var cases = []struct {
|
2017-09-04 14:08:38 +00:00
|
|
|
p [][]uint64
|
|
|
|
res []uint64
|
2016-12-27 10:32:10 +00:00
|
|
|
}{
|
|
|
|
{
|
2017-09-04 14:08:38 +00:00
|
|
|
p: [][]uint64{
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
{1, 2, 3, 4, 5, 6, 1000, 1001},
|
|
|
|
{2, 4, 5, 6, 7, 8, 999, 1001},
|
|
|
|
{1, 2, 5, 6, 7, 8, 1001, 1200},
|
|
|
|
},
|
2017-09-04 14:08:38 +00:00
|
|
|
res: []uint64{2, 5, 6, 1001},
|
2016-12-27 10:32:10 +00:00
|
|
|
},
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
// One of the reproduceable cases for:
|
|
|
|
// https://github.com/prometheus/prometheus/issues/2616
|
|
|
|
// The initialisation of intersectPostings was moving the iterator forward
|
|
|
|
// prematurely making us miss some postings.
|
|
|
|
{
|
2017-09-04 14:08:38 +00:00
|
|
|
p: [][]uint64{
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
{1, 2},
|
|
|
|
{1, 2},
|
|
|
|
{1, 2},
|
|
|
|
{2},
|
|
|
|
},
|
2017-09-04 14:08:38 +00:00
|
|
|
res: []uint64{2},
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
},
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
ps := make([]Postings, 0, len(c.p))
|
|
|
|
for _, postings := range c.p {
|
2019-03-21 16:23:00 +00:00
|
|
|
ps = append(ps, newListPostings(postings...))
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
}
|
2016-12-27 10:32:10 +00:00
|
|
|
|
2017-11-30 14:34:49 +00:00
|
|
|
res, err := ExpandPostings(Intersect(ps...))
|
2017-04-08 15:12:29 +00:00
|
|
|
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, c.res, res)
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkIntersect(t *testing.B) {
|
2017-09-04 14:08:38 +00:00
|
|
|
var a, b, c, d []uint64
|
2016-12-27 10:32:10 +00:00
|
|
|
|
|
|
|
for i := 0; i < 10000000; i += 2 {
|
2017-09-04 14:08:38 +00:00
|
|
|
a = append(a, uint64(i))
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
for i := 5000000; i < 5000100; i += 4 {
|
2017-09-04 14:08:38 +00:00
|
|
|
b = append(b, uint64(i))
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
for i := 5090000; i < 5090600; i += 4 {
|
2017-09-04 14:08:38 +00:00
|
|
|
b = append(b, uint64(i))
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
for i := 4990000; i < 5100000; i++ {
|
2017-09-04 14:08:38 +00:00
|
|
|
c = append(c, uint64(i))
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
for i := 4000000; i < 6000000; i++ {
|
2017-09-04 14:08:38 +00:00
|
|
|
d = append(d, uint64(i))
|
2016-12-27 10:32:10 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 16:23:00 +00:00
|
|
|
i1 := newListPostings(a...)
|
|
|
|
i2 := newListPostings(b...)
|
|
|
|
i3 := newListPostings(c...)
|
|
|
|
i4 := newListPostings(d...)
|
2016-12-27 10:32:10 +00:00
|
|
|
|
|
|
|
t.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < t.N; i++ {
|
2017-11-30 14:34:49 +00:00
|
|
|
if _, err := ExpandPostings(Intersect(i1, i2, i3, i4)); err != nil {
|
2016-12-27 10:32:10 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 10:02:19 +00:00
|
|
|
|
|
|
|
func TestMultiMerge(t *testing.T) {
|
2019-03-21 16:23:00 +00:00
|
|
|
i1 := newListPostings(1, 2, 3, 4, 5, 6, 1000, 1001)
|
|
|
|
i2 := newListPostings(2, 4, 5, 6, 7, 8, 999, 1001)
|
|
|
|
i3 := newListPostings(1, 2, 5, 6, 7, 8, 1001, 1200)
|
2016-12-28 10:02:19 +00:00
|
|
|
|
2019-03-21 16:23:00 +00:00
|
|
|
res, err := ExpandPostings(Merge(i1, i2, i3))
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, []uint64{1, 2, 3, 4, 5, 6, 7, 8, 999, 1000, 1001, 1200}, res)
|
2016-12-28 10:02:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-21 20:08:26 +00:00
|
|
|
func TestMergedPostings(t *testing.T) {
|
2016-12-28 10:02:19 +00:00
|
|
|
var cases = []struct {
|
2019-03-21 16:23:00 +00:00
|
|
|
in []Postings
|
|
|
|
|
|
|
|
res Postings
|
2016-12-28 10:02:19 +00:00
|
|
|
}{
|
|
|
|
{
|
2019-03-21 16:23:00 +00:00
|
|
|
in: []Postings{},
|
|
|
|
res: EmptyPostings(),
|
2016-12-28 10:02:19 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-21 16:23:00 +00:00
|
|
|
in: []Postings{
|
|
|
|
newListPostings(),
|
|
|
|
newListPostings(),
|
|
|
|
},
|
|
|
|
res: EmptyPostings(),
|
2016-12-28 10:02:19 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-21 16:23:00 +00:00
|
|
|
in: []Postings{
|
|
|
|
newListPostings(),
|
|
|
|
},
|
|
|
|
res: newListPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
EmptyPostings(),
|
|
|
|
EmptyPostings(),
|
|
|
|
EmptyPostings(),
|
|
|
|
EmptyPostings(),
|
|
|
|
},
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 5),
|
|
|
|
newListPostings(6, 7, 8, 9, 10),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 5),
|
|
|
|
newListPostings(4, 5, 6, 7, 8),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 2, 3, 4, 5, 6, 7, 8),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 9, 10),
|
|
|
|
newListPostings(1, 4, 5, 6, 7, 8, 10, 11),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2, 3, 4, 9, 10),
|
|
|
|
EmptyPostings(),
|
|
|
|
newListPostings(1, 4, 5, 6, 7, 8, 10, 11),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2),
|
|
|
|
newListPostings(),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 2),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: []Postings{
|
|
|
|
newListPostings(1, 2),
|
|
|
|
EmptyPostings(),
|
|
|
|
},
|
|
|
|
res: newListPostings(1, 2),
|
2016-12-28 10:02:19 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2019-03-21 16:23:00 +00:00
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
if c.res == nil {
|
|
|
|
t.Fatal("merge result expectancy cannot be nil")
|
|
|
|
}
|
2016-12-28 10:02:19 +00:00
|
|
|
|
2019-03-21 16:23:00 +00:00
|
|
|
expected, err := ExpandPostings(c.res)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
|
|
|
|
m := Merge(c.in...)
|
2017-04-08 15:12:29 +00:00
|
|
|
|
2019-03-21 16:23:00 +00:00
|
|
|
if c.res == EmptyPostings() {
|
|
|
|
testutil.Equals(t, EmptyPostings(), m)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if m == EmptyPostings() {
|
|
|
|
t.Fatal("merge unexpected result: EmptyPostings sentinel")
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := ExpandPostings(m)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, expected, res)
|
|
|
|
})
|
|
|
|
}
|
2017-04-21 20:08:26 +00:00
|
|
|
}
|
2017-04-08 15:12:29 +00:00
|
|
|
|
2017-04-21 20:08:26 +00:00
|
|
|
func TestMergedPostingsSeek(t *testing.T) {
|
|
|
|
var cases = []struct {
|
2017-09-04 14:08:38 +00:00
|
|
|
a, b []uint64
|
2017-04-08 15:12:29 +00:00
|
|
|
|
2017-09-04 14:08:38 +00:00
|
|
|
seek uint64
|
2017-04-21 20:08:26 +00:00
|
|
|
success bool
|
2017-09-04 14:08:38 +00:00
|
|
|
res []uint64
|
2017-04-21 20:08:26 +00:00
|
|
|
}{
|
|
|
|
{
|
2017-09-04 14:08:38 +00:00
|
|
|
a: []uint64{2, 3, 4, 5},
|
|
|
|
b: []uint64{6, 7, 8, 9, 10},
|
2017-04-08 15:12:29 +00:00
|
|
|
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
seek: 1,
|
2017-04-21 20:08:26 +00:00
|
|
|
success: true,
|
2017-09-04 14:08:38 +00:00
|
|
|
res: []uint64{2, 3, 4, 5, 6, 7, 8, 9, 10},
|
2017-04-21 20:08:26 +00:00
|
|
|
},
|
|
|
|
{
|
2017-09-04 14:08:38 +00:00
|
|
|
a: []uint64{1, 2, 3, 4, 5},
|
|
|
|
b: []uint64{6, 7, 8, 9, 10},
|
2017-04-08 15:12:29 +00:00
|
|
|
|
2017-04-21 20:08:26 +00:00
|
|
|
seek: 2,
|
|
|
|
success: true,
|
2017-09-04 14:08:38 +00:00
|
|
|
res: []uint64{2, 3, 4, 5, 6, 7, 8, 9, 10},
|
2017-04-21 20:08:26 +00:00
|
|
|
},
|
|
|
|
{
|
2017-09-04 14:08:38 +00:00
|
|
|
a: []uint64{1, 2, 3, 4, 5},
|
|
|
|
b: []uint64{4, 5, 6, 7, 8},
|
2017-04-09 11:50:39 +00:00
|
|
|
|
2017-04-21 20:08:26 +00:00
|
|
|
seek: 9,
|
|
|
|
success: false,
|
|
|
|
res: nil,
|
|
|
|
},
|
|
|
|
{
|
2017-09-04 14:08:38 +00:00
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 4, 5, 6, 7, 8, 10, 11},
|
2017-04-09 11:50:39 +00:00
|
|
|
|
2017-04-21 20:08:26 +00:00
|
|
|
seek: 10,
|
|
|
|
success: true,
|
2017-09-04 14:08:38 +00:00
|
|
|
res: []uint64{10, 11},
|
2017-04-21 20:08:26 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2019-03-21 16:23:00 +00:00
|
|
|
a := newListPostings(c.a...)
|
|
|
|
b := newListPostings(c.b...)
|
2017-04-21 20:08:26 +00:00
|
|
|
|
2019-01-03 16:59:52 +00:00
|
|
|
p := Merge(a, b)
|
2017-04-21 20:08:26 +00:00
|
|
|
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Equals(t, c.success, p.Seek(c.seek))
|
2017-12-17 18:08:21 +00:00
|
|
|
|
|
|
|
// After Seek(), At() should be called.
|
|
|
|
if c.success {
|
|
|
|
start := p.At()
|
2017-11-30 14:34:49 +00:00
|
|
|
lst, err := ExpandPostings(p)
|
2017-12-17 18:08:21 +00:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
|
|
|
|
lst = append([]uint64{start}, lst...)
|
|
|
|
testutil.Equals(t, c.res, lst)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemovedPostings(t *testing.T) {
|
|
|
|
var cases = []struct {
|
|
|
|
a, b []uint64
|
|
|
|
res []uint64
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
a: nil,
|
|
|
|
b: nil,
|
|
|
|
res: []uint64(nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4},
|
|
|
|
b: nil,
|
|
|
|
res: []uint64{1, 2, 3, 4},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: nil,
|
|
|
|
b: []uint64{1, 2, 3, 4},
|
|
|
|
res: []uint64(nil),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 5},
|
|
|
|
b: []uint64{6, 7, 8, 9, 10},
|
|
|
|
res: []uint64{1, 2, 3, 4, 5},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 5},
|
|
|
|
b: []uint64{4, 5, 6, 7, 8},
|
|
|
|
res: []uint64{1, 2, 3},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 4, 5, 6, 7, 8, 10, 11},
|
|
|
|
res: []uint64{2, 3, 9},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
|
|
|
|
res: []uint64(nil),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2019-03-21 16:23:00 +00:00
|
|
|
a := newListPostings(c.a...)
|
|
|
|
b := newListPostings(c.b...)
|
2017-12-17 18:08:21 +00:00
|
|
|
|
2017-11-30 14:34:49 +00:00
|
|
|
res, err := ExpandPostings(newRemovedPostings(a, b))
|
2017-12-17 18:08:21 +00:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, c.res, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-14 13:43:04 +00:00
|
|
|
func TestRemovedNextStackoverflow(t *testing.T) {
|
|
|
|
var full []uint64
|
|
|
|
var remove []uint64
|
|
|
|
|
|
|
|
var i uint64
|
|
|
|
for i = 0; i < 1e7; i++ {
|
|
|
|
full = append(full, i)
|
|
|
|
remove = append(remove, i)
|
|
|
|
}
|
|
|
|
|
2019-03-21 16:23:00 +00:00
|
|
|
flp := newListPostings(full...)
|
|
|
|
rlp := newListPostings(remove...)
|
2018-02-14 13:43:04 +00:00
|
|
|
rp := newRemovedPostings(flp, rlp)
|
|
|
|
gotElem := false
|
|
|
|
for rp.Next() {
|
|
|
|
gotElem = true
|
|
|
|
}
|
2018-05-07 12:39:54 +00:00
|
|
|
|
2018-02-14 13:43:04 +00:00
|
|
|
testutil.Ok(t, rp.Err())
|
|
|
|
testutil.Assert(t, !gotElem, "")
|
|
|
|
}
|
|
|
|
|
2017-12-17 18:08:21 +00:00
|
|
|
func TestRemovedPostingsSeek(t *testing.T) {
|
|
|
|
var cases = []struct {
|
|
|
|
a, b []uint64
|
|
|
|
|
|
|
|
seek uint64
|
|
|
|
success bool
|
|
|
|
res []uint64
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
a: []uint64{2, 3, 4, 5},
|
|
|
|
b: []uint64{6, 7, 8, 9, 10},
|
|
|
|
|
|
|
|
seek: 1,
|
|
|
|
success: true,
|
|
|
|
res: []uint64{2, 3, 4, 5},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 5},
|
|
|
|
b: []uint64{6, 7, 8, 9, 10},
|
|
|
|
|
|
|
|
seek: 2,
|
|
|
|
success: true,
|
|
|
|
res: []uint64{2, 3, 4, 5},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 5},
|
|
|
|
b: []uint64{4, 5, 6, 7, 8},
|
|
|
|
|
|
|
|
seek: 9,
|
|
|
|
success: false,
|
|
|
|
res: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 4, 5, 6, 7, 8, 10, 11},
|
|
|
|
|
|
|
|
seek: 10,
|
|
|
|
success: false,
|
|
|
|
res: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 4, 5, 6, 7, 8, 11},
|
|
|
|
|
|
|
|
seek: 4,
|
|
|
|
success: true,
|
|
|
|
res: []uint64{9, 10},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 4, 5, 6, 7, 8, 11},
|
|
|
|
|
|
|
|
seek: 5,
|
|
|
|
success: true,
|
|
|
|
res: []uint64{9, 10},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []uint64{1, 2, 3, 4, 9, 10},
|
|
|
|
b: []uint64{1, 4, 5, 6, 7, 8, 11},
|
|
|
|
|
|
|
|
seek: 10,
|
|
|
|
success: true,
|
|
|
|
res: []uint64{10},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
2019-03-21 16:23:00 +00:00
|
|
|
a := newListPostings(c.a...)
|
|
|
|
b := newListPostings(c.b...)
|
2017-12-17 18:08:21 +00:00
|
|
|
|
|
|
|
p := newRemovedPostings(a, b)
|
|
|
|
|
|
|
|
testutil.Equals(t, c.success, p.Seek(c.seek))
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
|
|
|
|
// After Seek(), At() should be called.
|
|
|
|
if c.success {
|
|
|
|
start := p.At()
|
2017-11-30 14:34:49 +00:00
|
|
|
lst, err := ExpandPostings(p)
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Ok(t, err)
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
|
2017-09-04 14:08:38 +00:00
|
|
|
lst = append([]uint64{start}, lst...)
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Equals(t, c.res, lst)
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
}
|
2016-12-28 10:02:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-27 10:16:55 +00:00
|
|
|
|
|
|
|
func TestBigEndian(t *testing.T) {
|
|
|
|
num := 1000
|
|
|
|
// mock a list as postings
|
|
|
|
ls := make([]uint32, num)
|
|
|
|
ls[0] = 2
|
|
|
|
for i := 1; i < num; i++ {
|
|
|
|
ls[i] = ls[i-1] + uint32(rand.Int31n(25)) + 2
|
|
|
|
}
|
|
|
|
|
|
|
|
beLst := make([]byte, num*4)
|
|
|
|
for i := 0; i < num; i++ {
|
|
|
|
b := beLst[i*4 : i*4+4]
|
|
|
|
binary.BigEndian.PutUint32(b, ls[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Iteration", func(t *testing.T) {
|
|
|
|
bep := newBigEndianPostings(beLst)
|
|
|
|
for i := 0; i < num; i++ {
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Assert(t, bep.Next() == true, "")
|
|
|
|
testutil.Equals(t, uint64(ls[i]), bep.At())
|
2017-03-27 10:16:55 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Assert(t, bep.Next() == false, "")
|
2017-12-08 21:42:08 +00:00
|
|
|
testutil.Assert(t, bep.Err() == nil, "")
|
2017-03-27 10:16:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Seek", func(t *testing.T) {
|
|
|
|
table := []struct {
|
|
|
|
seek uint32
|
|
|
|
val uint32
|
|
|
|
found bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
ls[0] - 1, ls[0], true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ls[4], ls[4], true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ls[500] - 1, ls[500], true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ls[600] + 1, ls[601], true,
|
|
|
|
},
|
|
|
|
{
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
ls[600] + 1, ls[601], true,
|
2017-03-27 10:16:55 +00:00
|
|
|
},
|
|
|
|
{
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
ls[600] + 1, ls[601], true,
|
2017-03-27 10:16:55 +00:00
|
|
|
},
|
|
|
|
{
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
ls[0], ls[601], true,
|
2017-03-27 10:16:55 +00:00
|
|
|
},
|
|
|
|
{
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
ls[600], ls[601], true,
|
2017-03-27 10:16:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ls[999], ls[999], true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ls[999] + 10, ls[999], false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
bep := newBigEndianPostings(beLst)
|
|
|
|
|
|
|
|
for _, v := range table {
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Equals(t, v.found, bep.Seek(uint64(v.seek)))
|
|
|
|
testutil.Equals(t, uint64(v.val), bep.At())
|
2017-12-08 21:42:08 +00:00
|
|
|
testutil.Assert(t, bep.Err() == nil, "")
|
2017-03-27 10:16:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
|
|
|
|
func TestIntersectWithMerge(t *testing.T) {
|
2019-03-21 16:23:00 +00:00
|
|
|
// One of the reproducible cases for:
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
// https://github.com/prometheus/prometheus/issues/2616
|
2019-03-21 16:23:00 +00:00
|
|
|
a := newListPostings(21, 22, 23, 24, 25, 30)
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
|
2019-01-03 16:59:52 +00:00
|
|
|
b := Merge(
|
2019-03-21 16:23:00 +00:00
|
|
|
newListPostings(10, 20, 30),
|
|
|
|
newListPostings(15, 26, 30),
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
p := Intersect(a, b)
|
2017-11-30 14:34:49 +00:00
|
|
|
res, err := ExpandPostings(p)
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
|
2017-12-07 01:12:38 +00:00
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, []uint64{30}, res)
|
Fix missing postings in Merge and Intersect (#77)
* Test for a previous implematation of Intersect
Before we were moving the postings list everytime we create a new
chained `intersectPostings`. That was causing some postings to be
skipped. This test fails on the older version.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Advance on Seek only when valid.
Issue:
Before in mergedPostings and others we advance everytime we `Seek`,
which causes issues with `Intersect`.
Take the case, where we have a mergedPostings = m merging, a: {10, 20, 30} and
b: {15, 25, 35}. Everytime we `Seek`, we do a.Seek and b.Seek.
Now if we Intersect m with {21, 22, 23, 30}, we would do Seek({21,22,23}) which
would advance a and b beyond 30.
Fix:
Now we advance only when the seeking value is greater than the current
value, as the definition specifies.
Also, posting 0 will not be a valid posting and will be used to signal
finished or un-initialized PostingsList.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add test for Merge+Intersect edgecase.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
* Add comments to trivial tests.
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
2017-05-12 07:44:41 +00:00
|
|
|
}
|
2019-03-21 16:23:00 +00:00
|
|
|
|
|
|
|
func TestWithoutPostings(t *testing.T) {
|
|
|
|
var cases = []struct {
|
|
|
|
base Postings
|
|
|
|
drop Postings
|
|
|
|
|
|
|
|
res Postings
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
base: EmptyPostings(),
|
|
|
|
drop: EmptyPostings(),
|
|
|
|
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
base: EmptyPostings(),
|
|
|
|
drop: newListPostings(1, 2),
|
|
|
|
|
|
|
|
res: EmptyPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
base: newListPostings(1, 2),
|
|
|
|
drop: EmptyPostings(),
|
|
|
|
|
|
|
|
res: newListPostings(1, 2),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
base: newListPostings(),
|
|
|
|
drop: newListPostings(),
|
|
|
|
|
|
|
|
res: newListPostings(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
base: newListPostings(1, 2, 3),
|
|
|
|
drop: newListPostings(),
|
|
|
|
|
|
|
|
res: newListPostings(1, 2, 3),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
base: newListPostings(1, 2, 3),
|
|
|
|
drop: newListPostings(4, 5, 6),
|
|
|
|
|
|
|
|
res: newListPostings(1, 2, 3),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
base: newListPostings(1, 2, 3),
|
|
|
|
drop: newListPostings(3, 4, 5),
|
|
|
|
|
|
|
|
res: newListPostings(1, 2),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
if c.res == nil {
|
|
|
|
t.Fatal("without result expectancy cannot be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
expected, err := ExpandPostings(c.res)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
|
|
|
|
w := Without(c.base, c.drop)
|
|
|
|
|
|
|
|
if c.res == EmptyPostings() {
|
|
|
|
testutil.Equals(t, EmptyPostings(), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if w == EmptyPostings() {
|
|
|
|
t.Fatal("without unexpected result: EmptyPostings sentinel")
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := ExpandPostings(w)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Equals(t, expected, res)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|