From 7fba4e851442922f6f53e55d9a4f4768c8e42a05 Mon Sep 17 00:00:00 2001 From: Adrien Aury <44274230+adrienaury@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:48:23 +0000 Subject: [PATCH] fix: add missing closes --- cmd/silo/main.go | 2 ++ internal/infra/backend.go | 6 +++++- pkg/silo/driver.go | 2 ++ test.jsonl | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test.jsonl diff --git a/cmd/silo/main.go b/cmd/silo/main.go index e953a0e..a1e9e3b 100644 --- a/cmd/silo/main.go +++ b/cmd/silo/main.go @@ -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) diff --git a/internal/infra/backend.go b/internal/infra/backend.go index 831c87d..4dde32f 100644 --- a/internal/infra/backend.go +++ b/internal/infra/backend.go @@ -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) } diff --git a/pkg/silo/driver.go b/pkg/silo/driver.go index c5c40ba..73d2d51 100644 --- a/pkg/silo/driver.go +++ b/pkg/silo/driver.go @@ -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 { diff --git a/test.jsonl b/test.jsonl new file mode 100644 index 0000000..c3f9312 --- /dev/null +++ b/test.jsonl @@ -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}