Skip to content

Commit

Permalink
fix: add missing closes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Mar 22, 2024
1 parent 1e30910 commit 7fba4e8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/silo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func run(_ *cobra.Command) error {
return fmt.Errorf("%w", err)
}

defer backend.Close()

writer := silo.NewDumpToStdout()

driver := silo.NewDriver(backend, writer)
Expand Down
6 changes: 5 additions & 1 deletion internal/infra/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,15 @@ func (b Backend) Store(key string, value string) error {
return nil
}

func (b Backend) Snapshot() silo.Snapshot {
func (b Backend) Snapshot() silo.Snapshot { //nolint:ireturn
return Snapshot{b.db.NewIndexedBatch()}
}

func (b Backend) Close() error {
if err := b.db.Flush(); err != nil {
return fmt.Errorf("%w", err)
}

if err := b.db.Close(); err != nil {
return fmt.Errorf("%w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/silo/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func NewDriver(backend Backend, writer DumpWriter) *Driver {
func (d *Driver) Dump() error {
snapshot := d.backend.Snapshot()

defer snapshot.Close()

for count := 0; ; count++ {
entryNode, present, err := snapshot.Next()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions test.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{"ID1": 1, "ID2": "1", "ID3": 1.10, "ID4": "00001"}
{"ID1": 2, "ID2": "2", "ID3": 2.20, "ID4": "00002"}
{"ID1": 3, "ID4": "00003"}
{"ID2": "3", "ID3": 3.30}
{"ID4": "00003", "ID3": 3.30}

0 comments on commit 7fba4e8

Please sign in to comment.