Skip to content

Commit 544247c

Browse files
holimankaralabe
authored andcommitted
* cmd/geth: add --nocompaction flag + multiple import files
* main,import: Add --nocompaction flag + multiple import files * geth/import: documentation * import: Added more info to err message * fix :P
1 parent 4c6f4e5 commit 544247c

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎cmd/geth/chaincmd.go‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ participating.
5454
Action: importChain,
5555
Name: "import",
5656
Usage: "Import a blockchain file",
57-
ArgsUsage: "<filename>",
57+
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
5858
Category: "BLOCKCHAIN COMMANDS",
5959
Description: `
60-
TODO: Please write this
60+
The import command imports blocks from an RLP-encoded form. The form can be one file
61+
with several RLP-encoded blocks, or several files can be used.
62+
If only one file is used, import error will result in failure. If several files are used,
63+
processing will proceed even if an individual RLP-file import failure occurs.
6164
`,
6265
}
6366
exportCommand = cli.Command{
@@ -122,7 +125,7 @@ func initGenesis(ctx *cli.Context) error {
122125
}
123126

124127
func importChain(ctx *cli.Context) error {
125-
if len(ctx.Args()) != 1 {
128+
if len(ctx.Args()) < 1 {
126129
utils.Fatalf("This command requires an argument.")
127130
}
128131
stack := makeFullNode(ctx)
@@ -146,9 +149,19 @@ func importChain(ctx *cli.Context) error {
146149
}()
147150
// Import the chain
148151
start := time.Now()
149-
if err := utils.ImportChain(chain, ctx.Args().First()); err != nil {
150-
utils.Fatalf("Import error: %v", err)
152+
153+
if len(ctx.Args()) == 1 {
154+
if err := utils.ImportChain(chain, ctx.Args().First()); err != nil {
155+
utils.Fatalf("Import error: %v", err)
156+
}
157+
} else {
158+
for _, arg := range ctx.Args() {
159+
if err := utils.ImportChain(chain, arg); err != nil {
160+
log.Error("Import error", "file", arg, "err", err)
161+
}
162+
}
151163
}
164+
152165
fmt.Printf("Import done in %v.\n\n", time.Since(start))
153166

154167
// Output pre-compaction stats mostly to see the import trashing
@@ -171,6 +184,10 @@ func importChain(ctx *cli.Context) error {
171184
fmt.Printf("Allocations: %.3f million\n", float64(mem.Mallocs)/1000000)
172185
fmt.Printf("GC pause: %v\n\n", time.Duration(mem.PauseTotalNs))
173186

187+
if ctx.GlobalIsSet(utils.NoCompactionFlag.Name) {
188+
return nil
189+
}
190+
174191
// Compact the entire database to more accurately measure disk io and print the stats
175192
start = time.Now()
176193
fmt.Println("Compacting entire database...")

‎cmd/geth/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func init() {
140140
utils.EthStatsURLFlag,
141141
utils.MetricsEnabledFlag,
142142
utils.FakePoWFlag,
143+
utils.NoCompactionFlag,
143144
utils.SolcPathFlag,
144145
utils.GpoMinGasPriceFlag,
145146
utils.GpoMaxGasPriceFlag,

‎cmd/utils/flags.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ var (
244244
Name: "fakepow",
245245
Usage: "Disables proof-of-work verification",
246246
}
247-
247+
NoCompactionFlag = cli.BoolFlag{
248+
Name: "nocompaction",
249+
Usage: "Disables db compaction after import",
250+
}
248251
// RPC settings
249252
RPCEnabledFlag = cli.BoolFlag{
250253
Name: "rpc",

0 commit comments

Comments
 (0)