-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Add MemberDowngrade failpoint #19038
Draft
siyuanfoundation
wants to merge
2
commits into
etcd-io:main
Choose a base branch
from
siyuanfoundation:downgrade-robust-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−35
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,13 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
pb "go.etcd.io/etcd/api/v3/etcdserverpb" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.etcd.io/etcd/pkg/v3/expect" | ||
"go.etcd.io/etcd/server/v3/etcdserver" | ||
"go.etcd.io/etcd/tests/v3/framework/e2e" | ||
"go.etcd.io/etcd/tests/v3/robustness/identity" | ||
|
@@ -35,6 +38,7 @@ import ( | |
) | ||
|
||
var MemberReplace Failpoint = memberReplace{} | ||
var MemberDowngrade Failpoint = memberDowngrade{} | ||
|
||
type memberReplace struct{} | ||
|
||
|
@@ -138,6 +142,94 @@ func (f memberReplace) Available(config e2e.EtcdProcessClusterConfig, member e2e | |
return config.ClusterSize > 1 && (config.Version == e2e.QuorumLastVersion || member.Config().ExecPath == e2e.BinPath.Etcd) | ||
} | ||
|
||
type memberDowngrade struct{} | ||
|
||
func (f memberDowngrade) Inject(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, baseTime time.Time, ids identity.Provider) ([]report.ClientReport, error) { | ||
v, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
targetVersion := semver.Version{Major: v.Major, Minor: v.Minor - 1} | ||
numberOfMembersToDowngrade := rand.Int()%len(clus.Procs) + 1 | ||
membersToDowngrade := rand.Perm(len(clus.Procs))[:numberOfMembersToDowngrade] | ||
lg.Info("Test downgrading members", zap.Any("members", membersToDowngrade)) | ||
|
||
member := clus.Procs[0] | ||
endpoints := []string{member.EndpointsGRPC()[0]} | ||
cc, err := clientv3.New(clientv3.Config{ | ||
Endpoints: endpoints, | ||
Logger: zap.NewNop(), | ||
DialKeepAliveTime: 10 * time.Second, | ||
DialKeepAliveTimeout: 100 * time.Millisecond, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer cc.Close() | ||
|
||
// Need to wait health interval for cluster to accept changes | ||
time.Sleep(etcdserver.HealthInterval) | ||
lg.Info("Enable downgrade") | ||
err = enableDowngrade(ctx, cc, &targetVersion) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// Need to wait health interval for cluster to prepare for downgrade | ||
time.Sleep(etcdserver.HealthInterval) | ||
|
||
for _, memberID := range membersToDowngrade { | ||
member = clus.Procs[memberID] | ||
lg.Info("Downgrading member", zap.String("member", member.Config().Name)) | ||
for member.IsRunning() { | ||
err = member.Stop() | ||
if err != nil { | ||
lg.Info("Stopping server failed", zap.Error(err)) | ||
} | ||
err = member.Wait(ctx) | ||
if err != nil && !strings.Contains(err.Error(), "unexpected exit code") { | ||
lg.Info("Failed to stop the process", zap.Error(err)) | ||
return nil, fmt.Errorf("failed to stop the process within %s, err: %w", triggerTimeout, err) | ||
} | ||
} | ||
// if lazyfs := member.LazyFS(); lazyfs != nil { | ||
// lg.Info("Removing data that was not fsynced") | ||
// err := lazyfs.ClearCache(ctx) | ||
// if err != nil { | ||
// return nil, err | ||
// } | ||
// } | ||
member.Config().ExecPath = e2e.BinPath.EtcdLastRelease | ||
err = patchArgs(member.Config().Args, "initial-cluster-state", "existing") | ||
if err != nil { | ||
return nil, err | ||
} | ||
lg.Info("Restarting member", zap.String("member", member.Config().Name)) | ||
err = member.Start(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
time.Sleep(etcdserver.HealthInterval) | ||
err = verifyVersion(t, clus, member, targetVersion) | ||
} | ||
time.Sleep(etcdserver.HealthInterval) | ||
lg.Info("Finished downgrading members", zap.Any("members", membersToDowngrade)) | ||
return nil, err | ||
} | ||
|
||
func (f memberDowngrade) Name() string { | ||
return "MemberDowngrade" | ||
} | ||
|
||
func (f memberDowngrade) Available(config e2e.EtcdProcessClusterConfig, member e2e.EtcdProcess, profile traffic.Profile) bool { | ||
v, err := e2e.GetVersionFromBinary(e2e.BinPath.Etcd) | ||
if err != nil { | ||
panic("Failed checking etcd version binary") | ||
} | ||
v3_6 := semver.Version{Major: 3, Minor: 6} | ||
// only current version cluster can be downgraded. | ||
return config.ClusterSize > 1 && v.Compare(v3_6) >= 0 && (config.Version == e2e.CurrentVersion && member.Config().ExecPath == e2e.BinPath.Etcd) | ||
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. Why only cluster size > 1? 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. +1 the same question. |
||
} | ||
|
||
func getID(ctx context.Context, cc *clientv3.Client, name string) (id uint64, found bool, err error) { | ||
// Ensure linearized MemberList by first making a linearized Get request from the same member. | ||
// This is required for v3.4 support as it doesn't support linearized MemberList https://github.com/etcd-io/etcd/issues/18929 | ||
|
@@ -170,3 +262,29 @@ func patchArgs(args []string, flag, newValue string) error { | |
} | ||
return fmt.Errorf("--%s flag not found", flag) | ||
} | ||
|
||
func enableDowngrade(ctx context.Context, cc *clientv3.Client, targetVersion *semver.Version) error { | ||
_, err := cc.Maintenance.Downgrade(ctx, clientv3.DowngradeAction(pb.DowngradeRequest_VALIDATE), targetVersion.String()) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = cc.Maintenance.Downgrade(ctx, clientv3.DowngradeAction(pb.DowngradeRequest_ENABLE), targetVersion.String()) | ||
return err | ||
} | ||
|
||
func verifyVersion(t *testing.T, clus *e2e.EtcdProcessCluster, member e2e.EtcdProcess, expectedVersion semver.Version) error { | ||
var err error | ||
expected := fmt.Sprintf(`"etcdserver":"%d.%d\..*"etcdcluster":"%d\.%d\.`, expectedVersion.Major, expectedVersion.Minor, expectedVersion.Major, expectedVersion.Minor) | ||
for i := 0; i < 35; i++ { | ||
if err = e2e.CURLGetFromMember(clus, member, e2e.CURLReq{Endpoint: "/version", Expected: expect.ExpectedResponse{Value: expected, IsRegularExpr: true}}); err != nil { | ||
t.Logf("#%d: v3 is not ready yet (%v)", i, err) | ||
time.Sleep(200 * time.Millisecond) | ||
continue | ||
} | ||
break | ||
} | ||
if err != nil { | ||
return fmt.Errorf("failed to verify version, expected %v got (%v)", expected, err) | ||
} | ||
return nil | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why not downgrade all members? Trying to think if there are any benefits on testing partial downgrade. Technically all partial upgrades are just subset of procedure of full downgrade.
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.
I think the benefit is to verify that the correctness should never be broken no matter how many members are downgraded.
I am thinking that we should explicitly verify the two cases: full downgrade and partial downgrade.