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
707e5498
Commit
707e5498
authored
Mar 22, 2018
by
Whyrusleeping
Committed by
GitHub
Mar 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4649 from ipfs/feat/blockservice-events
blockservice: add BlockedFetched/Added/Removed events
parents
9764858e
3d6da969
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
blockservice.go
blockservice.go
+10
-2
No files found.
blockservice.go
View file @
707e5498
...
...
@@ -146,6 +146,8 @@ func (s *blockService) AddBlock(o blocks.Block) error {
return
err
}
log
.
Event
(
context
.
TODO
(),
"BlockService.BlockAdded"
,
c
)
if
err
:=
s
.
exchange
.
HasBlock
(
o
);
err
!=
nil
{
// TODO(#4623): really an error?
return
errors
.
New
(
"blockservice is closed"
)
...
...
@@ -184,6 +186,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
}
for
_
,
o
:=
range
toput
{
log
.
Event
(
context
.
TODO
(),
"BlockService.BlockAdded"
,
o
.
Cid
())
if
err
:=
s
.
exchange
.
HasBlock
(
o
);
err
!=
nil
{
// TODO(#4623): Should this really *return*?
return
fmt
.
Errorf
(
"blockservice is closed (%s)"
,
err
)
...
...
@@ -227,6 +230,7 @@ func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f excha
}
return
nil
,
err
}
log
.
Event
(
ctx
,
"BlockService.BlockFetched"
,
c
)
return
blk
,
nil
}
...
...
@@ -263,7 +267,6 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
misses
=
append
(
misses
,
c
)
continue
}
log
.
Debug
(
"Blockservice: Got data in datastore"
)
select
{
case
out
<-
hit
:
case
<-
ctx
.
Done
()
:
...
...
@@ -282,6 +285,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
}
for
b
:=
range
rblocks
{
log
.
Event
(
ctx
,
"BlockService.BlockFetched"
,
b
.
Cid
())
select
{
case
out
<-
b
:
case
<-
ctx
.
Done
()
:
...
...
@@ -294,7 +298,11 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
// DeleteBlock deletes a block in the blockservice from the datastore
func
(
s
*
blockService
)
DeleteBlock
(
c
*
cid
.
Cid
)
error
{
return
s
.
blockstore
.
DeleteBlock
(
c
)
err
:=
s
.
blockstore
.
DeleteBlock
(
c
)
if
err
==
nil
{
log
.
Event
(
context
.
TODO
(),
"BlockService.BlockDeleted"
,
c
)
}
return
err
}
func
(
s
*
blockService
)
Close
()
error
{
...
...
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