Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: add initMergingIterLevel to flushable interface #3616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,14 @@ func (b *flushableBatch) Swap(i, j int) {
b.offsets[i], b.offsets[j] = b.offsets[j], b.offsets[i]
}

// initMergingIterLevel is part of the flushable interface.
func (b *flushableBatch) initMergingIterLevel(
ctx context.Context, o *IterOptions, mil *mergingIterLevel,
) {
mil.iter = b.newIter(o)
mil.rangeDelIter = b.newRangeDelIter(o)
}

// newIter is part of the flushable interface.
func (b *flushableBatch) newIter(o *IterOptions) internalIterator {
return &flushableBatchIter{
Expand Down
6 changes: 2 additions & 4 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,10 +1451,8 @@ func (i *Iterator) constructPointIter(
// Next are the memtables.
for j := len(memtables) - 1; j >= 0; j-- {
mem := memtables[j]
mlevels = append(mlevels, mergingIterLevel{
iter: mem.newIter(&i.opts),
rangeDelIter: mem.newRangeDelIter(&i.opts),
})
mlevels = append(mlevels, mergingIterLevel{})
mem.initMergingIterLevel(ctx, &i.opts, &mlevels[len(mlevels)-1])
}

// Next are the file levels: L0 sub-levels followed by lower levels.
Expand Down
15 changes: 13 additions & 2 deletions flushable.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/invalidating"
"github.com/cockroachdb/pebble/internal/invariants"
"github.com/cockroachdb/pebble/internal/keyspan"
"github.com/cockroachdb/pebble/internal/keyspan/keyspanimpl"
Expand All @@ -21,6 +22,9 @@ import (

// flushable defines the interface for immutable memtables.
type flushable interface {
// initMergingIterLevel initializes a mergingIterLevel for iteration over
// the flushable's point keys and range deletions.
initMergingIterLevel(ctx context.Context, o *IterOptions, mil *mergingIterLevel)
newIter(o *IterOptions) internalIterator
newFlushIter(o *IterOptions) internalIterator
newRangeDelIter(o *IterOptions) keyspan.FragmentIterator
Expand Down Expand Up @@ -209,6 +213,15 @@ func newIngestedFlushable(
// TODO(sumeer): ingestedFlushable iters also need to plumb context for
// tracing.

func (s *ingestedFlushable) initMergingIterLevel(
ctx context.Context, o *IterOptions, mil *mergingIterLevel,
) {
li := newLevelIter(ctx, *o, s.comparer, s.newIters, s.slice.Iter(), manifest.Level(0), internalIterOpts{})
li.initRangeDel(&mil.rangeDelIter)
mil.levelIter = li
mil.iter = invalidating.MaybeWrapIfInvariants(li)
}

// newIter is part of the flushable interface.
func (s *ingestedFlushable) newIter(o *IterOptions) internalIterator {
var opts IterOptions
Expand Down Expand Up @@ -244,8 +257,6 @@ func (s *ingestedFlushable) constructRangeDelIter(
}

// newRangeDelIter is part of the flushable interface.
// TODO(bananabrick): Using a level iter instead of a keyspan level iter to
// surface range deletes is more efficient.
//
// TODO(sumeer): *IterOptions are being ignored, so the index block load for
// the point iterator in constructRangeDeIter is not tracked.
Expand Down
10 changes: 10 additions & 0 deletions mem_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package pebble

import (
"bytes"
"context"
"fmt"
"os"
"sync"
Expand Down Expand Up @@ -252,6 +253,15 @@ func (m *memTable) apply(batch *Batch, seqNum uint64) error {
return nil
}

func (m *memTable) initMergingIterLevel(
ctx context.Context, o *IterOptions, mil *mergingIterLevel,
) {
*mil = mergingIterLevel{
iter: m.newIter(o),
rangeDelIter: m.newRangeDelIter(o),
}
}

// newIter is part of the flushable interface. It returns an iterator that is
// unpositioned (Iterator.Valid() will return false). The iterator can be
// positioned via a call to SeekGE, SeekLT, First or Last.
Expand Down
Loading