Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
238035c2
提交
238035c2
authored
1月 06, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
blockservice: async HasBlock with ratelimit
上级
12fd3555
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
10 行删除
+38
-10
blockservice.go
blockservice/blockservice.go
+33
-9
core.go
epictest/core.go
+5
-1
没有找到文件。
blockservice/blockservice.go
浏览文件 @
238035c2
...
...
@@ -8,6 +8,8 @@ import (
"fmt"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
process
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
procrl
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit"
blocks
"github.com/jbenet/go-ipfs/blocks"
"github.com/jbenet/go-ipfs/blocks/blockstore"
exchange
"github.com/jbenet/go-ipfs/exchange"
...
...
@@ -17,6 +19,9 @@ import (
var
log
=
u
.
Logger
(
"blockservice"
)
var
ErrNotFound
=
errors
.
New
(
"blockservice: key not found"
)
// MaxExchangeAddWorkers rate limits the number of exchange workers
var
MaxExchangeAddWorkers
=
100
// BlockService is a hybrid block datastore. It stores data in a local
// datastore and may retrieve data from a remote Exchange.
// It uses an internal `datastore.Datastore` instance to store values.
...
...
@@ -24,6 +29,9 @@ type BlockService struct {
// TODO don't expose underlying impl details
Blockstore
blockstore
.
Blockstore
Exchange
exchange
.
Interface
rateLimiter
*
procrl
.
RateLimiter
exchangeAdd
chan
blocks
.
Block
}
// NewBlockService creates a BlockService with given datastore instance.
...
...
@@ -34,7 +42,17 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) (*BlockService, error
if
rem
==
nil
{
log
.
Warning
(
"blockservice running in local (offline) mode."
)
}
return
&
BlockService
{
Blockstore
:
bs
,
Exchange
:
rem
},
nil
// exchangeAdd is a channel for async workers to add to the exchange.
// 100 blocks buffer. not clear what this number should be
exchangeAdd
:=
make
(
chan
blocks
.
Block
,
100
)
return
&
BlockService
{
Blockstore
:
bs
,
Exchange
:
rem
,
exchangeAdd
:
exchangeAdd
,
rateLimiter
:
procrl
.
NewRateLimiter
(
process
.
Background
(),
MaxExchangeAddWorkers
),
},
nil
}
// AddBlock adds a particular block to the service, Putting it into the datastore.
...
...
@@ -46,15 +64,21 @@ func (s *BlockService) AddBlock(b *blocks.Block) (u.Key, error) {
return
k
,
err
}
//
TODO this operation rate-limits blockservice operations, we should
//
consider moving this to an
sync process.
//
this operation rate-limits blockservice operations, so it is
//
now an a
sync process.
if
s
.
Exchange
!=
nil
{
ctx
:=
context
.
TODO
()
if
err
:=
s
.
Exchange
.
HasBlock
(
ctx
,
b
);
err
!=
nil
{
// suppress error, as the client shouldn't care about bitswap.
// the client only cares about the blockstore.Put.
log
.
Errorf
(
"Exchange.HasBlock error: %s"
,
err
)
}
// LimitedGo will spawn a goroutine but provide proper backpressure.
// it will not spawn the goroutine until the ratelimiter's work load
// is under the threshold.
s
.
rateLimiter
.
LimitedGo
(
func
(
worker
process
.
Process
)
{
ctx
:=
context
.
TODO
()
if
err
:=
s
.
Exchange
.
HasBlock
(
ctx
,
b
);
err
!=
nil
{
// suppress error, as the client shouldn't care about bitswap.
// the client only cares about the blockstore.Put.
log
.
Errorf
(
"Exchange.HasBlock error: %s"
,
err
)
}
})
}
return
k
,
nil
}
...
...
epictest/core.go
浏览文件 @
238035c2
...
...
@@ -74,7 +74,11 @@ func makeCore(ctx context.Context, rf RepoFactory) (*core, error) {
return
nil
,
err
}
bss
:=
&
blockservice
.
BlockService
{
repo
.
Blockstore
(),
repo
.
Exchange
()}
bss
,
err
:=
blockservice
.
New
(
repo
.
Blockstore
(),
repo
.
Exchange
())
if
err
!=
nil
{
return
nil
,
err
}
dag
:=
merkledag
.
NewDAGService
(
bss
)
// to make sure nothing is omitted, init each individual field and assign
// all at once at the bottom.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论