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-ds-leveldb
Commits
882341c7
Commit
882341c7
authored
Jan 09, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
query: send back errors when channels somehow
this is not a good inteface. should fix it
parent
a706e049
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
27 deletions
+36
-27
datastore.go
datastore.go
+36
-27
No files found.
datastore.go
View file @
882341c7
...
@@ -79,44 +79,53 @@ func (d *datastore) Query(q dsq.Query) (*dsq.Results, error) {
...
@@ -79,44 +79,53 @@ func (d *datastore) Query(q dsq.Query) (*dsq.Results, error) {
}
}
i
:=
d
.
DB
.
NewIterator
(
rnge
,
nil
)
i
:=
d
.
DB
.
NewIterator
(
rnge
,
nil
)
// offset
// buffer this channel so that we dont totally block leveldb if client
if
q
.
Offset
>
0
{
// is not reading from chan.
for
j
:=
0
;
j
<
q
.
Offset
;
j
++
{
ch
:=
make
(
chan
dsq
.
Entry
,
1000
)
i
.
Next
()
qr
:=
dsq
.
ResultsWithEntriesChan
(
q
,
ch
)
// qr := dsq.ResultsWithEntries(q, es)
go
func
()
{
defer
close
(
ch
)
// offset
if
q
.
Offset
>
0
{
for
j
:=
0
;
j
<
q
.
Offset
;
j
++
{
i
.
Next
()
}
}
}
}
var
es
[]
dsq
.
Entry
sent
:=
0
for
i
.
Next
()
{
for
i
.
Next
()
{
// limit
// limit
if
q
.
Limit
>
0
&&
l
en
(
es
)
>=
q
.
Limit
{
if
q
.
Limit
>
0
&&
s
en
t
>=
q
.
Limit
{
break
break
}
}
k
:=
ds
.
NewKey
(
string
(
i
.
Key
()))
.
String
()
k
:=
ds
.
NewKey
(
string
(
i
.
Key
()))
.
String
()
e
:=
dsq
.
Entry
{
Key
:
k
}
e
:=
dsq
.
Entry
{
Key
:
k
}
if
!
q
.
KeysOnly
{
if
!
q
.
KeysOnly
{
buf
:=
make
([]
byte
,
len
(
i
.
Value
()))
buf
:=
make
([]
byte
,
len
(
i
.
Value
()))
copy
(
buf
,
i
.
Value
())
copy
(
buf
,
i
.
Value
())
e
.
Value
=
buf
e
.
Value
=
buf
}
}
es
=
append
(
es
,
e
)
ch
<-
e
}
sent
++
i
.
Release
()
}
if
err
:=
i
.
Error
();
err
!=
nil
{
i
.
Release
()
return
nil
,
err
if
err
:=
i
.
Error
();
err
!=
nil
{
}
qr
.
Err
()
<-
err
}
}()
// Now, apply remaining pieces.
// Now, apply remaining pieces.
q2
:=
q
q2
:=
q
q2
.
Offset
=
0
// already applied
q2
.
Offset
=
0
// already applied
q2
.
Limit
=
0
// already applied
q2
.
Limit
=
0
// already applied
// TODO: make this async with:
// qr := dsq.ResultsWithEntriesChan(q, ch)
qr
:=
dsq
.
ResultsWithEntries
(
q
,
es
)
qr
=
q2
.
ApplyTo
(
qr
)
qr
=
q2
.
ApplyTo
(
qr
)
qr
.
Query
=
q
// set it back
qr
.
Query
=
q
// set it back
return
qr
,
nil
return
qr
,
nil
...
...
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