From 87b295359012d851b5ed698dfbc25727d5123153 Mon Sep 17 00:00:00 2001 From: Sandy Xu Date: Tue, 29 Mar 2022 11:48:09 +0800 Subject: [PATCH] meta: fix snap not released if error occurs when dumping meta --- pkg/meta/redis.go | 2 +- pkg/meta/sql.go | 2 +- pkg/meta/tkv.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index a82fd69b4235..fe8893462ca4 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -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) @@ -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() } diff --git a/pkg/meta/sql.go b/pkg/meta/sql.go index d6eac26a176a..30b2dbf84367 100644 --- a/pkg/meta/sql.go +++ b/pkg/meta/sql.go @@ -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) @@ -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() } diff --git a/pkg/meta/tkv.go b/pkg/meta/tkv.go index b9ee1af21d6c..0bd1a6551ae0 100644 --- a/pkg/meta/tkv.go +++ b/pkg/meta/tkv.go @@ -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 { @@ -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() }