Skip to content

Commit

Permalink
Merge ui: v0.51.1 into master (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored Apr 23, 2024
2 parents 3433f50 + 712c1d8 commit cdff67b
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 77 deletions.
11 changes: 11 additions & 0 deletions autopilot/contractor/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"go.sia.tech/renterd/api"
)

const (
// alertLostSectorsThresholdPct defines the the threshold at which we
// register the lost sectors alert. A value of 0.01 means that we register
// the alert if the host lost 1% (or more) of its stored data.
alertLostSectorsThresholdPct = 0.01
)

var (
alertChurnID = alerts.RandomAlertID() // constant until restarted
alertLostSectorsID = alerts.RandomAlertID() // constant until restarted
Expand Down Expand Up @@ -47,3 +54,7 @@ func newLostSectorsAlert(hk types.PublicKey, lostSectors uint64) alerts.Alert {
Timestamp: time.Now(),
}
}

func registerLostSectorsAlert(dataLost, dataStored uint64) bool {
return dataLost > 0 && float64(dataLost) >= float64(dataStored)*alertLostSectorsThresholdPct
}
26 changes: 26 additions & 0 deletions autopilot/contractor/alerts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package contractor

import (
"testing"

rhpv2 "go.sia.tech/core/rhp/v2"
)

func TestRegisterLostSectorsAlert(t *testing.T) {
for _, tc := range []struct {
dataLost uint64
dataStored uint64
expected bool
}{
{0, 0, false},
{0, rhpv2.SectorSize, false},
{rhpv2.SectorSize, 0, true},
{rhpv2.SectorSize, 99 * rhpv2.SectorSize, true},
{rhpv2.SectorSize, 100 * rhpv2.SectorSize, true}, // exactly 1%
{rhpv2.SectorSize, 101 * rhpv2.SectorSize, false}, // just short of 1%
} {
if result := registerLostSectorsAlert(tc.dataLost, tc.dataStored); result != tc.expected {
t.Fatalf("unexpected result for dataLost=%d, dataStored=%d: %v", tc.dataLost, tc.dataStored, result)
}
}
}
2 changes: 1 addition & 1 deletion autopilot/contractor/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (c *Contractor) performContractMaintenance(ctx *mCtx, w Worker) (bool, erro
// check if any used hosts have lost data to warn the user
var toDismiss []types.Hash256
for _, h := range hosts {
if h.Interactions.LostSectors > 0 {
if registerLostSectorsAlert(h.Interactions.LostSectors*rhpv2.SectorSize, h.StoredData) {
c.alerter.RegisterAlert(ctx, newLostSectorsAlert(h.PublicKey, h.Interactions.LostSectors))
} else {
toDismiss = append(toDismiss, alerts.IDForHost(alertLostSectorsID, h.PublicKey))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
go.sia.tech/jape v0.11.2-0.20240124024603-93559895d640
go.sia.tech/mux v1.2.0
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca
go.sia.tech/web/renterd v0.51.0
go.sia.tech/web/renterd v0.51.1
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.22.0
golang.org/x/sys v0.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,8 @@ go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca h1:aZMg2AKevn7jKx+wlusWQf
go.sia.tech/siad v1.5.10-0.20230228235644-3059c0b930ca/go.mod h1:h/1afFwpxzff6/gG5i1XdAgPK7dEY6FaibhK7N5F86Y=
go.sia.tech/web v0.0.0-20240403135501-82ff3a2a3e7c h1:os2ZFJojHi0ckCNbr8c2GnWGm0ftvHkQUJOfBRGGIfk=
go.sia.tech/web v0.0.0-20240403135501-82ff3a2a3e7c/go.mod h1:nGEhGmI8zV/BcC3LOCC5JLVYpidNYJIvLGIqVRWQBCg=
go.sia.tech/web/renterd v0.51.0 h1:hQfq6vOMll2lseQMaK9tUtc6RscO3zgLOzhCk9myHTk=
go.sia.tech/web/renterd v0.51.0/go.mod h1:FgXrdmAnu591a3h96RB/15pMZ74xO9457g902uE06BM=
go.sia.tech/web/renterd v0.51.1 h1:R+EvTdmyCrN7P4tjATyjUAUKCLMu7CmdXYAqb3eON9w=
go.sia.tech/web/renterd v0.51.1/go.mod h1:FgXrdmAnu591a3h96RB/15pMZ74xO9457g902uE06BM=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
Expand Down
1 change: 1 addition & 0 deletions stores/hostdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (s *SQLStore) insertTestAnnouncement(hk types.PublicKey, a hostdb.Announcem
// SQLite DB.
func TestSQLHostDB(t *testing.T) {
ss := newTestSQLStore(t, defaultTestSQLStoreConfig)
defer ss.Close()
if ss.ccid != modules.ConsensusChangeBeginning {
t.Fatal("wrong ccid", ss.ccid, modules.ConsensusChangeBeginning)
}
Expand Down
10 changes: 7 additions & 3 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1813,11 +1813,11 @@ func (s *SQLStore) UpdateObject(ctx context.Context, bucket, path, contractSet,
})
}

func (s *SQLStore) RemoveObject(ctx context.Context, bucket, key string) error {
func (s *SQLStore) RemoveObject(ctx context.Context, bucket, path string) error {
var rowsAffected int64
var err error
err = s.retryTransaction(ctx, func(tx *gorm.DB) error {
rowsAffected, err = s.deleteObject(tx, bucket, key)
rowsAffected, err = s.deleteObject(tx, bucket, path)
if err != nil {
return fmt.Errorf("RemoveObject: failed to delete object: %w", err)
}
Expand All @@ -1827,7 +1827,7 @@ func (s *SQLStore) RemoveObject(ctx context.Context, bucket, key string) error {
return err
}
if rowsAffected == 0 {
return fmt.Errorf("%w: key: %s", api.ErrObjectNotFound, key)
return fmt.Errorf("%w: key: %s", api.ErrObjectNotFound, path)
}
return nil
}
Expand Down Expand Up @@ -2748,6 +2748,10 @@ func (s *SQLStore) pruneSlabsLoop() {
})
} else {
s.alerts.DismissAlerts(s.shutdownCtx, pruneSlabsAlertID)

s.mu.Lock()
s.lastPrunedAt = time.Now()
s.mu.Unlock()
}
cancel()
}
Expand Down
Loading

0 comments on commit cdff67b

Please sign in to comment.