diff --git a/cmd/tools/segment-verify/main.go b/cmd/tools/segment-verify/main.go index ef979a37c..a11560c8e 100644 --- a/cmd/tools/segment-verify/main.go +++ b/cmd/tools/segment-verify/main.go @@ -201,7 +201,7 @@ func verifySegments(cmd *cobra.Command, args []string) error { if err != nil { return Error.Wrap(err) } - verifier.reportPiece = service.reportPiece + verifier.reportPiece = service.problemPieces.Write defer func() { err = errs.Combine(err, service.Close()) }() if cmd.Name() == "range" { return verifySegmentsRange(ctx, service, rangeCfg) diff --git a/cmd/tools/segment-verify/service.go b/cmd/tools/segment-verify/service.go index 3464e0305..b1adb7788 100644 --- a/cmd/tools/segment-verify/service.go +++ b/cmd/tools/segment-verify/service.go @@ -83,8 +83,9 @@ type Service struct { log *zap.Logger config ServiceConfig - notFound SegmentWriter - retry SegmentWriter + notFound SegmentWriter + retry SegmentWriter + problemPieces *pieceCSVWriter metabase Metabase verifier Verifier @@ -98,10 +99,6 @@ type Service struct { offlineCount map[metabase.NodeAlias]int bucketList BucketList nodesVersionMap map[metabase.NodeAlias]string - - // this is a callback so that problematic pieces can be reported as they are found, - // rather than being kept in a list which might grow unreasonably large. - reportPiece pieceReporterFunc } // NewService returns a new service for verifying segments. @@ -120,14 +117,14 @@ func NewService(log *zap.Logger, metabaseDB Metabase, verifier Verifier, overlay if err != nil { return nil, errs.Combine(Error.Wrap(err), retry.Close(), notFound.Close()) } - defer func() { _ = problemPieces.Close() }() return &Service{ log: log, config: config, - notFound: notFound, - retry: retry, + notFound: notFound, + retry: retry, + problemPieces: problemPieces, metabase: metabaseDB, verifier: verifier, @@ -139,8 +136,6 @@ func NewService(log *zap.Logger, metabaseDB Metabase, verifier Verifier, overlay offlineNodes: newNodeAliasExpiringSet(config.OfflineStatusCacheTime), offlineCount: map[metabase.NodeAlias]int{}, nodesVersionMap: map[metabase.NodeAlias]string{}, - - reportPiece: problemPieces.Write, }, nil } @@ -149,6 +144,7 @@ func (service *Service) Close() error { return Error.Wrap(errs.Combine( service.notFound.Close(), service.retry.Close(), + service.problemPieces.Close(), )) } diff --git a/cmd/tools/segment-verify/verify.go b/cmd/tools/segment-verify/verify.go index 33e24176d..0ef74f040 100644 --- a/cmd/tools/segment-verify/verify.go +++ b/cmd/tools/segment-verify/verify.go @@ -53,6 +53,8 @@ type NodeVerifier struct { dialer rpc.Dialer orders *orders.Service + // this is a callback so that problematic pieces can be reported as they are found, + // rather than being kept in a list which might grow unreasonably large. reportPiece pieceReporterFunc versionWithExists semver.Version