Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
4028e890
提交
4028e890
authored
2月 12, 2017
作者:
Jeromy Johnson
提交者:
GitHub
2月 12, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3640 from ipfs/fix/pinset-obj-explosion
Make pinset sharding deterministic
上级
ac2d7a00
728ff6dd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
55 行增加
和
33 行删除
+55
-33
set.go
pin/set.go
+5
-18
set_test.go
pin/set_test.go
+50
-15
没有找到文件。
pin/set.go
浏览文件 @
4028e890
...
...
@@ -3,7 +3,6 @@ package pin
import
(
"bytes"
"context"
"crypto/rand"
"encoding/binary"
"errors"
"fmt"
...
...
@@ -26,14 +25,6 @@ const (
maxItems
=
8192
)
func
randomSeed
()
(
uint32
,
error
)
{
var
buf
[
4
]
byte
if
_
,
err
:=
rand
.
Read
(
buf
[
:
]);
err
!=
nil
{
return
0
,
err
}
return
binary
.
LittleEndian
.
Uint32
(
buf
[
:
]),
nil
}
func
hash
(
seed
uint32
,
c
*
cid
.
Cid
)
uint32
{
var
buf
[
4
]
byte
binary
.
LittleEndian
.
PutUint32
(
buf
[
:
],
seed
)
...
...
@@ -63,11 +54,7 @@ func (s sortByHash) Swap(a, b int) {
s
.
links
[
a
],
s
.
links
[
b
]
=
s
.
links
[
b
],
s
.
links
[
a
]
}
func
storeItems
(
ctx
context
.
Context
,
dag
merkledag
.
DAGService
,
estimatedLen
uint64
,
iter
itemIterator
,
internalKeys
keyObserver
)
(
*
merkledag
.
ProtoNode
,
error
)
{
seed
,
err
:=
randomSeed
()
if
err
!=
nil
{
return
nil
,
err
}
func
storeItems
(
ctx
context
.
Context
,
dag
merkledag
.
DAGService
,
estimatedLen
uint64
,
depth
uint32
,
iter
itemIterator
,
internalKeys
keyObserver
)
(
*
merkledag
.
ProtoNode
,
error
)
{
links
:=
make
([]
*
node
.
Link
,
0
,
defaultFanout
+
maxItems
)
for
i
:=
0
;
i
<
defaultFanout
;
i
++
{
links
=
append
(
links
,
&
node
.
Link
{
Cid
:
emptyKey
})
...
...
@@ -82,7 +69,7 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
hdr
:=
&
pb
.
Set
{
Version
:
proto
.
Uint32
(
1
),
Fanout
:
proto
.
Uint32
(
defaultFanout
),
Seed
:
proto
.
Uint32
(
seed
),
Seed
:
proto
.
Uint32
(
depth
),
}
if
err
:=
writeHdr
(
n
,
hdr
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -129,7 +116,7 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
if
!
ok
{
break
}
h
:=
hash
(
seed
,
k
)
%
defaultFanout
h
:=
hash
(
depth
,
k
)
%
defaultFanout
hashed
[
h
]
=
append
(
hashed
[
h
],
k
)
}
...
...
@@ -142,7 +129,7 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
childIter
:=
getCidListIterator
(
items
)
// recursively create a pinset from the items for this bucket index
child
,
err
:=
storeItems
(
ctx
,
dag
,
uint64
(
len
(
items
)),
childIter
,
internalKeys
)
child
,
err
:=
storeItems
(
ctx
,
dag
,
uint64
(
len
(
items
)),
depth
+
1
,
childIter
,
internalKeys
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -296,7 +283,7 @@ func getCidListIterator(cids []*cid.Cid) itemIterator {
func
storeSet
(
ctx
context
.
Context
,
dag
merkledag
.
DAGService
,
cids
[]
*
cid
.
Cid
,
internalKeys
keyObserver
)
(
*
merkledag
.
ProtoNode
,
error
)
{
iter
:=
getCidListIterator
(
cids
)
n
,
err
:=
storeItems
(
ctx
,
dag
,
uint64
(
len
(
cids
)),
iter
,
internalKeys
)
n
,
err
:=
storeItems
(
ctx
,
dag
,
uint64
(
len
(
cids
)),
0
,
iter
,
internalKeys
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pin/set_test.go
浏览文件 @
4028e890
...
...
@@ -2,40 +2,75 @@ package pin
import
(
"context"
"fmt"
"os"
"encoding/binary"
"testing"
blockstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
bserv
"github.com/ipfs/go-ipfs/blockservice"
offline
"github.com/ipfs/go-ipfs/exchange/offline"
dag
"github.com/ipfs/go-ipfs/merkledag"
mdtest
"github.com/ipfs/go-ipfs/merkledag/test"
ds
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
dsq
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/query"
cid
"gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
)
func
ignoreCids
(
_
*
cid
.
Cid
)
{}
func
TestSet
(
t
*
testing
.
T
)
{
ds
:=
mdtest
.
Mock
()
limit
:=
10000
// 10000 reproduces the pinloss issue fairly reliably
if
os
.
Getenv
(
"STRESS_IT_OUT_YO"
)
!=
""
{
limit
=
10000000
func
objCount
(
d
ds
.
Datastore
)
int
{
q
:=
dsq
.
Query
{
KeysOnly
:
true
}
res
,
err
:=
d
.
Query
(
q
)
if
err
!=
nil
{
panic
(
err
)
}
var
inputs
[]
*
cid
.
Cid
for
i
:=
0
;
i
<
limit
;
i
++
{
c
,
err
:=
ds
.
Add
(
dag
.
NodeWithData
([]
byte
(
fmt
.
Sprint
(
i
))))
if
err
!=
nil
{
t
.
Fatal
(
err
)
var
count
int
for
{
_
,
ok
:=
res
.
NextSync
()
if
!
ok
{
break
}
count
++
}
return
count
}
func
TestSet
(
t
*
testing
.
T
)
{
dst
:=
ds
.
NewMapDatastore
()
bstore
:=
blockstore
.
NewBlockstore
(
dst
)
ds
:=
dag
.
NewDAGService
(
bserv
.
New
(
bstore
,
offline
.
Exchange
(
bstore
)))
// this value triggers the creation of a recursive shard.
// If the recursive sharding is done improperly, this will result in
// an infinite recursion and crash (OOM)
limit
:=
uint32
((
defaultFanout
*
maxItems
)
+
1
)
var
inputs
[]
*
cid
.
Cid
buf
:=
make
([]
byte
,
4
)
for
i
:=
uint32
(
0
);
i
<
limit
;
i
++
{
binary
.
BigEndian
.
PutUint32
(
buf
,
i
)
c
:=
dag
.
NewRawNode
(
buf
)
.
Cid
()
inputs
=
append
(
inputs
,
c
)
}
_
,
err
:=
storeSet
(
context
.
Background
(),
ds
,
inputs
[
:
len
(
inputs
)
-
1
],
ignoreCids
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
objs1
:=
objCount
(
dst
)
out
,
err
:=
storeSet
(
context
.
Background
(),
ds
,
inputs
,
ignoreCids
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
objs2
:=
objCount
(
dst
)
if
objs2
-
objs1
>
2
{
t
.
Fatal
(
"set sharding does not appear to be deterministic"
)
}
// weird wrapper node because loadSet expects us to pass an
// object pointing to multiple named sets
setroot
:=
&
dag
.
ProtoNode
{}
...
...
@@ -49,7 +84,7 @@ func TestSet(t *testing.T) {
t
.
Fatal
(
err
)
}
if
len
(
outset
)
!=
limit
{
if
uint32
(
len
(
outset
)
)
!=
limit
{
t
.
Fatal
(
"got wrong number"
,
len
(
outset
),
limit
)
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论