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
Commits
479761ec
Commit
479761ec
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change batch fetching methods of dagserv
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
2600a029
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
16 deletions
+50
-16
core/commands/refs.go
core/commands/refs.go
+1
-1
merkledag/merkledag.go
merkledag/merkledag.go
+47
-13
unixfs/archive/tar/writer.go
unixfs/archive/tar/writer.go
+1
-1
unixfs/io/dagreader.go
unixfs/io/dagreader.go
+1
-1
No files found.
core/commands/refs.go
View file @
479761ec
...
...
@@ -233,7 +233,7 @@ func (rw *RefWriter) writeRefsRecursive(n *dag.Node) (int, error) {
}
var
count
int
for
i
,
ng
:=
range
rw
.
DAG
.
GetDAG
(
rw
.
Ctx
,
n
)
{
for
i
,
ng
:=
range
dag
.
GetDAG
(
rw
.
Ctx
,
rw
.
DAG
,
n
)
{
lk
:=
key
.
Key
(
n
.
Links
[
i
]
.
Hash
)
if
rw
.
skip
(
lk
)
{
continue
...
...
This diff is collapsed.
Click to expand it.
merkledag/merkledag.go
View file @
479761ec
...
...
@@ -24,8 +24,7 @@ type DAGService interface {
// GetDAG returns, in order, all the single leve child
// nodes of the passed in node.
GetDAG
(
context
.
Context
,
*
Node
)
[]
NodeGetter
GetNodes
(
context
.
Context
,
[]
key
.
Key
)
[]
NodeGetter
GetMany
(
context
.
Context
,
[]
key
.
Key
)
(
<-
chan
*
Node
,
<-
chan
error
)
Batch
()
*
Batch
}
...
...
@@ -146,21 +145,52 @@ func FindLinks(links []key.Key, k key.Key, start int) []int {
return
out
}
func
(
ds
*
dagService
)
GetMany
(
ctx
context
.
Context
,
keys
[]
key
.
Key
)
(
<-
chan
*
Node
,
<-
chan
error
)
{
out
:=
make
(
chan
*
Node
)
errs
:=
make
(
chan
error
,
1
)
blocks
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
keys
)
go
func
()
{
defer
close
(
out
)
defer
close
(
errs
)
for
{
select
{
case
b
,
ok
:=
<-
blocks
:
if
!
ok
{
return
}
nd
,
err
:=
Decoded
(
b
.
Data
)
if
err
!=
nil
{
errs
<-
err
return
}
select
{
case
out
<-
nd
:
case
<-
ctx
.
Done
()
:
return
}
case
<-
ctx
.
Done
()
:
return
}
}
}()
return
out
,
errs
}
// GetDAG will fill out all of the links of the given Node.
// It returns a channel of nodes, which the caller can receive
// all the child nodes of 'root' on, in proper order.
func
(
ds
*
dagService
)
GetDAG
(
ctx
context
.
Context
,
root
*
Node
)
[]
NodeGetter
{
func
GetDAG
(
ctx
context
.
Context
,
ds
DAGService
,
root
*
Node
)
[]
NodeGetter
{
var
keys
[]
key
.
Key
for
_
,
lnk
:=
range
root
.
Links
{
keys
=
append
(
keys
,
key
.
Key
(
lnk
.
Hash
))
}
return
ds
.
GetNodes
(
ctx
,
keys
)
return
GetNodes
(
ctx
,
ds
,
keys
)
}
// GetNodes returns an array of 'NodeGetter' promises, with each corresponding
// to the key with the same index as the passed in keys
func
(
ds
*
dagService
)
GetNodes
(
ctx
context
.
Context
,
keys
[]
key
.
Key
)
[]
NodeGetter
{
func
GetNodes
(
ctx
context
.
Context
,
ds
DAGService
,
keys
[]
key
.
Key
)
[]
NodeGetter
{
// Early out if no work to do
if
len
(
keys
)
==
0
{
...
...
@@ -178,26 +208,29 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []key.Key) []NodeGetter
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
blkchan
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
dedupedKeys
)
nodechan
,
errchan
:=
ds
.
GetMany
(
ctx
,
dedupedKeys
)
for
count
:=
0
;
count
<
len
(
keys
);
{
select
{
case
blk
,
ok
:=
<-
blk
chan
:
case
nd
,
ok
:=
<-
node
chan
:
if
!
ok
{
return
}
nd
,
err
:=
Decoded
(
blk
.
Data
)
k
,
err
:=
nd
.
Key
(
)
if
err
!=
nil
{
// NB: can happen with improperly formatted input data
log
.
Debug
(
"Got back bad block!"
)
return
log
.
Error
(
"Failed to get node key: "
,
err
)
continue
}
is
:=
FindLinks
(
keys
,
blk
.
Key
(),
0
)
is
:=
FindLinks
(
keys
,
k
,
0
)
for
_
,
i
:=
range
is
{
count
++
sendChans
[
i
]
<-
nd
}
case
err
:=
<-
errchan
:
log
.
Error
(
"error fetching: "
,
err
)
return
case
<-
ctx
.
Done
()
:
return
}
...
...
@@ -389,9 +422,10 @@ func fetchNodes(ctx context.Context, ds DAGService, in <-chan []key.Key, out cha
}
for
ks
:=
range
in
{
ng
:=
ds
.
GetNodes
(
ctx
,
ks
)
ng
:=
GetNodes
(
ctx
,
ds
,
ks
)
for
_
,
g
:=
range
ng
{
go
get
(
g
)
}
}
}
This diff is collapsed.
Click to expand it.
unixfs/archive/tar/writer.go
View file @
479761ec
...
...
@@ -39,7 +39,7 @@ func (w *Writer) writeDir(nd *mdag.Node, fpath string) error {
return
err
}
for
i
,
ng
:=
range
w
.
D
ag
.
GetDAG
(
w
.
ctx
,
nd
)
{
for
i
,
ng
:=
range
md
ag
.
GetDAG
(
w
.
ctx
,
w
.
Dag
,
nd
)
{
child
,
err
:=
ng
.
Get
(
w
.
ctx
)
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
unixfs/io/dagreader.go
View file @
479761ec
...
...
@@ -90,7 +90,7 @@ func NewDagReader(ctx context.Context, n *mdag.Node, serv mdag.DAGService) (*Dag
func
NewDataFileReader
(
ctx
context
.
Context
,
n
*
mdag
.
Node
,
pb
*
ftpb
.
Data
,
serv
mdag
.
DAGService
)
*
DagReader
{
fctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
promises
:=
serv
.
GetDAG
(
fctx
,
n
)
promises
:=
mdag
.
GetDAG
(
fctx
,
serv
,
n
)
return
&
DagReader
{
node
:
n
,
serv
:
serv
,
...
...
This diff is collapsed.
Click to expand it.
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