Skip to content

Commit

Permalink
fix TestSQLMetadataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Dec 13, 2024
1 parent 9b23b41 commit 9ec595c
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions stores/sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,47 +1853,50 @@ func Slab(ctx context.Context, tx sql.Tx, key object.EncryptionKey) (object.Slab
defer hostStmt.Close()

for i, sectorID := range sectorIDs {
// contracts
rows, err := stmt.Query(ctx, sectorID)
slab.Shards[i].Contracts = make(map[types.PublicKey][]types.FileContractID)

// hosts
rows, err = hostStmt.Query(ctx, sectorID)
if err != nil {
return object.Slab{}, fmt.Errorf("failed to fetch contracts: %w", err)
return object.Slab{}, fmt.Errorf("failed to fetch hosts: %w", err)
}
if err := func() error {
defer rows.Close()

slab.Shards[i].Contracts = make(map[types.PublicKey][]types.FileContractID)
for rows.Next() {
var pk types.PublicKey
var fcid types.FileContractID
if err := rows.Scan((*PublicKey)(&pk), (*FileContractID)(&fcid)); err != nil {
return fmt.Errorf("failed to scan contract: %w", err)
if err := rows.Scan((*PublicKey)(&pk)); err != nil {
return fmt.Errorf("failed to scan host: %w", err)
}
if _, exists := slab.Shards[i].Contracts[pk]; !exists {
slab.Shards[i].Contracts[pk] = []types.FileContractID{}
}
if fcid != (types.FileContractID{}) {
slab.Shards[i].Contracts[pk] = append(slab.Shards[i].Contracts[pk], fcid)
}
}
return nil
}(); err != nil {
return object.Slab{}, err
}

// hosts
rows, err = hostStmt.Query(ctx, sectorID)
// contracts
rows, err := stmt.Query(ctx, sectorID)
if err != nil {
return object.Slab{}, fmt.Errorf("failed to fetch hosts: %w", err)
return object.Slab{}, fmt.Errorf("failed to fetch contracts: %w", err)
}
if err := func() error {
defer rows.Close()

for rows.Next() {
var pk types.PublicKey
if err := rows.Scan((*PublicKey)(&pk)); err != nil {
return fmt.Errorf("failed to scan host: %w", err)
var fcid types.FileContractID
if err := rows.Scan((*PublicKey)(&pk), (*FileContractID)(&fcid)); err != nil {
return fmt.Errorf("failed to scan contract: %w", err)
}
if _, exists := slab.Shards[i].Contracts[pk]; !exists {
slab.Shards[i].Contracts[pk] = []types.FileContractID{}
}
if fcid != (types.FileContractID{}) {
slab.Shards[i].Contracts[pk] = append(slab.Shards[i].Contracts[pk], fcid)
}
slab.Shards[i].Contracts[pk] = []types.FileContractID{}
}
return nil
}(); err != nil {
Expand Down

0 comments on commit 9ec595c

Please sign in to comment.