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

Fix timeout when defragmenting etcd on startup #11164

Merged
merged 3 commits into from
Oct 30, 2024

Conversation

brandond
Copy link
Member

@brandond brandond commented Oct 24, 2024

Proposed Changes

Fix timeout when defragmenting etcd on startup:

  • Use custom client with no hidden background connection, and without automatic retry of RPCs.
  • Only timeout status requests; allow defrag and alarm clear requests to run to completion. The defrag and alarm clear may take more than 30 seconds to complete if the datastore is large and the disk is slow.
  • Don't clear all alarms on the cluster after defragging, just clear the NOSPACE alarm on the local node.
  • Print datastore utilization before/after defrag
  • Add tests

Types of Changes

bugfix / enhancement

Verification

  • See linked issue - however this seems to require a large (8gb+) fragmented datastore on a fairly slow disk to reproduce.

Testing

new tests added

Linked Issues

User-Facing Change

Further Comments

@brandond brandond requested a review from a team as a code owner October 24, 2024 00:19
@@ -1593,24 +1598,6 @@ func (e *ETCD) GetMembersClientURLs(ctx context.Context) ([]string, error) {
return clientURLs, nil
}

// GetMembersNames will list through the member lists in etcd and return
// back a combined list of member names
func (e *ETCD) GetMembersNames(ctx context.Context) ([]string, error) {
Copy link
Member Author

@brandond brandond Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function was not used here or in rke2 and is not required by the interface.

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 46.82540% with 67 lines in your changes missing coverage. Please review.

Project coverage is 38.10%. Comparing base (c0d661b) to head (09cea43).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
pkg/etcd/etcd.go 48.05% 32 Missing and 8 partials ⚠️
pkg/etcd/resolver.go 45.83% 23 Missing and 3 partials ⚠️
pkg/etcd/snapshot.go 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (c0d661b) and HEAD (09cea43). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (c0d661b) HEAD (09cea43)
unittests 1 0
e2etests 8 6
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #11164       +/-   ##
===========================================
- Coverage   48.72%   38.10%   -10.63%     
===========================================
  Files         178      162       -16     
  Lines       14813    17979     +3166     
===========================================
- Hits         7218     6850      -368     
- Misses       6288     9932     +3644     
+ Partials     1307     1197      -110     
Flag Coverage Δ
e2etests 33.97% <0.00%> (-12.10%) ⬇️
inttests 34.72% <46.82%> (?)
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@manuelbuil
Copy link
Contributor

Shouldn't we add a (larger) timeout for defrag? Could etcd get stuck in defrag forever for some reason?

@brandond
Copy link
Member Author

brandond commented Oct 24, 2024

The reason we added a timeout on the status command is that the etcd grpc client will retry it automatically if the connection to the service is unavailable. I don't believe the other commands are subject to retry, but I'm going to add some tests to this to verify behavior before merging.

dereknola
dereknola previously approved these changes Oct 25, 2024
cwayne18
cwayne18 previously approved these changes Oct 25, 2024
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
@brandond
Copy link
Member Author

brandond commented Oct 25, 2024

Confirmed no breakage here:

NAME           STATUS   ROLES                       AGE     VERSION                INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                   KERNEL-VERSION   CONTAINER-RUNTIME
k3s-server-1   Ready    control-plane,etcd,master   2m33s   v1.31.1+k3s-5e6dc725   172.17.0.4    <none>        K3s v1.31.1-k3s-5e6dc725   6.8.0-1016-aws   containerd://1.7.22-k3s1
k3s-server-2   Ready    etcd                        80s     v1.31.1+k3s-5e6dc725   172.17.0.5    <none>        K3s v1.31.1-k3s-5e6dc725   6.8.0-1016-aws   containerd://1.7.22-k3s1
k3s-server-3   Ready    control-plane,etcd,master   58s     v1.31.1+k3s-5e6dc725   172.17.0.6    <none>        K3s v1.31.1-k3s-5e6dc725   6.8.0-1016-aws   containerd://1.7.22-k3s1
k3s-server-4   Ready    control-plane,master        33s     v1.31.1+k3s-5e6dc725   172.17.0.7    <none>        K3s v1.31.1-k3s-5e6dc725   6.8.0-1016-aws   containerd://1.7.22-k3s1

Confirmed no breakage on the RKE2 side with these changes: rancher/rke2#7139

And the startup actually seems to be a bit faster, with less log spam while etcd is starting.

dereknola
dereknola previously approved these changes Oct 28, 2024
* Use clientv3.NewCtxClient instead of New to avoid automatic retry of all RPCs
* Only timeout status requests; allow defrag and alarm clear requests to run to completion.
* Only clear alarms on the local cluster member, not ALL cluster members

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
wantErr: false,
},
{
name: "slow defrag",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants