Commit b5f64d84 authored by Łukasz Magiera's avatar Łukasz Magiera

Fix use of close in mount.Query

parent a1d868ee
...@@ -126,9 +126,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -126,9 +126,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
// current itorator state // current itorator state
var res query.Results var res query.Results
var ds datastore.Datastore
var mount datastore.Key var mount datastore.Key
var rest datastore.Key
i := 0 i := 0
return query.ResultsFromIterator(q, query.Iterator{ return query.ResultsFromIterator(q, query.Iterator{
...@@ -137,19 +135,19 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -137,19 +135,19 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
var more bool var more bool
for try := true; try; try = len(dses) > i { for try := true; try; try = len(dses) > i {
if ds == nil { if res == nil {
if len(dses) <= i { if len(dses) <= i {
//This should not happen normally //This should not happen normally
return query.Result{}, false return query.Result{}, false
} }
ds = dses[i] dst := dses[i]
mount = mounts[i] mount = mounts[i]
rest = rests[i] rest := rests[i]
q2 := q q2 := q
q2.Prefix = rest.String() q2.Prefix = rest.String()
r, err := ds.Query(q2) r, err := dst.Query(q2)
if err != nil { if err != nil {
return query.Result{Error: err}, false return query.Result{Error: err}, false
} }
...@@ -158,7 +156,12 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -158,7 +156,12 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
r, more = res.NextSync() r, more = res.NextSync()
if !more { if !more {
ds = nil err := res.Close()
if err != nil {
return query.Result{Error: err}, false
}
res = nil
i++ i++
more = len(dses) > i more = len(dses) > i
} else { } else {
...@@ -170,7 +173,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -170,7 +173,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
return r, more return r, more
}, },
Close: func() error { Close: func() error {
if len(mounts) > i { if len(mounts) > i && res != nil {
return res.Close() return res.Close()
} }
return nil return nil
......
...@@ -238,6 +238,11 @@ func TestQuerySimple(t *testing.T) { ...@@ -238,6 +238,11 @@ func TestQuerySimple(t *testing.T) {
if !seen { if !seen {
t.Errorf("did not see wanted key %q in %+v", myKey, entries) t.Errorf("did not see wanted key %q in %+v", myKey, entries)
} }
err = res.Close()
if err != nil {
t.Errorf("result.Close failed %d", err)
}
} }
func TestQueryCross(t *testing.T) { func TestQueryCross(t *testing.T) {
...@@ -292,6 +297,11 @@ func TestQueryCross(t *testing.T) { ...@@ -292,6 +297,11 @@ func TestQueryCross(t *testing.T) {
if seen != 4 { if seen != 4 {
t.Errorf("expected to see 3 values, saw %d", seen) t.Errorf("expected to see 3 values, saw %d", seen)
} }
err = res.Close()
if err != nil {
t.Errorf("result.Close failed %d", err)
}
} }
func TestLookupPrio(t *testing.T) { func TestLookupPrio(t *testing.T) {
......
...@@ -133,9 +133,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -133,9 +133,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
// current itorator state // current itorator state
var res query.Results var res query.Results
var dst ds.Datastore
var mount ds.Key var mount ds.Key
var rest ds.Key
i := 0 i := 0
return query.ResultsFromIterator(q, query.Iterator{ return query.ResultsFromIterator(q, query.Iterator{
...@@ -144,15 +142,15 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -144,15 +142,15 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
var more bool var more bool
for try := true; try; try = len(dses) > i { for try := true; try; try = len(dses) > i {
if dst == nil { if res == nil {
if len(dses) <= i { if len(dses) <= i {
//This should not happen normally //This should not happen normally
return query.Result{}, false return query.Result{}, false
} }
dst = dses[i] dst := dses[i]
mount = mounts[i] mount = mounts[i]
rest = rests[i] rest := rests[i]
q2 := q q2 := q
q2.Prefix = rest.String() q2.Prefix = rest.String()
...@@ -165,7 +163,12 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -165,7 +163,12 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
r, more = res.NextSync() r, more = res.NextSync()
if !more { if !more {
dst = nil err := res.Close()
if err != nil {
return query.Result{Error: err}, false
}
res = nil
i++ i++
more = len(dses) > i more = len(dses) > i
} else { } else {
...@@ -177,7 +180,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) { ...@@ -177,7 +180,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
return r, more return r, more
}, },
Close: func() error { Close: func() error {
if len(mounts) > i { if len(mounts) > i && res != nil {
return res.Close() return res.Close()
} }
return nil return nil
......
...@@ -238,6 +238,11 @@ func TestQuerySimple(t *testing.T) { ...@@ -238,6 +238,11 @@ func TestQuerySimple(t *testing.T) {
if !seen { if !seen {
t.Errorf("did not see wanted key %q in %+v", myKey, entries) t.Errorf("did not see wanted key %q in %+v", myKey, entries)
} }
err = res.Close()
if err != nil {
t.Errorf("result.Close failed %d", err)
}
} }
func TestQueryCross(t *testing.T) { func TestQueryCross(t *testing.T) {
...@@ -292,6 +297,11 @@ func TestQueryCross(t *testing.T) { ...@@ -292,6 +297,11 @@ func TestQueryCross(t *testing.T) {
if seen != 4 { if seen != 4 {
t.Errorf("expected to see 3 values, saw %d", seen) t.Errorf("expected to see 3 values, saw %d", seen)
} }
err = res.Close()
if err != nil {
t.Errorf("result.Close failed %d", err)
}
} }
func TestLookupPrio(t *testing.T) { func TestLookupPrio(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment