Skip to content

Commit

Permalink
db: don't use internal types in ScanInternal
Browse files Browse the repository at this point in the history
This change updates the ScanInternal function signature
to not use the internal keyspan.Key type. Instead we use
the rangekey.Key type alias that exports it.

Also update the pointCollapsingIter to just call SeekGE
in NextPrefix instead of panicking.

Necessary for cockroachdb/cockroach#103028.
  • Loading branch information
itsbilal committed Jun 14, 2023
1 parent 2fed2e7 commit 16e353f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cockroachdb/pebble/internal/manifest"
"github.com/cockroachdb/pebble/internal/manual"
"github.com/cockroachdb/pebble/objstorage"
"github.com/cockroachdb/pebble/rangekey"
"github.com/cockroachdb/pebble/record"
"github.com/cockroachdb/pebble/sstable"
"github.com/cockroachdb/pebble/vfs"
Expand Down Expand Up @@ -1183,7 +1184,7 @@ func (d *DB) ScanInternal(
lower, upper []byte,
visitPointKey func(key *InternalKey, value LazyValue) error,
visitRangeDel func(start, end []byte, seqNum uint64) error,
visitRangeKey func(start, end []byte, keys []keyspan.Key) error,
visitRangeKey func(start, end []byte, keys []rangekey.Key) error,
visitSharedFile func(sst *SharedSSTMeta) error,
) error {
iter := d.newInternalIter(nil /* snapshot */, &scanInternalOptions{
Expand Down
7 changes: 4 additions & 3 deletions scan_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cockroachdb/pebble/internal/keyspan"
"github.com/cockroachdb/pebble/internal/manifest"
"github.com/cockroachdb/pebble/objstorage"
"github.com/cockroachdb/pebble/rangekey"
"github.com/cockroachdb/pebble/sstable"
)

Expand Down Expand Up @@ -591,10 +592,10 @@ func (p *pointCollapsingIterator) Next() (*base.InternalKey, base.LazyValue) {

// NextPrefix implements the InternalIterator interface.
func (p *pointCollapsingIterator) NextPrefix(succKey []byte) (*base.InternalKey, base.LazyValue) {
// TODO(bilal): Implement this. It'll be similar to SeekGE, except we'll call
// TODO(bilal): Implement this optimally. It'll be similar to SeekGE, except we'll call
// the child iterator's NextPrefix, and have some special logic in case pos
// is pcIterPosNext.
panic("unimplemented")
return p.SeekGE(succKey, base.SeekGEFlagsNone)
}

// Prev implements the InternalIterator interface.
Expand Down Expand Up @@ -852,7 +853,7 @@ func scanInternalImpl(
iter *scanInternalIterator,
visitPointKey func(key *InternalKey, value LazyValue) error,
visitRangeDel func(start, end []byte, seqNum uint64) error,
visitRangeKey func(start, end []byte, keys []keyspan.Key) error,
visitRangeKey func(start, end []byte, keys []rangekey.Key) error,
visitSharedFile func(sst *SharedSSTMeta) error,
) error {
if visitSharedFile != nil && (lower == nil || upper == nil) {
Expand Down
5 changes: 3 additions & 2 deletions scan_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cockroachdb/pebble/internal/keyspan"
"github.com/cockroachdb/pebble/internal/testkeys"
"github.com/cockroachdb/pebble/objstorage/shared"
"github.com/cockroachdb/pebble/rangekey"
"github.com/cockroachdb/pebble/sstable"
"github.com/cockroachdb/pebble/vfs"
"github.com/stretchr/testify/require"
Expand All @@ -31,7 +32,7 @@ func TestScanInternal(t *testing.T) {
ctx context.Context,
lower, upper []byte, visitPointKey func(key *InternalKey, value LazyValue) error,
visitRangeDel func(start, end []byte, seqNum uint64) error,
visitRangeKey func(start, end []byte, keys []keyspan.Key) error,
visitRangeKey func(start, end []byte, keys []rangekey.Key) error,
visitSharedFile func(sst *SharedSSTMeta) error) error
}
batches := map[string]*Batch{}
Expand Down Expand Up @@ -243,7 +244,7 @@ func TestScanInternal(t *testing.T) {
}, func(start, end []byte, seqNum uint64) error {
fmt.Fprintf(&b, "%s-%s#%d,RANGEDEL\n", start, end, seqNum)
return nil
}, func(start, end []byte, keys []keyspan.Key) error {
}, func(start, end []byte, keys []rangekey.Key) error {
s := keyspan.Span{Start: start, End: end, Keys: keys}
fmt.Fprintf(&b, "%s\n", s.String())
return nil
Expand Down
4 changes: 2 additions & 2 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"io"
"math"

"github.com/cockroachdb/pebble/internal/keyspan"
"github.com/cockroachdb/pebble/rangekey"
)

// Snapshot provides a read-only point-in-time view of the DB state.
Expand Down Expand Up @@ -68,7 +68,7 @@ func (s *Snapshot) ScanInternal(
lower, upper []byte,
visitPointKey func(key *InternalKey, value LazyValue) error,
visitRangeDel func(start, end []byte, seqNum uint64) error,
visitRangeKey func(start, end []byte, keys []keyspan.Key) error,
visitRangeKey func(start, end []byte, keys []rangekey.Key) error,
visitSharedFile func(sst *SharedSSTMeta) error,
) error {
if s.db == nil {
Expand Down

0 comments on commit 16e353f

Please sign in to comment.