Skip to content

Commit

Permalink
get rid of os.Getpagesize() calls where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Aug 11, 2017
1 parent 12923fe commit 78ca4fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ func TestBucket_Stats(t *testing.T) {
}

// Only check allocations for 4KB pages.
if os.Getpagesize() == 4096 {
if db.Info().PageSize == 4096 {
if stats.BranchAlloc != 4096 {
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
} else if stats.LeafAlloc != 36864 {
Expand Down Expand Up @@ -1347,7 +1347,7 @@ func TestBucket_Stats_Small(t *testing.T) {
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
}

if os.Getpagesize() == 4096 {
if db.Info().PageSize == 4096 {
if stats.BranchAlloc != 0 {
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
} else if stats.LeafAlloc != 0 {
Expand Down Expand Up @@ -1406,7 +1406,7 @@ func TestBucket_Stats_EmptyBucket(t *testing.T) {
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
}

if os.Getpagesize() == 4096 {
if db.Info().PageSize == 4096 {
if stats.BranchAlloc != 0 {
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
} else if stats.LeafAlloc != 0 {
Expand Down Expand Up @@ -1508,7 +1508,7 @@ func TestBucket_Stats_Nested(t *testing.T) {
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
}

if os.Getpagesize() == 4096 {
if db.Info().PageSize == 4096 {
if stats.BranchAlloc != 0 {
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
} else if stats.LeafAlloc != 8192 {
Expand Down Expand Up @@ -1581,7 +1581,7 @@ func TestBucket_Stats_Large(t *testing.T) {
t.Fatalf("unexpected LeafInuse: %d", stats.LeafInuse)
}

if os.Getpagesize() == 4096 {
if db.Info().PageSize == 4096 {
if stats.BranchAlloc != 53248 {
t.Fatalf("unexpected BranchAlloc: %d", stats.BranchAlloc)
} else if stats.LeafAlloc != 4898816 {
Expand Down
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
// If the first page is invalid and this OS uses a different
// page size than what the database was created with then we
// are out of luck and cannot access the database.
db.pageSize = os.Getpagesize()
db.pageSize = defaultPageSize
} else {
db.pageSize = int(m.pageSize)
}
Expand Down Expand Up @@ -371,7 +371,7 @@ func (db *DB) mmapSize(size int) (int, error) {
// init creates a new database file and initializes its meta pages.
func (db *DB) init() error {
// Set the page size to the OS page size.
db.pageSize = os.Getpagesize()
db.pageSize = defaultPageSize

// Create two meta pages on a buffer.
buf := make([]byte, db.pageSize*4)
Expand Down
3 changes: 2 additions & 1 deletion db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ func TestOpen_FileTooSmall(t *testing.T) {
if err != nil {
t.Fatal(err)
}
pageSize := int64(db.Info().PageSize)
if err := db.Close(); err != nil {
t.Fatal(err)
}

// corrupt the database
if err := os.Truncate(path, int64(os.Getpagesize())); err != nil {
if err := os.Truncate(path, pageSize); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit 78ca4fd

Please sign in to comment.