lib/syncthing: Expose backend instead of lowlevel (#6224)

This commit is contained in:
Simon Frei 2019-12-12 16:50:09 +01:00 committed by Jakob Borg
parent 82ed8e702c
commit 8140350094
4 changed files with 9 additions and 12 deletions

View File

@ -486,7 +486,7 @@ func checkUpgrade() upgrade.Release {
func performUpgrade(release upgrade.Release) { func performUpgrade(release upgrade.Release) {
// Use leveldb database locks to protect against concurrent upgrades // Use leveldb database locks to protect against concurrent upgrades
_, err := syncthing.OpenGoleveldb(locations.Get(locations.Database), config.TuningAuto) _, err := syncthing.OpenDBBackend(locations.Get(locations.Database), config.TuningAuto)
if err == nil { if err == nil {
err = upgrade.To(release) err = upgrade.To(release)
if err != nil { if err != nil {
@ -578,7 +578,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
} }
dbFile := locations.Get(locations.Database) dbFile := locations.Get(locations.Database)
ldb, err := syncthing.OpenGoleveldb(dbFile, cfg.Options().DatabaseTuning) ldb, err := syncthing.OpenDBBackend(dbFile, cfg.Options().DatabaseTuning)
if err != nil { if err != nil {
l.Warnln("Error opening database:", err) l.Warnln("Error opening database:", err)
os.Exit(1) os.Exit(1)

View File

@ -23,6 +23,7 @@ import (
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections" "github.com/syncthing/syncthing/lib/connections"
"github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/db/backend"
"github.com/syncthing/syncthing/lib/discover" "github.com/syncthing/syncthing/lib/discover"
"github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/locations" "github.com/syncthing/syncthing/lib/locations"
@ -84,10 +85,10 @@ type App struct {
stopped chan struct{} stopped chan struct{}
} }
func New(cfg config.Wrapper, ll *db.Lowlevel, evLogger events.Logger, cert tls.Certificate, opts Options) *App { func New(cfg config.Wrapper, dbBackend backend.Backend, evLogger events.Logger, cert tls.Certificate, opts Options) *App {
a := &App{ a := &App{
cfg: cfg, cfg: cfg,
ll: ll, ll: db.NewLowlevel(dbBackend),
evLogger: evLogger, evLogger: evLogger,
opts: opts, opts: opts,
cert: cert, cert: cert,

View File

@ -14,6 +14,7 @@ import (
"time" "time"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/db/backend"
"github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/tlsutil" "github.com/syncthing/syncthing/lib/tlsutil"
@ -77,7 +78,7 @@ func TestStartupFail(t *testing.T) {
}, events.NoopLogger) }, events.NoopLogger)
defer os.Remove(cfg.ConfigPath()) defer os.Remove(cfg.ConfigPath())
app := New(cfg, nil, events.NoopLogger, cert, Options{}) app := New(cfg, backend.OpenMemory(), events.NoopLogger, cert, Options{})
startErr := app.Start() startErr := app.Start()
if startErr == nil { if startErr == nil {
t.Fatal("Expected an error from Start, got nil") t.Fatal("Expected an error from Start, got nil")

View File

@ -16,7 +16,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/db/backend" "github.com/syncthing/syncthing/lib/db/backend"
"github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs" "github.com/syncthing/syncthing/lib/fs"
@ -124,10 +123,6 @@ func copyFile(src, dst string) error {
return nil return nil
} }
func OpenGoleveldb(path string, tuning config.Tuning) (*db.Lowlevel, error) { func OpenDBBackend(path string, tuning config.Tuning) (backend.Backend, error) {
ldb, err := backend.Open(path, backend.Tuning(tuning)) return backend.Open(path, backend.Tuning(tuning))
if err != nil {
return nil, err
}
return db.NewLowlevel(ldb), nil
} }