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
cc91da6f
Commit
cc91da6f
authored
May 05, 2016
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make blocks.Block an interface.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
0b8ac0fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
13 deletions
+13
-13
blockstore.go
blockstore.go
+8
-8
blockstore_test.go
blockstore_test.go
+1
-1
write_cache.go
write_cache.go
+4
-4
No files found.
blockstore.go
View file @
cc91da6f
...
...
@@ -30,9 +30,9 @@ var ErrNotFound = errors.New("blockstore: block not found")
type
Blockstore
interface
{
DeleteBlock
(
key
.
Key
)
error
Has
(
key
.
Key
)
(
bool
,
error
)
Get
(
key
.
Key
)
(
*
blocks
.
Block
,
error
)
Put
(
*
blocks
.
Block
)
error
PutMany
([]
*
blocks
.
Block
)
error
Get
(
key
.
Key
)
(
blocks
.
Block
,
error
)
Put
(
blocks
.
Block
)
error
PutMany
([]
blocks
.
Block
)
error
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
key
.
Key
,
error
)
}
...
...
@@ -73,7 +73,7 @@ type blockstore struct {
gcreqlk
sync
.
Mutex
}
func
(
bs
*
blockstore
)
Get
(
k
key
.
Key
)
(
*
blocks
.
Block
,
error
)
{
func
(
bs
*
blockstore
)
Get
(
k
key
.
Key
)
(
blocks
.
Block
,
error
)
{
maybeData
,
err
:=
bs
.
datastore
.
Get
(
k
.
DsKey
())
if
err
==
ds
.
ErrNotFound
{
return
nil
,
ErrNotFound
...
...
@@ -89,7 +89,7 @@ func (bs *blockstore) Get(k key.Key) (*blocks.Block, error) {
return
blocks
.
NewBlockWithHash
(
bdata
,
mh
.
Multihash
(
k
))
}
func
(
bs
*
blockstore
)
Put
(
block
*
blocks
.
Block
)
error
{
func
(
bs
*
blockstore
)
Put
(
block
blocks
.
Block
)
error
{
k
:=
block
.
Key
()
.
DsKey
()
// Has is cheaper than Put, so see if we already have it
...
...
@@ -97,10 +97,10 @@ func (bs *blockstore) Put(block *blocks.Block) error {
if
err
==
nil
&&
exists
{
return
nil
// already stored.
}
return
bs
.
datastore
.
Put
(
k
,
block
.
Data
)
return
bs
.
datastore
.
Put
(
k
,
block
.
Data
()
)
}
func
(
bs
*
blockstore
)
PutMany
(
blocks
[]
*
blocks
.
Block
)
error
{
func
(
bs
*
blockstore
)
PutMany
(
blocks
[]
blocks
.
Block
)
error
{
t
,
err
:=
bs
.
datastore
.
Batch
()
if
err
!=
nil
{
return
err
...
...
@@ -112,7 +112,7 @@ func (bs *blockstore) PutMany(blocks []*blocks.Block) error {
continue
}
err
=
t
.
Put
(
k
,
b
.
Data
)
err
=
t
.
Put
(
k
,
b
.
Data
()
)
if
err
!=
nil
{
return
err
}
...
...
blockstore_test.go
View file @
cc91da6f
...
...
@@ -40,7 +40,7 @@ func TestPutThenGetBlock(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
block
.
Data
,
blockFromBlockstore
.
Data
)
{
if
!
bytes
.
Equal
(
block
.
Data
()
,
blockFromBlockstore
.
Data
()
)
{
t
.
Fail
()
}
}
...
...
write_cache.go
View file @
cc91da6f
...
...
@@ -34,11 +34,11 @@ func (w *writecache) Has(k key.Key) (bool, error) {
return
w
.
blockstore
.
Has
(
k
)
}
func
(
w
*
writecache
)
Get
(
k
key
.
Key
)
(
*
blocks
.
Block
,
error
)
{
func
(
w
*
writecache
)
Get
(
k
key
.
Key
)
(
blocks
.
Block
,
error
)
{
return
w
.
blockstore
.
Get
(
k
)
}
func
(
w
*
writecache
)
Put
(
b
*
blocks
.
Block
)
error
{
func
(
w
*
writecache
)
Put
(
b
blocks
.
Block
)
error
{
k
:=
b
.
Key
()
if
_
,
ok
:=
w
.
cache
.
Get
(
k
);
ok
{
return
nil
...
...
@@ -49,8 +49,8 @@ func (w *writecache) Put(b *blocks.Block) error {
return
w
.
blockstore
.
Put
(
b
)
}
func
(
w
*
writecache
)
PutMany
(
bs
[]
*
blocks
.
Block
)
error
{
var
good
[]
*
blocks
.
Block
func
(
w
*
writecache
)
PutMany
(
bs
[]
blocks
.
Block
)
error
{
var
good
[]
blocks
.
Block
for
_
,
b
:=
range
bs
{
if
_
,
ok
:=
w
.
cache
.
Get
(
b
.
Key
());
!
ok
{
good
=
append
(
good
,
b
)
...
...
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