Skip to content

Commit

Permalink
Merge pull request #19 from heyitsanthony/skip-freelist-read
Browse files Browse the repository at this point in the history
do not read freelist if database opened readonly
  • Loading branch information
Anthony Romano authored Aug 11, 2017
2 parents c5d7f33 + ec37ce8 commit 2fe83be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
return nil, err
}

if db.readOnly {
return db, nil
}

db.freelist = newFreelist()
noFreeList := db.meta().freelist == pgidNoFreelist
if noFreeList {
Expand All @@ -253,7 +257,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {

// Flush freelist when transitioning from no sync to sync so
// NoFreelistSync unaware boltdb can open the db later.
if !db.NoFreelistSync && noFreeList && ((mode & 0222) != 0) {
if !db.NoFreelistSync && noFreeList {
tx, err := db.Begin(true)
if tx != nil {
err = tx.Commit()
Expand Down

0 comments on commit 2fe83be

Please sign in to comment.