cmd/tools/segment-verify: fix problem-pieces.csv

This csv file was being closed as soon as the service was created.
All subsequent writes to the closed file handle produced errors,
which were logged but otherwise ignored.

Instead, we would like the file to remain open and writable, until
the service is destroyed.

Change-Id: Ib29944d25b2f5b2d0f90fdbdcde44fea8d769321
This commit is contained in:
paul cannon 2023-01-05 11:32:18 -06:00 committed by Storj Robot
parent 0773b4efbc
commit 3a9ad48345
3 changed files with 10 additions and 12 deletions

View File

@ -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)

View File

@ -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(),
))
}

View File

@ -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