lib/db: Checkpoint during schema updates (fixes #6422) (#6424)

This commit is contained in:
Simon Frei 2020-03-18 20:33:43 +01:00 committed by GitHub
parent cc2a55892f
commit 00b2340f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -201,6 +201,9 @@ func (db *schemaUpdater) updateSchema0to1(_ int) error {
ignAdded++ ignAdded++
} }
} }
if err := t.Checkpoint(); err != nil {
return err
}
} }
for folder := range changedFolders { for folder := range changedFolders {
@ -339,7 +342,7 @@ func (db *schemaUpdater) updateSchema5to6(_ int) error {
for _, folderStr := range db.ListFolders() { for _, folderStr := range db.ListFolders() {
folder := []byte(folderStr) folder := []byte(folderStr)
var putErr error var iterErr error
err := t.withHave(folder, protocol.LocalDeviceID[:], nil, false, func(f FileIntf) bool { err := t.withHave(folder, protocol.LocalDeviceID[:], nil, false, func(f FileIntf) bool {
if !f.IsInvalid() { if !f.IsInvalid() {
return true return true
@ -350,16 +353,18 @@ func (db *schemaUpdater) updateSchema5to6(_ int) error {
fi.LocalFlags = protocol.FlagLocalIgnored fi.LocalFlags = protocol.FlagLocalIgnored
bs, _ := fi.Marshal() bs, _ := fi.Marshal()
dk, putErr = db.keyer.GenerateDeviceFileKey(dk, folder, protocol.LocalDeviceID[:], []byte(fi.Name)) dk, iterErr = db.keyer.GenerateDeviceFileKey(dk, folder, protocol.LocalDeviceID[:], []byte(fi.Name))
if putErr != nil { if iterErr != nil {
return false return false
} }
putErr = t.Put(dk, bs) if iterErr = t.Put(dk, bs); iterErr != nil {
return false
return putErr == nil }
iterErr = t.Checkpoint()
return iterErr == nil
}) })
if putErr != nil { if iterErr != nil {
return putErr return iterErr
} }
if err != nil { if err != nil {
return err return err
@ -421,6 +426,9 @@ func (db *schemaUpdater) updateSchema6to7(_ int) error {
if err != nil { if err != nil {
return err return err
} }
if err := t.Checkpoint(); err != nil {
return err
}
} }
return t.Commit() return t.Commit()
} }
@ -460,6 +468,9 @@ func (db *schemaUpdater) updateSchemato9(prev int) error {
if err := t.putFile(it.Key(), fi); err != nil { if err := t.putFile(it.Key(), fi); err != nil {
return err return err
} }
if err := t.Checkpoint(); err != nil {
return err
}
} }
it.Release() it.Release()
if err := it.Error(); err != nil { if err := it.Error(); err != nil {