From bf7510a249261aac0512efe3943265cbdab92564 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 3 Dec 2022 09:20:23 +0800 Subject: [PATCH] allow retry if incomplete --- client/file/sync.go | 3 ++- client/file/watcher.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/file/sync.go b/client/file/sync.go index 7a4abefb07..8fddca903e 100644 --- a/client/file/sync.go +++ b/client/file/sync.go @@ -98,12 +98,13 @@ func Sync(versionDB *tmdb.Store, remoteGrpcUrl, remoteUrl, remoteWsUrl, rootDir fmt.Printf("mm-pairs: %+v, %+v\n", len(pairs), err) if err != nil { fmt.Println("invalid decode") - panic(err) } if err = versionDB.PutAtVersion(int64(data.BlockNum), pairs); err != nil { fmt.Println("mm-put-at-version-panic") panic(err) } + data.ChResult <- err + case err := <-chErr: // fail read fmt.Println("mm-fail-read-panic") diff --git a/client/file/watcher.go b/client/file/watcher.go index 00526a779c..a2ec055b8d 100644 --- a/client/file/watcher.go +++ b/client/file/watcher.go @@ -56,6 +56,7 @@ func (d *httpFileDownloader) GetData(path string) ([]byte, error) { type BlockData struct { BlockNum int Data []byte + ChResult chan<- error } type BlockFileWatcher struct { @@ -131,11 +132,14 @@ func (w *BlockFileWatcher) fetch(blockNum int) error { } return err } + + chResult := make(chan error) w.chData <- &BlockData{ BlockNum: blockNum, Data: data, + ChResult: chResult, } - return nil + return <-chResult } func (w *BlockFileWatcher) Start(