fixup config parsing and add new options
This commit is contained in:
parent
01667dfff3
commit
d3dda3d0ea
|
@ -14,7 +14,6 @@ package forestdb
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -23,25 +22,6 @@ import (
|
||||||
"github.com/couchbase/goforestdb"
|
"github.com/couchbase/goforestdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ForestDBConfig struct {
|
|
||||||
BlockSize uint32
|
|
||||||
BufferCacheSize uint64
|
|
||||||
ChunkSize uint16
|
|
||||||
CleanupCacheOnClose bool
|
|
||||||
CompactionBufferSizeMax uint32
|
|
||||||
CompactionMinimumFilesize uint64
|
|
||||||
CompactionMode forestdb.CompactOpt
|
|
||||||
CompactionThreshold uint8
|
|
||||||
CompactorSleepDuration uint64
|
|
||||||
CompressDocumentBody bool
|
|
||||||
DurabilityOpt forestdb.DurabilityOpt
|
|
||||||
OpenFlags forestdb.OpenFlags
|
|
||||||
PurgingInterval uint32
|
|
||||||
SeqTreeOpt forestdb.SeqTreeOpt
|
|
||||||
WalFlushBeforeCommit bool
|
|
||||||
WalThreshold uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
const Name = "forestdb"
|
const Name = "forestdb"
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
|
@ -226,72 +206,83 @@ func init() {
|
||||||
|
|
||||||
func applyConfig(c *forestdb.Config, config map[string]interface{}) (
|
func applyConfig(c *forestdb.Config, config map[string]interface{}) (
|
||||||
*forestdb.Config, error) {
|
*forestdb.Config, error) {
|
||||||
v, exists := config["forestDBConfig"]
|
|
||||||
if !exists || v == nil {
|
if v, exists := config["blockSize"].(float64); exists {
|
||||||
return c, nil
|
c.SetBlockSize(uint32(v))
|
||||||
}
|
}
|
||||||
m, ok := v.(map[string]interface{})
|
if v, exists := config["bufferCacheSize"].(float64); exists {
|
||||||
if !ok {
|
c.SetBufferCacheSize(uint64(v))
|
||||||
return c, nil
|
|
||||||
}
|
}
|
||||||
// These extra steps of json.Marshal()/Unmarshal() help to convert
|
if v, exists := config["chunkSize"].(float64); exists {
|
||||||
// to the types that we need for the setter calls.
|
c.SetChunkSize(uint16(v))
|
||||||
b, err := json.Marshal(m)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
var f ForestDBConfig
|
if v, exists := config["cleanupCacheOnClose"].(bool); exists {
|
||||||
err = json.Unmarshal(b, &f)
|
c.SetCleanupCacheOnClose(v)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
if _, exists := m["blockSize"]; exists {
|
if v, exists := config["compactionBufferSizeMax"].(float64); exists {
|
||||||
c.SetBlockSize(f.BlockSize)
|
c.SetCompactionBufferSizeMax(uint32(v))
|
||||||
}
|
}
|
||||||
if _, exists := m["bufferCacheSize"]; exists {
|
if v, exists := config["compactionMinimumFilesize"].(float64); exists {
|
||||||
c.SetBufferCacheSize(f.BufferCacheSize)
|
c.SetCompactionMinimumFilesize(uint64(v))
|
||||||
}
|
}
|
||||||
if _, exists := m["chunkSize"]; exists {
|
if v, exists := config["compactionMode"].(string); exists {
|
||||||
c.SetChunkSize(f.ChunkSize)
|
switch v {
|
||||||
|
case "manual":
|
||||||
|
c.SetCompactionMode(forestdb.COMPACT_MANUAL)
|
||||||
|
case "auto":
|
||||||
|
c.SetCompactionMode(forestdb.COMPACT_AUTO)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Unknown compaction mode: %s", v)
|
||||||
}
|
}
|
||||||
if _, exists := m["cleanupCacheOnClose"]; exists {
|
|
||||||
c.SetCleanupCacheOnClose(f.CleanupCacheOnClose)
|
|
||||||
}
|
}
|
||||||
if _, exists := m["compactionBufferSizeMax"]; exists {
|
if v, exists := config["compactionThreshold"].(float64); exists {
|
||||||
c.SetCompactionBufferSizeMax(f.CompactionBufferSizeMax)
|
c.SetCompactionThreshold(uint8(v))
|
||||||
}
|
}
|
||||||
if _, exists := m["compactionMinimumFilesize"]; exists {
|
if v, exists := config["compactorSleepDuration"].(float64); exists {
|
||||||
c.SetCompactionMinimumFilesize(f.CompactionMinimumFilesize)
|
c.SetCompactorSleepDuration(uint64(v))
|
||||||
}
|
}
|
||||||
if _, exists := m["compactionMode"]; exists {
|
if v, exists := config["compressDocumentBody"].(bool); exists {
|
||||||
c.SetCompactionMode(f.CompactionMode)
|
c.SetCompressDocumentBody(v)
|
||||||
}
|
}
|
||||||
if _, exists := m["compactionThreshold"]; exists {
|
if v, exists := config["durabilityOpt"].(string); exists {
|
||||||
c.SetCompactionThreshold(f.CompactionThreshold)
|
switch v {
|
||||||
|
case "none":
|
||||||
|
c.SetDurabilityOpt(forestdb.DRB_NONE)
|
||||||
|
case "odirect":
|
||||||
|
c.SetDurabilityOpt(forestdb.DRB_ODIRECT)
|
||||||
|
case "async":
|
||||||
|
c.SetDurabilityOpt(forestdb.DRB_ASYNC)
|
||||||
|
case "async_odirect":
|
||||||
|
c.SetDurabilityOpt(forestdb.DRB_ODIRECT_ASYNC)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Unknown durability option: %s", v)
|
||||||
}
|
}
|
||||||
if _, exists := m["compactorSleepDuration"]; exists {
|
|
||||||
c.SetCompactorSleepDuration(f.CompactorSleepDuration)
|
|
||||||
}
|
}
|
||||||
if _, exists := m["compressDocumentBody"]; exists {
|
if v, exists := config["openFlags"].(string); exists {
|
||||||
c.SetCompressDocumentBody(f.CompressDocumentBody)
|
switch v {
|
||||||
|
case "create":
|
||||||
|
c.SetOpenFlags(forestdb.OPEN_FLAG_CREATE)
|
||||||
|
case "readonly":
|
||||||
|
c.SetOpenFlags(forestdb.OPEN_FLAG_RDONLY)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("Unknown open flag: %s", v)
|
||||||
}
|
}
|
||||||
if _, exists := m["durabilityOpt"]; exists {
|
|
||||||
c.SetDurabilityOpt(f.DurabilityOpt)
|
|
||||||
}
|
}
|
||||||
if _, exists := m["openFlags"]; exists {
|
if v, exists := config["purgingInterval"].(float64); exists {
|
||||||
c.SetOpenFlags(f.OpenFlags)
|
c.SetPurgingInterval(uint32(v))
|
||||||
}
|
}
|
||||||
if _, exists := m["purgingInterval"]; exists {
|
if v, exists := config["seqTreeOpt"].(bool); exists {
|
||||||
c.SetPurgingInterval(f.PurgingInterval)
|
if !v {
|
||||||
|
c.SetSeqTreeOpt(forestdb.SEQTREE_NOT_USE)
|
||||||
}
|
}
|
||||||
if _, exists := m["seqTreeOpt"]; exists {
|
|
||||||
c.SetSeqTreeOpt(f.SeqTreeOpt)
|
|
||||||
}
|
}
|
||||||
if _, exists := m["walFlushBeforeCommit"]; exists {
|
if v, exists := config["walFlushBeforeCommit"].(bool); exists {
|
||||||
c.SetWalFlushBeforeCommit(f.WalFlushBeforeCommit)
|
c.SetWalFlushBeforeCommit(v)
|
||||||
}
|
}
|
||||||
if _, exists := m["walThreshold"]; exists {
|
if v, exists := config["walThreshold"].(float64); exists {
|
||||||
c.SetWalThreshold(f.WalThreshold)
|
c.SetWalThreshold(uint64(v))
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,5 +142,15 @@ func applyConfig(o *gorocksdb.Options, config map[string]interface{}) (
|
||||||
o.SetWriteBufferSize(int(wbs))
|
o.SetWriteBufferSize(int(wbs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mof, ok := config["max_open_files"].(float64)
|
||||||
|
if ok {
|
||||||
|
o.SetMaxOpenFiles(int(mof))
|
||||||
|
}
|
||||||
|
|
||||||
|
tt, ok := config["total_threads"].(float64)
|
||||||
|
if ok {
|
||||||
|
o.IncreaseParallelism(int(tt))
|
||||||
|
}
|
||||||
|
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user