mvcc/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-17 15:33:05 -08:00
parent a905430d27
commit d30a4fbf0c
2 changed files with 30 additions and 9 deletions

View File

@ -120,7 +120,16 @@ func TestBackendBatchIntervalCommit(t *testing.T) {
}
func TestBackendDefrag(t *testing.T) {
b, tmpPath := NewDefaultTmpBackend()
bcfg := 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, tmpPath := NewTmpBackendFromCfg(bcfg)
defer cleanup(b, tmpPath)
tx := b.BatchTx()
@ -167,6 +176,10 @@ func TestBackendDefrag(t *testing.T) {
t.Errorf("new size = %v, want < %d", nsize, size)
}
if b.db.FreelistType != bcfg.BackendFreelistType {
t.Errorf("db FreelistType = [%v], want [%v]", b.db.FreelistType, bcfg.BackendFreelistType)
}
// try put more keys after shrink.
tx = b.BatchTx()
tx.Lock()