lib/db: Refactor: use a Lowlevel type underneath Instance (ref #5198) (#5212)

This adds a thin type that holds the state associated with the
leveldb.DB, leaving the huge Instance type more or less stateless. Also
moves some keying stuff into the DB package so that other packages need
not know the keying specifics.

(This does not, yet, fix the cmd/stindex program, in order to keep the
diff size down. Hence the keying constants are still exported.)
This commit is contained in:
Jakob Borg
2018-10-10 11:34:24 +02:00
committed by GitHub
parent 8e645ab782
commit b50d57b7fd
22 changed files with 382 additions and 374 deletions

View File

@@ -712,11 +712,13 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
if err != nil {
l.Fatalln("Error opening database:", err)
}
if err := db.UpdateSchema(ldb); err != nil {
l.Fatalln("Database schema:", err)
}
if runtimeOptions.resetDeltaIdxs {
l.Infoln("Reinitializing delta index IDs")
ldb.DropLocalDeltaIndexIDs()
ldb.DropRemoteDeltaIndexIDs()
db.DropDeltaIndexIDs(ldb)
}
protectedFiles := []string{
@@ -737,7 +739,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// Grab the previously running version string from the database.
miscDB := db.NewNamespacedKV(ldb, string(db.KeyTypeMiscData))
miscDB := db.NewMiscDataNamespace(ldb)
prevVersion, _ := miscDB.String("prevVersion")
// Strip away prerelease/beta stuff and just compare the release
@@ -753,7 +755,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// Drop delta indexes in case we've changed random stuff we
// shouldn't have. We will resend our index on next connect.
ldb.DropLocalDeltaIndexIDs()
db.DropDeltaIndexIDs(ldb)
// Remember the new version.
miscDB.PutString("prevVersion", Version)