Skip to content

lib/db, lib/syncthing: Don't repair DB on upgrade, but on error (fixes #6917) - #6971

Merged
calmh merged 3 commits into
syncthing:mainfrom
imsodin:lib/noDBRepOnUpgrade
Sep 10, 2020
Merged

calmh merged 3 commits into
syncthing:mainfrom
imsodin:lib/noDBRepOnUpgrade

Conversation

@imsodin

@imsodin imsodin commented Sep 8, 2020

Copy link
Copy Markdown
Member

No longer repair the db unconditionally on upgrade (fixes #6917). Instead when an error due to an inconsistency occurs, mark the db as needing repair. Then on next startup, do the repair.

@calmh

calmh commented Sep 9, 2020 •

Copy link
Copy Markdown
Member

I think this is reasonable, but it doesn't feel like something that needs to leak outside the db package. I suggest:

  • setting the repair bit outside the database itself, because it may not be writable or the write+panic might make it not flush (maybe?). Something like touching databaseDir+".needsrepair"?

  • having the lowlevel itself check for this on open and run the repair before returning the database

I'm sure there are complications (the lowlevel doesn't know where the database lives on disk), but...

@calmh

calmh commented Sep 9, 2020

Copy link
Copy Markdown
Member

Oh and perhaps we should add a repair cycle before running migrations, but that's halfway unrelated.

Comment thread lib/db/lowlevel.go Outdated
db.keyer = newDefaultKeyer(db.folderIdx, db.deviceIdx)
db.Add(util.AsService(db.gcRunner, "db.Lowlevel/gcRunner"))
if loc := backend.Location(); loc != "" {
path := filepath.Join(loc, needsRepairFile)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably not assume that loc is a directory that we can do stuff in. We should be able to tack on an extension to loc though

Comment thread lib/db/lowlevel.go Outdated
path := filepath.Join(loc, needsRepairFile)
if _, err := os.Lstat(path); err == nil {
l.Infoln("Database was marked for repair - this may take a while")
db.CheckRepair()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckRepair no longer needs to be exported I think

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A model test was using it, but luckily that was replaceable by WithRecheckInterval(time.Millisecond).

@calmh
calmh merged commit 08bebbe into syncthing:main Sep 10, 2020
@imsodin
imsodin deleted the lib/noDBRepOnUpgrade branch September 10, 2020 09:07
@calmh calmh added this to the v1.10.0 milestone Sep 10, 2020
calmh added a commit to calmh/syncthing that referenced this pull request Sep 24, 2020
* main: (50 commits)
  cmd/ursrv: Properly sort versions (fixes syncthing#6991)
  cmd/ursrv: Recognize new-style dev versions
  gui, man, authors: Update docs, translations, and contributors
  build: Dockerfile that expects ready baked binaries
  lib/model: Consider case conflicts when checking to be deleted items (syncthing#6986)
  lib/fs: Optimize UnicodeLowercase (syncthing#6979)
  lib/db, lib/syncthing: Don't repair DB on upgrade, but on error (fixes syncthing#6917) (syncthing#6971)
  lib/model: Consider existing file when handling symlink on windows (syncthing#6977)
  lib/model: Handle symlink deletion on windows (fixes syncthing#6972) (syncthing#6976)
  lib/model: Fix case-only renames on pull (syncthing#6978)
  lib/fs: More efficient casefs cache (syncthing#6974)
  lib/model: Don't fail over case-conflict on tempfile (fixes syncthing#6973) (syncthing#6975)
  gui, man, authors: Update docs, translations, and contributors
  lib/fs: Use generic case resolver on windows (fixes syncthing#6968) (syncthing#6969)
  lib/model: Prevent duplicate need count on recalculating metadata (syncthing#6964)
  lib/db, lib/protocol: Never need empty-version entries (fixes syncthing#6961) (syncthing#6962)
  lib/model: Correct completion perc. when globalBytes is 0 (syncthing#6963)
  lib/db: Don't hang on double iterator release with Badger (syncthing#6960)
  test, lib/model: Various integration test updates & improvements (syncthing#6956)
  lib/db: Copy returned, old FileVersion (syncthing#6952)
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Sep 11, 2021
@syncthing syncthing locked and limited conversation to collaborators Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconsider db check on upgrade

3 participants