Make Close() method on Iterators return an error
This commit is contained in:
parent
5c9979ec8b
commit
1b6395ed0a
19 changed files with 89 additions and 33 deletions
|
|
@ -174,10 +174,11 @@ func (it *AllIterator) Contains(v graph.Value) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *AllIterator) Close() {
|
func (it *AllIterator) Close() error {
|
||||||
it.result = nil
|
it.result = nil
|
||||||
it.buffer = nil
|
it.buffer = nil
|
||||||
it.done = true
|
it.done = true
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *AllIterator) Size() (int64, bool) {
|
func (it *AllIterator) Size() (int64, bool) {
|
||||||
|
|
|
||||||
|
|
@ -106,10 +106,11 @@ func (it *Iterator) Clone() graph.Iterator {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Close() {
|
func (it *Iterator) Close() error {
|
||||||
it.result = nil
|
it.result = nil
|
||||||
it.buffer = nil
|
it.buffer = nil
|
||||||
it.done = true
|
it.done = true
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) isLiveValue(val []byte) bool {
|
func (it *Iterator) isLiveValue(val []byte) bool {
|
||||||
|
|
|
||||||
|
|
@ -130,12 +130,13 @@ func (it *Iterator) Reset() {
|
||||||
it.result = nil
|
it.result = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Close() {
|
func (it *Iterator) Close() error {
|
||||||
it.buffer = nil
|
it.buffer = nil
|
||||||
it.offset = 0
|
it.offset = 0
|
||||||
it.done = true
|
it.done = true
|
||||||
it.last = ""
|
it.last = ""
|
||||||
it.result = nil
|
it.result = nil
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Tagger() *graph.Tagger {
|
func (it *Iterator) Tagger() *graph.Tagger {
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ type Iterator interface {
|
||||||
Describe() Description
|
Describe() Description
|
||||||
|
|
||||||
// Close the iterator and do internal cleanup.
|
// Close the iterator and do internal cleanup.
|
||||||
Close()
|
Close() error
|
||||||
|
|
||||||
// UID returns the unique identifier of the iterator.
|
// UID returns the unique identifier of the iterator.
|
||||||
UID() uint64
|
UID() uint64
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,9 @@ func (it *Int64) Reset() {
|
||||||
it.at = it.min
|
it.at = it.min
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Int64) Close() {}
|
func (it *Int64) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (it *Int64) Clone() graph.Iterator {
|
func (it *Int64) Clone() graph.Iterator {
|
||||||
out := NewInt64(it.min, it.max)
|
out := NewInt64(it.min, it.max)
|
||||||
|
|
|
||||||
|
|
@ -263,12 +263,22 @@ func (it *And) cleanUp() {}
|
||||||
// Close this iterator, and, by extension, close the subiterators.
|
// Close this iterator, and, by extension, close the subiterators.
|
||||||
// Close should be idempotent, and it follows that if it's subiterators
|
// Close should be idempotent, and it follows that if it's subiterators
|
||||||
// follow this contract, the And follows the contract.
|
// follow this contract, the And follows the contract.
|
||||||
func (it *And) Close() {
|
//
|
||||||
|
// Note: as this potentially involves closing multiple subiterators, only
|
||||||
|
// the first error encountered while closing will be reported (if any).
|
||||||
|
func (it *And) Close() error {
|
||||||
it.cleanUp()
|
it.cleanUp()
|
||||||
it.primaryIt.Close()
|
|
||||||
|
var ret error
|
||||||
|
|
||||||
|
ret = it.primaryIt.Close()
|
||||||
for _, sub := range it.internalIterators {
|
for _, sub := range it.internalIterators {
|
||||||
sub.Close()
|
if err := sub.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register this as an "and" iterator.
|
// Register this as an "and" iterator.
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,9 @@ func (it *Fixed) Reset() {
|
||||||
it.lastIndex = 0
|
it.lastIndex = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Fixed) Close() {}
|
func (it *Fixed) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (it *Fixed) Tagger() *graph.Tagger {
|
func (it *Fixed) Tagger() *graph.Tagger {
|
||||||
return &it.tags
|
return &it.tags
|
||||||
|
|
|
||||||
|
|
@ -247,11 +247,17 @@ func (it *HasA) Stats() graph.IteratorStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the subiterator, the result iterator (if any) and the HasA.
|
// Close the subiterator, the result iterator (if any) and the HasA.
|
||||||
func (it *HasA) Close() {
|
func (it *HasA) Close() error {
|
||||||
|
var ret error
|
||||||
|
|
||||||
if it.resultIt != nil {
|
if it.resultIt != nil {
|
||||||
it.resultIt.Close()
|
ret = it.resultIt.Close()
|
||||||
}
|
}
|
||||||
it.primaryIt.Close()
|
if err := it.primaryIt.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register this iterator as a HasA.
|
// Register this iterator as a HasA.
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,9 @@ func (it *Null) Size() (int64, bool) {
|
||||||
|
|
||||||
func (it *Null) Reset() {}
|
func (it *Null) Reset() {}
|
||||||
|
|
||||||
func (it *Null) Close() {}
|
func (it *Null) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// A null iterator costs nothing. Use it!
|
// A null iterator costs nothing. Use it!
|
||||||
func (it *Null) Stats() graph.IteratorStats {
|
func (it *Null) Stats() graph.IteratorStats {
|
||||||
|
|
|
||||||
|
|
@ -181,9 +181,17 @@ func (it *LinksTo) Result() graph.Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close our subiterators.
|
// Close our subiterators.
|
||||||
func (it *LinksTo) Close() {
|
func (it *LinksTo) Close() error {
|
||||||
it.nextIt.Close()
|
var ret error
|
||||||
it.primaryIt.Close()
|
|
||||||
|
if err := it.nextIt.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
|
if err := it.primaryIt.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// We won't ever have a new result, but our subiterators might.
|
// We won't ever have a new result, but our subiterators might.
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,11 @@ func (it *Materialize) Reset() {
|
||||||
it.index = -1
|
it.index = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Materialize) Close() {
|
func (it *Materialize) Close() error {
|
||||||
it.subIt.Close()
|
|
||||||
it.containsMap = nil
|
it.containsMap = nil
|
||||||
it.values = nil
|
it.values = nil
|
||||||
it.hasRun = false
|
it.hasRun = false
|
||||||
|
return it.subIt.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Materialize) Tagger() *graph.Tagger {
|
func (it *Materialize) Tagger() *graph.Tagger {
|
||||||
|
|
|
||||||
|
|
@ -123,9 +123,19 @@ func (it *Not) NextPath() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Not) Close() {
|
// Close closes the primary and all iterators. If an error occurs, only the
|
||||||
it.primaryIt.Close()
|
// first one will be returned.
|
||||||
it.allIt.Close()
|
func (it *Not) Close() error {
|
||||||
|
var ret error
|
||||||
|
|
||||||
|
if err := it.primaryIt.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
|
if err := it.allIt.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Not) Type() graph.Type { return graph.Not }
|
func (it *Not) Type() graph.Type { return graph.Not }
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ func (it *Optional) Reset() {
|
||||||
it.lastCheck = false
|
it.lastCheck = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Optional) Close() {
|
func (it *Optional) Close() error {
|
||||||
it.subIt.Close()
|
return it.subIt.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Optional) Tagger() *graph.Tagger {
|
func (it *Optional) Tagger() *graph.Tagger {
|
||||||
|
|
|
||||||
|
|
@ -241,12 +241,21 @@ func (it *Or) cleanUp() {}
|
||||||
|
|
||||||
// Close this graph.iterator, and, by extension, close the subiterators.
|
// Close this graph.iterator, and, by extension, close the subiterators.
|
||||||
// Close should be idempotent, and it follows that if it's subiterators
|
// Close should be idempotent, and it follows that if it's subiterators
|
||||||
// follow this contract, the And follows the contract.
|
// follow this contract, the Or follows the contract.
|
||||||
func (it *Or) Close() {
|
//
|
||||||
|
// Note: as this potentially involves closing multiple subiterators, only
|
||||||
|
// the first error encountered while closing will be reported (if any).
|
||||||
|
func (it *Or) Close() error {
|
||||||
it.cleanUp()
|
it.cleanUp()
|
||||||
|
|
||||||
|
var ret error
|
||||||
for _, sub := range it.internalIterators {
|
for _, sub := range it.internalIterators {
|
||||||
sub.Close()
|
if err := sub.Close(); err != nil && ret != nil {
|
||||||
|
ret = err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Or) Optimize() (graph.Iterator, bool) {
|
func (it *Or) Optimize() (graph.Iterator, bool) {
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,8 @@ func (it *Comparison) doComparison(val graph.Value) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Comparison) Close() {
|
func (it *Comparison) Close() error {
|
||||||
it.subIt.Close()
|
return it.subIt.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunIntOp(a int64, op Operator, b int64) bool {
|
func RunIntOp(a int64, op Operator, b int64) bool {
|
||||||
|
|
|
||||||
|
|
@ -145,11 +145,12 @@ func (it *AllIterator) Contains(v graph.Value) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *AllIterator) Close() {
|
func (it *AllIterator) Close() error {
|
||||||
if it.open {
|
if it.open {
|
||||||
it.iter.Release()
|
it.iter.Release()
|
||||||
it.open = false
|
it.open = false
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *AllIterator) Size() (int64, bool) {
|
func (it *AllIterator) Size() (int64, bool) {
|
||||||
|
|
|
||||||
|
|
@ -109,11 +109,12 @@ func (it *Iterator) Clone() graph.Iterator {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Close() {
|
func (it *Iterator) Close() error {
|
||||||
if it.open {
|
if it.open {
|
||||||
it.iter.Release()
|
it.iter.Release()
|
||||||
it.open = false
|
it.open = false
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) isLiveValue(val []byte) bool {
|
func (it *Iterator) isLiveValue(val []byte) bool {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,9 @@ func (it *Iterator) Clone() graph.Iterator {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Close() {}
|
func (it *Iterator) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (it *Iterator) checkValid(index int64) bool {
|
func (it *Iterator) checkValid(index int64) bool {
|
||||||
return it.qs.log[index].DeletedBy == 0
|
return it.qs.log[index].DeletedBy == 0
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ func (it *Iterator) Reset() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Close() {
|
func (it *Iterator) Close() error {
|
||||||
it.iter.Close()
|
return it.iter.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *Iterator) Tagger() *graph.Tagger {
|
func (it *Iterator) Tagger() *graph.Tagger {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue