Skip to content

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

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