diff --git a/cmd/satellite/metainfo.go b/cmd/satellite/metainfo.go index 4f2711241..2f8292b26 100644 --- a/cmd/satellite/metainfo.go +++ b/cmd/satellite/metainfo.go @@ -177,6 +177,8 @@ func verifyPieceHashes(ctx context.Context) (err error) { return runVerifierCmd(ctx, func(verifier *audit.Verifier) error { var total, fixed int + verifier.UsedToVerifyPieceHashes = true + scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { key, err := hex.DecodeString(scanner.Text()) diff --git a/satellite/audit/verifier.go b/satellite/audit/verifier.go index 0513919d2..caecbdf4c 100644 --- a/satellite/audit/verifier.go +++ b/satellite/audit/verifier.go @@ -67,7 +67,10 @@ type Verifier struct { minDownloadTimeout time.Duration OnTestingCheckSegmentAlteredHook func() - OnTestingVerifyMockFunc func() (Report, error) + + // Temporary fields for the verify-piece-hashes command + OnTestingVerifyMockFunc func() (Report, error) + UsedToVerifyPieceHashes bool } // NewVerifier creates a Verifier. @@ -107,6 +110,9 @@ func (verifier *Verifier) Verify(ctx context.Context, path storj.Path, skip map[ } defer func() { + if verifier.UsedToVerifyPieceHashes { + return + } // if piece hashes have not been verified for this segment, do not mark nodes as failing audit if !pointer.PieceHashesVerified { report.PendingAudits = nil diff --git a/satellite/audit/verifier_test.go b/satellite/audit/verifier_test.go index 1675cb5e0..2cd5c3710 100644 --- a/satellite/audit/verifier_test.go +++ b/satellite/audit/verifier_test.go @@ -1056,3 +1056,54 @@ func TestVerifyPieceHashes(t *testing.T) { } }) } + +func TestVerifierMissingPieceHashesNotVerified_UsedToVerifyPieceHashes(t *testing.T) { + testplanet.Run(t, testplanet.Config{ + SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1, + }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { + satellite := planet.Satellites[0] + audits := satellite.Audit + + audits.Worker.Loop.Pause() + audits.Chore.Loop.Pause() + + ul := planet.Uplinks[0] + testData := testrand.Bytes(8 * memory.KiB) + + err := ul.Upload(ctx, satellite, "testbucket", "test/path", testData) + require.NoError(t, err) + + audits.Chore.Loop.TriggerWait() + queue := audits.Queues.Fetch() + path, err := queue.Next() + require.NoError(t, err) + + pointer, err := satellite.Metainfo.Service.Get(ctx, metabase.SegmentKey(path)) + require.NoError(t, err) + + // update pointer to have PieceHashesVerified false + err = satellite.Metainfo.Service.UnsynchronizedDelete(ctx, metabase.SegmentKey(path)) + require.NoError(t, err) + pointer.PieceHashesVerified = false + err = satellite.Metainfo.Service.Put(ctx, metabase.SegmentKey(path), pointer) + require.NoError(t, err) + + // delete the piece from the first node + origNumPieces := len(pointer.GetRemote().GetRemotePieces()) + piece := pointer.GetRemote().GetRemotePieces()[0] + pieceID := pointer.GetRemote().RootPieceId.Derive(piece.NodeId, piece.PieceNum) + node := planet.FindNode(piece.NodeId) + err = node.Storage2.Store.Delete(ctx, satellite.ID(), pieceID) + require.NoError(t, err) + + audits.Verifier.UsedToVerifyPieceHashes = true + report, err := audits.Verifier.Verify(ctx, path, nil) + require.NoError(t, err) + + assert.Len(t, report.Successes, origNumPieces-1) + // expect a failed audit + assert.Len(t, report.Fails, 1) + assert.Len(t, report.Offlines, 0) + assert.Len(t, report.PendingAudits, 0) + }) +}