Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new boltdb options #11895

Merged
merged 6 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/11895.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
raft: change freelist type to map and set nofreelistsync to true
```
11 changes: 10 additions & 1 deletion physical/raft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,19 @@ func (f *FSM) openDBFile(dbPath string) error {
return errors.New("can not open empty filename")
}

boltDB, err := bolt.Open(dbPath, 0o666, &bolt.Options{Timeout: 1 * time.Second})
freelistType, noFreelistSync := freelistOptions()
start := time.Now()
boltDB, err := bolt.Open(dbPath, 0o666, &bolt.Options{
Timeout: 1 * time.Second,
FreelistType: freelistType,
NoFreelistSync: noFreelistSync,
})
if err != nil {
return err
}
elapsed := time.Now().Sub(start)
f.logger.Debug("time to open database", "elapsed", elapsed, "path", dbPath)
metrics.MeasureSince([]string{"raft_storage", "fsm", "open_db_file"}, start)

err = boltDB.Update(func(tx *bolt.Tx) error {
// make sure we have the necessary buckets created
Expand Down
28 changes: 27 additions & 1 deletion physical/raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,15 @@ func NewRaftBackend(conf map[string]string, logger log.Logger) (physical.Backend
}

// Create the backend raft store for logs and stable storage.
store, err := raftboltdb.NewBoltStore(filepath.Join(path, "raft.db"))
freelistType, noFreelistSync := freelistOptions()
raftOptions := raftboltdb.Options{
Path: filepath.Join(path, "raft.db"),
BoltOptions: &bolt.Options{
FreelistType: freelistType,
NoFreelistSync: noFreelistSync,
},
}
store, err := raftboltdb.New(raftOptions)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1573,3 +1581,21 @@ func (s sealer) Open(ctx context.Context, ct []byte) ([]byte, error) {

return s.access.Decrypt(ctx, &eblob, nil)
}

// freelistOptions returns the freelist type and nofreelistsync values to use
// when opening boltdb files, based on our preferred defaults, and the possible
// presence of overriding environment variables.
func freelistOptions() (bolt.FreelistType, bool) {
freelistType := bolt.FreelistMapType
noFreelistSync := true

if os.Getenv("VAULT_RAFT_FREELIST_TYPE") == "array" {
freelistType = bolt.FreelistArrayType
}

if os.Getenv("VAULT_RAFT_FREELIST_SYNC") != "" {
noFreelistSync = false
}

return freelistType, noFreelistSync
}