-
Notifications
You must be signed in to change notification settings - Fork 24
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
[close #231] TiKV-BR support v5.x.x #282
Changes from 19 commits
ac8636e
a771b08
07a6189
0d1bd59
af1011a
4e71c6d
ffaf917
428a1b7
5d07b7b
fa53c47
b76eb22
6d08b56
956460e
b72a936
f73276e
14b651c
c70dc40
05d1c5c
3276852
1cbb9e8
2534adb
616d61e
80f7a2d
467c64e
81bb104
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 |
---|---|---|
|
@@ -89,6 +89,46 @@ func (push *pushDown) pushBackup( | |
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
failpoint.Inject("backup-storage-error", func(val failpoint.Value) { | ||
msg := val.(string) | ||
logutil.CL(ctx).Debug("failpoint backup-storage-error injected.", zap.String("msg", msg)) | ||
resp := new(backuppb.BackupResponse) | ||
resp.Error = &backuppb.Error{ | ||
Msg: msg, | ||
} | ||
push.respCh <- responseAndStore{ | ||
Resp: resp, | ||
Store: store, | ||
} | ||
}) | ||
failpoint.Inject("tikv-rw-error", func(val failpoint.Value) { | ||
msg := val.(string) | ||
logutil.CL(ctx).Debug("failpoint tikv-rw-error injected.", zap.String("msg", msg)) | ||
resp := new(backuppb.BackupResponse) | ||
resp.Error = &backuppb.Error{ | ||
Msg: msg, | ||
} | ||
push.respCh <- responseAndStore{ | ||
Resp: resp, | ||
Store: store, | ||
} | ||
}) | ||
failpoint.Inject("tikv-region-error", func(val failpoint.Value) { | ||
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. Have we verified that the failpoint is effective ? This failpoint should cause an incomplete range and enter procedure 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. 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. This change will change the original behavior, as all regions will fail, other than only one of them. In real scenarios, there should be only a small number of regions will fail. I think we can change 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. Done, thanks. |
||
msg := val.(string) | ||
resp := new(backuppb.BackupResponse) | ||
logutil.CL(ctx).Debug("failpoint tikv-region-error injected.", zap.String("msg", msg)) | ||
resp.Error = &backuppb.Error{ | ||
Detail: &backuppb.Error_RegionError{ | ||
RegionError: &errorpb.Error{ | ||
Message: msg, | ||
}, | ||
}, | ||
} | ||
push.respCh <- responseAndStore{ | ||
Resp: resp, | ||
Store: store, | ||
} | ||
}) | ||
err := SendBackup( | ||
lctx, storeID, client, req, | ||
func(resp *backuppb.BackupResponse) error { | ||
|
@@ -117,7 +157,6 @@ func (push *pushDown) pushBackup( | |
close(push.respCh) | ||
}() | ||
|
||
regionErrorIngestedOnce := false | ||
for { | ||
select { | ||
case respAndStore, ok := <-push.respCh: | ||
|
@@ -127,35 +166,6 @@ func (push *pushDown) pushBackup( | |
// Finished. | ||
return res, nil | ||
} | ||
failpoint.Inject("backup-storage-error", func(val failpoint.Value) { | ||
msg := val.(string) | ||
logutil.CL(ctx).Debug("failpoint backup-storage-error injected.", zap.String("msg", msg)) | ||
resp.Error = &backuppb.Error{ | ||
Msg: msg, | ||
} | ||
}) | ||
failpoint.Inject("tikv-rw-error", func(val failpoint.Value) { | ||
msg := val.(string) | ||
logutil.CL(ctx).Debug("failpoint tikv-rw-error injected.", zap.String("msg", msg)) | ||
resp.Error = &backuppb.Error{ | ||
Msg: msg, | ||
} | ||
}) | ||
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, | ||
}, | ||
}, | ||
} | ||
} | ||
regionErrorIngestedOnce = true | ||
}) | ||
if resp.GetError() == nil { | ||
// None error means range has been backuped successfully. | ||
res.Put(resp.GetStartKey(), resp.GetEndKey(), resp.GetFiles()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package feature | ||
|
||
import "github.com/coreos/go-semver/semver" | ||
|
||
type Feature int | ||
|
||
const ( | ||
APIVersionConversion Feature = iota | ||
Checksum | ||
BackupTs | ||
SplitRegion | ||
) | ||
|
||
var ( | ||
minAPIVersionConversionVersion = semver.New("6.1.0") | ||
minChecksumVersion = semver.New("6.1.1") | ||
minBackupTsVersion = semver.New("6.2.0") | ||
minSplitRegionVersion = semver.New("5.2.0") | ||
) | ||
|
||
type Gate struct { | ||
features map[Feature]*semver.Version | ||
pdVersion *semver.Version | ||
} | ||
|
||
func NewFeatureGate(pdVersion *semver.Version) *Gate { | ||
featureGate := new(Gate) | ||
featureGate.features = make(map[Feature]*semver.Version) | ||
featureGate.features[APIVersionConversion] = minAPIVersionConversionVersion | ||
featureGate.features[Checksum] = minChecksumVersion | ||
featureGate.features[BackupTs] = minBackupTsVersion | ||
featureGate.features[SplitRegion] = minSplitRegionVersion | ||
featureGate.pdVersion = pdVersion | ||
return featureGate | ||
} | ||
|
||
func (f *Gate) IsEnabled(feature Feature) bool { | ||
return f.pdVersion.Compare(*f.features[feature]) >= 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package feature | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFeatureGate(t *testing.T) { | ||
gate := NewFeatureGate(semver.New("6.0.0")) | ||
require.False(t, gate.IsEnabled(APIVersionConversion)) | ||
require.False(t, gate.IsEnabled(Checksum)) | ||
require.False(t, gate.IsEnabled(BackupTs)) | ||
require.True(t, gate.IsEnabled(SplitRegion)) | ||
|
||
gate = NewFeatureGate(semver.New("6.1.0")) | ||
require.True(t, gate.IsEnabled(APIVersionConversion)) | ||
require.False(t, gate.IsEnabled(Checksum)) | ||
require.False(t, gate.IsEnabled(BackupTs)) | ||
|
||
gate = NewFeatureGate(semver.New("6.1.1")) | ||
require.True(t, gate.IsEnabled(Checksum)) | ||
|
||
gate = NewFeatureGate(semver.New("6.2.0")) | ||
require.True(t, gate.IsEnabled(BackupTs)) | ||
|
||
gate = NewFeatureGate(semver.New("5.1.0")) | ||
require.False(t, gate.IsEnabled(SplitRegion)) | ||
|
||
gate = NewFeatureGate(semver.New("5.2.0")) | ||
require.True(t, gate.IsEnabled(SplitRegion)) | ||
} |
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.
Nit: add a space before
?=
and align other lines.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.
Done