lib/db: Improve error message on meta inconsistency (#6751)

This commit is contained in:
Simon Frei 2020-06-17 10:03:39 +02:00 committed by GitHub
parent a218a69530
commit cbe0d2fffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -811,7 +811,12 @@ func (db *Lowlevel) getMetaAndCheck(folder string) *metadataTracker {
func (db *Lowlevel) loadMetadataTracker(folder string) *metadataTracker {
meta := newMetadataTracker()
if err := meta.fromDB(db, []byte(folder)); err != nil {
l.Infof("No stored folder metadata for %q; recalculating", folder)
if err == errMetaInconsistent {
l.Infof("Stored folder metadata for %q is inconsistent; recalculating", folder)
} else {
l.Infof("No stored folder metadata for %q; recalculating", folder)
}
return db.getMetaAndCheck(folder)
}

View File

@ -8,6 +8,7 @@ package db
import (
"bytes"
"errors"
"math/bits"
"time"
@ -15,6 +16,8 @@ import (
"github.com/syncthing/syncthing/lib/sync"
)
var errMetaInconsistent = errors.New("inconsistent counts detected")
type countsMap struct {
counts CountsSet
indexes map[metaKey]int // device ID + local flags -> index in counts
@ -104,7 +107,13 @@ func (m *metadataTracker) fromDB(db *Lowlevel, folder []byte) error {
if err != nil {
return err
}
return m.Unmarshal(bs)
if err = m.Unmarshal(bs); err != nil {
return err
}
if m.counts.Created == 0 {
return errMetaInconsistent
}
return nil
}
// countsPtr returns a pointer to the corresponding Counts struct, if