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) {
// current itorator state
var res query.Results
var ds datastore.Datastore
var mount datastore.Key
var rest datastore.Key
i := 0
return query.ResultsFromIterator(q, query.Iterator{
......@@ -137,19 +135,19 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
var more bool
for try := true; try; try = len(dses) > i {
if ds == nil {
if res == nil {
if len(dses) <= i {
//This should not happen normally
return query.Result{}, false
}
ds = dses[i]
dst := dses[i]
mount = mounts[i]
rest = rests[i]
rest := rests[i]
q2 := q
q2.Prefix = rest.String()
r, err := ds.Query(q2)
r, err := dst.Query(q2)
if err != nil {
return query.Result{Error: err}, false
}
......@@ -158,7 +156,12 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
r, more = res.NextSync()
if !more {
ds = nil
err := res.Close()
if err != nil {
return query.Result{Error: err}, false
}
res = nil
i++
more = len(dses) > i
} else {
......@@ -170,7 +173,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
return r, more
},
Close: func() error {
if len(mounts) > i {
if len(mounts) > i && res != nil {
return res.Close()
}
return nil
......
......@@ -238,6 +238,11 @@ func TestQuerySimple(t *testing.T) {
if !seen {
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) {
......@@ -292,6 +297,11 @@ func TestQueryCross(t *testing.T) {
if seen != 4 {
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) {
......
......@@ -133,9 +133,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
// current itorator state
var res query.Results
var dst ds.Datastore
var mount ds.Key
var rest ds.Key
i := 0
return query.ResultsFromIterator(q, query.Iterator{
......@@ -144,15 +142,15 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
var more bool
for try := true; try; try = len(dses) > i {
if dst == nil {
if res == nil {
if len(dses) <= i {
//This should not happen normally
return query.Result{}, false
}
dst = dses[i]
dst := dses[i]
mount = mounts[i]
rest = rests[i]
rest := rests[i]
q2 := q
q2.Prefix = rest.String()
......@@ -165,7 +163,12 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
r, more = res.NextSync()
if !more {
dst = nil
err := res.Close()
if err != nil {
return query.Result{Error: err}, false
}
res = nil
i++
more = len(dses) > i
} else {
......@@ -177,7 +180,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
return r, more
},
Close: func() error {
if len(mounts) > i {
if len(mounts) > i && res != nil {
return res.Close()
}
return nil
......
......@@ -238,6 +238,11 @@ func TestQuerySimple(t *testing.T) {
if !seen {
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) {
......@@ -292,6 +297,11 @@ func TestQueryCross(t *testing.T) {
if seen != 4 {
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) {
......
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