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-ld-format
Commits
0f9e9ed7
Commit
0f9e9ed7
authored
Jun 26, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Batch a helper type/function
parent
b3a1f4b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
15 deletions
+44
-15
batch.go
batch.go
+43
-0
merkledag.go
merkledag.go
+1
-15
No files found.
batch.go
0 → 100644
View file @
0f9e9ed7
package
format
import
(
cid
"github.com/ipfs/go-cid"
)
func
Batching
(
ds
DAGService
)
*
Batch
{
return
&
Batch
{
ds
:
ds
,
MaxSize
:
8
<<
20
,
// By default, only batch up to 128 nodes at a time.
// The current implementation of flatfs opens this many file
// descriptors at the same time for the optimized batch write.
MaxBlocks
:
128
,
}
}
type
Batch
struct
{
ds
DAGService
// TODO: try to re-use memory.
nodes
[]
Node
size
int
MaxSize
int
MaxBlocks
int
}
func
(
t
*
Batch
)
Add
(
nd
Node
)
(
*
cid
.
Cid
,
error
)
{
t
.
nodes
=
append
(
t
.
nodes
,
nd
)
t
.
size
+=
len
(
nd
.
RawData
())
if
t
.
size
>
t
.
MaxSize
||
len
(
t
.
nodes
)
>
t
.
MaxBlocks
{
return
nd
.
Cid
(),
t
.
Commit
()
}
return
nd
.
Cid
(),
nil
}
func
(
t
*
Batch
)
Commit
()
error
{
_
,
err
:=
t
.
ds
.
AddMany
(
t
.
nodes
)
t
.
nodes
=
nil
t
.
size
=
0
return
err
}
merkledag.go
View file @
0f9e9ed7
...
@@ -36,25 +36,11 @@ type DAGService interface {
...
@@ -36,25 +36,11 @@ type DAGService interface {
// nodes of the passed in node.
// nodes of the passed in node.
GetMany
(
context
.
Context
,
[]
*
cid
.
Cid
)
<-
chan
*
NodeOption
GetMany
(
context
.
Context
,
[]
*
cid
.
Cid
)
<-
chan
*
NodeOption
Batch
()
Batch
AddMany
([]
Node
)
([]
*
cid
.
Cid
,
error
)
LinkService
LinkService
}
}
// An interface for batch-adding nodes to a DAG.
// TODO: Is this really the *right* level to do this at?
// Why not just `DAGService.AddMany` + a concrete helper type?
//
// This will be a breaking change *regardless* of what we do as `Batch` *used*
// to be a plain struct (passed around by pointer). I had to change this to
// avoid requiring a `BlockService` (which would introduce the concept of
// exchanges and I really don't want to go down that rabbit hole).
type
Batch
interface
{
Add
(
nd
Node
)
(
*
cid
.
Cid
,
error
)
Commit
()
error
}
// TODO: Replace this? I'm really not convinced this interface pulls its weight.
// TODO: Replace this? I'm really not convinced this interface pulls its weight.
//
//
// Instead, we could add an `Offline()` function to `NodeGetter` that returns an
// Instead, we could add an `Offline()` function to `NodeGetter` that returns an
...
...
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