mirror of https://github.com/hak5/bolt.git
commit
ca5f582710
2
db.go
2
db.go
|
@ -212,7 +212,7 @@ func (db *DB) munmap() error {
|
||||||
// mmapSize determines the appropriate size for the mmap given the current size
|
// mmapSize determines the appropriate size for the mmap given the current size
|
||||||
// of the database. The minimum size is 4MB and doubles until it reaches 1GB.
|
// of the database. The minimum size is 4MB and doubles until it reaches 1GB.
|
||||||
func (db *DB) mmapSize(size int) int {
|
func (db *DB) mmapSize(size int) int {
|
||||||
if size < minMmapSize {
|
if size <= minMmapSize {
|
||||||
return minMmapSize
|
return minMmapSize
|
||||||
} else if size < maxMmapStep {
|
} else if size < maxMmapStep {
|
||||||
size *= 2
|
size *= 2
|
||||||
|
|
|
@ -297,7 +297,8 @@ func TestDB_mmapSize(t *testing.T) {
|
||||||
assert.Equal(t, db.mmapSize(0), minMmapSize)
|
assert.Equal(t, db.mmapSize(0), minMmapSize)
|
||||||
assert.Equal(t, db.mmapSize(16384), minMmapSize)
|
assert.Equal(t, db.mmapSize(16384), minMmapSize)
|
||||||
assert.Equal(t, db.mmapSize(minMmapSize-1), minMmapSize)
|
assert.Equal(t, db.mmapSize(minMmapSize-1), minMmapSize)
|
||||||
assert.Equal(t, db.mmapSize(minMmapSize), minMmapSize*2)
|
assert.Equal(t, db.mmapSize(minMmapSize), minMmapSize)
|
||||||
|
assert.Equal(t, db.mmapSize(minMmapSize+1), (minMmapSize*2)+4096)
|
||||||
assert.Equal(t, db.mmapSize(10000000), 20000768)
|
assert.Equal(t, db.mmapSize(10000000), 20000768)
|
||||||
assert.Equal(t, db.mmapSize((1<<30)-1), 2147483648)
|
assert.Equal(t, db.mmapSize((1<<30)-1), 2147483648)
|
||||||
assert.Equal(t, db.mmapSize(1<<30), 1<<31)
|
assert.Equal(t, db.mmapSize(1<<30), 1<<31)
|
||||||
|
|
Loading…
Reference in New Issue