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

lightning: remove ctx from dupDetectIter #41867

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion br/pkg/lightning/backend/local/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ func (e *Engine) newKVIter(ctx context.Context, opts *pebble.IterOptions) Iter {
zap.String("table", common.UniqueTable(e.tableInfo.DB, e.tableInfo.Name)),
zap.Int64("tableID", e.tableInfo.ID),
zap.Stringer("engineUUID", e.UUID))
return newDupDetectIter(ctx, e.db, e.keyAdapter, opts, e.duplicateDB, logger, e.dupDetectOpt)
return newDupDetectIter(e.db, e.keyAdapter, opts, e.duplicateDB, logger, e.dupDetectOpt)
}

// getFirstAndLastKey reads the first and last key in range [lowerBound, upperBound)
Expand Down
10 changes: 2 additions & 8 deletions br/pkg/lightning/backend/local/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package local

import (
"bytes"
"context"

"github.com/cockroachdb/pebble"
sst "github.com/pingcap/kvproto/pkg/import_sstpb"
Expand Down Expand Up @@ -70,7 +69,6 @@ var _ Iter = pebbleIter{}
const maxDuplicateBatchSize = 4 << 20

type dupDetectIter struct {
ctx context.Context
iter *pebble.Iterator
curKey []byte
curRawKey []byte
Expand Down Expand Up @@ -143,7 +141,7 @@ func (d *dupDetectIter) record(rawKey, key, val []byte) {

func (d *dupDetectIter) Next() bool {
recordFirst := false
for d.err == nil && d.ctx.Err() == nil && d.iter.Next() {
for d.err == nil && d.iter.Next() {
d.nextKey, d.err = d.keyAdapter.Decode(d.nextKey[:0], d.iter.Key())
if d.err != nil {
return false
Expand All @@ -168,9 +166,6 @@ func (d *dupDetectIter) Next() bool {
}
d.record(d.iter.Key(), d.nextKey, d.iter.Value())
}
if d.err == nil {
d.err = d.ctx.Err()
}
return false
}

Expand Down Expand Up @@ -204,7 +199,7 @@ func (d *dupDetectIter) OpType() sst.Pair_OP {

var _ Iter = &dupDetectIter{}

func newDupDetectIter(ctx context.Context, db *pebble.DB, keyAdapter KeyAdapter,
func newDupDetectIter(db *pebble.DB, keyAdapter KeyAdapter,
opts *pebble.IterOptions, dupDB *pebble.DB, logger log.Logger, dupOpt dupDetectOpt) *dupDetectIter {
newOpts := &pebble.IterOptions{TableFilter: opts.TableFilter}
if len(opts.LowerBound) > 0 {
Expand All @@ -214,7 +209,6 @@ func newDupDetectIter(ctx context.Context, db *pebble.DB, keyAdapter KeyAdapter,
newOpts.UpperBound = keyAdapter.Encode(nil, opts.UpperBound, MinRowID)
}
return &dupDetectIter{
ctx: ctx,
iter: db.NewIter(newOpts),
keyAdapter: keyAdapter,
writeBatch: dupDB.NewBatch(),
Expand Down
5 changes: 2 additions & 3 deletions br/pkg/lightning/backend/local/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package local

import (
"bytes"
"context"
"math/rand"
"path/filepath"
"sort"
Expand Down Expand Up @@ -122,7 +121,7 @@ func TestDupDetectIterator(t *testing.T) {
dupDB, err := pebble.Open(filepath.Join(storeDir, "duplicates"), &pebble.Options{})
require.NoError(t, err)
var iter Iter
iter = newDupDetectIter(context.Background(), db, keyAdapter, &pebble.IterOptions{}, dupDB, log.L(), dupDetectOpt{})
iter = newDupDetectIter(db, keyAdapter, &pebble.IterOptions{}, dupDB, log.L(), dupDetectOpt{})
sort.Slice(pairs, func(i, j int) bool {
key1 := keyAdapter.Encode(nil, pairs[i].Key, pairs[i].RowID)
key2 := keyAdapter.Encode(nil, pairs[j].Key, pairs[j].RowID)
Expand Down Expand Up @@ -217,7 +216,7 @@ func TestDupDetectIterSeek(t *testing.T) {

dupDB, err := pebble.Open(filepath.Join(storeDir, "duplicates"), &pebble.Options{})
require.NoError(t, err)
iter := newDupDetectIter(context.Background(), db, keyAdapter, &pebble.IterOptions{}, dupDB, log.L(), dupDetectOpt{})
iter := newDupDetectIter(db, keyAdapter, &pebble.IterOptions{}, dupDB, log.L(), dupDetectOpt{})

require.True(t, iter.Seek([]byte{1, 2, 3, 1}))
require.Equal(t, pairs[1].Val, iter.Value())
Expand Down