Skip to content

v3rpc: allow Defragment RPC on learner members#21950

Open
crawfordxx wants to merge 1 commit into
etcd-io:mainfrom
crawfordxx:fix-allow-defrag-on-learner-members
Open

v3rpc: allow Defragment RPC on learner members#21950
crawfordxx wants to merge 1 commit into
etcd-io:mainfrom
crawfordxx:fix-allow-defrag-on-learner-members

Conversation

@crawfordxx

Copy link
Copy Markdown

Problem

Learner members cannot be defragmented. Running etcdctl defrag skips
learner endpoints, and targeting the learner directly fails with:

rpc error: code = Unavailable desc = etcdserver: rpc not supported for learner

Over time, a learner's BoltDB file grows unbounded while voting members
can reclaim space via defragmentation. There is no supported workaround.

Root cause

isRPCSupportedForLearner() in server/etcdserver/api/v3rpc/util.go
only permits StatusRequest and serializable RangeRequest for learner
members. DefragmentRequest falls through to the default: return false
case, causing the unary interceptor to reject it before the handler runs.

Fix

Add *pb.DefragmentRequest to the set of RPCs permitted for learner members.

Defragmentation is a purely local, read-write maintenance operation on the
BoltDB file (bbolt compact + copy). It:

  • does not propose any entry to the Raft log
  • does not modify any replicated state
  • does not require leader contact or quorum
  • is already permitted on followers without restriction

Allowing it on learners is therefore safe and consistent with how it works
on voting members.

Fixes #21740

Defragmentation is a purely local maintenance operation that reclaims
disk space in the BoltDB file without any Raft consensus involvement.
Unlike Write/Put/Delete operations, it does not propose entries to the
Raft log and cannot corrupt cluster state.

However, isRPCSupportedForLearner() currently returns false for
DefragmentRequest, causing learner members to reject defrag calls with
ErrGRPCNotSupportedForLearner. As a result, learner databases grow
unbounded over time since they cannot be defragmented via etcdctl or
the maintenance API.

Add DefragmentRequest to the set of RPCs permitted for learner members
so that operators can run `etcdctl defrag` against a learner endpoint
directly, matching the expected behavior for a read-only local
maintenance operation.

Fixes etcd-io#21740

Signed-off-by: crawfordxx <crawfordxx@users.noreply.github.com>
@k8s-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: crawfordxx
Once this PR has been reviewed and has the lgtm label, please assign fuweid for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot

Copy link
Copy Markdown

Hi @crawfordxx. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

ETCD learner members cannot be defragmented, causing persistent storage bloat.

2 participants