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:
Bogdan Kanivets
2022-02-09 10:46:18 -08:00
parent 20c89df5e5
commit 01347a8f53
2 changed files with 21 additions and 11 deletions

View File

@ -122,7 +122,17 @@ func TestBackendBatchIntervalCommit(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)
tx := b.BatchTx()
@ -168,6 +178,10 @@ func TestBackendDefrag(t *testing.T) {
if 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.
tx = b.BatchTx()