Skip to content

Commit

Permalink
downloader: added set log prefix grpc method (#11731)
Browse files Browse the repository at this point in the history
To print the current download progress, we currently call the GRPC
method RecalcStats for every log entry. However, given the frequent
updates to the downloader in recent days, we may need to add more
information to the logs. This would require updating the Go interfaces,
which can be painful.

To streamline this process, I've added a log prefix to move the
responsibility of logging the download progress directly to the
downloader. This change also allows us to print a proper prefix
(currently "OtterSync"). As a result, we may soon be able to remove
StatsReply, since Erigon is primarily concerned with whether the
download is complete or not.
  • Loading branch information
dvovk authored Aug 24, 2024
1 parent 4b128df commit cc8eb60
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 39 deletions.
3 changes: 3 additions & 0 deletions erigon-lib/direct/downloader_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ func (c *DownloaderClient) Verify(ctx context.Context, in *proto_downloader.Veri
func (c *DownloaderClient) Stats(ctx context.Context, in *proto_downloader.StatsRequest, opts ...grpc.CallOption) (*proto_downloader.StatsReply, error) {
return c.server.Stats(ctx, in)
}
func (c *DownloaderClient) SetLogPrefix(ctx context.Context, in *proto_downloader.SetLogPrefixRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
return c.server.SetLogPrefix(ctx, in)
}
14 changes: 13 additions & 1 deletion erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ type Downloader struct {
downloadLimit *rate.Limit

stuckFileDetailedLogs bool

logPrefix string
}

type downloadInfo struct {
Expand Down Expand Up @@ -341,6 +343,7 @@ func New(ctx context.Context, cfg *downloadercfg.Cfg, logger log.Logger, verbosi
webDownloadSessions: map[string]*RCloneSession{},
downloading: map[string]*downloadInfo{},
webseedsDiscover: discover,
logPrefix: "",
}
d.webseeds.SetTorrent(d.torrentFS, snapLock.Downloads, cfg.DownloadTorrentFilesFromWebseed)

Expand Down Expand Up @@ -2174,8 +2177,13 @@ func (d *Downloader) ReCalcStats(interval time.Duration) {
stats.Completed = false
}

prefix := d.logPrefix
if d.logPrefix == "" {
prefix = "[snapshots]"
}

if !stats.Completed {
logger.Debug("[snapshots] download info",
logger.Debug(fmt.Sprintf("[%s]", prefix),
"len", len(torrents),
"webTransfers", webTransfers,
"torrent", torrentInfo,
Expand Down Expand Up @@ -2861,3 +2869,7 @@ func openClient(ctx context.Context, dbDir, snapDir string, cfg *torrent.ClientC

return db, c, m, torrentClient, nil
}

func (d *Downloader) SetLogPrefix(prefix string) {
d.logPrefix = prefix
}
6 changes: 6 additions & 0 deletions erigon-lib/downloader/downloader_grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,9 @@ func (s *GrpcServer) Stats(ctx context.Context, request *proto_downloader.StatsR
func Proto2InfoHash(in *prototypes.H160) metainfo.Hash {
return gointerfaces.ConvertH160toAddress(in)
}

func (s *GrpcServer) SetLogPrefix(ctx context.Context, request *proto_downloader.SetLogPrefixRequest) (*emptypb.Empty, error) {
s.d.SetLogPrefix(request.Prefix)

return &emptypb.Empty{}, nil
}
141 changes: 106 additions & 35 deletions erigon-lib/gointerfaces/downloaderproto/downloader.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions erigon-lib/gointerfaces/downloaderproto/downloader_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions erigon-lib/gointerfaces/downloaderproto/downloader_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion eth/stagedsync/stage_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func SnapshotsPrune(s *PruneState, cfg SnapshotsCfg, ctx context.Context, tx kv.

cfg.blockRetire.RetireBlocksInBackground(ctx, minBlockNumber, s.ForwardProgress, log.LvlDebug, func(downloadRequest []services.DownloadRequest) error {
if cfg.snapshotDownloader != nil && !reflect.ValueOf(cfg.snapshotDownloader).IsNil() {
if err := snapshotsync.RequestSnapshotsDownload(ctx, downloadRequest, cfg.snapshotDownloader); err != nil {
if err := snapshotsync.RequestSnapshotsDownload(ctx, downloadRequest, cfg.snapshotDownloader, ""); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit cc8eb60

Please sign in to comment.