mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 08:33:06 +00:00
Zero timestamp as base, use binary search list postings
This commit is contained in:
parent
dd72b52098
commit
ab7fbc05ad
5
db.go
5
db.go
@ -201,13 +201,12 @@ func OpenShard(path string, logger log.Logger) (*Shard, error) {
|
||||
}
|
||||
|
||||
// TODO(fabxc): get time from client-defined `now` function.
|
||||
baset := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
// baset := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
baset := time.Unix(0, 0).UnixNano() / int64(time.Millisecond)
|
||||
if len(pbs) > 0 {
|
||||
baset = pbs[len(pbs)-1].stats.MaxTime
|
||||
}
|
||||
if head == nil {
|
||||
fmt.Println("creating new head", baset)
|
||||
|
||||
head, err = OpenHeadBlock(filepath.Join(path, fmt.Sprintf("%d", baset)), baset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -164,6 +164,10 @@ type listPostings struct {
|
||||
idx int
|
||||
}
|
||||
|
||||
func newListPostings(list []uint32) *listPostings {
|
||||
return &listPostings{list: list, idx: -1}
|
||||
}
|
||||
|
||||
func (it *listPostings) Value() uint32 {
|
||||
return it.list[it.idx]
|
||||
}
|
||||
@ -175,7 +179,7 @@ func (it *listPostings) Next() bool {
|
||||
|
||||
func (it *listPostings) Seek(x uint32) bool {
|
||||
// Do binary search between current position and end.
|
||||
it.idx = sort.Search(len(it.list)-it.idx, func(i int) bool {
|
||||
it.idx += sort.Search(len(it.list)-it.idx, func(i int) bool {
|
||||
return it.list[i+it.idx] >= x
|
||||
})
|
||||
return it.idx < len(it.list)
|
||||
|
@ -17,27 +17,6 @@ func (m *mockPostings) Seek(v uint32) bool { return m.seek(v) }
|
||||
func (m *mockPostings) Value() uint32 { return m.value() }
|
||||
func (m *mockPostings) Err() error { return m.err() }
|
||||
|
||||
func newListPostings(list []uint32) *mockPostings {
|
||||
i := -1
|
||||
return &mockPostings{
|
||||
next: func() bool {
|
||||
i++
|
||||
return i < len(list)
|
||||
},
|
||||
seek: func(v uint32) bool {
|
||||
for ; i < len(list); i++ {
|
||||
if list[i] >= v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
value: func() uint32 {
|
||||
return list[i]
|
||||
},
|
||||
err: func() error { return nil },
|
||||
}
|
||||
}
|
||||
func TestIntersectIterator(t *testing.T) {
|
||||
var cases = []struct {
|
||||
a, b []uint32
|
||||
|
Loading…
Reference in New Issue
Block a user