Skip to content

Conversation

@mattsains
Copy link
Contributor

Fixes #1108

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mattsains
Once this PR has been reviewed and has the lgtm label, please assign serathius 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

Signed-off-by: Matthew Sainsbury <msainsbury@microsoft.com>
Comment on lines +1171 to +1172
// however, I don't quite understand it. Why is the allocation increment added to the size required,
// rather than the size required rounded up to the next multiple of the allocation increment?
Copy link
Member

Choose a reason for hiding this comment

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

It's over allocation, to amortize the cost of truncate and fsync
refer to a122e1c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My issue was mostly that what I think happens here is that if you ask for 1 byte, but the alloc size is 10 bytes, it actually allocates 11 bytes. Shouldn't it be 10?

Copy link
Member

Choose a reason for hiding this comment

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

yes, as mentioned above it's a bit over allocation. By default it's 16MB at most. It shouldn't be a big problem. The logic has been there for almost a decade, let's keep it as it's unless you have a very strong justification.

mattsains and others added 2 commits December 15, 2025 10:13
Co-authored-by: Benjamin Wang <benjamin.wang@broadcom.com>
Signed-off-by: Matthew Sainsbury <msainsbury@microsoft.com>
Signed-off-by: Matthew Sainsbury <msainsbury@microsoft.com>
@mattsains
Copy link
Contributor Author

@ahrtr I'm going to have to add special logic for windows because on that platform, to open a file with an mmap size larger than the file, you have to expand the file

@ahrtr
Copy link
Member

ahrtr commented Dec 16, 2025

@ahrtr I'm going to have to add special logic for windows because on that platform, to open a file with an mmap size larger than the file, you have to expand the file

I don't think we need a special logic for windows. I don't see an issue. If you see an issue, then pls add a test to reproduce/prove it first.

// that is beyond the maximum size does not grow the db on Windows.
// In Windows, the file must be expanded to the mmap initial size.
// https://github.com/etcd-io/bbolt/issues/928
func TestDB_MaxSizeExceededDoesNotGrow(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahrtr I've updated this test to demonstrate the issue on Windows I was talking about. When you set InitialMmapSize to be greater than the actual size of the file, the file must be expanded to map it that way.

The assertion on line 1666 fails because newSize is exactly double expandedSize (or, exactly equal to InitialMmapSize)

Copy link
Member

Choose a reason for hiding this comment

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

I see.

I think we need to disable InitialMmapSize for Windows; in other words, we don't use it for Windows.

Matthew Sainsbury added 2 commits December 16, 2025 10:28
Signed-off-by: Matthew Sainsbury <msainsbury@microsoft.com>
Signed-off-by: Matthew Sainsbury <msainsbury@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

When a db write fails because MaxSize is reached, the db client should still accept future reads and writes

3 participants