Skip to content

add support for data file size limit #929

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

Merged
merged 2 commits into from
Apr 25, 2025
Merged

add support for data file size limit #929

merged 2 commits into from
Apr 25, 2025

Conversation

mattsains
Copy link
Contributor

closes #928

@k8s-ci-robot
Copy link

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

@mattsains
Copy link
Contributor Author

@fuweid , would you be able to take a look at this PR?

@mattsains
Copy link
Contributor Author

mattsains commented Mar 27, 2025

Investigating the test-windows failure, I discovered that the db.allocate function can actually cause the file size to grow through the truncate in the mmap function. Should I change the allocate function to call grow if a request to allocate beyond the end of the file is received, or should I just duplicate the max size check in allocate?

specifically, this line here causes the file size to grow: https://github.com/etcd-io/bbolt/blob/main/db.go#L1168

@mattsains
Copy link
Contributor Author

@fuweid , I've added a test for making sure the db can open even if it's beyond the configured max size. I've also got all the builds to pass, so I think this is ready for a review and potentially approval

@mattsains
Copy link
Contributor Author

hi @fuweid , I am awaiting feedback from you for this PR

@ahrtr
Copy link
Member

ahrtr commented Apr 7, 2025

Thanks for the PR.

My thoughts,

  • This PR might be affecting the existing db file, which already reaches the max size. So it's a breaking change.
  • Also it updates multiple places, which complicates the implementation.
  • It's hard to accurately control the max size; instead It should be a best-effort solution.
    • FYI. etcd implements similar max size (quota) controlling using flag --quota-backend-bytes , which is best effort. Also it won't lose data (return error after persisting the data)
    • Also there may be hundreds of etcd's transactions in each bbolt's transaction. etcd controls the db quota on etcd's transaction granularity instead of bbolt's transaction level.

Overall, I agree that it's a valid requirement. However, I don't feel safe to support it in bbolt. Instead, I'd suggest to add this feature in your application, and as a best-effort approach.

@mattsains
Copy link
Contributor Author

Could you explain what you mean by:

This PR might be affecting the existing db file, which already reaches the max size. So it's a breaking change.

The max file size does not take effect unless (1) you turn it on in the configuration, and (b) you write to a database in a way that causes it to grow

Also it updates multiple places, which complicates the implementation.

I am happy to change it to only one location, but it seems to me that there are many places in the code where the size of the file is unintentionally grown, for example when mmaping the file on windows

It's hard to accurately control the max size; instead It should be a best-effort solution.

What makes it hard? I think this PR does it, does it not? Am I missing some complexity?

I'd suggest to add this feature in your application, and as a best-effort approach.

I am really trying to make this maximum feature not be best effort, which is why I created this PR

Look forward to your comments, @ahrtr

@mattsains mattsains force-pushed the 928 branch 2 times, most recently from 20a41d8 to 07e0fdd Compare April 9, 2025 17:44
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

The test cases have very similar implementation. Is it possible to create a common function to be reused/shared by all (or some) test cases?

@mattsains
Copy link
Contributor Author

@ahrtr hi there, I think this is ready for re-review

@ivanvc ivanvc requested a review from ahrtr April 16, 2025 23:37
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

I will review the test cases when all the comments are resolved.

@mattsains
Copy link
Contributor Author

@ahrtr I've updated the PR based on your comments

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

Overall looks good with several minor comments. Thanks for your contribution!

@ahrtr
Copy link
Member

ahrtr commented Apr 18, 2025

I see that you use assert in the test cases. I think require is better at most of the places. The rule is: if it doesn't make sense to continue to execute the test if a check fails, then use require; otherwise use assert.

  • github.com/stretchr/testify/assert
  • github.com/stretchr/testify/require

@mattsains
Copy link
Contributor Author

@ahrtr I've made the changes you requested and audited my use of require vs assert. This PR is ready for re-review

@ahrtr
Copy link
Member

ahrtr commented Apr 21, 2025

Overall looks good to me. Can you please squash the commits?

@fuweid @tjungblu PTAL, thx

@mattsains
Copy link
Contributor Author

I've squashed the commits

@fuweid fuweid self-requested a review April 24, 2025 14:25
@fuweid
Copy link
Member

fuweid commented Apr 24, 2025

@mattsains please rebase to fix CI issue. thanks!

closes #928

Signed-off-by: Matthew Sainsbury <matthew@sainsbury.io>
@mattsains
Copy link
Contributor Author

@fuweid rebased. Do we need the lgtm tag and/or assigning an approver?

@fuweid
Copy link
Member

fuweid commented Apr 24, 2025

@mattsains It needs @ahrtr 's approval. :)

@mattsains mattsains requested a review from ahrtr April 24, 2025 20:26
Signed-off-by: Matthew Sainsbury <matthew@sainsbury.io>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for your first contribution!

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, fuweid, mattsains

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

The pull request process is described 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

@ahrtr ahrtr merged commit 88d2b54 into etcd-io:main Apr 25, 2025
19 checks passed
@mattsains mattsains deleted the 928 branch April 25, 2025 17:47
@ahrtr ahrtr mentioned this pull request Apr 30, 2025
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.

Feature request: Config option to limit maximum size of database file
4 participants