@@ -3,12 +3,11 @@ package main
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "os"
7
-
8
6
logging "github.com/ipfs/go-log/v2"
9
7
_ "github.com/jinzhu/gorm/dialects/mysql"
10
8
"github.com/urfave/cli/v2"
11
9
"golang.org/x/xerrors"
10
+ "os"
12
11
)
13
12
14
13
var log = logging .Logger ("graphsplit" )
@@ -17,6 +16,7 @@ func main() {
17
16
logging .SetLogLevel ("*" , "INFO" )
18
17
local := []* cli.Command {
19
18
chunkCmd ,
19
+ retrieveCmd ,
20
20
}
21
21
22
22
app := & cli.App {
@@ -33,31 +33,32 @@ func main() {
33
33
34
34
var chunkCmd = & cli.Command {
35
35
Name : "chunk" ,
36
- Usage : "" ,
36
+ Usage : "Generate CAR files of the specified size " ,
37
37
Flags : []cli.Flag {
38
38
& cli.Int64Flag {
39
39
Name : "slice-size" ,
40
40
Value : 17179869184 , // 16G
41
- Usage : fmt . Sprintf ( "specify chunk piece size" ) ,
41
+ Usage : "specify chunk piece size" ,
42
42
},
43
43
& cli.IntFlag {
44
44
Name : "parallel" ,
45
45
Value : 4 ,
46
- Usage : fmt . Sprintf ( "specify how many number of goroutines runs when generate file node" ) ,
46
+ Usage : "specify how many number of goroutines runs when generate file node" ,
47
47
},
48
48
& cli.StringFlag {
49
49
Name : "graph-name" ,
50
50
Required : true ,
51
- Usage : fmt . Sprintf ( "specify graph name" ) ,
51
+ Usage : "specify graph name" ,
52
52
},
53
53
& cli.StringFlag {
54
54
Name : "parent-path" ,
55
55
Value : "" ,
56
- Usage : fmt . Sprintf ( "specify graph parent path" ) ,
56
+ Usage : "specify graph parent path" ,
57
57
},
58
58
& cli.StringFlag {
59
59
Name : "car-dir" ,
60
60
Required : true ,
61
+ Usage : "specify output CAR directory" ,
61
62
},
62
63
},
63
64
Action : func (c * cli.Context ) error {
@@ -73,6 +74,9 @@ var chunkCmd = &cli.Command{
73
74
if sliceSize == 0 {
74
75
return xerrors .Errorf ("Unexpected! Slice size has been set as 0" )
75
76
}
77
+ if parallel <= 0 {
78
+ return xerrors .Errorf ("Unexpected! Parallel has to be greater than 0" )
79
+ }
76
80
77
81
args := c .Args ().Slice ()
78
82
sliceTotal := GetGraphCount (args , sliceSize )
@@ -154,7 +158,6 @@ var chunkCmd = &cli.Command{
154
158
}
155
159
156
160
}
157
-
158
161
}
159
162
if cumuSize > 0 {
160
163
// todo build ipld from graphFiles
@@ -166,3 +169,39 @@ var chunkCmd = &cli.Command{
166
169
return nil
167
170
},
168
171
}
172
+
173
+ var retrieveCmd = & cli.Command {
174
+ Name : "retrieve" ,
175
+ Usage : "Retrieve files from CAR files" ,
176
+ Flags : []cli.Flag {
177
+ & cli.StringFlag {
178
+ Name : "car-path" ,
179
+ Required : true ,
180
+ Usage : "specify source car path, directory or file" ,
181
+ },
182
+ & cli.StringFlag {
183
+ Name : "output-dir" ,
184
+ Required : true ,
185
+ Usage : "specify output directory" ,
186
+ },
187
+ & cli.IntFlag {
188
+ Name : "parallel" ,
189
+ Value : 4 ,
190
+ Usage : "specify how many number of goroutines runs when generate file node" ,
191
+ },
192
+ },
193
+ Action : func (c * cli.Context ) error {
194
+ parallel := c .Int ("parallel" )
195
+ outputDir := c .String ("output-dir" )
196
+ carPath := c .String ("car-path" )
197
+ if parallel <= 0 {
198
+ return xerrors .Errorf ("Unexpected! Parallel has to be greater than 0" )
199
+ }
200
+
201
+ CarTo (carPath , outputDir , parallel )
202
+ Merge (outputDir , parallel )
203
+
204
+ fmt .Println ("completed!" )
205
+ return nil
206
+ },
207
+ }
0 commit comments