Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
cb3bda78
提交
cb3bda78
authored
9月 29, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug in pinsets and add a stress test for the scenario
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
189fa76b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
47 行增加
和
85 行删除
+47
-85
set.go
pin/set.go
+1
-1
set_test.go
pin/set_test.go
+46
-84
没有找到文件。
pin/set.go
浏览文件 @
cb3bda78
...
...
@@ -143,7 +143,7 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
if
!
ok
{
break
}
h
:=
hash
(
seed
,
k
)
h
:=
hash
(
seed
,
k
)
%
defaultFanout
hashed
[
h
]
=
append
(
hashed
[
h
],
item
{
k
,
data
})
}
for
h
,
items
:=
range
hashed
{
...
...
pin/set_test.go
浏览文件 @
cb3bda78
package
pin
import
(
"context"
"fmt"
"os"
"testing"
"testing/quick"
"github.com/ipfs/go-ipfs/blocks/blockstore"
"github.com/ipfs/go-ipfs/blocks/key"
"github.com/ipfs/go-ipfs/blockservice"
"github.com/ipfs/go-ipfs/exchange/offline"
"github.com/ipfs/go-ipfs/merkledag"
"gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore"
dssync
"gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/sync"
mh
"gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
u
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
key
"github.com/ipfs/go-ipfs/blocks/key"
dag
"github.com/ipfs/go-ipfs/merkledag"
mdtest
"github.com/ipfs/go-ipfs/merkledag/test"
)
func
ignoreKey
s
(
key
.
Key
)
{}
func
ignoreKey
(
_
key
.
Key
)
{}
func
copyMap
(
m
map
[
key
.
Key
]
uint16
)
map
[
key
.
Key
]
uint64
{
c
:=
make
(
map
[
key
.
Key
]
uint64
,
len
(
m
))
for
k
,
v
:=
range
m
{
c
[
k
]
=
uint64
(
v
)
}
return
c
}
func
TestSet
(
t
*
testing
.
T
)
{
ds
:=
mdtest
.
Mock
()
limit
:=
10000
// 10000 reproduces the pinloss issue fairly reliably
func
TestMultisetRoundtrip
(
t
*
testing
.
T
)
{
dstore
:=
dssync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
bstore
:=
blockstore
.
NewBlockstore
(
dstore
)
bserv
:=
blockservice
.
New
(
bstore
,
offline
.
Exchange
(
bstore
))
dag
:=
merkledag
.
NewDAGService
(
bserv
)
fn
:=
func
(
m
map
[
key
.
Key
]
uint16
)
bool
{
// Convert invalid multihash from input to valid ones
for
k
,
v
:=
range
m
{
if
_
,
err
:=
mh
.
Cast
([]
byte
(
k
));
err
!=
nil
{
delete
(
m
,
k
)
m
[
key
.
Key
(
u
.
Hash
([]
byte
(
k
)))]
=
v
}
if
os
.
Getenv
(
"STRESS_IT_OUT_YO"
)
!=
""
{
limit
=
10000000
}
var
inputs
[]
key
.
Key
for
i
:=
0
;
i
<
limit
;
i
++
{
c
,
err
:=
ds
.
Add
(
dag
.
NodeWithData
([]
byte
(
fmt
.
Sprint
(
i
))))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Generate a smaller range for refcounts than full uint64, as
// otherwise this just becomes overly cpu heavy, splitting it
// out into too many items. That means we need to convert to
// the right kind of map. As storeMultiset mutates the map as
// part of its bookkeeping, this is actually good.
refcounts
:=
copyMap
(
m
)
inputs
=
append
(
inputs
,
c
)
}
ctx
:=
context
.
Background
()
n
,
err
:=
storeMultiset
(
ctx
,
dag
,
refcounts
,
ignoreKeys
)
if
err
!=
nil
{
t
.
Fatalf
(
"storing multiset: %v"
,
err
)
}
out
,
err
:=
storeSet
(
context
.
Background
(),
ds
,
inputs
,
ignoreKey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Check that the node n is in the DAG
k
,
err
:=
n
.
Key
()
if
err
!=
nil
{
t
.
Fatalf
(
"Could not get key: %v"
,
err
)
}
_
,
err
=
dag
.
Get
(
ctx
,
k
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not get node: %v"
,
err
)
}
// weird wrapper node because loadSet expects us to pass an
// object pointing to multiple named sets
setroot
:=
&
dag
.
Node
{}
err
=
setroot
.
AddNodeLinkClean
(
"foo"
,
out
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
root
:=
&
merkledag
.
Node
{}
const
linkName
=
"dummylink"
if
err
:=
root
.
AddNodeLink
(
linkName
,
n
);
err
!=
nil
{
t
.
Fatalf
(
"adding link to root node: %v"
,
err
)
}
outset
,
err
:=
loadSet
(
context
.
Background
(),
ds
,
setroot
,
"foo"
,
ignoreKey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
roundtrip
,
err
:=
loadMultiset
(
ctx
,
dag
,
root
,
linkName
,
ignoreKeys
)
if
err
!=
nil
{
t
.
Fatalf
(
"loading multiset: %v"
,
err
)
}
if
len
(
outset
)
!=
limit
{
t
.
Fatal
(
"got wrong number"
,
len
(
outset
),
limit
)
}
orig
:=
copyMap
(
m
)
success
:=
true
for
k
,
want
:=
range
orig
{
if
got
,
ok
:=
roundtrip
[
k
];
ok
{
if
got
!=
want
{
success
=
false
t
.
Logf
(
"refcount changed: %v -> %v for %q"
,
want
,
got
,
k
)
}
delete
(
orig
,
k
)
delete
(
roundtrip
,
k
)
}
}
for
k
,
v
:=
range
orig
{
success
=
false
t
.
Logf
(
"refcount missing: %v for %q"
,
v
,
k
)
}
for
k
,
v
:=
range
roundtrip
{
success
=
false
t
.
Logf
(
"refcount extra: %v for %q"
,
v
,
k
)
}
return
success
seen
:=
key
.
NewKeySet
()
for
_
,
c
:=
range
outset
{
seen
.
Add
(
c
)
}
if
err
:=
quick
.
Check
(
fn
,
nil
);
err
!=
nil
{
t
.
Fatal
(
err
)
for
_
,
c
:=
range
inputs
{
if
!
seen
.
Has
(
c
)
{
t
.
Fatalf
(
"expected to have %s, didnt find it"
)
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论