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-blockstore
Commits
8f266cac
Commit
8f266cac
authored
Jan 07, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: switch to raw multihashes for blocks
Part of:
https://github.com/ipfs/go-ipfs/issues/6815
parent
5f9214c8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
14 deletions
+33
-14
arc_cache.go
arc_cache.go
+3
-3
blockstore_test.go
blockstore_test.go
+26
-7
bloom_cache.go
bloom_cache.go
+4
-4
No files found.
arc_cache.go
View file @
8f266cac
...
...
@@ -59,7 +59,7 @@ func (b *arccache) hasCached(k cid.Cid) (has bool, size int, ok bool) {
return
false
,
-
1
,
false
}
h
,
ok
:=
b
.
arc
.
Get
(
k
.
KeyString
(
))
h
,
ok
:=
b
.
arc
.
Get
(
string
(
k
.
Hash
()
))
if
ok
{
b
.
hits
.
Inc
()
switch
h
:=
h
.
(
type
)
{
...
...
@@ -160,11 +160,11 @@ func (b *arccache) HashOnRead(enabled bool) {
}
func
(
b
*
arccache
)
cacheHave
(
c
cid
.
Cid
,
have
bool
)
{
b
.
arc
.
Add
(
c
.
KeyString
(
),
cacheHave
(
have
))
b
.
arc
.
Add
(
string
(
c
.
Hash
()
),
cacheHave
(
have
))
}
func
(
b
*
arccache
)
cacheSize
(
c
cid
.
Cid
,
blockSize
int
)
{
b
.
arc
.
Add
(
c
.
KeyString
(
),
cacheSize
(
blockSize
))
b
.
arc
.
Add
(
string
(
c
.
Hash
()
),
cacheSize
(
blockSize
))
}
func
(
b
*
arccache
)
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
cid
.
Cid
,
error
)
{
...
...
blockstore_test.go
View file @
8f266cac
...
...
@@ -53,6 +53,24 @@ func TestPutThenGetBlock(t *testing.T) {
}
}
func
TestCidv0v1
(
t
*
testing
.
T
)
{
bs
:=
NewBlockstore
(
ds_sync
.
MutexWrap
(
ds
.
NewMapDatastore
()))
block
:=
blocks
.
NewBlock
([]
byte
(
"some data"
))
err
:=
bs
.
Put
(
block
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
blockFromBlockstore
,
err
:=
bs
.
Get
(
cid
.
NewCidV1
(
cid
.
DagProtobuf
,
block
.
Cid
()
.
Hash
()))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
block
.
RawData
(),
blockFromBlockstore
.
RawData
())
{
t
.
Fail
()
}
}
func
TestPutThenGetSizeBlock
(
t
*
testing
.
T
)
{
bs
:=
NewBlockstore
(
ds_sync
.
MutexWrap
(
ds
.
NewMapDatastore
()))
block
:=
blocks
.
NewBlock
([]
byte
(
"some data"
))
...
...
@@ -218,18 +236,19 @@ func TestAllKeysRespectsContext(t *testing.T) {
}
func
expectMatches
(
t
*
testing
.
T
,
expect
,
actual
[]
cid
.
Cid
)
{
t
.
Helper
()
if
len
(
expect
)
!=
len
(
actual
)
{
t
.
Errorf
(
"expect and actual differ: %d != %d"
,
len
(
expect
),
len
(
actual
))
}
for
_
,
ek
:=
range
expect
{
found
:=
false
for
_
,
ak
:=
range
actual
{
if
ek
.
Equals
(
ak
)
{
found
=
true
}
actualSet
:=
make
(
map
[
string
]
bool
,
len
(
actual
))
for
_
,
k
:=
range
actual
{
actualSet
[
string
(
k
.
Hash
())]
=
true
}
if
!
found
{
for
_
,
ek
:=
range
expect
{
if
!
actualSet
[
string
(
ek
.
Hash
())]
{
t
.
Error
(
"expected key not found: "
,
ek
)
}
}
...
...
bloom_cache.go
View file @
8f266cac
...
...
@@ -103,7 +103,7 @@ func (b *bloomcache) build(ctx context.Context) error {
atomic
.
StoreInt32
(
&
b
.
active
,
1
)
return
nil
}
b
.
bloom
.
AddTS
(
key
.
Bytes
())
// Use binary key, the more compact the better
b
.
bloom
.
AddTS
(
key
.
Hash
())
// Use binary key, the more compact the better
case
<-
ctx
.
Done
()
:
b
.
buildErr
=
ctx
.
Err
()
return
b
.
buildErr
...
...
@@ -130,7 +130,7 @@ func (b *bloomcache) hasCached(k cid.Cid) (has bool, ok bool) {
return
false
,
false
}
if
b
.
BloomActive
()
{
blr
:=
b
.
bloom
.
HasTS
(
k
.
Bytes
())
blr
:=
b
.
bloom
.
HasTS
(
k
.
Hash
())
if
!
blr
{
// not contained in bloom is only conclusive answer bloom gives
b
.
hits
.
Inc
()
return
false
,
true
...
...
@@ -163,7 +163,7 @@ func (b *bloomcache) Put(bl blocks.Block) error {
// See comment in PutMany
err
:=
b
.
blockstore
.
Put
(
bl
)
if
err
==
nil
{
b
.
bloom
.
AddTS
(
bl
.
Cid
()
.
Bytes
())
b
.
bloom
.
AddTS
(
bl
.
Cid
()
.
Hash
())
}
return
err
}
...
...
@@ -178,7 +178,7 @@ func (b *bloomcache) PutMany(bs []blocks.Block) error {
return
err
}
for
_
,
bl
:=
range
bs
{
b
.
bloom
.
AddTS
(
bl
.
Cid
()
.
Bytes
())
b
.
bloom
.
AddTS
(
bl
.
Cid
()
.
Hash
())
}
return
nil
}
...
...
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