Skip to content

Commit

Permalink
store: retryTransaction in Object
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed May 23, 2024
1 parent bc8448e commit f419267
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ GROUP BY d.id
}

func (s *SQLStore) Object(ctx context.Context, bucket, path string) (obj api.Object, err error) {
err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
err = s.retryTransaction(ctx, func(tx *gorm.DB) error {
obj, err = s.object(tx, bucket, path)
return err
})
Expand Down
6 changes: 3 additions & 3 deletions stores/sql/mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,21 +560,21 @@ func (tx *MainDatabaseTx) UpdateSlab(ctx context.Context, s object.Slab, contrac
}

// find shards of slab
var nSectors int
var roots []types.Hash256
rows, err := tx.Query(ctx, "SELECT COUNT(*), root FROM sectors WHERE db_slab_id = ? ORDER BY sectors.slab_index ASC", slabID)
rows, err := tx.Query(ctx, "SELECT root FROM sectors WHERE db_slab_id = ? ORDER BY sectors.slab_index ASC", slabID)
if err != nil {
return fmt.Errorf("failed to fetch sectors: %w", err)
}
defer rows.Close()

for rows.Next() {
var root ssql.Hash256
if err := rows.Scan(&nSectors, &root); err != nil {
if err := rows.Scan(&root); err != nil {
return fmt.Errorf("failed to scan sector id: %w", err)
}
roots = append(roots, types.Hash256(root))
}
nSectors := len(roots)

// make sure the number of shards doesn't change.
// NOTE: check both the slice as well as the TotalShards field to be
Expand Down
6 changes: 3 additions & 3 deletions stores/sql/sqlite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,21 +535,21 @@ func (tx *MainDatabaseTx) UpdateSlab(ctx context.Context, s object.Slab, contrac
}

// find shards of slab
var nSectors int
var roots []types.Hash256
rows, err := tx.Query(ctx, "SELECT COUNT(*), root FROM sectors WHERE db_slab_id = ? ORDER BY sectors.slab_index ASC", slabID)
rows, err := tx.Query(ctx, "SELECT root FROM sectors WHERE db_slab_id = ? ORDER BY sectors.slab_index ASC", slabID)
if err != nil {
return fmt.Errorf("failed to fetch sectors: %w", err)
}
defer rows.Close()

for rows.Next() {
var root ssql.Hash256
if err := rows.Scan(&nSectors, &root); err != nil {
if err := rows.Scan(&root); err != nil {
return fmt.Errorf("failed to scan sector id: %w", err)
}
roots = append(roots, types.Hash256(root))
}
nSectors := len(roots)

// make sure the number of shards doesn't change.
// NOTE: check both the slice as well as the TotalShards field to be
Expand Down

0 comments on commit f419267

Please sign in to comment.