Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-datastore
Commits
b5f64d84
Commit
b5f64d84
authored
Jul 03, 2017
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use of close in mount.Query
parent
a1d868ee
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
15 deletions
+41
-15
mount/mount.go
mount/mount.go
+11
-8
mount/mount_test.go
mount/mount_test.go
+10
-0
syncmount/mount.go
syncmount/mount.go
+10
-7
syncmount/mount_test.go
syncmount/mount_test.go
+10
-0
No files found.
mount/mount.go
View file @
b5f64d84
...
...
@@ -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
d
s
==
nil
{
if
re
s
==
nil
{
if
len
(
dses
)
<=
i
{
//This should not happen normally
return
query
.
Result
{},
false
}
ds
=
dses
[
i
]
ds
t
:
=
dses
[
i
]
mount
=
mounts
[
i
]
rest
=
rests
[
i
]
rest
:
=
rests
[
i
]
q2
:=
q
q2
.
Prefix
=
rest
.
String
()
r
,
err
:=
ds
.
Query
(
q2
)
r
,
err
:=
ds
t
.
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
...
...
mount/mount_test.go
View file @
b5f64d84
...
...
@@ -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
)
{
...
...
syncmount/mount.go
View file @
b5f64d84
...
...
@@ -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
...
...
syncmount/mount_test.go
View file @
b5f64d84
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment