Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/SiaFoundation/renterd int…
Browse files Browse the repository at this point in the history
…o pj/state-route
  • Loading branch information
peterjan committed Aug 14, 2023
2 parents 53be163 + dee1d8f commit 4f161f6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
4 changes: 3 additions & 1 deletion cmd/renterd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ func main() {

auth := jape.BasicAuth(getAPIPassword())
mux := treeMux{
h: renterd.Handler(),
sub: make(map[string]treeMux),
}

Expand Down Expand Up @@ -320,6 +319,9 @@ func main() {
mux.sub["/api/bus"] = treeMux{h: auth(b)}
busAddr = *apiAddr + "/api/bus"
busPassword = getAPIPassword()

// only serve the UI if a bus is created
mux.h = renterd.Handler()
} else {
fmt.Println("connecting to remote bus at", busAddr)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/renterd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ func (t treeMux) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
}
t.h.ServeHTTP(w, req)
if t.h != nil {
t.h.ServeHTTP(w, req)
return
}
http.NotFound(w, req)
}
24 changes: 24 additions & 0 deletions internal/testing/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,30 @@ func TestUploadPacking(t *testing.T) {
t.Fatal(err)
}
download(name, data, 0, uint64(len(data)))
obj, _, err := b.Object(context.Background(), name)
if err != nil {
t.Fatal(err)
}
if obj.Size != int64(len(data)) {
t.Fatal("unexpected size after upload", obj.Size, len(data))
}
entries, err := w.ObjectEntries(context.Background(), "/", "", 0, -1)
if err != nil {
t.Fatal(err)
}
var found bool
for _, entry := range entries {
if entry.Name == "/"+name {
if entry.Size != int64(len(data)) {
t.Fatal("unexpected size after upload", entry.Size, len(data))
}
found = true
break
}
}
if !found {
t.Fatal("object not found in list", name, entries)
}
}

// upload file 1 and download it.
Expand Down
2 changes: 1 addition & 1 deletion object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GenerateEncryptionKey() EncryptionKey {
type Object struct {
Key EncryptionKey `json:"key"`
Slabs []SlabSlice `json:"slabs"`
PartialSlab *PartialSlab `json:"partial_slab,omitempty"`
PartialSlab *PartialSlab `json:"partialSlab,omitempty"`
}

// NewObject returns a new Object with a random key.
Expand Down
24 changes: 9 additions & 15 deletions stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,26 +413,20 @@ func (s *SQLStore) ObjectsStats(ctx context.Context) (api.ObjectsStatsResponse,
var resp api.ObjectsStatsResponse
return resp, s.db.Transaction(func(tx *gorm.DB) error {
// Number of objects.
var objInfo struct {
NumObjects uint64
TotalObjectsSize uint64
}
err := tx.
Model(&dbObject{}).
Select("COUNT(*)").
Scan(&resp.NumObjects).
Select("COUNT(*) AS NumObjects, SUM(size) AS TotalObjectsSize").
Scan(&objInfo).
Error
if err != nil {
return err
}

// Size of objects.
if resp.NumObjects > 0 {
err = tx.
Model(&dbSlice{}).
Select("COALESCE(SUM(length), 0)").
Scan(&resp.TotalObjectsSize).
Error
if err != nil {
return err
}
}
resp.NumObjects = objInfo.NumObjects
resp.TotalObjectsSize = objInfo.TotalObjectsSize

// Size of sectors
var sectorSizes struct {
Expand Down Expand Up @@ -1358,7 +1352,7 @@ GROUP BY slabs.id
`)
return s.retryTransaction(func(tx *gorm.DB) error {
if isSQLite(s.db) {
return s.db.Exec("UPDATE slabs SET health = (SELECT health FROM (?) WHERE slabs.id = id)", healthQuery).Error
return s.db.Exec("UPDATE slabs SET health = COALESCE((SELECT health FROM (?) WHERE slabs.id = id), 1)", healthQuery).Error
} else {
return s.db.Exec("UPDATE slabs sla INNER JOIN (?) h ON sla.id = h.id SET sla.health = h.health", healthQuery).Error
}
Expand Down
23 changes: 23 additions & 0 deletions stores/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ func performMigrations(db *gorm.DB, logger glogger.Interface) error {
},
Rollback: nil,
},
{
ID: "00007_contractspending",
Migrate: func(tx *gorm.DB) error {
return performMigration00007_archivedcontractspending(tx, logger)
},
Rollback: nil,
},
}

// Create migrator.
Expand Down Expand Up @@ -453,3 +460,19 @@ func performMigration00006_contractspending(txn *gorm.DB, logger glogger.Interfa
logger.Info(context.Background(), "migration 00006_contractspending complete")
return nil
}

func performMigration00007_archivedcontractspending(txn *gorm.DB, logger glogger.Interface) error {
logger.Info(context.Background(), "performing migration 00007_archivedcontractspending")
if !txn.Migrator().HasColumn(&dbArchivedContract{}, "delete_spending") {
if err := txn.Migrator().AddColumn(&dbArchivedContract{}, "delete_spending"); err != nil {
return err
}
}
if !txn.Migrator().HasColumn(&dbArchivedContract{}, "list_spending") {
if err := txn.Migrator().AddColumn(&dbArchivedContract{}, "list_spending"); err != nil {
return err
}
}
logger.Info(context.Background(), "migration 00007_archivedcontractspending complete")
return nil
}

0 comments on commit 4f161f6

Please sign in to comment.