mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server/storage/backend: restore original bolt db options after defrag
Problem: Defrag was implemented before custom bolt options were added. Currently defrag doesn't restore backend options. For example BackendFreelistType will be unset after defrag. Solution: save bolt db options and use them in defrag.
This commit is contained in:
@@ -100,8 +100,9 @@ type backend struct {
|
||||
// mlock prevents backend database file to be swapped
|
||||
mlock bool
|
||||
|
||||
mu sync.RWMutex
|
||||
db *bolt.DB
|
||||
mu sync.RWMutex
|
||||
bopts *bolt.Options
|
||||
db *bolt.DB
|
||||
|
||||
batchInterval time.Duration
|
||||
batchLimit int
|
||||
@@ -185,7 +186,8 @@ func newBackend(bcfg BackendConfig) *backend {
|
||||
// In future, may want to make buffering optional for low-concurrency systems
|
||||
// or dynamically swap between buffered/non-buffered depending on workload.
|
||||
b := &backend{
|
||||
db: db,
|
||||
bopts: bopts,
|
||||
db: db,
|
||||
|
||||
batchInterval: bcfg.BatchInterval,
|
||||
batchLimit: bcfg.BatchLimit,
|
||||
@@ -511,13 +513,7 @@ func (b *backend) defrag() error {
|
||||
b.lg.Fatal("failed to rename tmp database", zap.Error(err))
|
||||
}
|
||||
|
||||
defragmentedBoltOptions := bolt.Options{}
|
||||
if boltOpenOptions != nil {
|
||||
defragmentedBoltOptions = *boltOpenOptions
|
||||
}
|
||||
defragmentedBoltOptions.Mlock = b.mlock
|
||||
|
||||
b.db, err = bolt.Open(dbp, 0600, &defragmentedBoltOptions)
|
||||
b.db, err = bolt.Open(dbp, 0600, b.bopts)
|
||||
if err != nil {
|
||||
b.lg.Fatal("failed to open database", zap.String("path", dbp), zap.Error(err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user