Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only log lost sectors if sector was part of an active contract #996

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type (
ContractSizes(ctx context.Context) (map[types.FileContractID]api.ContractSize, error)
ContractSize(ctx context.Context, id types.FileContractID) (api.ContractSize, error)

DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) error
DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) (int, error)

Bucket(_ context.Context, bucketName string) (api.Bucket, error)
CreateBucket(_ context.Context, bucketName string, policy api.BucketPolicy) error
Expand Down Expand Up @@ -1409,9 +1409,11 @@ func (b *bus) sectorsHostRootHandlerDELETE(jc jape.Context) {
} else if jc.DecodeParam("root", &root) != nil {
return
}
err := b.ms.DeleteHostSector(jc.Request.Context(), hk, root)
n, err := b.ms.DeleteHostSector(jc.Request.Context(), hk, root)
if jc.Check("failed to mark sector as lost", err) != nil {
return
} else if n > 0 {
b.logger.Infow("successfully marked sector as lost", "hk", hk, "root", root)
}
}

Expand Down
7 changes: 5 additions & 2 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,9 @@ func (s *SQLStore) CopyObject(ctx context.Context, srcBucket, dstBucket, srcPath
return
}

func (s *SQLStore) DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) error {
return s.retryTransaction(func(tx *gorm.DB) error {
func (s *SQLStore) DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) (int, error) {
var deletedSectors int
err := s.retryTransaction(func(tx *gorm.DB) error {
// Fetch contract_sectors to delete.
var sectors []dbContractSector
err := tx.Raw(`
Expand Down Expand Up @@ -1660,6 +1661,7 @@ func (s *SQLStore) DeleteHostSector(ctx context.Context, hk types.PublicKey, roo
} else if res.RowsAffected != int64(len(sectors)) {
return fmt.Errorf("expected %v affected rows but got %v", len(sectors), res.RowsAffected)
}
deletedSectors = len(sectors)

// Increment the host's lostSectors by the number of lost sectors.
if err := tx.Exec("UPDATE hosts SET lost_sectors = lost_sectors + ? WHERE public_key = ?", len(sectors), publicKey(hk)).Error; err != nil {
Expand Down Expand Up @@ -1687,6 +1689,7 @@ func (s *SQLStore) DeleteHostSector(ctx context.Context, hk types.PublicKey, roo
}
return nil
})
return deletedSectors, err
ChrisSchinnerl marked this conversation as resolved.
Show resolved Hide resolved
}

func (s *SQLStore) UpdateObject(ctx context.Context, bucket, path, contractSet, eTag, mimeType string, metadata api.ObjectUserMetadata, o object.Object) error {
Expand Down
4 changes: 3 additions & 1 deletion stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3582,8 +3582,10 @@ func TestDeleteHostSector(t *testing.T) {
}

// Prune the sector from hk1.
if err := ss.DeleteHostSector(context.Background(), hk1, root); err != nil {
if n, err := ss.DeleteHostSector(context.Background(), hk1, root); err != nil {
t.Fatal(err)
} else if n != 2 {
t.Fatal("no sectors were pruned", n)
}

// Make sure 2 contractSector entries exist.
Expand Down
2 changes: 0 additions & 2 deletions worker/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,6 @@ loop:
if isSectorNotFound(resp.err) {
if err := s.mgr.os.DeleteHostSector(ctx, resp.req.host.PublicKey(), resp.req.root); err != nil {
s.mgr.logger.Errorw("failed to mark sector as lost", "hk", resp.req.host.PublicKey(), "root", resp.req.root, zap.Error(err))
} else {
s.mgr.logger.Infow("successfully marked sector as lost", "hk", resp.req.host.PublicKey(), "root", resp.req.root)
}
} else if isPriceTableGouging(resp.err) && s.overpay && !resp.req.overpay {
resp.req.overpay = true // ensures we don't retry the same request over and over again
Expand Down
Loading