-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
358 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.