mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #13701 from lavacat/defrag-bopts-fix-3.5
server/storage/backend: restore original bolt db options after defrag
This commit is contained in:
commit
541635e36a
@ -100,8 +100,9 @@ type backend struct {
|
|||||||
// mlock prevents backend database file to be swapped
|
// mlock prevents backend database file to be swapped
|
||||||
mlock bool
|
mlock bool
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
db *bolt.DB
|
bopts *bolt.Options
|
||||||
|
db *bolt.DB
|
||||||
|
|
||||||
batchInterval time.Duration
|
batchInterval time.Duration
|
||||||
batchLimit int
|
batchLimit int
|
||||||
@ -185,7 +186,8 @@ func newBackend(bcfg BackendConfig) *backend {
|
|||||||
// In future, may want to make buffering optional for low-concurrency systems
|
// In future, may want to make buffering optional for low-concurrency systems
|
||||||
// or dynamically swap between buffered/non-buffered depending on workload.
|
// or dynamically swap between buffered/non-buffered depending on workload.
|
||||||
b := &backend{
|
b := &backend{
|
||||||
db: db,
|
bopts: bopts,
|
||||||
|
db: db,
|
||||||
|
|
||||||
batchInterval: bcfg.BatchInterval,
|
batchInterval: bcfg.BatchInterval,
|
||||||
batchLimit: bcfg.BatchLimit,
|
batchLimit: bcfg.BatchLimit,
|
||||||
@ -511,13 +513,7 @@ func (b *backend) defrag() error {
|
|||||||
b.lg.Fatal("failed to rename tmp database", zap.Error(err))
|
b.lg.Fatal("failed to rename tmp database", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
defragmentedBoltOptions := bolt.Options{}
|
b.db, err = bolt.Open(dbp, 0600, b.bopts)
|
||||||
if boltOpenOptions != nil {
|
|
||||||
defragmentedBoltOptions = *boltOpenOptions
|
|
||||||
}
|
|
||||||
defragmentedBoltOptions.Mlock = b.mlock
|
|
||||||
|
|
||||||
b.db, err = bolt.Open(dbp, 0600, &defragmentedBoltOptions)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.lg.Fatal("failed to open database", zap.String("path", dbp), zap.Error(err))
|
b.lg.Fatal("failed to open database", zap.String("path", dbp), zap.Error(err))
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,17 @@ func TestBackendBatchIntervalCommit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBackendDefrag(t *testing.T) {
|
func TestBackendDefrag(t *testing.T) {
|
||||||
b, _ := betesting.NewDefaultTmpBackend(t)
|
bcfg := backend.DefaultBackendConfig()
|
||||||
|
// Make sure we change BackendFreelistType
|
||||||
|
// The goal is to verify that we restore config option after defrag.
|
||||||
|
if bcfg.BackendFreelistType == bolt.FreelistMapType {
|
||||||
|
bcfg.BackendFreelistType = bolt.FreelistArrayType
|
||||||
|
} else {
|
||||||
|
bcfg.BackendFreelistType = bolt.FreelistMapType
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := betesting.NewTmpBackendFromCfg(t, bcfg)
|
||||||
|
|
||||||
defer betesting.Close(t, b)
|
defer betesting.Close(t, b)
|
||||||
|
|
||||||
tx := b.BatchTx()
|
tx := b.BatchTx()
|
||||||
@ -168,6 +178,10 @@ func TestBackendDefrag(t *testing.T) {
|
|||||||
if nsize >= size {
|
if nsize >= size {
|
||||||
t.Errorf("new size = %v, want < %d", nsize, size)
|
t.Errorf("new size = %v, want < %d", nsize, size)
|
||||||
}
|
}
|
||||||
|
db := backend.DbFromBackendForTest(b)
|
||||||
|
if db.FreelistType != bcfg.BackendFreelistType {
|
||||||
|
t.Errorf("db FreelistType = [%v], want [%v]", db.FreelistType, bcfg.BackendFreelistType)
|
||||||
|
}
|
||||||
|
|
||||||
// try put more keys after shrink.
|
// try put more keys after shrink.
|
||||||
tx = b.BatchTx()
|
tx = b.BatchTx()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user