lib/db: Remove Badger experiment (#7413)

This commit is contained in:
Jakob Borg
2021-03-01 09:16:08 +01:00
committed by GitHub
parent cca17f5306
commit 55d5e03639
7 changed files with 1 additions and 638 deletions
-76
View File
@@ -8,12 +8,7 @@ package backend
import (
"errors"
"os"
"strings"
"sync"
"time"
"github.com/syncthing/syncthing/lib/locations"
)
// CommitHook is a function that is executed before a WriteTransaction is
@@ -131,10 +126,6 @@ const (
)
func Open(path string, tuning Tuning) (Backend, error) {
if err := maybeCopyDatabase(path, strings.Replace(path, locations.LevelDBDir, locations.BadgerDir, 1), OpenLevelDBAuto, OpenBadger); err != nil {
return nil, err
}
return OpenLevelDB(path, tuning)
}
@@ -209,70 +200,3 @@ func (cg *closeWaitGroup) CloseWait() {
cg.closeMut.Unlock()
cg.WaitGroup.Wait()
}
type opener func(path string) (Backend, error)
// maybeCopyDatabase copies the database if the destination doesn't exist
// but the source does.
func maybeCopyDatabase(toPath, fromPath string, toOpen, fromOpen opener) error {
if _, err := os.Lstat(toPath); !os.IsNotExist(err) {
// Destination database exists (or is otherwise unavailable), do not
// attempt to overwrite it.
return nil
}
if _, err := os.Lstat(fromPath); err != nil {
// Source database is not available, so nothing to copy
return nil
}
fromDB, err := fromOpen(fromPath)
if err != nil {
return err
}
defer fromDB.Close()
toDB, err := toOpen(toPath)
if err != nil {
// That's odd, but it will be handled & reported in the usual path
// so we can ignore it here.
return err
}
defer toDB.Close()
l.Infoln("Copying database for format conversion...")
if err := copyBackend(toDB, fromDB); err != nil {
return err
}
// Move the old database out of the way to mark it as migrated.
fromDB.Close()
_ = os.Rename(fromPath, fromPath+".migrated."+time.Now().Format("20060102150405"))
return nil
}
func copyBackend(to, from Backend) error {
srcIt, err := from.NewPrefixIterator(nil)
if err != nil {
return err
}
defer srcIt.Release()
dstTx, err := to.NewWriteTransaction()
if err != nil {
return err
}
defer dstTx.Release()
for srcIt.Next() {
if err := dstTx.Put(srcIt.Key(), srcIt.Value()); err != nil {
return err
}
}
if srcIt.Error() != nil {
return err
}
srcIt.Release()
return dstTx.Commit()
}