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

br: Fix RangeTree.GetIncompleteRange when the rangeTree is empty. (#37086) #46168

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions br/pkg/backup/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func (push *pushDown) pushBackup(
close(push.respCh)
}()

regionErrorIngestedOnce := false
for {
select {
case respAndStore, ok := <-push.respCh:
Expand Down Expand Up @@ -151,19 +150,16 @@ func (push *pushDown) pushBackup(
}
})
failpoint.Inject("tikv-region-error", func(val failpoint.Value) {
if !regionErrorIngestedOnce {
msg := val.(string)
logutil.CL(ctx).Debug("failpoint tikv-regionh-error injected.", zap.String("msg", msg))
resp.Error = &backuppb.Error{
// Msg: msg,
Detail: &backuppb.Error_RegionError{
RegionError: &errorpb.Error{
Message: msg,
},
msg := val.(string)
logutil.CL(ctx).Debug("failpoint tikv-region-error injected.", zap.String("msg", msg))
resp.Error = &backuppb.Error{
// Msg: msg,
Detail: &backuppb.Error_RegionError{
RegionError: &errorpb.Error{
Message: msg,
},
}
},
}
regionErrorIngestedOnce = true
})
if resp.GetError() == nil {
// None error means range has been backuped successfully.
Expand Down
13 changes: 8 additions & 5 deletions br/pkg/rtree/rtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,19 @@ func (rangeTree *RangeTree) GetIncompleteRange(
return []Range{}
}
incomplete := make([]Range, 0, 64)
requsetRange := Range{StartKey: startKey, EndKey: endKey}
requestRange := Range{StartKey: startKey, EndKey: endKey}
lastEndKey := startKey
pviot := &Range{StartKey: startKey}
if first := rangeTree.Find(pviot); first != nil {
pviot.StartKey = first.StartKey
}
pviotNotFound := true
rangeTree.AscendGreaterOrEqual(pviot, func(i btree.Item) bool {
pviotNotFound = false
rg := i.(*Range)
if bytes.Compare(lastEndKey, rg.StartKey) < 0 {
start, end, isIntersect :=
requsetRange.Intersect(lastEndKey, rg.StartKey)
requestRange.Intersect(lastEndKey, rg.StartKey)
if isIntersect {
// There is a gap between the last item and the current item.
incomplete =
Expand All @@ -207,9 +209,10 @@ func (rangeTree *RangeTree) GetIncompleteRange(
})

// Check whether we need append the last range
if !bytes.Equal(lastEndKey, endKey) && len(lastEndKey) != 0 &&
(len(endKey) == 0 || bytes.Compare(lastEndKey, endKey) < 0) {
start, end, isIntersect := requsetRange.Intersect(lastEndKey, endKey)
if pviotNotFound ||
(!bytes.Equal(lastEndKey, endKey) && len(lastEndKey) != 0 &&
(len(endKey) == 0 || bytes.Compare(lastEndKey, endKey) < 0)) {
start, end, isIntersect := requestRange.Intersect(lastEndKey, endKey)
if isIntersect {
incomplete =
append(incomplete, Range{StartKey: start, EndKey: end})
Expand Down
5 changes: 5 additions & 0 deletions br/pkg/rtree/rtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func TestRangeTree(t *testing.T) {
}
}

assertIncomplete([]byte(""), []byte("b"), []rtree.Range{{StartKey: []byte(""), EndKey: []byte("b")}})
assertIncomplete([]byte(""), []byte(""), []rtree.Range{{StartKey: []byte(""), EndKey: []byte("")}})
assertIncomplete([]byte("b"), []byte(""), []rtree.Range{{StartKey: []byte("b"), EndKey: []byte("")}})

range0 := newRange([]byte(""), []byte("a"))
rangeA := newRange([]byte("a"), []byte("b"))
rangeB := newRange([]byte("b"), []byte("c"))
Expand All @@ -61,6 +65,7 @@ func TestRangeTree(t *testing.T) {
{StartKey: []byte(""), EndKey: []byte("a")},
{StartKey: []byte("b"), EndKey: []byte("")},
})
assertIncomplete([]byte("b"), []byte(""), []rtree.Range{{StartKey: []byte("b"), EndKey: []byte("")}})

rangeTree.Update(*rangeC)
require.Equal(t, 2, rangeTree.Len())
Expand Down
9 changes: 5 additions & 4 deletions br/tests/br_rawkv/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ test_full_rawkv() {

checksum_full=$(checksum $check_range_start $check_range_end)
# backup current state of key-values
# raw backup is not working with range [nil, nil]. TODO: fix it.
run_br --pd $PD_ADDR backup raw -s "local://$BACKUP_FULL" --crypter.method "aes128-ctr" --crypter.key "0123456789abcdef0123456789abcdef" --start $check_range_start --format hex
run_br --pd $PD_ADDR backup raw -s "local://$BACKUP_FULL" --crypter.method "aes128-ctr" --crypter.key "0123456789abcdef0123456789abcdef"

clean $check_range_start $check_range_end
# Ensure the data is deleted
Expand All @@ -63,7 +62,7 @@ test_full_rawkv() {
fail_and_exit
fi

run_br --pd $PD_ADDR restore raw -s "local://$BACKUP_FULL" --crypter.method "aes128-ctr" --crypter.key "0123456789abcdef0123456789abcdef" --start $check_range_start --format hex
run_br --pd $PD_ADDR restore raw -s "local://$BACKUP_FULL" --crypter.method "aes128-ctr" --crypter.key "0123456789abcdef0123456789abcdef"
checksum_new=$(checksum $check_range_start $check_range_end)
if [ "$checksum_new" != "$checksum_full" ];then
echo "failed to restore"
Expand Down Expand Up @@ -185,5 +184,7 @@ run_test() {

run_test ""

# ingest "region error" to trigger fineGrainedBackup
# ingest "region error" to trigger fineGrainedBackup, only one region error.
run_test "github.com/pingcap/tidb/br/pkg/backup/tikv-region-error=1*return(\"region error\")"
# all regions failed.
run_test "github.com/pingcap/tidb/br/pkg/backup/tikv-region-error=return(\"region error\")"