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-blockservice
Commits
75d10001
Commit
75d10001
authored
Nov 23, 2014
by
Brian Tiger Chow
Committed by
Jeromy
Dec 05, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(blockservice) respect context in GetBlocks
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
10090dc7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
blockservice.go
blockservice.go
+17
-9
No files found.
blockservice.go
View file @
75d10001
...
@@ -99,29 +99,37 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
...
@@ -99,29 +99,37 @@ func (s *BlockService) GetBlock(ctx context.Context, k u.Key) (*blocks.Block, er
// the returned channel.
// the returned channel.
// NB: No guarantees are made about order.
// NB: No guarantees are made about order.
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
<-
chan
*
blocks
.
Block
{
func
(
s
*
BlockService
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
u
.
Key
)
<-
chan
*
blocks
.
Block
{
out
:=
make
(
chan
*
blocks
.
Block
,
32
)
out
:=
make
(
chan
*
blocks
.
Block
,
0
)
go
func
()
{
go
func
()
{
var
toFetch
[]
u
.
Key
defer
close
(
out
)
var
misses
[]
u
.
Key
for
_
,
k
:=
range
ks
{
for
_
,
k
:=
range
ks
{
block
,
err
:=
s
.
Blockstore
.
Get
(
k
)
hit
,
err
:=
s
.
Blockstore
.
Get
(
k
)
if
err
!=
nil
{
if
err
!=
nil
{
toFetch
=
append
(
toFetch
,
k
)
misses
=
append
(
misses
,
k
)
continue
continue
}
}
log
.
Debug
(
"Blockservice: Got data in datastore."
)
log
.
Debug
(
"Blockservice: Got data in datastore."
)
out
<-
block
select
{
case
out
<-
hit
:
case
<-
ctx
.
Done
()
:
return
}
}
}
n
blocks
,
err
:=
s
.
Remote
.
GetBlocks
(
ctx
,
toFetch
)
r
blocks
,
err
:=
s
.
Remote
.
GetBlocks
(
ctx
,
misses
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Error with GetBlocks: %s"
,
err
)
log
.
Errorf
(
"Error with GetBlocks: %s"
,
err
)
return
return
}
}
for
blk
:=
range
nblocks
{
for
b
:=
range
rblocks
{
out
<-
blk
select
{
case
out
<-
b
:
case
<-
ctx
.
Done
()
:
return
}
}
}
close
(
out
)
}()
}()
return
out
return
out
}
}
...
...
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