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 73ce2b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ func TestPartialSlab(t *testing.T) {
t.Fatal(err)
}
if !reflect.DeepEqual(obj, *fetched.Object) {
t.Fatal("mismatch", cmp.Diff(obj, fetched.Object, cmp.AllowUnexported(object.EncryptionKey{})))
t.Fatal("mismatch", cmp.Diff(obj, *fetched.Object, cmp.AllowUnexported(object.EncryptionKey{})))
}

// Add the second slab.
Expand Down
37 changes: 20 additions & 17 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 Expand Up @@ -2565,7 +2568,7 @@ func Object(ctx context.Context, tx Tx, bucket, key string) (api.Object, error)
SELECT sla.db_buffered_slab_id IS NOT NULL, sli.object_index, sli.offset, sli.length, sla.health, sla.key, sla.min_shards, COALESCE(sec.slab_index, 0), COALESCE(sec.root, ?), COALESCE(c.fcid, ?), COALESCE(h.public_key, ?)
FROM slices sli
INNER JOIN slabs sla ON sli.db_slab_id = sla.id
INNER JOIN sectors sec ON sec.db_slab_id = sla.id
LEFT JOIN sectors sec ON sec.db_slab_id = sla.id
LEFT JOIN contract_sectors csec ON csec.db_sector_id = sec.id
LEFT JOIN contracts c ON c.id = csec.db_contract_id
LEFT JOIN host_sectors hs ON hs.db_sector_id = csec.db_sector_id
Expand Down

0 comments on commit 73ce2b2

Please sign in to comment.