cache: support new leveldb (>=1.21) max-file-size option

requires build/install with -tags="ldbpost121"
master
Oliver Tonnhofer 2017-11-20 10:55:48 +01:00
parent 93c5298712
commit 25b4c01917
4 changed files with 46 additions and 1 deletions

7
cache/config.go vendored
View File

@ -13,6 +13,7 @@ type cacheOptions struct {
BlockRestartInterval int
WriteBufferSizeM int
BlockSizeK int
MaxFileSizeM int
}
type coordsCacheOptions struct {
@ -36,6 +37,7 @@ const defaultConfig = `
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"MaxFileSizeM": 32,
"BlockRestartInterval": 256,
"BunchSize": 32,
"BunchCacheCapacity": 8096
@ -45,6 +47,7 @@ const defaultConfig = `
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"MaxFileSizeM": 32,
"BlockRestartInterval": 128
},
"Ways": {
@ -52,6 +55,7 @@ const defaultConfig = `
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"MaxFileSizeM": 32,
"BlockRestartInterval": 128
},
"Relations": {
@ -59,6 +63,7 @@ const defaultConfig = `
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"MaxFileSizeM": 32,
"BlockRestartInterval": 128
},
"CoordsIndex": {
@ -66,6 +71,7 @@ const defaultConfig = `
"WriteBufferSizeM": 128,
"BlockSizeK": 0,
"MaxOpenFiles": 256,
"MaxFileSizeM": 8,
"BlockRestartInterval": 256
},
"WaysIndex": {
@ -73,6 +79,7 @@ const defaultConfig = `
"WriteBufferSizeM": 64,
"BlockSizeK": 0,
"MaxOpenFiles": 64,
"MaxFileSizeM": 8,
"BlockRestartInterval": 128
}
}

18
cache/ldb_post_121.go vendored Normal file
View File

@ -0,0 +1,18 @@
// +build ldbpost121
package cache
// #cgo LDFLAGS: -lleveldb
// #include "leveldb/c.h"
import "C"
import (
"unsafe"
"github.com/jmhodges/levigo"
)
func setMaxFileSize(o *levigo.Options, maxFileSize int) {
p := (*C.struct_leveldb_options_t)(unsafe.Pointer(o.Opt))
C.leveldb_options_set_max_file_size(p, C.size_t(maxFileSize))
}

15
cache/ldb_pre_121.go vendored Normal file
View File

@ -0,0 +1,15 @@
// +build !ldbpost121
package cache
// #cgo LDFLAGS: -lleveldb
// #include "leveldb/c.h"
import "C"
import (
"github.com/jmhodges/levigo"
)
func setMaxFileSize(o *levigo.Options, maxFileSize int) {
// setMaxFileSize is only available with LevelDB 1.21 and higher.
}

7
cache/osm.go vendored
View File

@ -175,6 +175,11 @@ func (c *cache) open(path string) error {
if c.options.BlockSizeK > 0 {
opts.SetBlockSize(c.options.BlockSizeK * 1024)
}
if c.options.MaxFileSizeM > 0 {
// max file size option is only available with LevelDB 1.21 and higher
// build with -tags="ldppost121" to enable this option.
setMaxFileSize(opts, c.options.MaxFileSizeM*1024*1024)
}
db, err := levigo.Open(path, opts)
if err != nil {
@ -183,6 +188,7 @@ func (c *cache) open(path string) error {
c.db = db
c.wo = levigo.NewWriteOptions()
c.ro = levigo.NewReadOptions()
return nil
}
@ -213,5 +219,4 @@ func (c *cache) Close() {
c.cache.Close()
c.cache = nil
}
}