Skip to content

Commit

Permalink
Merge pull request #1159 from nats-io/bolt_config
Browse files Browse the repository at this point in the history
[ADDED] Configuration parameters for RAFT's BoltDB store
  • Loading branch information
kozlovic authored Feb 19, 2021
2 parents 2c5b3a6 + 24b433f commit 30c5ffb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
15 changes: 7 additions & 8 deletions server/clustering.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ type ClusteringOptions struct {
// speed up recovery since there is no need for a full database re-sync.
BoltFreeListSync bool

// BoltFreeListArray sets the backend freelist type to "array".
// There are two options:
// - "array" which is simple but suffers dramatic performance degradation if database is
// large and framentation in freelist is common.
// - "hashmap" which is faster in almost all circumstances but doesn't guarantee
// that it offers the smallest page id available. In normal case it is safe.
// Since v0.21.0, the default is "hashmap". Set this option to "true" to use "array" instead.
BoltFreeListArray bool
// BoltFreeListMap sets the backend freelist type to use a map instead of
// the default array type.
// The "array" type (the default) is simple but suffers dramatic performance
// degradation if database is large and framentation in freelist is common.
// The "hashmap which is faster in almost all circumstances but doesn't guarantee
// that it offers the smallest page id available. In normal case it is safe.
BoltFreeListMap bool
}

// raftNode is a handle to a member in a Raft consensus group.
Expand Down
4 changes: 2 additions & 2 deletions server/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ func parseCluster(itf interface{}, opts *Options) error {
return err
}
opts.Clustering.BoltFreeListSync = v.(bool)
case "bolt_free_list_array":
case "bolt_free_list_map":
if err := checkType(k, reflect.Bool, v); err != nil {
return err
}
opts.Clustering.BoltFreeListArray = v.(bool)
opts.Clustering.BoltFreeListMap = v.(bool)
case "nodes_connections":
if err := checkType(k, reflect.Bool, v); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions server/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ func TestParseConfig(t *testing.T) {
if !opts.Clustering.BoltFreeListSync {
t.Fatal("Expected BoltFreeListSync to be true")
}
if !opts.Clustering.BoltFreeListArray {
t.Fatal("Expected BoltFreeListArray to be true")
if !opts.Clustering.BoltFreeListMap {
t.Fatal("Expected BoltFreeListMap to be true")
}
if !opts.Clustering.NodesConnections {
t.Fatal("Expected NodesConnections to be true")
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestParseWrongTypes(t *testing.T) {
expectFailureFor(t, "cluster:{raft_commit_timeout:\"not_a_time\"}", wrongTimeErr)
expectFailureFor(t, "cluster:{allow_add_remove_node:1}", wrongTypeErr)
expectFailureFor(t, "cluster:{bolt_free_list_sync:123}", wrongTypeErr)
expectFailureFor(t, "cluster:{bolt_free_list_array:123}", wrongTypeErr)
expectFailureFor(t, "cluster:{bolt_free_list_map:123}", wrongTypeErr)
expectFailureFor(t, "sql:{driver:false}", wrongTypeErr)
expectFailureFor(t, "sql:{source:false}", wrongTypeErr)
expectFailureFor(t, "sql:{no_caching:123}", wrongTypeErr)
Expand Down
6 changes: 3 additions & 3 deletions server/raft_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func newRaftLog(log logger.Logger, fileName string, opts *Options) (*raftLog, er
fileName: fileName,
codec: &codec.MsgpackHandle{},
}
freeListType := bolt.FreelistMapType
if opts.Clustering.BoltFreeListArray {
freeListType = bolt.FreelistArrayType
freeListType := bolt.FreelistArrayType
if opts.Clustering.BoltFreeListMap {
freeListType = bolt.FreelistMapType
}
dbOpts := &bolt.Options{
NoSync: !opts.Clustering.Sync,
Expand Down
2 changes: 1 addition & 1 deletion test/configs/test_parse.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ streaming: {
raft_commit_timeout: "50ms"
allow_add_remove_node: true
bolt_free_list_sync: true
bolt_free_list_array: true
bolt_free_list_map: true
nodes_connections: true
}

Expand Down

0 comments on commit 30c5ffb

Please sign in to comment.