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

etcdserver: compact raft log entries more frequently #18622

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

clement2026
Copy link
Contributor

@clement2026 clement2026 commented Sep 23, 2024

Part of #17098

Goal

Compact raft log more frequently to save memory.

Key Changes

  • Added a new function maybeCompactRaftLog to handle raft log compaction.
  • Introduce 2 variables: CompactRaftLogEveryNApplies and DefaultCompactRaftLogEveryNApplies to control how frequently the raft log is compacted.
  • Fix a test

TODO

  • Add tests for the changes
  • Run benchmarks

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

Hi @clement2026. 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.

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.

@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.81%. Comparing base (59cfd7a) to head (273905b).

Current head 273905b differs from pull request most recent head f1a76a2

Please upload reports for the commit f1a76a2 to get more accurate results.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
Files with missing lines Coverage Δ
server/config/config.go 79.76% <ø> (ø)
server/etcdserver/server.go 81.48% <100.00%> (+0.13%) ⬆️

... and 14 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #18622      +/-   ##
==========================================
+ Coverage   68.79%   68.81%   +0.01%     
==========================================
  Files         420      420              
  Lines       35522    35532      +10     
==========================================
+ Hits        24438    24451      +13     
+ Misses       9657     9654       -3     
  Partials     1427     1427              

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59cfd7a...f1a76a2. Read the comment docs.

Comment on lines +2191 to +2197
// Keep some in memory log entries for slow followers, while keeping the entries up to snapshot index.
// Only compact raft log once every N applies
if ep.appliedi <= ep.snapi+s.Cfg.SnapshotCatchUpEntries || ep.appliedi%s.Cfg.CompactRaftLogEveryNApplies != 0 {
return
}

compacti := ep.appliedi - s.Cfg.SnapshotCatchUpEntries
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Keep some in memory log entries for slow followers, while keeping the entries up to snapshot index.
// Only compact raft log once every N applies
if ep.appliedi <= ep.snapi+s.Cfg.SnapshotCatchUpEntries || ep.appliedi%s.Cfg.CompactRaftLogEveryNApplies != 0 {
return
}
compacti := ep.appliedi - s.Cfg.SnapshotCatchUpEntries
// Retain all log entries up to the latest snapshot index to ensure any member can recover from that snapshot.
// Beyond the snapshot index, preserve the most recent s.Cfg.SnapshotCatchUpEntries entries in memory.
// This allows slow followers to catch up by synchronizing entries instead of requiring a full snapshot transfer.
// Only compact raft log once every N applies
if ep.snapi > s.Cfg.SnapshotCatchUpEntries {
return
}
compacti := ep.snapi - s.Cfg.SnapshotCatchUpEntries

In the first PR, let's keep the same number of entries, just make the compaction independent from snapshot.

@serathius
Copy link
Member

This change does to many things, there are two changes here that should be independent:

  • Separate maybeCompactRaftLog function allowing us to compact log independently from snapshots.
  • Run compaction more frequently. As currently compacti is dependent on snapshot, we would first need to confirm that we are ok with lower number of entries.

@clement2026
Copy link
Contributor Author

Sure. I'll break down this PR.

@k8s-ci-robot
Copy link

PR needs rebase.

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.

4 participants