Skip to content

Commit

Permalink
meta: fix snap not released if error occurs when dumping meta (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD authored Mar 29, 2022
1 parent d52704e commit 68010fd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,7 @@ func (m *redisMeta) DumpMeta(w io.Writer, root Ino) (err error) {
var tree, trash *DumpedEntry
root = m.checkRoot(root)
if root == 1 {
defer func() { m.snap = nil }()
bar := progress.AddCountBar("Snapshot keys", m.rdb.DBSize(ctx).Val())
if err = m.makeSnap(bar); err != nil {
return errors.Errorf("Fetch all metadata from Redis: %s", err)
Expand Down Expand Up @@ -2983,7 +2984,6 @@ func (m *redisMeta) DumpMeta(w io.Writer, root Ino) (err error) {
return err
}
progress.Done()
m.snap = nil

return bw.Flush()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,7 @@ func (m *dbMeta) DumpMeta(w io.Writer, root Ino) (err error) {
var tree, trash *DumpedEntry
root = m.checkRoot(root)
if root == 1 {
defer func() { m.snap = nil }()
bar := progress.AddCountBar("Snapshot keys", 0)
if err = m.makeSnap(bar); err != nil {
return fmt.Errorf("Fetch all metadata from DB: %s", err)
Expand Down Expand Up @@ -2622,7 +2623,6 @@ func (m *dbMeta) DumpMeta(w io.Writer, root Ino) (err error) {
return err
}
progress.Done()
m.snap = nil

return bw.Flush()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,7 @@ func (m *kvMeta) DumpMeta(w io.Writer, root Ino) (err error) {
case *memKV:
m.snap = c
default:
defer func() { m.snap = nil }()
m.snap = &memKV{items: btree.New(2), temp: &kvItem{}}
bar := progress.AddCountBar("Snapshot keys", 0)
if err = m.txn(func(tx kvTxn) error {
Expand Down Expand Up @@ -2275,7 +2276,6 @@ func (m *kvMeta) DumpMeta(w io.Writer, root Ino) (err error) {
return err
}
progress.Done()
m.snap = nil

return bw.Flush()
}
Expand Down

0 comments on commit 68010fd

Please sign in to comment.