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
7e356be6
Commit
7e356be6
authored
Jun 26, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use batching transaction interface from datastore
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
67f1e932
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
1 deletion
+40
-1
blockstore.go
blockstore.go
+22
-1
blockstore_test.go
blockstore_test.go
+4
-0
write_cache.go
write_cache.go
+10
-0
write_cache_test.go
write_cache_test.go
+4
-0
No files found.
blockstore.go
View file @
7e356be6
...
...
@@ -30,6 +30,7 @@ type Blockstore interface {
Has
(
key
.
Key
)
(
bool
,
error
)
Get
(
key
.
Key
)
(
*
blocks
.
Block
,
error
)
Put
(
*
blocks
.
Block
)
error
PutMany
([]
*
blocks
.
Block
)
error
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
key
.
Key
,
error
)
}
...
...
@@ -42,7 +43,7 @@ func NewBlockstore(d ds.ThreadSafeDatastore) Blockstore {
}
type
blockstore
struct
{
datastore
ds
.
Datastore
datastore
ds
.
Batching
Datastore
// cant be ThreadSafeDatastore cause namespace.Datastore doesnt support it.
// we do check it on `NewBlockstore` though.
}
...
...
@@ -74,6 +75,26 @@ func (bs *blockstore) Put(block *blocks.Block) error {
return
bs
.
datastore
.
Put
(
k
,
block
.
Data
)
}
func
(
bs
*
blockstore
)
PutMany
(
blocks
[]
*
blocks
.
Block
)
error
{
t
,
err
:=
bs
.
datastore
.
Batch
()
if
err
!=
nil
{
return
err
}
for
_
,
b
:=
range
blocks
{
k
:=
b
.
Key
()
.
DsKey
()
exists
,
err
:=
bs
.
datastore
.
Has
(
k
)
if
err
==
nil
&&
exists
{
continue
}
err
=
t
.
Put
(
k
,
b
.
Data
)
if
err
!=
nil
{
return
err
}
}
return
t
.
Commit
()
}
func
(
bs
*
blockstore
)
Has
(
k
key
.
Key
)
(
bool
,
error
)
{
return
bs
.
datastore
.
Has
(
k
.
DsKey
())
}
...
...
blockstore_test.go
View file @
7e356be6
...
...
@@ -266,3 +266,7 @@ func (c *queryTestDS) Query(q dsq.Query) (dsq.Results, error) {
}
return
c
.
ds
.
Query
(
q
)
}
func
(
c
*
queryTestDS
)
Batch
()
(
ds
.
Batch
,
error
)
{
return
ds
.
NewBasicBatch
(
c
),
nil
}
write_cache.go
View file @
7e356be6
...
...
@@ -45,6 +45,16 @@ 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
for
_
,
b
:=
range
bs
{
if
_
,
ok
:=
w
.
cache
.
Get
(
b
.
Key
());
!
ok
{
good
=
append
(
good
,
b
)
}
}
return
w
.
blockstore
.
PutMany
(
good
)
}
func
(
w
*
writecache
)
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
key
.
Key
,
error
)
{
return
w
.
blockstore
.
AllKeysChan
(
ctx
)
}
write_cache_test.go
View file @
7e356be6
...
...
@@ -88,3 +88,7 @@ func (c *callbackDatastore) Query(q dsq.Query) (dsq.Results, error) {
c
.
f
()
return
c
.
ds
.
Query
(
q
)
}
func
(
c
*
callbackDatastore
)
Batch
()
(
ds
.
Batch
,
error
)
{
return
ds
.
NewBasicBatch
(
c
),
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