cache: support new leveldb (>=1.21) max-file-size option
requires build/install with -tags="ldbpost121"master
parent
93c5298712
commit
25b4c01917
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
|
@ -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.
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue