Skip to content

moved max size check; added test for post-max size functioning#1130

Closed
mattsains wants to merge 5 commits into
etcd-io:mainfrom
mattsains:1108
Closed

moved max size check; added test for post-max size functioning#1130
mattsains wants to merge 5 commits into
etcd-io:mainfrom
mattsains:1108

Conversation

@mattsains

Copy link
Copy Markdown
Contributor

Fixes #1108

@k8s-ci-robot

Copy link
Copy Markdown

[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 thread db.go Outdated
Comment thread db.go
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread db_test.go
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
Copy Markdown
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

ahrtr commented Dec 16, 2025

Copy link
Copy Markdown
Member

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

Comment thread db_test.go
// 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
Copy Markdown
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
Copy Markdown
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>
@ahrtr

ahrtr commented Jan 17, 2026

Copy link
Copy Markdown
Member

are you still working on this PR?

@mattsains

Copy link
Copy Markdown
Contributor Author

are you still working on this PR?

sorry, I am having trouble prioritising this issue. If anyone else can do it, go ahead, otherwise I'll get to it when I can

@ahrtr ahrtr mentioned this pull request Apr 13, 2026
17 tasks
@github-actions github-actions Bot added the stale label Apr 27, 2026
@github-actions github-actions Bot closed this May 18, 2026
@ahrtr ahrtr reopened this May 18, 2026
@github-actions github-actions Bot removed the stale label May 19, 2026
Elbehery added a commit to Elbehery/bbolt that referenced this pull request May 21, 2026
…izeReached

Fixes etcd-io#1108.

Squashed from etcd-io#1130:
* db4544f moved max size check; added test for post-max size functioning
* 9445cc1 Apply suggestions from code review
* 2a8037d merge fillDBWithKeys
* 60ee0ee add test demonstrating windows issue
* e4590be update comment for test

Signed-off-by: Matthew Sainsbury <msainsbury@microsoft.com>
Elbehery added a commit to Elbehery/bbolt that referenced this pull request May 21, 2026
…izeReached

Fixes etcd-io#1108.

Squashed from etcd-io#1130:
* db4544f moved max size check; added test for post-max size functioning
* 9445cc1 Apply suggestions from code review
* 2a8037d merge fillDBWithKeys
* 60ee0ee add test demonstrating windows issue
* e4590be update comment for test

Co-authored-by: Matthew Sainsbury <msainsbury@microsoft.com>
Signed-off-by: elbehery <elbeherymustafa@gmail.com>
@ahrtr

ahrtr commented May 23, 2026

Copy link
Copy Markdown
Member

superseded by #1206 and/or #1205

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