Skip to content

Commit

Permalink
fix: return MergeIterator.Close errors (#24975)
Browse files Browse the repository at this point in the history
Ensure that errors from closing the
iterators underneath a MergeIterator
are returned up the stack.
  • Loading branch information
davidby-influx authored May 13, 2024
1 parent d1da486 commit 5fda409
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
26 changes: 16 additions & 10 deletions query/iterator.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package query
import (
"container/heap"
"context"
"errors"
"io"
"sort"
"sync"
Expand Down Expand Up @@ -161,14 +162,15 @@ func (itr *floatMergeIterator) Close() error {
itr.mu.Lock()
defer itr.mu.Unlock()

var errs []error
for _, input := range itr.inputs {
input.Close()
errs = append(errs, input.Close())
}
itr.curr = nil
itr.inputs = nil
itr.heap.items = nil
itr.closed = true
return nil
return errors.Join(errs...)
}

// Next returns the next point from the iterator.
Expand Down Expand Up @@ -2824,14 +2826,15 @@ func (itr *integerMergeIterator) Close() error {
itr.mu.Lock()
defer itr.mu.Unlock()

var errs []error
for _, input := range itr.inputs {
input.Close()
errs = append(errs, input.Close())
}
itr.curr = nil
itr.inputs = nil
itr.heap.items = nil
itr.closed = true
return nil
return errors.Join(errs...)
}

// Next returns the next point from the iterator.
Expand Down Expand Up @@ -5487,14 +5490,15 @@ func (itr *unsignedMergeIterator) Close() error {
itr.mu.Lock()
defer itr.mu.Unlock()

var errs []error
for _, input := range itr.inputs {
input.Close()
errs = append(errs, input.Close())
}
itr.curr = nil
itr.inputs = nil
itr.heap.items = nil
itr.closed = true
return nil
return errors.Join(errs...)
}

// Next returns the next point from the iterator.
Expand Down Expand Up @@ -8150,14 +8154,15 @@ func (itr *stringMergeIterator) Close() error {
itr.mu.Lock()
defer itr.mu.Unlock()

var errs []error
for _, input := range itr.inputs {
input.Close()
errs = append(errs, input.Close())
}
itr.curr = nil
itr.inputs = nil
itr.heap.items = nil
itr.closed = true
return nil
return errors.Join(errs...)
}

// Next returns the next point from the iterator.
Expand Down Expand Up @@ -10799,14 +10804,15 @@ func (itr *booleanMergeIterator) Close() error {
itr.mu.Lock()
defer itr.mu.Unlock()

var errs []error
for _, input := range itr.inputs {
input.Close()
errs = append(errs, input.Close())
}
itr.curr = nil
itr.inputs = nil
itr.heap.items = nil
itr.closed = true
return nil
return errors.Join(errs...)
}

// Next returns the next point from the iterator.
Expand Down
6 changes: 4 additions & 2 deletions query/iterator.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package query
import (
"context"
"container/heap"
"errors"
"io"
"sort"
"sync"
Expand Down Expand Up @@ -159,14 +160,15 @@ func (itr *{{$k.name}}MergeIterator) Close() error {
itr.mu.Lock()
defer itr.mu.Unlock()

var errs []error
for _, input := range itr.inputs {
input.Close()
errs = append(errs, input.Close())
}
itr.curr = nil
itr.inputs = nil
itr.heap.items = nil
itr.closed = true
return nil
return errors.Join(errs...)
}

// Next returns the next point from the iterator.
Expand Down

0 comments on commit 5fda409

Please sign in to comment.