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
5e786b5d
Commit
5e786b5d
authored
Dec 09, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(arc): return the correct size when only "has" is cached
parent
87bfe426
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
arc_cache.go
arc_cache.go
+7
-2
arc_cache_test.go
arc_cache_test.go
+20
-1
No files found.
arc_cache.go
View file @
5e786b5d
...
@@ -86,10 +86,15 @@ func (b *arccache) Has(k cid.Cid) (bool, error) {
...
@@ -86,10 +86,15 @@ func (b *arccache) Has(k cid.Cid) (bool, error) {
func
(
b
*
arccache
)
GetSize
(
k
cid
.
Cid
)
(
int
,
error
)
{
func
(
b
*
arccache
)
GetSize
(
k
cid
.
Cid
)
(
int
,
error
)
{
if
has
,
blockSize
,
ok
:=
b
.
hasCached
(
k
);
ok
{
if
has
,
blockSize
,
ok
:=
b
.
hasCached
(
k
);
ok
{
if
has
{
if
!
has
{
// don't have it, return
return
-
1
,
ErrNotFound
}
if
blockSize
>=
0
{
// have it and we know the size
return
blockSize
,
nil
return
blockSize
,
nil
}
}
return
-
1
,
ErrNotFound
// we have it but don't know the size, ask the datastore.
}
}
blockSize
,
err
:=
b
.
blockstore
.
GetSize
(
k
)
blockSize
,
err
:=
b
.
blockstore
.
GetSize
(
k
)
if
err
==
ErrNotFound
{
if
err
==
ErrNotFound
{
...
...
arc_cache_test.go
View file @
5e786b5d
...
@@ -123,7 +123,7 @@ func TestGetFillsCache(t *testing.T) {
...
@@ -123,7 +123,7 @@ func TestGetFillsCache(t *testing.T) {
t
.
Fatal
(
"has returned invalid result"
)
t
.
Fatal
(
"has returned invalid result"
)
}
}
if
blockSize
,
err
:=
arc
.
GetSize
(
exampleBlock
.
Cid
());
blockSize
==
-
1
||
err
!=
nil
{
if
blockSize
,
err
:=
arc
.
GetSize
(
exampleBlock
.
Cid
());
blockSize
==
-
1
||
err
!=
nil
{
t
.
Fatal
(
"getsize returned invalid result"
)
t
.
Fatal
(
"getsize returned invalid result"
,
blockSize
,
err
)
}
}
}
}
...
@@ -185,6 +185,25 @@ func TestGetSizeAfterSucessfulGetIsCached(t *testing.T) {
...
@@ -185,6 +185,25 @@ func TestGetSizeAfterSucessfulGetIsCached(t *testing.T) {
arc
.
GetSize
(
exampleBlock
.
Cid
())
arc
.
GetSize
(
exampleBlock
.
Cid
())
}
}
func
TestGetSizeAfterSucessfulHas
(
t
*
testing
.
T
)
{
arc
,
bs
,
_
:=
createStores
(
t
)
bs
.
Put
(
exampleBlock
)
has
,
err
:=
arc
.
Has
(
exampleBlock
.
Cid
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
has
{
t
.
Fatal
(
"expected to have block"
)
}
if
size
,
err
:=
arc
.
GetSize
(
exampleBlock
.
Cid
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
else
if
size
!=
len
(
exampleBlock
.
RawData
())
{
t
.
Fatalf
(
"expected size %d, got %d"
,
len
(
exampleBlock
.
RawData
()),
size
)
}
}
func
TestGetSizeMissingZeroSizeBlock
(
t
*
testing
.
T
)
{
func
TestGetSizeMissingZeroSizeBlock
(
t
*
testing
.
T
)
{
arc
,
bs
,
cd
:=
createStores
(
t
)
arc
,
bs
,
cd
:=
createStores
(
t
)
emptyBlock
:=
blocks
.
NewBlock
([]
byte
{})
emptyBlock
:=
blocks
.
NewBlock
([]
byte
{})
...
...
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