diff --git a/db.go b/db.go index e04bdd3c27b17ba7bacac9faf907f3ef046e5d76..f4902f4d5e381743976bb169ac7e31dcfaa37362 100644 --- a/db.go +++ b/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 diff --git a/postings.go b/postings.go index db0f9107775eab2472ddbfaaac518d224fd6d5c3..0beb3339c6b4c7e0849e824df36852f84456412b 100644 --- a/postings.go +++ b/postings.go @@ -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) diff --git a/postings_test.go b/postings_test.go index f348e4d2a8c8651ef15e2847287f6b63633f5e4a..f3fde043da04188a630bb9801795469bb7d37366 100644 --- a/postings_test.go +++ b/postings_test.go @@ -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