backupds kvlog: Address review

This commit is contained in:
Łukasz Magiera 2021-03-10 13:58:02 +01:00
parent 2b380c96a5
commit 3f1054daf4
2 changed files with 29 additions and 27 deletions

View File

@ -6,6 +6,7 @@ import (
"sync" "sync"
"time" "time"
"go.uber.org/multierr"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
@ -189,11 +190,10 @@ func (d *Datastore) CloseLog() error {
} }
func (d *Datastore) Close() error { func (d *Datastore) Close() error {
if err := d.child.Close(); err != nil { return multierr.Combine(
return xerrors.Errorf("closing child datastore: %w", err) d.child.Close(),
} d.CloseLog(),
)
return d.CloseLog()
} }
func (d *Datastore) Batch() (datastore.Batch, error) { func (d *Datastore) Batch() (datastore.Batch, error) {

View File

@ -65,7 +65,12 @@ func (d *Datastore) startLog(logdir string) error {
return xerrors.Errorf("writing new log head: %w", err) return xerrors.Errorf("writing new log head: %w", err)
} }
go func() { go d.runLog(l)
return nil
}
func (d *Datastore) runLog(l *logfile) {
defer close(d.closed) defer close(d.closed)
for { for {
select { select {
@ -86,9 +91,6 @@ func (d *Datastore) startLog(logdir string) error {
return return
} }
} }
}()
return nil
} }
type logfile struct { type logfile struct {