Skip to content

Commit 46f6789

Browse files
committed
don't read file when discarding output, at least for now
trying to test this without access to lotus daemon volumes
1 parent 6f4411c commit 46f6789

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

cmd/filecoin-chain-archiver/cmds/create.go

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -370,49 +370,10 @@ var cmdCreate = &cli.Command{
370370
}
371371
}()
372372

373-
rrPath := filepath.Join(flagExportDir, flagFileName)
374-
for {
375-
info, err := os.Stat(rrPath)
376-
if os.IsNotExist(err) {
377-
logger.Infow("waiting for snapshot car file to begin writing")
378-
time.Sleep(time.Second * 15)
379-
continue
380-
} else if info.IsDir() {
381-
return xerrors.Errorf("trying to open directory instead of car file")
382-
}
383-
break
384-
}
385-
rr, err := os.OpenFile(rrPath, os.O_RDONLY, 444)
386-
if err != nil {
387-
return err
388-
}
389-
defer rr.Close()
390-
391-
go func() {
392-
var lastSize int64
393-
fmt.Printf("rrPath: %v", rrPath)
394-
for {
395-
select {
396-
case <-time.After(flagProgressUpdate):
397-
size := e.Progress(rrPath)
398-
if size == 0 {
399-
continue
400-
}
401-
logger.Infow("update", "total", size, "speed", (size-lastSize)/int64(flagProgressUpdate/time.Second))
402-
lastSize = size
403-
}
404-
}
405-
}()
406-
407373
if flagDiscard {
408374
logger.Infow("discarding output")
409375
g, _ := errgroup.WithContext(ctx)
410376

411-
g.Go(func() error {
412-
_, err := io.Copy(io.Discard, rr)
413-
return err
414-
})
415-
416377
if err := g.Wait(); err != nil {
417378
return err
418379
}
@@ -421,6 +382,40 @@ var cmdCreate = &cli.Command{
421382
return err
422383
}
423384
} else {
385+
rrPath := filepath.Join(flagExportDir, flagFileName)
386+
for {
387+
info, err := os.Stat(rrPath)
388+
if os.IsNotExist(err) {
389+
logger.Infow("waiting for snapshot car file to begin writing")
390+
time.Sleep(time.Second * 15)
391+
continue
392+
} else if info.IsDir() {
393+
return xerrors.Errorf("trying to open directory instead of car file")
394+
}
395+
break
396+
}
397+
rr, err := os.OpenFile(rrPath, os.O_RDONLY, 444)
398+
if err != nil {
399+
return err
400+
}
401+
defer rr.Close()
402+
403+
go func() {
404+
var lastSize int64
405+
fmt.Printf("rrPath: %v", rrPath)
406+
for {
407+
select {
408+
case <-time.After(flagProgressUpdate):
409+
size := e.Progress(rrPath)
410+
if size == 0 {
411+
continue
412+
}
413+
logger.Infow("update", "total", size, "speed", (size-lastSize)/int64(flagProgressUpdate/time.Second))
414+
lastSize = size
415+
}
416+
}
417+
}()
418+
424419
host := u.Hostname()
425420
port := u.Port()
426421
if port == "" {

0 commit comments

Comments
 (0)