This repository has been archived by the owner on Mar 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
introduce initialMmapSize #432
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,47 @@ func TestOpen_ReadOnly(t *testing.T) { | |
} | ||
} | ||
|
||
// TestDB_Open_InitialMmapSize tests the passed in InitialMmapSize takes | ||
// effect. This is a very hacky test since the mmap size is not exposed. | ||
// | ||
// This test indirecly ensures the behavior by trying to block the re-mmap | ||
// by a reader and aks a writer to write a large value that will trigger | ||
// a mmap if the initial mmap size is small. | ||
func TestDB_Open_InitialMmapSize(t *testing.T) { | ||
path := tempfile() | ||
defer os.Remove(path) | ||
|
||
isz := 1 << 31 // 2GB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think zero size is better, so we don't need to commit a large write :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. *indirectly? |
||
db, err := bolt.Open(path, 0666, &bolt.Options{InitialMmapSize: isz}) | ||
assert(t, err == nil, "") | ||
|
||
// a reader tx | ||
rtx, err := db.Begin(false) | ||
assert(t, err == nil, "") | ||
defer rtx.Rollback() | ||
|
||
// create a write tx and commit a large write | ||
wtx, err := db.Begin(true) | ||
assert(t, err == nil, "") | ||
b, err := wtx.CreateBucket([]byte("test")) | ||
assert(t, err == nil, "") | ||
err = b.Put([]byte("foo"), make([]byte, 1<<23)) | ||
assert(t, err == nil, "") | ||
|
||
done := make(chan struct{}) | ||
|
||
go func() { | ||
wtx.Commit() | ||
done <- struct{}{} | ||
}() | ||
|
||
select { | ||
case <-time.After(5 * time.Second): | ||
t.Errorf("unexpected that the reader blocks writer") | ||
case <-done: | ||
} | ||
} | ||
|
||
// TODO(benbjohnson): Test corruption at every byte of the first two pages. | ||
|
||
// Ensure that a database cannot open a transaction when it's not open. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Read transactions are guaranteed not to block write transactions ..."