-
Notifications
You must be signed in to change notification settings - Fork 66
backend/local: check and return iter.Error when pebble is not valid #497
Changes from all commits
61d6382
b470eb9
c23ae71
d488a0b
aa6be9f
1d8b293
11e4cc6
5cf42d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,8 +500,12 @@ func (local *local) WriteToTiKV( | |
opt := &pebble.IterOptions{LowerBound: regionRange.start, UpperBound: regionRange.end} | ||
iter := engineFile.db.NewIter(opt) | ||
defer iter.Close() | ||
iter.First() | ||
if iter.Error() != nil { | ||
return nil, nil, errors.Annotate(iter.Error(), "failed to read the first key") | ||
} | ||
|
||
if !iter.First() { | ||
if !iter.Valid() { | ||
log.L().Info("keys within region is empty, skip ingest", zap.Binary("start", start), | ||
zap.Binary("regionStart", region.Region.StartKey), zap.Binary("end", end), | ||
zap.Binary("regionEnd", region.Region.EndKey)) | ||
|
@@ -510,6 +514,9 @@ func (local *local) WriteToTiKV( | |
|
||
firstKey := codec.EncodeBytes([]byte{}, iter.Key()) | ||
iter.Last() | ||
if iter.Error() != nil { | ||
return nil, nil, errors.Annotate(iter.Error(), "failed to seek to the last key") | ||
} | ||
lastKey := codec.EncodeBytes([]byte{}, iter.Key()) | ||
|
||
u := uuid.New() | ||
|
@@ -596,6 +603,10 @@ func (local *local) WriteToTiKV( | |
} | ||
} | ||
|
||
if iter.Error() != nil { | ||
return nil, nil, errors.Trace(iter.Error()) | ||
} | ||
|
||
if count > 0 { | ||
for i := range clients { | ||
requests[i].Chunk.(*sst.WriteRequest_Batch).Batch.Pairs = pairs[:count] | ||
|
@@ -605,10 +616,6 @@ func (local *local) WriteToTiKV( | |
} | ||
} | ||
|
||
if iter.Error() != nil { | ||
return nil, nil, errors.Trace(iter.Error()) | ||
} | ||
|
||
var leaderPeerMetas []*sst.SSTMeta | ||
for i, wStream := range clients { | ||
if resp, closeErr := wStream.CloseAndRecv(); closeErr != nil { | ||
|
@@ -705,16 +712,24 @@ func (local *local) readAndSplitIntoRange(engineFile *LocalFile) ([]Range, error | |
iter := engineFile.db.NewIter(nil) | ||
defer iter.Close() | ||
|
||
iterError := func(e string) error { | ||
err := iter.Error() | ||
if err != nil { | ||
return errors.Annotate(err, e) | ||
} | ||
return errors.New(e) | ||
} | ||
|
||
var firstKey, lastKey []byte | ||
if iter.First() { | ||
firstKey = append([]byte{}, iter.Key()...) | ||
} else { | ||
return nil, errors.New("could not find first pair, this shouldn't happen") | ||
return nil, iterError("could not find first pair") | ||
} | ||
if iter.Last() { | ||
lastKey = append([]byte{}, iter.Key()...) | ||
} else { | ||
return nil, errors.New("could not find last pair, this shouldn't happen") | ||
return nil, iterError("could not find last pair") | ||
} | ||
endKey := nextKey(lastKey) | ||
|
||
|
@@ -851,6 +866,9 @@ func (local *local) writeAndIngestByRange( | |
defer iter.Close() | ||
// Needs seek to first because NewIter returns an iterator that is unpositioned | ||
hasKey := iter.First() | ||
if iter.Error() != nil { | ||
return errors.Annotate(iter.Error(), "failed to read the first key") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about iter.Last() at line 877? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this comment? @glorv There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, see #880-883 @lance6716 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we only need to check iter.Error() != nil which indicates that something goes wrong. iter.Error() != nil always means iter.Valid() is false. if iter.Error() == nil and iter.Valid() is false, this means the iterator iters to the end, this is ok to our logic. |
||
if !hasKey { | ||
log.L().Info("There is no pairs in iterator", | ||
zap.Binary("start", start), | ||
|
@@ -860,6 +878,9 @@ func (local *local) writeAndIngestByRange( | |
} | ||
pairStart := append([]byte{}, iter.Key()...) | ||
iter.Last() | ||
if iter.Error() != nil { | ||
return errors.Annotate(iter.Error(), "failed to seek to the last key") | ||
} | ||
pairEnd := append([]byte{}, iter.Key()...) | ||
|
||
var regions []*split.RegionInfo | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
iter.Last()
at line 516?