go/store/nbs: refactor journal close method

This commit is contained in:
Andy Arthur
2023-03-27 11:37:36 -07:00
parent 41b5a7a613
commit b288911fb7
2 changed files with 9 additions and 13 deletions
+8 -12
View File
@@ -372,22 +372,18 @@ func (j *chunkJournal) maybeInit(ctx context.Context) (err error) {
// Close implements io.Closer
func (j *chunkJournal) Close() (err error) {
ctx := context.Background()
_, last, cerr := j.backing.ParseIfExists(ctx, &Stats{}, nil)
if cerr != nil {
err = cerr
} else if !emptyAddr(j.contents.lock) {
// best effort update to |backing|, this will
// fail if the database has been deleted.
// if we spuriously fail, we'll update |backing|
// next time we open this chunkJournal
_, _ = j.backing.Update(ctx, last.lock, j.contents, &Stats{}, nil)
}
if j.wr != nil {
err = j.wr.Close()
// flush the latest root to the backing manifest
if !j.backing.readOnly() {
cerr := j.flushToBackingManifest(context.Background(), j.contents, &Stats{})
if err == nil {
err = cerr
}
}
}
// close the journal manifest to release the file lock
if cerr = j.backing.Close(); err == nil {
if cerr := j.backing.Close(); err == nil {
err = cerr // keep first error
}
return
+1 -1
View File
@@ -465,7 +465,7 @@ func (wr *journalWriter) Close() (err error) {
return err
}
if wr.index != nil {
wr.index.Close()
_ = wr.index.Close()
}
if cerr := wr.journal.Sync(); cerr != nil {
err = cerr