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-dms3-pinner
Commits
8298dcca
Commit
8298dcca
authored
8 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug in pinsets and add a stress test for the scenario
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
e5e18a5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
8 deletions
+61
-8
set.go
set.go
+1
-1
set_test.go
set_test.go
+60
-7
No files found.
set.go
View file @
8298dcca
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
set_test.go
View file @
8298dcca
package
pin
import
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
import
(
"context"
"fmt"
"os"
"testing"
func
ignoreKeys
(
key
.
Key
)
{}
dag
"github.com/ipfs/go-ipfs/merkledag"
mdtest
"github.com/ipfs/go-ipfs/merkledag/test"
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
)
cid
"gx/ipfs/QmakyCk6Vnn16WEKjbkxieZmM2YLTzkFWizbmGowoYPjro/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
}
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
)
}
inputs
=
append
(
inputs
,
c
)
}
out
,
err
:=
storeSet
(
context
.
Background
(),
ds
,
inputs
,
ignoreCids
)
if
err
!=
nil
{
t
.
Fatal
(
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
)
}
outset
,
err
:=
loadSet
(
context
.
Background
(),
ds
,
setroot
,
"foo"
,
ignoreCids
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
outset
)
!=
limit
{
t
.
Fatal
(
"got wrong number"
,
len
(
outset
),
limit
)
}
seen
:=
cid
.
NewSet
()
for
_
,
c
:=
range
outset
{
seen
.
Add
(
c
)
}
for
_
,
c
:=
range
inputs
{
if
!
seen
.
Has
(
c
)
{
t
.
Fatalf
(
"expected to have %s, didnt find it"
)
}
}
return
c
}
This diff is collapsed.
Click to expand it.
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