Skip to content
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

add option to skip freelist sync #1

Merged
merged 1 commit into from
Jun 22, 2017
Merged

add option to skip freelist sync #1

merged 1 commit into from
Jun 22, 2017

Conversation

xiang90
Copy link
Contributor

@xiang90 xiang90 commented Jun 18, 2017

When the database has a lot of freepages, the cost to sync all
freepages down to disk is high. If the total database size is
small (<10GB), and the application can tolerate ~10 seconds
recovery time, then it is reasonable to simply not sync freelist
and rescan the db to rebuild freelist on recovery.

@xiang90 xiang90 force-pushed the no_sync branch 3 times, most recently from 236381f to dacec63 Compare June 18, 2017 23:33
bucket_test.go Outdated
@@ -13,7 +13,7 @@ import (
"testing"
"testing/quick"

"github.com/boltdb/bolt"
Copy link
Contributor

Choose a reason for hiding this comment

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

can this renaming be split into a separate patch to merge first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. will do.

@xiang90
Copy link
Contributor Author

xiang90 commented Jun 21, 2017

@heyitsanthony fixed. PTAL.

Copy link
Contributor

@heyitsanthony heyitsanthony 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 OK, but is switching between no free list sync and free list sync safe? Not super worried about leaking pages, but loading a stale free list and scribbling over an allocated page would be bad

db.go Outdated
return fids
}

func checkReachable(tx *Tx, b *Bucket, reachable map[pgid]*page) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is very similar to Tx.checkBucket; would it be possible to have this so both share some code? Maybe func (tx *Tx) freepages() []pgid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will give it a try.

db_test.go Outdated
}

// MustOpenDB returns a new, open DB at a temporary location with given options.
func MustOpenWitOption(o *bolt.Options) *DB {
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Wit/With

db_test.go Outdated
}
}

// MustOpenDB returns a new, open DB at a temporary location with given options.
Copy link
Contributor

Choose a reason for hiding this comment

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

// MustOpenWithOpen ...

db_test.go Outdated
@@ -1399,6 +1419,15 @@ func (db *DB) MustClose() {
}
}

// MustClose reopen the database. Panic on error.
Copy link
Contributor

Choose a reason for hiding this comment

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

// MustReopen reopens...

freelist.go Outdated
@@ -22,6 +22,14 @@ func newFreelist() *freelist {
}
}

func newFreelistWithIDs(ids []pgid) *freelist {
Copy link
Contributor

Choose a reason for hiding this comment

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

some indexing assumptions might be violated by passing in a raw pgid slice, how about:

func (f *freelist) readIds(ids []pgid) {
    f.ids = ids
    ...
}

where freelist.read()'s tail calls into readIds()

tx.go Outdated
if tx.meta.pgid > opgid {
if err := tx.db.grow(int(tx.meta.pgid+1) * tx.db.pageSize); err != nil {
if !tx.db.NoFreelistSync {
opgid := tx.meta.pgid
Copy link
Contributor

Choose a reason for hiding this comment

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

split into a separate method like tx.commitFreelist(...)?

@xiang90
Copy link
Contributor Author

xiang90 commented Jun 21, 2017

overall looks OK, but is switching between no free list sync and free list sync safe?

it is safe from free list sync to no sync, but not the other way around.

@xiang90
Copy link
Contributor Author

xiang90 commented Jun 22, 2017

@heyitsanthony fixed. PTAL.

@heyitsanthony
Copy link
Contributor

lgtm but the test/second patch seems to have code that belongs in the implementation/first patch.

Also it'd be nice to have some way to protect against no sync -> sync (commit with no-sync writes an invalid page for the freelist?), but that can be deferred; open an issue?

@xiang90
Copy link
Contributor Author

xiang90 commented Jun 22, 2017

lgtm but the test/second patch seems to have code that belongs in the implementation/first patch.

yea... i made a mistake when rebasing... I guess i will just squash the two commits into one.

I will open an issue on the other thing you mentioned.

When the database has a lot of freepages, the cost to sync all
freepages down to disk is high. If the total database size is
small (<10GB), and the application can tolerate ~10 seconds
recovery time, then it is reasonable to simply not sync freelist
and rescan the db to rebuild freelist on recovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants