Skip to content

Commit ad00bf4

Browse files
committed
use new migration indexing table
1 parent d0ea1d7 commit ad00bf4

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

cmd/migrate-curio/migrate.go

+49-25
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,33 @@ func migrateBoostDeals(ctx context.Context, activeSectors bitfield.BitField, mad
306306
}
307307

308308
if !c {
309-
var proof abi.RegisteredSealProof
310-
err = tx.QueryRow(`SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = $1 AND sector_num = $2`, mid, deal.SectorID).Scan(&proof)
309+
// Check if we can index and announce i.e. we have unsealed copy
310+
var exists bool
311+
err = tx.QueryRow(`SELECT EXISTS (SELECT 1 FROM sector_location WHERE miner_id = $1
312+
AND sector_num = $2
313+
AND sector_filetype = 1);`, mid, deal.SectorID).Scan(&exists)
311314
if err != nil {
312-
return false, fmt.Errorf("seal: %s: failed to get sector proof: %w", deal.DealUuid.String(), err)
315+
return false, fmt.Errorf("seal: %s: failed to check if sector is unsealed: %w", deal.DealUuid.String(), err)
313316
}
314317

315-
// Add deal to mk12 pipeline in Curio for indexing and announcement
316-
_, err = tx.Exec(`INSERT INTO market_mk12_deal_pipeline (uuid, sp_id, started, piece_cid, piece_size, raw_size, offline,
317-
after_commp, after_psd, after_find_deal, sector, reg_seal_proof, sector_offset,
318-
sealed, should_index, indexing_created_at, announce)
319-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) ON CONFLICT (uuid) DO NOTHING`,
320-
deal.DealUuid.String(), mid, true, prop.PieceCID.String(), prop.PieceSize, deal.NBytesReceived, deal.IsOffline,
321-
true, true, true, deal.SectorID, proof, deal.Offset, true, true, time.Now(), true)
322-
if err != nil {
323-
return false, fmt.Errorf("deal: %s: failed to add deal to pipeline for indexing and announcing: %w", deal.DealUuid.String(), err)
318+
if exists {
319+
var proof abi.RegisteredSealProof
320+
err = tx.QueryRow(`SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = $1 AND sector_num = $2`, mid, deal.SectorID).Scan(&proof)
321+
if err != nil {
322+
return false, fmt.Errorf("seal: %s: failed to get sector proof: %w", deal.DealUuid.String(), err)
323+
}
324+
325+
// Add deal to mk12 pipeline in Curio for indexing and announcement
326+
_, err = tx.Exec(`INSERT INTO market_mk12_deal_pipeline_migration (
327+
uuid, sp_id, piece_cid, piece_size, raw_size, sector, reg_seal_proof, sector_offset, should_announce
328+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (uuid) DO NOTHING`,
329+
deal.DealUuid.String(), mid, prop.PieceCID.String(), prop.PieceSize, deal.NBytesReceived,
330+
deal.SectorID, proof, deal.Offset, deal.AnnounceToIPNI)
331+
if err != nil {
332+
return false, fmt.Errorf("deal: %s: failed to add deal to pipeline for indexing and announcing: %w", deal.DealUuid.String(), err)
333+
}
334+
} else {
335+
llog.Infof("Skipping indexing as sector %d is not unsealed", deal.SectorID)
324336
}
325337
}
326338
return true, nil
@@ -470,7 +482,7 @@ func migrateDDODeals(ctx context.Context, full v1api.FullNode, activeSectors bit
470482
if i > 0 && i%100 == 0 {
471483
fmt.Printf("Migrating DDO Deals: %d / %d (%0.2f%%)\n", i, len(deals), float64(i)/float64(len(deals))*100)
472484
}
473-
llog := log.With("Boost Deal", deal.ID.String())
485+
llog := log.With("DDO Deal", deal.ID.String())
474486
if deal.Err != "" && deal.Retry == types.DealRetryFatal {
475487
llog.Infow("Skipping as deal retry is fatal")
476488
continue
@@ -553,21 +565,33 @@ func migrateDDODeals(ctx context.Context, full v1api.FullNode, activeSectors bit
553565

554566
// TODO: Confirm if using the mk12 pipeline will have any impact for DDO deals
555567
if !c {
556-
var proof abi.RegisteredSealProof
557-
err = tx.QueryRow(`SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = $1 AND sector_num = $2`, mid, deal.SectorID).Scan(&proof)
568+
// Check if we can index and announce i.e. we have unsealed copy
569+
var exists bool
570+
err = tx.QueryRow(`SELECT EXISTS (SELECT 1 FROM sector_location WHERE miner_id = $1
571+
AND sector_num = $2
572+
AND sector_filetype = 1);`, mid, deal.SectorID).Scan(&exists)
558573
if err != nil {
559-
return false, fmt.Errorf("deal: %s: failed to get sector proof: %w", deal.ID.String(), err)
574+
return false, fmt.Errorf("seal: %s: failed to check if sector is unsealed: %w", deal.ID.String(), err)
560575
}
561576

562-
// Add deal to mk12 pipeline in Curio for indexing and announcement
563-
_, err = tx.Exec(`INSERT INTO market_mk12_deal_pipeline (uuid, sp_id, started, piece_cid, piece_size, raw_size, offline,
564-
after_commp, after_psd, after_find_deal, sector, reg_seal_proof, sector_offset,
565-
sealed, should_index, indexing_created_at, announce)
566-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) ON CONFLICT (uuid) DO NOTHING`,
567-
deal.ID.String(), mid, true, deal.PieceCID.String(), deal.PieceSize, deal.InboundFileSize, true,
568-
true, true, true, deal.SectorID, proof, deal.Offset, true, true, time.Now(), true)
569-
if err != nil {
570-
return false, fmt.Errorf("deal: %s: failed to add DDO deal to pipeline for indexing and announcing: %w", deal.ID.String(), err)
577+
if exists {
578+
var proof abi.RegisteredSealProof
579+
err = tx.QueryRow(`SELECT reg_seal_proof FROM sectors_meta WHERE sp_id = $1 AND sector_num = $2`, mid, deal.SectorID).Scan(&proof)
580+
if err != nil {
581+
return false, fmt.Errorf("deal: %s: failed to get sector proof: %w", deal.ID.String(), err)
582+
}
583+
584+
// Add deal to mk12 pipeline in Curio for indexing and announcement
585+
_, err = tx.Exec(`INSERT INTO market_mk12_deal_pipeline_migration (
586+
uuid, sp_id, piece_cid, piece_size, raw_size, sector, reg_seal_proof, sector_offset, should_announce
587+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (uuid) DO NOTHING`,
588+
deal.ID.String(), mid, deal.PieceCID.String(), deal.PieceSize, deal.InboundFileSize,
589+
deal.SectorID, proof, deal.Offset, true)
590+
if err != nil {
591+
return false, fmt.Errorf("deal: %s: failed to add DDO deal to pipeline for indexing and announcing: %w", deal.ID.String(), err)
592+
}
593+
} else {
594+
llog.Infof("Skipping indexing as sector %d is not unsealed", deal.SectorID)
571595
}
572596
}
573597
return true, nil

0 commit comments

Comments
 (0)